⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nonrosterpanel.java.svn-base

📁 开源项目openfire的完整源程序
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2007 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.sparkplugin.ui.call;

import org.jivesoftware.spark.plugin.phone.resource.PhoneRes;
import org.jivesoftware.sparkplugin.callhistory.TelephoneUtils;
import org.jivesoftware.sparkplugin.components.CallPanelButton;
import org.jivesoftware.sparkplugin.components.EndCallButton;
import org.jivesoftware.sparkplugin.components.RedialButton;
import org.jivesoftware.sparkplugin.ui.PhonePad;
import org.jivesoftware.sparkplugin.ui.components.ControlPanel;
import org.jivesoftware.sparkplugin.ui.components.JavaMixer;
import org.jivesoftware.sparkplugin.ui.transfer.TransferManager;
import net.java.sipmack.sip.Call;
import net.java.sipmack.sip.InterlocutorUI;
import net.java.sipmack.softphone.SoftPhoneManager;
import net.java.sipmack.softphone.SoftPhoneManager.CallRoomState;
import org.jivesoftware.spark.ChatManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * The UI to represent a phone call.
 *
 * @author Derek DeMoro
 */
public class NonRosterPanel extends PhonePanel {

    private JLabel connectedLabel;
    private String phoneNumber;

    private PreviousConversationPanel historyPanel;

    private boolean onHold;
    private boolean muted;

    private CallPanelButton muteButton;
    private CallPanelButton holdButton;
    private CallPanelButton transferButton;

    private EndCallButton hangUpButton;
    private RedialButton redialButton;

    private SoftPhoneManager softPhone;

    private String CONNECTED = PhoneRes.getIString("phone.connected");

    private InterlocutorUI activeCall;

    private CallManager callManager;

    private boolean callWasTransferred;

    private boolean uiBuilt;

    private JavaMixer mixer = new JavaMixer();

    public NonRosterPanel() {
        setLayout(new GridBagLayout());
        setBorder(BorderFactory.createLineBorder(Color.lightGray));

        callManager = CallManager.getInstance();

        // Initilize mixer.
        softPhone = SoftPhoneManager.getInstance();
    }

    public JPanel buildTopPanel() {
        final JLabel avatarLabel = new JLabel(PhoneRes.getImageIcon("LARGE_PHONE_ICON"));

        final JLabel nameLabel = new JLabel();
        nameLabel.setFont(new Font("Arial", Font.BOLD, 19));
        nameLabel.setForeground(new Color(64, 103, 162));
        String remoteName = getActiveCall().getCall().getRemoteName();
        if (remoteName.equals(phoneNumber)) {
            remoteName = TelephoneUtils.formatPattern(phoneNumber,PhoneRes.getIString("phone.numpattern"));
        }
        nameLabel.setText(remoteName);

        final JPanel topPanel = new JPanel();
        topPanel.setOpaque(false);
        topPanel.setLayout(new GridBagLayout());

        // Add Connected Label
        connectedLabel = new JLabel(CONNECTED);
        connectedLabel.setFont(new Font("Arial", Font.BOLD, 16));
        connectedLabel.setForeground(greenColor);

        // Add All Items to Top Panel
        topPanel.add(avatarLabel, new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        topPanel.add(nameLabel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        topPanel.add(connectedLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

        topPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.lightGray));

        return topPanel;
    }

    /**
     * Builds the Control Panel.
     *
     * @return the control panel.
     */
    private JPanel buildMiddlePanel() {
        // Add Control Panel
        final JPanel mainPanel = new JPanel(new GridBagLayout()) {

            public Dimension getPreferredSize() {
                final Dimension dim = super.getPreferredSize();
                dim.height = 100;
                return dim;
            }
        };

        mainPanel.setOpaque(false);

        // Add Input Volume To Control Panel
        try {
            final ControlPanel inputPanel = new ControlPanel(new GridBagLayout());

            final JLabel inputIcon = new JLabel(PhoneRes.getImageIcon("MICROPHONE_IMAGE"));
            inputPanel.add(mixer.getPrefferedInputVolume(), new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(2, 2, 2, 2), 0, 0));
            inputPanel.add(inputIcon, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));

            mainPanel.add(inputPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 2, 1), 0, 0));
        }
        catch (Exception e) {
            Log.error(e);
        }

        try {
            // Add Output Volume To Control Panel
            final ControlPanel outputPanel = new ControlPanel(new GridBagLayout());

            final JLabel outputIcon = new JLabel(PhoneRes.getImageIcon("SPEAKER_IMAGE"));
            outputPanel.add(mixer.getPrefferedMasterVolume(), new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(2, 2, 2, 2), 0, 0));
            outputPanel.add(outputIcon, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
            mainPanel.add(outputPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 1, 2, 5), 0, 0));
        }
        catch (Exception e) {
            Log.error(e);
        }

        // Build ControlPanel List
        final JPanel controlPanel = new JPanel(new GridBagLayout());
        controlPanel.setOpaque(false);
        muteButton = new CallPanelButton(PhoneRes.getImageIcon("MUTE_IMAGE").getImage(), PhoneRes.getIString("phone.mute"));
        muteButton.setToolTipText(PhoneRes.getIString("phone.tips.mute"));
        controlPanel.add(muteButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));

        holdButton = new CallPanelButton(PhoneRes.getImageIcon("ON_HOLD_IMAGE").getImage(), PhoneRes.getIString("phone.hold"));
        holdButton.setToolTipText(PhoneRes.getIString("phone.tips.hold"));
        controlPanel.add(holdButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));

        transferButton = new CallPanelButton(PhoneRes.getImageIcon("TRANSFER_IMAGE").getImage(), PhoneRes.getIString("phone.transfer"));
        transferButton.setToolTipText(PhoneRes.getIString("phone.tips.transfer"));
        controlPanel.add(transferButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));

        // Add End Call button
        hangUpButton = new EndCallButton();
        redialButton = new RedialButton();
        redialButton.setVisible(false);

        // Add Components to Main Panel
        mainPanel.add(controlPanel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 1, 2, 1), 0, 0));
        mainPanel.add(hangUpButton, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 1, 2, 1), 0, 0));
        mainPanel.add(redialButton, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 1, 2, 1), 0, 0));

        return mainPanel;
    }


    public void setInterlocutorUI(final InterlocutorUI interlocutorUI) {
        this.activeCall = interlocutorUI;

        // Set defaults
        muted = false;
        onHold = false;

        this.phoneNumber = TelephoneUtils.formatPattern(interlocutorUI.getCall().getNumber(),PhoneRes.getIString("phone.numpattern"));

        if (!uiBuilt) {
            buildDefaultUI();
        }

        callStarted();
    }

    private void buildDefaultUI() {
        // Add Top Panel
        final JPanel topPanel = buildTopPanel();
        add(topPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

        // Build Control Panel
        final JPanel middlePanel = buildMiddlePanel();
        add(middlePanel, new GridBagConstraints(0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

        // Build Bottom Panel
        final PhonePad phonePad = new PhonePad();
        historyPanel = new PreviousConversationPanel();

        add(phonePad, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.9, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
        add(historyPanel, new GridBagConstraints(1, 8, 1, 1, 1.0, 0.9, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));

        // Setup default settings
        setupDefaults();

        uiBuilt = true;
    }

    public void setupDefaults() {
        holdButton.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent mouseEvent) {
                toggleHold();
            }
        });

        muteButton.addMouseListener(new MouseAdapter() {

⌨️ 快捷键说明

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