onphone.java

来自「开源项目openfire的完整源程序」· Java 代码 · 共 75 行

JAVA
75
字号
/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.sparkimpl.plugin.phone;

import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.component.TimeTrackingLabel;

import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Date;

public class OnPhone extends JPanel {
    private JLabel iconLabel;
    private TimeTrackingLabel timeLabel;

    public OnPhone() {
        setLayout(new BorderLayout());

        final JPanel imagePanel = new JPanel();
        imagePanel.setLayout(new GridBagLayout());


        imagePanel.setBackground(Color.white);

        // Handle Icon Label
        iconLabel = new JLabel(SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24));
        iconLabel.setHorizontalAlignment(JLabel.CENTER);
        iconLabel.setVerticalTextPosition(JLabel.BOTTOM);
        iconLabel.setHorizontalTextPosition(JLabel.CENTER);
        iconLabel.setFont(new Font("Dialog", Font.BOLD, 14));
        iconLabel.setText(Res.getString("title.on.the.phone"));

        // Handle Time Tracker
        timeLabel = new TimeTrackingLabel(new Date(), this);
        timeLabel.setOpaque(false);
        timeLabel.setHorizontalAlignment(JLabel.CENTER);
        timeLabel.setHorizontalTextPosition(JLabel.CENTER);
        timeLabel.setFont(new Font("Dialog", Font.BOLD, 14));

        // Add Icon Label
        imagePanel.add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.7, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

        // Add Time Label
        imagePanel.add(timeLabel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.3, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

        add(imagePanel, BorderLayout.CENTER);
    }

    public void changeText(String text) {
        iconLabel.setText(text);
    }

    public void stopTimer() {
        timeLabel.stopTimer();
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?