softphonetabhandler.java.svn-base

来自「开源项目openfire的完整源程序」· SVN-BASE 代码 · 共 133 行

SVN-BASE
133
字号
/** * $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 net.java.sipmack.softphone.SoftPhoneManager;import net.java.sipmack.softphone.SoftPhoneManager.CallRoomState;import org.jivesoftware.resource.SparkRes;import org.jivesoftware.spark.SparkManager;import org.jivesoftware.spark.component.tabbedPane.SparkTab;import org.jivesoftware.spark.ui.ChatFrame;import org.jivesoftware.spark.ui.ChatRoom;import org.jivesoftware.spark.ui.SparkTabHandler;import java.awt.Color;import java.awt.Component;/** * */public class SoftPhoneTabHandler extends SparkTabHandler {    private SoftPhoneManager manager;    public SoftPhoneTabHandler() {        manager = SoftPhoneManager.getInstance();    }    public boolean isTabHandled(SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {        CallRoomState callState = manager.getCallRoomState(component);        if (callState != null) {            // This is a room with a call.            handlePhoneCall(callState, tab, component, isSelectedTab, chatFrameFocused);            return true;        }        return false;    }    /**     * Called when the underlying component has a phone call.     *     * @param state            the CallRoomState.     * @param tab              the SparkTab.     * @param component        the component within the tab.     * @param isSelectedTab    true if the tab is selected.     * @param chatFrameFocused true if the chat frame is in focus.     */    private void handlePhoneCall(CallRoomState state, SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {        boolean isTyping = false;        if (component instanceof ChatRoom) {            isTyping = SparkManager.getChatManager().containsTypingNotification(((ChatRoom)component));        }        // Check if is typing.        if (isTyping) {            tab.setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));        }        else if (CallRoomState.inCall == state) {            tab.setIcon(PhoneRes.getImageIcon("RECEIVER2_IMAGE"));        }        else if (CallRoomState.muted == state) {            tab.setIcon(PhoneRes.getImageIcon("MUTE_IMAGE"));        }        else if (CallRoomState.onHold == state) {            tab.setIcon(PhoneRes.getImageIcon("ON_HOLD_IMAGE"));        }        else if (CallRoomState.callWasEnded == state) {            tab.setIcon(PhoneRes.getImageIcon("HANG_UP_PHONE_16x16_IMAGE"));        }        if (component instanceof ChatRoom) {            handleChatRoom(component, tab, chatFrameFocused, isSelectedTab);            return;        }        else {            if (isSelectedTab && chatFrameFocused) {                tab.setTitleColor(Color.black);                tab.setTabFont(tab.getDefaultFont());            }        }        // Handle title frame        if (isSelectedTab && component instanceof PhonePanel) {            final ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();            chatFrame.setTitle(((PhonePanel)component).getFrameTitle());        }    }    private void handleChatRoom(Component component, SparkTab tab, boolean chatFrameFocused, boolean isSelectedTab) {        final ChatRoom chatRoom = (ChatRoom)component;        if (!chatFrameFocused || !isSelectedTab) {            if (chatRoom.getUnreadMessageCount() > 0) {                // Make tab red.                tab.setTitleColor(Color.red);                tab.setTabBold(true);            }            // Handle unread message count.            int unreadMessageCount = chatRoom.getUnreadMessageCount();            String appendedMessage = "";            if (unreadMessageCount > 1) {                appendedMessage = " (" + unreadMessageCount + ")";            }            tab.getTitleLabel().setText(chatRoom.getTabTitle() + appendedMessage);        }        // Should only set the icon to default if the frame is in focus        // and the tab is the selected component.        if (isSelectedTab && chatFrameFocused) {            tab.setTitleColor(Color.black);            tab.setTabFont(tab.getDefaultFont());            tab.getTitleLabel().setText(chatRoom.getTabTitle());            // Clear unread message count.            chatRoom.clearUnreadMessageCount();        }    }}

⌨️ 快捷键说明

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