From 65d9be2c3429a7daf2e2c3ef9cb311282fcac4a7 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Thu, 26 Aug 2010 12:07:28 +0000 Subject: Reverts the touch screen changes, which are moved to the touchgui now. --- .../sip/communicator/impl/gui/UIServiceImpl.java | 8 +- .../sip/communicator/impl/gui/main/DialPanel.java | 334 ---- .../sip/communicator/impl/gui/main/MainFrame.java | 1655 ++++++++++++++++++- .../impl/gui/main/MainFrameInterface.java | 322 ---- .../impl/gui/main/MainFrameStandard.java | 1666 ------------------- .../communicator/impl/gui/main/MainFrameTouch.java | 1688 -------------------- 6 files changed, 1645 insertions(+), 4028 deletions(-) delete mode 100755 src/net/java/sip/communicator/impl/gui/main/DialPanel.java delete mode 100644 src/net/java/sip/communicator/impl/gui/main/MainFrameInterface.java delete mode 100644 src/net/java/sip/communicator/impl/gui/main/MainFrameStandard.java delete mode 100644 src/net/java/sip/communicator/impl/gui/main/MainFrameTouch.java (limited to 'src/net') diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index ee92bd5..f7cbfa9 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -114,11 +114,7 @@ public class UIServiceImpl { this.setDefaultThemePack(); - boolean touch = GuiActivator.getConfigurationService().getBoolean("net.java.sip.communicator.TOUCHSCREEN", false); - if (!touch) - this.mainFrame = new MainFrameStandard(); - else - this.mainFrame = new MainFrameTouch(); + this.mainFrame = new MainFrame(); if (UIManager.getLookAndFeel() instanceof SIPCommLookAndFeel) initCustomFonts(); @@ -1231,4 +1227,4 @@ public class UIServiceImpl { return MasterPasswordInputDialog.showInput(prevSuccess); } -} +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/DialPanel.java b/src/net/java/sip/communicator/impl/gui/main/DialPanel.java deleted file mode 100755 index dd1e4d6..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/DialPanel.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.main; - -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; -import java.util.List; - -import javax.swing.*; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.main.call.CallManager; -import net.java.sip.communicator.impl.gui.main.call.ChooseCallAccountPopupMenu; -import net.java.sip.communicator.impl.gui.main.contactlist.SearchField; -import net.java.sip.communicator.impl.gui.utils.*; -import net.java.sip.communicator.service.protocol.ProtocolProviderService; -import net.java.sip.communicator.service.resources.*; -import net.java.sip.communicator.util.swing.*; - -/** - * The DialPanel is the panel that contains the buttons to dial a - * phone number. - * - * @author Werner Dittmann - * @author Yana Stamcheva - */ -public class DialPanel - extends JPanel - implements MouseListener -{ - /** - * The dial panel. - */ - private final JPanel dialPadPanel = - new JPanel(new GridLayout(4, 3, - GuiActivator.getResources() - .getSettingsInt("impl.gui.DIAL_PAD_HORIZONTAL_GAP"), - GuiActivator.getResources() - .getSettingsInt("impl.gui.DIAL_PAD_VERTICAL_GAP"))); - - private static final String CALL = "CALL"; - private static final String BACK = "BACK"; - private static final String DELETE = "DELETE"; - - static final DialButtonInfo[] availableTones = new DialButtonInfo[] { - new DialButtonInfo("1", ImageLoader.ONE_DIAL_BUTTON), - new DialButtonInfo("2", ImageLoader.TWO_DIAL_BUTTON), - new DialButtonInfo("3", ImageLoader.THREE_DIAL_BUTTON), - new DialButtonInfo("4", ImageLoader.FOUR_DIAL_BUTTON), - new DialButtonInfo("5", ImageLoader.FIVE_DIAL_BUTTON), - new DialButtonInfo("6", ImageLoader.SIX_DIAL_BUTTON), - new DialButtonInfo("7", ImageLoader.SEVEN_DIAL_BUTTON), - new DialButtonInfo("8", ImageLoader.EIGHT_DIAL_BUTTON), - new DialButtonInfo("9", ImageLoader.NINE_DIAL_BUTTON), -// new DialButtonInfo("a", null), new DialButtonInfo("b", null), -// new DialButtonInfo("c", null), new DialButtonInfo("d", null), - new DialButtonInfo("*", ImageLoader.STAR_DIAL_BUTTON), - new DialButtonInfo("0", ImageLoader.ZERO_DIAL_BUTTON), - new DialButtonInfo("#", ImageLoader.DIEZ_DIAL_BUTTON) }; - - private final MainFrameTouch mainFrameTouch; - private final SearchField searchField; - - private final SIPCommButton callButton = new SIPCommButton( - ImageLoader.getImage(ImageLoader.CALL_BUTTON_BG)); - - private final SIPCommButton deleteButton = new SIPCommButton( - ImageLoader.getImage(ImageLoader.DIAL_BUTTON_BG), - ImageLoader.getImage(ImageLoader.DELETE_TEXT_ICON)); - - private final SIPCommButton backButton = new SIPCommButton( - ImageLoader.getImage(ImageLoader.DIAL_BUTTON_BG), - ImageLoader.getImage(ImageLoader.PREVIOUS_ICON)); - - private final JButton callContact = new JButton( - GuiActivator.getResources().getI18NString("service.gui.CALL_CONTACT"), - GuiActivator.getResources() - .getImage("service.gui.icons.CALL_16x16_ICON")); - - - /** - * Creates an instance of DialPanel - * - * @param mfTouch The MainFrameTouch window that contains the tabs and - * other elements. - * @param sField The search field that receives the input of the DialPanel. - */ - public DialPanel(MainFrameTouch mfTouch, SearchField sField) - { - super(new BorderLayout()); - this.mainFrameTouch = mfTouch; - this.searchField = sField; - - this.init(); - } - - /** - * Initializes this panel by adding all dial buttons to it. - */ - public void init() - { - this.dialPadPanel.setOpaque(false); - - this.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); - - int width = GuiActivator.getResources() - .getSettingsInt("impl.gui.DIAL_PAD_WIDTH"); - - int height = GuiActivator.getResources() - .getSettingsInt("impl.gui.DIAL_PAD_HEIGHT"); - - this.dialPadPanel.setPreferredSize(new Dimension(width, height)); - - Image bgImage = ImageLoader.getImage(ImageLoader.DIAL_BUTTON_BG); - - for (int i = 0; i < availableTones.length; i++) - { - DialButtonInfo info = availableTones[i]; - // we add only buttons having image - if(info.imageID == null) - continue; - - dialPadPanel.add( - createDialButton(bgImage, info.imageID, info.keyChar)); - } - - TransparentPanel centerPanel = new TransparentPanel(); - centerPanel.add(dialPadPanel, BorderLayout.CENTER); - - TransparentPanel southPanel = new TransparentPanel(new GridLayout(1, 4)); - - deleteButton.setName(DELETE); - deleteButton.addMouseListener(this); - southPanel.add(deleteButton); - - backButton.setName(BACK); - backButton.addMouseListener(this); - southPanel.add(backButton); - - southPanel.add(Box.createHorizontalStrut(10)); - - callButton.setName(CALL); - callButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - String searchText = searchField.getText(); - - if (searchText == null || searchText.length() == 0) - return; - - List telephonyProviders - = CallManager.getTelephonyProviders(); - - if (telephonyProviders.size() == 1) - { - CallManager.createCall( - telephonyProviders.get(0), searchText); - } - else if (telephonyProviders.size() > 1) - { - ChooseCallAccountPopupMenu chooseAccountDialog - = new ChooseCallAccountPopupMenu( - callContact, - searchText, - telephonyProviders); - - chooseAccountDialog.showPopupMenu(); - } - } - }); - southPanel.add(callButton); - - this.add(centerPanel, BorderLayout.CENTER); - this.add(southPanel, BorderLayout.SOUTH); - } - - /** - * Creates DTMF button. - * @param bgImage - * @param iconImage - * @param name - * @return - */ - private JButton createDialButton(Image bgImage, ImageID iconImage, - String name) - { - JButton button = - new SIPCommButton(bgImage, ImageLoader.getImage(iconImage)); - - button.setAlignmentY(JButton.LEFT_ALIGNMENT); - button.setName(name); - button.setOpaque(false); - button.addMouseListener(this); - return button; - } - - public void mouseClicked(MouseEvent e) - { - } - - public void mouseEntered(MouseEvent e) - { - } - - public void mouseExited(MouseEvent e) - { - } - - /** - * Handles the MouseEvent triggered when user presses one of the - * dial buttons. - * @param e the event - */ - public void mousePressed(MouseEvent e) - { - JButton button = (JButton) e.getSource(); - String name = button.getName(); - String inText = searchField.getText(); - - if (BACK.equals(name)) { - if (inText == null || inText.length() == 0) - return; - if (inText.length() == 1) { - searchField.setText(null); - return; - } - String newText = inText.substring(0, inText.length() - 1); - searchField.setText(newText); - return; - } - if (DELETE.equals(name)) { - searchField.setText(null); - return; - } - if (inText == null || inText.length() == 0) { - searchField.setText(name); - return; - } - searchField.setText(inText + name); - } - - /** - * Handles the MouseEvent triggered when user releases one of the - * dial buttons. - * @param e the event - */ - public void mouseReleased(MouseEvent e) - { - } - - /** - * Paints the main background image to the background of this dial panel. - */ - public void paintComponent(Graphics g) - { - // do the superclass behavior first - super.paintComponent(g); - - Graphics2D g2 = (Graphics2D) g; - - boolean isTextureBackground = Boolean.parseBoolean(GuiActivator.getResources() - .getSettingsString("impl.gui.IS_CONTACT_LIST_TEXTURE_BG_ENABLED")); - - BufferedImage bgImage - = ImageLoader.getImage(ImageLoader.MAIN_WINDOW_BACKGROUND); - - // paint the image - if (bgImage != null) - { - if (isTextureBackground) - { - Rectangle rect - = new Rectangle(0, 0, - bgImage.getWidth(null), - bgImage.getHeight(null)); - - TexturePaint texture = new TexturePaint(bgImage, rect); - - g2.setPaint(texture); - - g2.fillRect(0, 0, this.getWidth(), this.getHeight()); - } - else - { - g.setColor(new Color( - GuiActivator.getResources() - .getColor("contactListBackground"))); - - // paint the background with the choosen color - g.fillRect(0, 0, getWidth(), getHeight()); - - g2.drawImage(bgImage, - this.getWidth() - bgImage.getWidth(), - this.getHeight() - bgImage.getHeight(), - this); - } - } - } - /** - * Dial button information - */ - static class DialButtonInfo - { - /** - * The char associated with this dial button. - */ - String keyChar; - - /** - * The image to display in buttons sending DTMFs. - */ - ImageID imageID; - - /** - * Creates button info. - * @param keyChar the char associated with the DTMF - * @param imageID the image if any. - */ - public DialButtonInfo( - String keyChar, - ImageID imageID) - { - this.keyChar = keyChar; - this.imageID = imageID; - } - } - -} diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java index be60b4f..d37a4b8 100644 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java +++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java @@ -6,13 +6,38 @@ */ package net.java.sip.communicator.impl.gui.main; +import java.awt.*; +import java.awt.event.*; +import java.beans.PropertyChangeEvent; +import java.util.*; +import java.util.List; +import javax.swing.*; +import javax.swing.tree.*; + +import net.java.sip.communicator.impl.gui.*; +import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.event.*; +import net.java.sip.communicator.impl.gui.main.call.*; +import net.java.sip.communicator.impl.gui.main.chat.conference.*; +import net.java.sip.communicator.impl.gui.main.contactlist.*; +import net.java.sip.communicator.impl.gui.main.menus.*; +import net.java.sip.communicator.impl.gui.main.presence.*; +import net.java.sip.communicator.impl.gui.utils.*; +import net.java.sip.communicator.service.configuration.*; +import net.java.sip.communicator.service.contacteventhandler.*; +import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.protocol.OperationSet; -import net.java.sip.communicator.service.protocol.OperationSetPresence; -import net.java.sip.communicator.service.protocol.ProtocolProviderService; +import net.java.sip.communicator.service.gui.Container; +import net.java.sip.communicator.service.keybindings.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.service.resources.*; +import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.swing.*; +import net.java.sip.communicator.util.swing.event.*; + +import org.osgi.framework.*; /** * The main application window. This class is the core of this UI @@ -20,21 +45,556 @@ import net.java.sip.communicator.util.swing.*; * operation sets, as well as all registered accounts, the * MetaContactListService and all sent messages that aren't * delivered yet. - * - * This is an abstract wrapper class that extends and implement all - * base classes and interfaces for real GUI classes. The MainFrameStandard - * and the MainFrameTouch GUI classes extend this class and implement - * all missing functions definied in MainFrameInterface. * * @author Yana Stamcheva * @author Lubomir Marinov - * @outhor Werner Dittmann */ -public abstract class MainFrame +public class MainFrame extends SIPCommFrame implements ExportedWindow, - PluginComponentListener, MainFrameInterface -{ + PluginComponentListener +{ + /** + * The logger. + */ + private final Logger logger = Logger.getLogger(MainFrame.class); + + /** + * The main container. + */ + private final TransparentPanel mainPanel + = new TransparentPanel(new BorderLayout(0, 0)); + + /** + * The status bar panel. + */ + private final TransparentPanel statusBarPanel + = new TransparentPanel(new BorderLayout()); + + /** + * The center panel, containing the contact list. + */ + private final TransparentPanel centerPanel + = new TransparentPanel(new BorderLayout(0, 0)); + + /** + * The main menu. + */ + private MainMenu menu; + + /** + * The search field shown above the contact list. + */ + private final SearchField searchField; + + /** + * A mapping of ProtocolProviderServices and their indexes. + */ + private final HashMap protocolProviders + = new LinkedHashMap(); + + /** + * The panel containing the accounts status menu. + */ + private AccountStatusPanel accountStatusPanel; + + /** + * The panel replacing the contact list, shown when no matching is found + * for the search filter. + */ + private UnknownContactPanel unknownContactPanel; + + /** + * A mapping of ProtocolProviderServices and corresponding + * ContactEventHandlers. + */ + private final Map + providerContactHandlers = + new Hashtable(); + + /** + * A mapping of plug-in components and their corresponding native components. + */ + private final Map nativePluginsTable = + new Hashtable(); + + /** + * The north plug-in panel. + */ + private final JPanel pluginPanelNorth = new TransparentPanel(); + + /** + * The south plug-in panel. + */ + private final JPanel pluginPanelSouth = new TransparentPanel(); + + /** + * The west plug-in panel. + */ + private final JPanel pluginPanelWest = new TransparentPanel(); + + /** + * The east plug-in panel. + */ + private final JPanel pluginPanelEast = new TransparentPanel(); + + /** + * The container containing the contact list. + */ + private ContactListPane contactListPanel; + + /** + * Creates an instance of MainFrame. + */ + public MainFrame() + { + if (!ConfigurationManager.isWindowDecorated()) + { + this.setUndecorated(true); + } + + this.searchField = new SearchField(this); + + this.contactListPanel = new ContactListPane(this); + + this.accountStatusPanel = new AccountStatusPanel(this); + + menu = new MainMenu(this); + + /* + * If the application is configured to quit when this frame is closed, + * do so. + */ + this.addWindowListener(new WindowAdapter() + { + /** + * Invoked when a window has been closed. + */ + public void windowClosed(WindowEvent event) + { + MainFrame.this.windowClosed(event); + } + /** + * Invoked when a window has been opened. + */ + public void windowOpened(WindowEvent e) + { + GuiActivator.getContactList().requestFocusInWindow(); + } + }); + + this.initTitleFont(); + + ResourceManagementService resources = GuiActivator.getResources(); + String applicationName + = resources.getSettingsString("service.gui.APPLICATION_NAME"); + + this.setTitle(applicationName); + + this.mainPanel.setBackground(new Color( + GuiActivator.getResources() + .getColor("service.gui.MAIN_WINDOW_BACKGROUND"))); + + KeyboardFocusManager keyManager + = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + keyManager.addKeyEventDispatcher(new MainKeyDispatcher(keyManager)); + + this.init(); + + this.initPluginComponents(); + } + + /** + * Requests the focus in the center panel, which contains either the + * contact list or the unknown contact panel. + */ + public void requestFocusInCenterPanel() + { + centerPanel.requestFocusInWindow(); + } + + /** + * Initiates the content of this frame. + */ + private void init() + { + setDefaultCloseOperation( + GuiActivator.getUIService().getExitOnMainWindowClose() + ? JFrame.DISPOSE_ON_CLOSE + : JFrame.HIDE_ON_CLOSE); + + this.setKeybindingInput(KeybindingSet.Category.MAIN); + this.addKeybindingAction("main-rename", + new RenameAction()); + + // Remove the default escape key mapping as its a special + // one for the main frame and the contactlist + getRootPane().getInputMap( + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) + .remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); + + TransparentPanel northPanel + = new TransparentPanel(new BorderLayout(0, 0)); + + this.setJMenuBar(menu); + + northPanel.add(accountStatusPanel, BorderLayout.CENTER); + + TransparentPanel searchPanel + = new TransparentPanel(new BorderLayout(2, 0)); + searchPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); + searchPanel.add(searchField); + searchPanel.add(new CallHistoryButton(), BorderLayout.EAST); + + centerPanel.add(searchPanel, BorderLayout.NORTH); + centerPanel.add(contactListPanel, BorderLayout.CENTER); + + this.mainPanel.add(northPanel, BorderLayout.NORTH); + this.mainPanel.add(centerPanel, BorderLayout.CENTER); + + java.awt.Container contentPane = getContentPane(); + contentPane.add(mainPanel, BorderLayout.CENTER); + contentPane.add(statusBarPanel, BorderLayout.SOUTH); + } + + /** + * Sets frame size and position. + */ + public void initBounds() + { + int width = GuiActivator.getResources() + .getSettingsInt("impl.gui.MAIN_WINDOW_WIDTH"); + + int height = GuiActivator.getResources() + .getSettingsInt("impl.gui.MAIN_WINDOW_HEIGHT"); + + int minWidth = GuiActivator.getResources() + .getSettingsInt("impl.gui.MAIN_WINDOW_MIN_WIDTH"); + + int minHeight = GuiActivator.getResources() + .getSettingsInt("impl.gui.MAIN_WINDOW_MIN_HEIGHT"); + + this.getContentPane().setMinimumSize(new Dimension(minWidth, minHeight)); + + this.setSize(width, height); + + this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width + - this.getWidth(), 50); + } + + /** + * Initialize main window font. + */ + private void initTitleFont() + { + JComponent layeredPane = this.getLayeredPane(); + + ResourceManagementService resources = GuiActivator.getResources(); + String fontName + = resources.getSettingsString("service.gui.FONT_NAME"); + + String titleFontSize + = resources.getSettingsString("service.gui.FONT_SIZE"); + + Font font = new Font( fontName, + Font.BOLD, + Integer.parseInt(titleFontSize)); + + final int componentCount = layeredPane.getComponentCount(); + for (int i = 0; i < componentCount; i++) + { + layeredPane.getComponent(i).setFont(font); + } + } + + /** + * Enters or exits the "unknown contact" view. This view will propose to + * the user some specific operations if the current filter doesn't match + * any contacts. + * @param isEnabled true to enable the "unknown contact" view, + * false - otherwise. + */ + public void enableUnknownContactView(boolean isEnabled) + { + if (isEnabled) + { + if (unknownContactPanel == null) + unknownContactPanel = new UnknownContactPanel(this); + + if (unknownContactPanel.getParent() != centerPanel) + { + contactListPanel.setVisible(false); + unknownContactPanel.setVisible(true); + centerPanel.remove(contactListPanel); + centerPanel.add(unknownContactPanel, BorderLayout.CENTER); + } + } + else + { + if (contactListPanel.getParent() != centerPanel) + { + if (unknownContactPanel != null) + { + unknownContactPanel.setVisible(false); + centerPanel.remove(unknownContactPanel); + } + contactListPanel.setVisible(true); + centerPanel.add(contactListPanel, BorderLayout.CENTER); + } + } + centerPanel.revalidate(); + centerPanel.repaint(); + } + + /** + * Initializes the contact list panel. + * + * @param contactList The MetaContactListService containing + * the contact list data. + */ + public void setContactList(MetaContactListService contactList) + { + contactListPanel.initList(contactList); + } + + /** + * Adds all protocol supported operation sets. + * + * @param protocolProvider The protocol provider. + */ + public void addProtocolSupportedOperationSets( + ProtocolProviderService protocolProvider) + { + Map supportedOperationSets + = protocolProvider.getSupportedOperationSets(); + + String ppOpSetClassName = OperationSetPersistentPresence + .class.getName(); + String pOpSetClassName = OperationSetPresence.class.getName(); + + // Obtain the presence operation set. + if (supportedOperationSets.containsKey(ppOpSetClassName) + || supportedOperationSets.containsKey(pOpSetClassName)) + { + OperationSetPresence presence = (OperationSetPresence) + supportedOperationSets.get(ppOpSetClassName); + + if(presence == null) { + presence = (OperationSetPresence) + supportedOperationSets.get(pOpSetClassName); + } + + presence.addProviderPresenceStatusListener( + new GUIProviderPresenceStatusListener()); + presence.addContactPresenceStatusListener( + GuiActivator.getContactList()); + } + + // Obtain the basic instant messaging operation set. + String imOpSetClassName = OperationSetBasicInstantMessaging + .class.getName(); + + if (supportedOperationSets.containsKey(imOpSetClassName)) + { + OperationSetBasicInstantMessaging im + = (OperationSetBasicInstantMessaging) + supportedOperationSets.get(imOpSetClassName); + + //Add to all instant messaging operation sets the Message + //listener implemented in the ContactListPanel, which handles + //all received messages. + im.addMessageListener(getContactListPanel()); + } + + // Obtain the typing notifications operation set. + String tnOpSetClassName = OperationSetTypingNotifications + .class.getName(); + + if (supportedOperationSets.containsKey(tnOpSetClassName)) + { + OperationSetTypingNotifications tn + = (OperationSetTypingNotifications) + supportedOperationSets.get(tnOpSetClassName); + + //Add to all typing notification operation sets the Message + //listener implemented in the ContactListPanel, which handles + //all received messages. + tn.addTypingNotificationsListener(this.getContactListPanel()); + } + + // Obtain the basic telephony operation set. + String telOpSetClassName = OperationSetBasicTelephony.class.getName(); + + if (supportedOperationSets.containsKey(telOpSetClassName)) + { + OperationSetBasicTelephony telephony + = (OperationSetBasicTelephony) + supportedOperationSets.get(telOpSetClassName); + + telephony.addCallListener(new CallManager.GuiCallListener()); + } + + // Obtain the multi user chat operation set. + String multiChatClassName = OperationSetMultiUserChat.class.getName(); + + if (supportedOperationSets.containsKey(multiChatClassName)) + { + OperationSetMultiUserChat multiUserChat + = (OperationSetMultiUserChat) + supportedOperationSets.get(multiChatClassName); + + ConferenceChatManager conferenceManager + = GuiActivator.getUIService().getConferenceChatManager(); + + multiUserChat.addInvitationListener(conferenceManager); + multiUserChat.addInvitationRejectionListener(conferenceManager); + multiUserChat.addPresenceListener(conferenceManager); + } + + // Obtain the ad-hoc multi user chat operation set. + OperationSetAdHocMultiUserChat adHocMultiChatOpSet + = protocolProvider + .getOperationSet(OperationSetAdHocMultiUserChat.class); + + if (adHocMultiChatOpSet != null) + { + ConferenceChatManager conferenceManager + = GuiActivator.getUIService().getConferenceChatManager(); + + adHocMultiChatOpSet.addInvitationListener(conferenceManager); + adHocMultiChatOpSet.addInvitationRejectionListener(conferenceManager); + adHocMultiChatOpSet.addPresenceListener(conferenceManager); + } + + // Obtain file transfer operation set. + OperationSetFileTransfer fileTransferOpSet + = protocolProvider.getOperationSet(OperationSetFileTransfer.class); + + if (fileTransferOpSet != null) + { + fileTransferOpSet.addFileTransferListener(getContactListPanel()); + } + } + + /** + * Returns a set of all protocol providers. + * + * @return a set of all protocol providers. + */ + public Iterator getProtocolProviders() + { + return new LinkedList( + protocolProviders.keySet()) + .iterator(); + } + + /** + * Returns the protocol provider associated to the account given + * by the account user identifier. + * + * @param accountName The account user identifier. + * @return The protocol provider associated to the given account. + */ + public ProtocolProviderService getProtocolProviderForAccount( + String accountName) + { + for (ProtocolProviderService pps : protocolProviders.keySet()) + { + if (pps.getAccountID().getUserID().equals(accountName)) + { + return pps; + } + } + return null; + } + + /** + * Adds a protocol provider. + * @param protocolProvider The protocol provider to add. + */ + public void addProtocolProvider(ProtocolProviderService protocolProvider) + { + if (logger.isTraceEnabled()) + logger.trace("Add the following protocol provider to the gui: " + + protocolProvider.getAccountID().getAccountAddress()); + + this.protocolProviders.put(protocolProvider, + initiateProviderIndex(protocolProvider)); + + this.addProtocolSupportedOperationSets(protocolProvider); + + this.addAccount(protocolProvider); + + ContactEventHandler contactHandler + = this.getContactHandlerForProvider(protocolProvider); + + if (contactHandler == null) + contactHandler = new DefaultContactEventHandler(this); + + this.addProviderContactHandler(protocolProvider, contactHandler); + } + + /** + * Returns the index of the given protocol provider. + * @param protocolProvider the protocol provider to search for + * @return the index of the given protocol provider + */ + public int getProviderIndex(ProtocolProviderService protocolProvider) + { + Integer o = protocolProviders.get(protocolProvider); + + return (o != null) ? o : 0; + } + + /** + * Adds an account to the application. + * + * @param protocolProvider The protocol provider of the account. + */ + public void addAccount(ProtocolProviderService protocolProvider) + { + if (!accountStatusPanel.containsAccount(protocolProvider)) + { + if (logger.isTraceEnabled()) + logger.trace("Add the following account to the status bar: " + + protocolProvider.getAccountID().getAccountAddress()); + + accountStatusPanel.addAccount(protocolProvider); + + //request the focus in the contact list panel, which + //permits to search in the contact list + this.contactListPanel.getContactList() + .requestFocus(); + } + } + + /** + * Adds an account to the application. + * + * @param protocolProvider The protocol provider of the account. + */ + public void removeProtocolProvider(ProtocolProviderService protocolProvider) + { + this.protocolProviders.remove(protocolProvider); + this.updateProvidersIndexes(protocolProvider); + + if (accountStatusPanel.containsAccount(protocolProvider)) + { + accountStatusPanel.removeAccount(protocolProvider); + } + } + + /** + * Returns the account user id for the given protocol provider. + * @param protocolProvider the protocol provider corresponding to the + * account to add + * @return The account user id for the given protocol provider. + */ + public String getAccount(ProtocolProviderService protocolProvider) + { + return protocolProvider.getAccountID().getUserID(); + } + /** * Returns the presence operation set for the given protocol provider. * @@ -53,4 +613,1075 @@ public abstract class MainFrame ? (OperationSetPresence) opSet : null; } + + /** + * Returns the Web Contact Info operation set for the given + * protocol provider. + * + * @param protocolProvider The protocol provider for which the TN + * is searched. + * @return OperationSetWebContactInfo The Web Contact Info operation + * set for the given protocol provider. + */ + public OperationSetWebContactInfo getWebContactInfoOpSet( + ProtocolProviderService protocolProvider) + { + OperationSet opSet + = protocolProvider.getOperationSet(OperationSetWebContactInfo.class); + + return (opSet instanceof OperationSetWebContactInfo) + ? (OperationSetWebContactInfo) opSet + : null; + } + + /** + * Returns the telephony operation set for the given protocol provider. + * + * @param protocolProvider The protocol provider for which the telephony + * operation set is about. + * @return OperationSetBasicTelephony The telephony operation + * set for the given protocol provider. + */ + public OperationSetBasicTelephony getTelephonyOpSet( + ProtocolProviderService protocolProvider) + { + OperationSet opSet + = protocolProvider.getOperationSet(OperationSetBasicTelephony.class); + + return (opSet instanceof OperationSetBasicTelephony) + ? (OperationSetBasicTelephony) opSet + : null; + } + + /** + * Returns the multi user chat operation set for the given protocol provider. + * + * @param protocolProvider The protocol provider for which the multi user + * chat operation set is about. + * @return OperationSetAdHocMultiUserChat The telephony operation + * set for the given protocol provider. + */ + public OperationSetAdHocMultiUserChat getAdHocMultiUserChatOpSet( + ProtocolProviderService protocolProvider) + { + OperationSet opSet + = protocolProvider.getOperationSet( + OperationSetAdHocMultiUserChat.class); + + return (opSet instanceof OperationSetAdHocMultiUserChat) + ? (OperationSetAdHocMultiUserChat) opSet + : null; + } + + /** + * Returns the multi user chat operation set for the given protocol provider. + * + * @param protocolProvider The protocol provider for which the multi user + * chat operation set is about. + * @return OperationSetMultiUserChat The telephony operation + * set for the given protocol provider. + */ + public OperationSetMultiUserChat getMultiUserChatOpSet( + ProtocolProviderService protocolProvider) + { + OperationSet opSet + = protocolProvider.getOperationSet(OperationSetMultiUserChat.class); + + return (opSet instanceof OperationSetMultiUserChat) + ? (OperationSetMultiUserChat) opSet + : null; + } + + /** + * Listens for all providerStatusChanged and providerStatusMessageChanged + * events in order to refresh the account status panel, when a status is + * changed. + */ + private class GUIProviderPresenceStatusListener + implements ProviderPresenceStatusListener + { + public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) + { + ProtocolProviderService pps = evt.getProvider(); + + accountStatusPanel.updateStatus(pps, evt.getNewStatus()); + } + + public void providerStatusMessageChanged(PropertyChangeEvent evt) {} + } + + /** + * Returns the panel containing the ContactList. + * @return ContactListPanel the panel containing the ContactList + */ + public ContactListPane getContactListPanel() + { + return this.contactListPanel; + } + + /** + * Returns the text currently shown in the search field. + * @return the text currently shown in the search field + */ + public String getCurrentSearchText() + { + return searchField.getText(); + } + + /** + * Clears the current text in the search field. + */ + public void clearCurrentSearchText() + { + searchField.setText(""); + } + + /** + * Adds the given TextFieldChangeListener to listen for any changes + * that occur in the search field. + * @param l the TextFieldChangeListener to add + */ + public void addSearchFieldListener(TextFieldChangeListener l) + { + searchField.addTextChangeListener(l); + } + + /** + * Removes the given TextFieldChangeListener that listens for any + * changes that occur in the search field. + * @param l the TextFieldChangeListener to remove + */ + public void removeSearchFieldListener(TextFieldChangeListener l) + { + searchField.addTextChangeListener(l); + } + + /** + * Checks in the configuration xml if there is already stored index for + * this provider and if yes, returns it, otherwise creates a new account + * index and stores it. + * + * @param protocolProvider the protocol provider + * @return the protocol provider index + */ + private int initiateProviderIndex( + ProtocolProviderService protocolProvider) + { + ConfigurationService configService + = GuiActivator.getConfigurationService(); + + String prefix = "net.java.sip.communicator.impl.gui.accounts"; + + List accounts = configService + .getPropertyNamesByPrefix(prefix, true); + + for (String accountRootPropName : accounts) { + String accountUID + = configService.getString(accountRootPropName); + + if(accountUID.equals(protocolProvider + .getAccountID().getAccountUniqueID())) + { + String index = configService.getString( + accountRootPropName + ".accountIndex"); + + if(index != null) { + //if we have found the accountIndex for this protocol provider + //return this index + return Integer.parseInt(index); + } + else + { + //if there's no stored accountIndex for this protocol + //provider, calculate the index, set it in the configuration + //service and return it. + + return createAccountIndex(protocolProvider, + accountRootPropName); + } + } + } + + String accNodeName + = "acc" + Long.toString(System.currentTimeMillis()); + + String accountPackage + = "net.java.sip.communicator.impl.gui.accounts." + + accNodeName; + + configService.setProperty(accountPackage, + protocolProvider.getAccountID().getAccountUniqueID()); + + return createAccountIndex(protocolProvider, + accountPackage); + } + + /** + * Creates and calculates the account index for the given protocol + * provider. + * @param protocolProvider the protocol provider + * @param accountRootPropName the path to where the index should be saved + * in the configuration xml + * @return the created index + */ + private int createAccountIndex(ProtocolProviderService protocolProvider, + String accountRootPropName) + { + ConfigurationService configService + = GuiActivator.getConfigurationService(); + int accountIndex = -1; + + for (ProtocolProviderService pps : protocolProviders.keySet()) + { + if (pps.getProtocolDisplayName().equals( + protocolProvider.getProtocolDisplayName()) + && !pps.equals(protocolProvider)) + { + + int index = protocolProviders.get(pps); + + if (accountIndex < index) + accountIndex = index; + } + } + accountIndex++; + configService.setProperty( + accountRootPropName + ".accountIndex", + accountIndex); + + return accountIndex; + } + + /** + * Updates the indexes in the configuration xml, when a provider has been + * removed. + * @param removedProvider the removed protocol provider + */ + private void updateProvidersIndexes(ProtocolProviderService removedProvider) + { + ConfigurationService configService + = GuiActivator.getConfigurationService(); + + String prefix = "net.java.sip.communicator.impl.gui.accounts"; + + ProtocolProviderService currentProvider = null; + int sameProtocolProvidersCount = 0; + + for (ProtocolProviderService pps : protocolProviders.keySet()) { + if(pps.getProtocolDisplayName().equals( + removedProvider.getProtocolDisplayName())) { + + sameProtocolProvidersCount++; + if(sameProtocolProvidersCount > 1) { + break; + } + currentProvider = pps; + } + } + + if(sameProtocolProvidersCount < 2 && currentProvider != null) { + protocolProviders.put(currentProvider, 0); + + List accounts = configService + .getPropertyNamesByPrefix(prefix, true); + + for (String rootPropName : accounts) { + String accountUID + = configService.getString(rootPropName); + + if(accountUID.equals(currentProvider + .getAccountID().getAccountUniqueID())) { + + configService.setProperty( + rootPropName + ".accountIndex", + 0); + } + } + } + } + + /** + * If the protocol provider supports presence operation set searches the + * last status which was selected, otherwise returns null. + * + * @param protocolProvider the protocol provider we're interested in. + * @return the last protocol provider presence status, or null if this + * provider doesn't support presence operation set + */ + public Object getProtocolProviderLastStatus( + ProtocolProviderService protocolProvider) + { + if(getProtocolPresenceOpSet(protocolProvider) != null) + return accountStatusPanel.getLastPresenceStatus(protocolProvider); + else + return accountStatusPanel.getLastStatusString(protocolProvider); + } + + /** + * RenameAction is invoked when user presses the F2 key. Depending + * on the selection opens the appropriate form for renaming. + */ + private class RenameAction extends AbstractAction + { + private static final long serialVersionUID = 0L; + + public void actionPerformed(ActionEvent e) + { + Object selectedObject + = GuiActivator.getContactList().getSelectionPath() + .getLastPathComponent(); + + if(selectedObject instanceof MetaContact) { + RenameContactDialog dialog = new RenameContactDialog( + MainFrame.this, (MetaContact)selectedObject); + + dialog.setLocation( + Toolkit.getDefaultToolkit().getScreenSize().width/2 + - 200, + Toolkit.getDefaultToolkit().getScreenSize().height/2 + - 50 + ); + + dialog.setVisible(true); + + dialog.requestFocusInFiled(); + } + else if(selectedObject instanceof MetaContactGroup) { + + RenameGroupDialog dialog = new RenameGroupDialog( + MainFrame.this, (MetaContactGroup)selectedObject); + + Dimension screenSize = + Toolkit.getDefaultToolkit().getScreenSize(); + dialog.setLocation(screenSize.width / 2 - 200, + screenSize.height / 2 - 50); + + dialog.setVisible(true); + + dialog.requestFocusInFiled(); + } + } + } + + /** + * Overwrites the SIPCommFrame close method. This method is + * invoked when user presses the Escape key. + * @param isEscaped indicates if this window has been closed by pressing + * the escape key + */ + protected void close(boolean isEscaped) + { + TreeContactList contactList = GuiActivator.getContactList(); + + Component contactListRightMenu + = contactList.getRightButtonMenu(); + + CommonRightButtonMenu commonPopupMenu + = getContactListPanel().getCommonRightButtonMenu(); + + if(contactListRightMenu != null && contactListRightMenu.isVisible()) + { + contactListRightMenu.setVisible(false); + } + else if(commonPopupMenu != null && commonPopupMenu.isVisible()) + { + commonPopupMenu.setVisible(false); + } + else if(accountStatusPanel.hasSelectedMenus() + || menu.hasSelectedMenus()) + { + MenuSelectionManager selectionManager + = MenuSelectionManager.defaultManager(); + + selectionManager.clearSelectedPath(); + } + } + + /** + * Returns the main menu in the application window. + * @return the main menu in the application window + */ + public MainMenu getMainMenu() + { + return menu; + } + + /** + * + * @param protocolProvider + * @param contactHandler + */ + public void addProviderContactHandler( + ProtocolProviderService protocolProvider, + ContactEventHandler contactHandler) + { + providerContactHandlers.put(protocolProvider, contactHandler); + } + + /** + * Returns the ContactEventHandler registered for this protocol + * provider. + * + * @param protocolProvider the ProtocolProviderService for which + * we are searching a ContactEventHandler. + * @return the ContactEventHandler registered for this protocol + * provider + */ + public ContactEventHandler getContactHandler( + ProtocolProviderService protocolProvider) + { + return providerContactHandlers.get(protocolProvider); + } + + /** + * Returns the ContactEventHandler for contacts given by the + * protocolProvider. The ContactEventHandler is meant to + * be used from other bundles in order to change the default behavior of + * events generated when clicking a contact. + * @param protocolProvider the protocol provider for which we want to obtain + * a contact event handler + * @return the ContactEventHandler for contacts given by the + * protocolProvider + */ + private ContactEventHandler getContactHandlerForProvider( + ProtocolProviderService protocolProvider) + { + ServiceReference[] serRefs = null; + + String osgiFilter = "(" + + ProtocolProviderFactory.PROTOCOL + + "=" + protocolProvider.getProtocolName()+")"; + + try + { + serRefs = GuiActivator.bundleContext.getServiceReferences( + ContactEventHandler.class.getName(), osgiFilter); + } + catch (InvalidSyntaxException ex){ + logger.error("GuiActivator : " + ex); + } + + if(serRefs == null) + return null; + + return (ContactEventHandler) GuiActivator.bundleContext + .getService(serRefs[0]); + } + + /** + * Initialize plugin components already registered for this container. + */ + private void initPluginComponents() + { + pluginPanelSouth.setLayout( + new BoxLayout(pluginPanelSouth, BoxLayout.Y_AXIS)); + pluginPanelNorth.setLayout( + new BoxLayout(pluginPanelNorth, BoxLayout.Y_AXIS)); + pluginPanelEast.setLayout( + new BoxLayout(pluginPanelEast, BoxLayout.Y_AXIS)); + pluginPanelWest.setLayout( + new BoxLayout(pluginPanelWest, BoxLayout.Y_AXIS)); + + java.awt.Container contentPane = getContentPane(); + contentPane.add(pluginPanelNorth, BorderLayout.NORTH); + contentPane.add(pluginPanelEast, BorderLayout.EAST); + contentPane.add(pluginPanelWest, BorderLayout.WEST); + this.mainPanel.add(pluginPanelSouth, BorderLayout.SOUTH); + + // Search for plugin components registered through the OSGI bundle + // context. + ServiceReference[] serRefs = null; + + try + { + serRefs + = GuiActivator + .bundleContext + .getServiceReferences( + PluginComponent.class.getName(), + "(|(" + + Container.CONTAINER_ID + + "=" + + Container.CONTAINER_MAIN_WINDOW.getID() + + ")(" + + Container.CONTAINER_ID + + "=" + + Container.CONTAINER_STATUS_BAR.getID() + + "))"); + } + catch (InvalidSyntaxException exc) + { + logger.error("Could not obtain plugin reference.", exc); + } + + if (serRefs != null) + { + for (ServiceReference serRef : serRefs) + { + PluginComponent c + = (PluginComponent) + GuiActivator.bundleContext.getService(serRef); + + if (c.isNativeComponent()) + nativePluginsTable.put(c, new JPanel()); + else + { + String pluginConstraints = c.getConstraints(); + Object constraints; + + if (pluginConstraints != null) + constraints + = UIServiceImpl + .getBorderLayoutConstraintsFromContainer( + pluginConstraints); + else + constraints = BorderLayout.SOUTH; + + this.addPluginComponent((Component) c.getComponent(), c + .getContainer(), constraints); + } + } + } + + GuiActivator.getUIService().addPluginComponentListener(this); + } + + /** + * Adds the associated with this PluginComponentEvent component to + * the appropriate container. + * @param event the PluginComponentEvent that has notified us of + * the add of a plugin component + */ + public void pluginComponentAdded(PluginComponentEvent event) + { + PluginComponent pluginComponent = event.getPluginComponent(); + Container pluginContainer = pluginComponent.getContainer(); + + if (pluginContainer.equals(Container.CONTAINER_MAIN_WINDOW) + || pluginContainer.equals(Container.CONTAINER_STATUS_BAR)) + { + String pluginConstraints = pluginComponent.getConstraints(); + Object constraints; + + if (pluginConstraints != null) + constraints = + UIServiceImpl + .getBorderLayoutConstraintsFromContainer(pluginConstraints); + else + constraints = BorderLayout.SOUTH; + + if (pluginComponent.isNativeComponent()) + { + this.nativePluginsTable.put(pluginComponent, new JPanel()); + + if (isVisible()) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + addNativePlugins(); + } + }); + } + } + else + { + this.addPluginComponent((Component) pluginComponent + .getComponent(), pluginContainer, constraints); + } + } + } + + /** + * Removes the associated with this PluginComponentEvent component + * from this container. + * @param event the PluginComponentEvent that notified us of the + * remove of a plugin component + */ + public void pluginComponentRemoved(PluginComponentEvent event) + { + final PluginComponent pluginComponent = event.getPluginComponent(); + final Container containerID = pluginComponent.getContainer(); + + if (containerID.equals(Container.CONTAINER_MAIN_WINDOW)) + { + Object constraints = UIServiceImpl + .getBorderLayoutConstraintsFromContainer( + pluginComponent.getConstraints()); + + if (constraints == null) + constraints = BorderLayout.SOUTH; + + if (pluginComponent.isNativeComponent()) + { + if (nativePluginsTable.containsKey(pluginComponent)) + { + final Component c = nativePluginsTable.get(pluginComponent); + final Object finalConstraints = constraints; + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + removePluginComponent(c, containerID, + finalConstraints); + + getContentPane().repaint(); + } + }); + } + } + else + { + this.removePluginComponent((Component) pluginComponent + .getComponent(), containerID, constraints); + } + + nativePluginsTable.remove(pluginComponent); + } + } + + /** + * Removes all native plugins from this container. + */ + private void removeNativePlugins() + { + for (Map.Entry entry + : nativePluginsTable.entrySet()) + { + PluginComponent pluginComponent = entry.getKey(); + Component c = entry.getValue(); + + Object constraints + = UIServiceImpl + .getBorderLayoutConstraintsFromContainer(pluginComponent + .getConstraints()); + + if (constraints == null) + constraints = BorderLayout.SOUTH; + + this.removePluginComponent(c, pluginComponent.getContainer(), + constraints); + + this.getContentPane().repaint(); + } + } + + /** + * Adds all native plugins to this container. + */ + public void addNativePlugins() + { + this.removeNativePlugins(); + + for (Map.Entry pluginEntry + : nativePluginsTable.entrySet()) + { + PluginComponent plugin = pluginEntry.getKey(); + Object constraints + = UIServiceImpl + .getBorderLayoutConstraintsFromContainer( + plugin.getConstraints()); + + Component c = (Component) plugin.getComponent(); + + this.addPluginComponent(c, plugin.getContainer(), constraints); + + this.nativePluginsTable.put(plugin, c); + } + } + + /** + * Brings this window to front. + */ + public void bringToFront() + { + this.toFront(); + } + + /** + * Returns the identifier of this window. + * @return the identifier of this window + */ + public WindowID getIdentifier() + { + return ExportedWindow.MAIN_WINDOW; + } + + /** + * Returns this window. + * @return this window + */ + public Object getSource() + { + return this; + } + + /** + * Maximizes this window. + */ + public void maximize() + { + this.setExtendedState(JFrame.MAXIMIZED_BOTH); + } + + /** + * Minimizes this window. + */ + public void minimize() + { + this.setExtendedState(JFrame.ICONIFIED); + } + + /** + * Implements isVisible in the UIService interface. Checks if + * the main application window is visible. + * + * @return true if main application window is visible, + * false otherwise + * @see UIService#isVisible() + */ + public boolean isVisible() + { + return super.isVisible() + && (super.getExtendedState() != JFrame.ICONIFIED); + } + + /** + * Implements setVisible in the UIService interface. Shows or + * hides the main application window depending on the parameter + * visible. + * + * @param isVisible true if we are to show the main application frame and + * false otherwise. + * + * @see UIService#setVisible(boolean) + */ + public void setVisible(final boolean isVisible) + { + SwingUtilities.invokeLater(new Runnable(){ + public void run() + { + if(isVisible) + { + MainFrame.this.addNativePlugins(); + MainFrame.super.setVisible(isVisible); + MainFrame.super.setExtendedState(MainFrame.NORMAL); + MainFrame.super.toFront(); + } + else + { + MainFrame.super.setVisible(isVisible); + } + } + }); + } + + /** + * Adds the given component with to the container corresponding to the + * given constraints. + * + * @param c the component to add + * @param container the container to which to add the given component + * @param constraints the constraints determining the container + */ + private void addPluginComponent(Component c, + Container container, + Object constraints) + { + if (container.equals(Container.CONTAINER_MAIN_WINDOW)) + { + if (constraints.equals(BorderLayout.NORTH)) + { + pluginPanelNorth.add(c); + pluginPanelNorth.repaint(); + } + else if (constraints.equals(BorderLayout.SOUTH)) + { + pluginPanelSouth.add(c); + pluginPanelSouth.repaint(); + } + else if (constraints.equals(BorderLayout.WEST)) + { + pluginPanelWest.add(c); + pluginPanelWest.repaint(); + } + else if (constraints.equals(BorderLayout.EAST)) + { + pluginPanelEast.add(c); + pluginPanelEast.repaint(); + } + } + else if (container.equals(Container.CONTAINER_STATUS_BAR)) + { + statusBarPanel.add(c); + } + + this.getContentPane().repaint(); + this.getContentPane().validate(); + } + + /** + * Removes the given component from the container corresponding to the given + * constraints. + * + * @param c the component to remove + * @param container the container from which to remove the given component + * @param constraints the constraints determining the container + */ + private void removePluginComponent( Component c, + Container container, + Object constraints) + { + if (container.equals(Container.CONTAINER_MAIN_WINDOW)) + { + if (constraints.equals(BorderLayout.NORTH)) + pluginPanelNorth.remove(c); + else if (constraints.equals(BorderLayout.SOUTH)) + pluginPanelSouth.remove(c); + else if (constraints.equals(BorderLayout.WEST)) + pluginPanelWest.remove(c); + else if (constraints.equals(BorderLayout.EAST)) + pluginPanelEast.remove(c); + } + else if (container.equals(Container.CONTAINER_STATUS_BAR)) + { + this.statusBarPanel.remove(c); + } + } + + /** + * Returns the account status panel. + * @return the account status panel. + */ + public AccountStatusPanel getAccountStatusPanel() + { + return accountStatusPanel; + } + + /** + * Implementation of {@link ExportedWindow#setParams(Object[])}. + */ + public void setParams(Object[] windowParams) {} + + /** + * @param event Currently not used + */ + protected void windowClosed(WindowEvent event) + { + if(GuiActivator.getUIService().getExitOnMainWindowClose()) + { + try + { + GuiActivator.bundleContext.getBundle(0).stop(); + } + catch (BundleException ex) + { + logger.error("Failed to gently shutdown Felix", ex); + System.exit(0); + } + //stopping a bundle doesn't leave the time to the felix thread to + //properly end all bundles and call their Activator.stop() methods. + //if this causes problems don't uncomment the following line but + //try and see why felix isn't exiting (suggesting: is it running + //in embedded mode?) + //System.exit(0); + } + } + + /** + * Overrides SIPCommFrame#windowClosing(WindowEvent). Reflects the closed + * state of this MainFrame in the configuration in order to make it + * accessible to interested parties, displays the warning that the + * application will not quit. + * @param event the WindowEvent that notified us + */ + protected void windowClosing(WindowEvent event) + { + super.windowClosing(event); + + if (!GuiActivator.getUIService().getExitOnMainWindowClose()) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + if (ConfigurationManager.isQuitWarningShown()) + { + MessageDialog dialog = + new MessageDialog(null, + GuiActivator.getResources().getI18NString( + "service.gui.CLOSE"), + GuiActivator.getResources().getI18NString( + "service.gui.HIDE_MAIN_WINDOW"), false); + + if (dialog.showDialog() == MessageDialog.OK_DONT_ASK_CODE) + ConfigurationManager.setQuitWarningShown(false); + } + } + }); + + ConfigurationManager.setApplicationVisible(false); + } + } + + /** + * The MainKeyDispatcher is added to pre-listen KeyEvents before + * they're delivered to the current focus owner in order to introduce a + * specific behavior for the SearchField on top of the contact + * list. + */ + private class MainKeyDispatcher implements KeyEventDispatcher + { + private KeyboardFocusManager keyManager; + + /** + * Creates an instance of MainKeyDispatcher. + * @param keyManager the parent KeyboardFocusManager + */ + public MainKeyDispatcher(KeyboardFocusManager keyManager) + { + this.keyManager = keyManager; + } + + /** + * Dispatches the given KeyEvent. + * @param e the KeyEvent to dispatch + * @return true if the KeyboardFocusManager should take no + * further action with regard to the KeyEvent; false + * otherwise + */ + public boolean dispatchKeyEvent(KeyEvent e) + { + // If this window is not the focus window or if the event is not + // of type PRESSED we have nothing more to do here. + if (!isFocused() + || (e.getID() != KeyEvent.KEY_PRESSED + && e.getID() != KeyEvent.KEY_TYPED)) + return false; + + // Ctrl-Enter || Cmd-Enter typed when this window is the focused + // window. + // + // Tried to make this with key bindings first, but has a problem + // with enter key binding. When the popup menu containing call + // contacts was opened the default keyboard manager was prioritizing + // the window ENTER key, which will open a chat and we wanted that + // the enter starts a call with the selected contact from the menu. + // This is why we need to do it here and to check if the + // permanent focus owner is equal to the focus owner, which is not + // the case when a popup menu is opened. + if (e.getKeyCode() == KeyEvent.VK_ENTER + && (e.isControlDown() || e.isMetaDown())) + { + ctrlEnterKeyTyped(); + return false; + } + else if (e.getKeyCode() == KeyEvent.VK_ENTER + && keyManager.getFocusOwner() + .equals(keyManager.getPermanentFocusOwner())) + { + enterKeyTyped(); + return false; + } + + TreeContactList contactList + = getContactListPanel().getContactList(); + + // If the search field is the focus owner. + if (searchField.isFocusOwner() + && (e.getKeyCode() == KeyEvent.VK_UP + || e.getKeyCode() == KeyEvent.VK_DOWN + || e.getKeyCode() == KeyEvent.VK_PAGE_UP + || e.getKeyCode() == KeyEvent.VK_PAGE_DOWN)) + { + contactList.selectFirstContact(); + contactList.requestFocus(); + return false; + } + + // If the contact list is the focus owner. + if (contactList.isFocusOwner() + && e.getKeyCode() == KeyEvent.VK_ESCAPE) + { + // Removes all current selections. + contactList.removeSelectionRows(contactList.getSelectionRows()); + + if (searchField.getText() != null) + { + searchField.requestFocus(); + } + return false; + } + TreePath selectionPath = contactList.getSelectionPath(); + + // No matter who is the focus owner. + if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED + || e.getKeyCode() == KeyEvent.VK_ENTER + || e.getKeyCode() == KeyEvent.VK_DELETE + || e.getKeyCode() == KeyEvent.VK_BACK_SPACE + || e.getKeyCode() == KeyEvent.VK_TAB + || e.getKeyCode() == KeyEvent.VK_SPACE + || (selectionPath != null + && selectionPath.getLastPathComponent() instanceof GroupNode + && (e.getKeyChar() == '+' + || e.getKeyChar() == '-'))) + { + return false; + } + + if (!searchField.isFocusOwner() + && keyManager.getFocusOwner() != null + && keyManager.getFocusOwner() + .equals(keyManager.getPermanentFocusOwner())) + { + // Request the focus in the search field if a letter is typed. + searchField.requestFocusInWindow(); + + // We re-dispatch the event to search field. + keyManager.redispatchEvent(searchField, e); + + // We don't want to dispatch further this event. + return true; + } + return false; + } + } + + /** + * Called when the ENTER key was typed when this window was the focused + * window. Performs the appropriate actions depending on the current state + * of the contact list. + */ + private void enterKeyTyped() + { + if (unknownContactPanel != null && unknownContactPanel.isVisible()) + { + unknownContactPanel.addUnknownContact(); + } + else if (contactListPanel.isVisible()) + { + // Starts a chat with the currently selected contact. + GuiActivator.getContactList().startSelectedContactChat(); + } + } + + /** + * Called when the CTRL-ENTER or CMD-ENTER keys were typed when this window + * was the focused window. Performs the appropriate actions depending on the + * current state of the contact list. + */ + public void ctrlEnterKeyTyped() + { + if (unknownContactPanel != null && unknownContactPanel.isVisible()) + { + unknownContactPanel.startCall(); + } + else if (contactListPanel.isVisible()) + { + // Starts a chat with the currently selected contact. + GuiActivator.getContactList().startSelectedContactCall(); + } + } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrameInterface.java b/src/net/java/sip/communicator/impl/gui/main/MainFrameInterface.java deleted file mode 100644 index 6cf2f4b..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrameInterface.java +++ /dev/null @@ -1,322 +0,0 @@ -package net.java.sip.communicator.impl.gui.main; - -import java.util.Iterator; - -import net.java.sip.communicator.impl.gui.event.PluginComponentEvent; -import net.java.sip.communicator.impl.gui.main.contactlist.ContactListPane; -import net.java.sip.communicator.impl.gui.main.menus.MainMenu; -import net.java.sip.communicator.impl.gui.main.presence.AccountStatusPanel; -import net.java.sip.communicator.service.contacteventhandler.ContactEventHandler; -import net.java.sip.communicator.service.contactlist.MetaContactListService; -import net.java.sip.communicator.service.gui.ExportedWindow; -import net.java.sip.communicator.service.gui.UIService; -import net.java.sip.communicator.service.gui.WindowID; -import net.java.sip.communicator.service.protocol.OperationSetAdHocMultiUserChat; -import net.java.sip.communicator.service.protocol.OperationSetBasicTelephony; -import net.java.sip.communicator.service.protocol.OperationSetMultiUserChat; -import net.java.sip.communicator.service.protocol.OperationSetWebContactInfo; -import net.java.sip.communicator.service.protocol.ProtocolProviderService; -import net.java.sip.communicator.util.swing.event.TextFieldChangeListener; - -/** - * The main GUI window intzerface. - * - * This Interface defines all methods that the real GUI classes - * implement. - * - * @author Yana Stamcheva - * @author Lubomir Marinov - * @outhor Werner Dittmann - */ - -public interface MainFrameInterface { - - /** - * Requests the focus in the center panel, which contains either the - * contact list or the unknown contact panel. - */ - void requestFocusInCenterPanel(); - - /** - * Sets frame size and position. - */ - void initBounds(); - - /** - * Enters or exits the "unknown contact" view. This view will propose to - * the user some specific operations if the current filter doesn't match - * any contacts. - * @param isEnabled true to enable the "unknown contact" view, - * false - otherwise. - */ - void enableUnknownContactView(boolean isEnabled); - - /** - * Initializes the contact list panel. - * - * @param contactList The MetaContactListService containing - * the contact list data. - */ - void setContactList(MetaContactListService contactList); - - /** - * Adds all protocol supported operation sets. - * - * @param protocolProvider The protocol provider. - */ - void addProtocolSupportedOperationSets( - ProtocolProviderService protocolProvider); - - /** - * Returns a set of all protocol providers. - * - * @return a set of all protocol providers. - */ - Iterator getProtocolProviders(); - - /** - * Returns the protocol provider associated to the account given - * by the account user identifier. - * - * @param accountName The account user identifier. - * @return The protocol provider associated to the given account. - */ - ProtocolProviderService getProtocolProviderForAccount(String accountName); - - /** - * Adds a protocol provider. - * @param protocolProvider The protocol provider to add. - */ - void addProtocolProvider(ProtocolProviderService protocolProvider); - - /** - * Returns the index of the given protocol provider. - * @param protocolProvider the protocol provider to search for - * @return the index of the given protocol provider - */ - int getProviderIndex(ProtocolProviderService protocolProvider); - - /** - * Adds an account to the application. - * - * @param protocolProvider The protocol provider of the account. - */ - void addAccount(ProtocolProviderService protocolProvider); - - /** - * Adds an account to the application. - * - * @param protocolProvider The protocol provider of the account. - */ - void removeProtocolProvider(ProtocolProviderService protocolProvider); - - /** - * Returns the account user id for the given protocol provider. - * @param protocolProvider the protocol provider corresponding to the - * account to add - * @return The account user id for the given protocol provider. - */ - String getAccount(ProtocolProviderService protocolProvider); - - /** - * Returns the Web Contact Info operation set for the given - * protocol provider. - * - * @param protocolProvider The protocol provider for which the TN - * is searched. - * @return OperationSetWebContactInfo The Web Contact Info operation - * set for the given protocol provider. - */ - OperationSetWebContactInfo getWebContactInfoOpSet( - ProtocolProviderService protocolProvider); - - /** - * Returns the telephony operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the telephony - * operation set is about. - * @return OperationSetBasicTelephony The telephony operation - * set for the given protocol provider. - */ - OperationSetBasicTelephony getTelephonyOpSet( - ProtocolProviderService protocolProvider); - - /** - * Returns the multi user chat operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the multi user - * chat operation set is about. - * @return OperationSetAdHocMultiUserChat The telephony operation - * set for the given protocol provider. - */ - OperationSetAdHocMultiUserChat getAdHocMultiUserChatOpSet( - ProtocolProviderService protocolProvider); - - /** - * Returns the multi user chat operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the multi user - * chat operation set is about. - * @return OperationSetMultiUserChat The telephony operation - * set for the given protocol provider. - */ - OperationSetMultiUserChat getMultiUserChatOpSet( - ProtocolProviderService protocolProvider); - - /** - * Returns the panel containing the ContactList. - * @return ContactListPanel the panel containing the ContactList - */ - ContactListPane getContactListPanel(); - - /** - * Returns the text currently shown in the search field. - * @return the text currently shown in the search field - */ - String getCurrentSearchText(); - - /** - * Clears the current text in the search field. - */ - void clearCurrentSearchText(); - - /** - * Adds the given TextFieldChangeListener to listen for any changes - * that occur in the search field. - * @param l the TextFieldChangeListener to add - */ - void addSearchFieldListener(TextFieldChangeListener l); - - /** - * Removes the given TextFieldChangeListener that listens for any - * changes that occur in the search field. - * @param l the TextFieldChangeListener to remove - */ - void removeSearchFieldListener(TextFieldChangeListener l); - - /** - * If the protocol provider supports presence operation set searches the - * last status which was selected, otherwise returns null. - * - * @param protocolProvider the protocol provider we're interested in. - * @return the last protocol provider presence status, or null if this - * provider doesn't support presence operation set - */ - Object getProtocolProviderLastStatus( - ProtocolProviderService protocolProvider); - - /** - * Returns the main menu in the application window. - * @return the main menu in the application window - */ - MainMenu getMainMenu(); - - /** - * - * @param protocolProvider - * @param contactHandler - */ - void addProviderContactHandler(ProtocolProviderService protocolProvider, - ContactEventHandler contactHandler); - - /** - * Returns the ContactEventHandler registered for this protocol - * provider. - * - * @param protocolProvider the ProtocolProviderService for which - * we are searching a ContactEventHandler. - * @return the ContactEventHandler registered for this protocol - * provider - */ - ContactEventHandler getContactHandler( - ProtocolProviderService protocolProvider); - - /** - * Adds the associated with this PluginComponentEvent component to - * the appropriate container. - * @param event the PluginComponentEvent that has notified us of - * the add of a plugin component - */ - void pluginComponentAdded(PluginComponentEvent event); - - /** - * Removes the associated with this PluginComponentEvent component - * from this container. - * @param event the PluginComponentEvent that notified us of the - * remove of a plugin component - */ - void pluginComponentRemoved(PluginComponentEvent event); - - /** - * Adds all native plugins to this container. - */ - void addNativePlugins(); - - /** - * Brings this window to front. - */ - void bringToFront(); - - /** - * Returns the identifier of this window. - * @return the identifier of this window - */ - WindowID getIdentifier(); - - /** - * Returns this window. - * @return this window - */ - Object getSource(); - - /** - * Maximizes this window. - */ - void maximize(); - - /** - * Minimizes this window. - */ - void minimize(); - - /** - * Implements isVisible in the UIService interface. Checks if - * the main application window is visible. - * - * @return true if main application window is visible, - * false otherwise - * @see UIService#isVisible() - */ - boolean isVisible(); - - /** - * Implements setVisible in the UIService interface. Shows or - * hides the main application window depending on the parameter - * visible. - * - * @param isVisible true if we are to show the main application frame and - * false otherwise. - * - * @see UIService#setVisible(boolean) - */ - void setVisible(final boolean isVisible); - - /** - * Returns the account status panel. - * @return the account status panel. - */ - AccountStatusPanel getAccountStatusPanel(); - - /** - * Implementation of {@link ExportedWindow#setParams(Object[])}. - */ - void setParams(Object[] windowParams); - - /** - * Called when the CTRL-ENTER or CMD-ENTER keys were typed when this window - * was the focused window. Performs the appropriate actions depending on the - * current state of the contact list. - */ - void ctrlEnterKeyTyped(); - -} \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrameStandard.java b/src/net/java/sip/communicator/impl/gui/main/MainFrameStandard.java deleted file mode 100644 index 32dda38..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrameStandard.java +++ /dev/null @@ -1,1666 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.main; - -import java.awt.*; -import java.awt.event.*; -import java.beans.PropertyChangeEvent; -import java.util.*; -import java.util.List; - -import javax.swing.*; -import javax.swing.tree.*; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.customcontrols.*; -import net.java.sip.communicator.impl.gui.event.*; -import net.java.sip.communicator.impl.gui.main.call.*; -import net.java.sip.communicator.impl.gui.main.chat.conference.*; -import net.java.sip.communicator.impl.gui.main.contactlist.*; -import net.java.sip.communicator.impl.gui.main.menus.*; -import net.java.sip.communicator.impl.gui.main.presence.*; -import net.java.sip.communicator.impl.gui.utils.*; -import net.java.sip.communicator.service.configuration.*; -import net.java.sip.communicator.service.contacteventhandler.*; -import net.java.sip.communicator.service.contactlist.*; -import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.gui.Container; -import net.java.sip.communicator.service.keybindings.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.service.resources.*; -import net.java.sip.communicator.util.*; -import net.java.sip.communicator.util.swing.*; -import net.java.sip.communicator.util.swing.event.*; - -import org.osgi.framework.*; - -/** - * The main application window. This class is the core of this UI - * implementation. It stores all available protocol providers and their - * operation sets, as well as all registered accounts, the - * MetaContactListService and all sent messages that aren't - * delivered yet. - * - * @author Yana Stamcheva - * @author Lubomir Marinov - */ -public class MainFrameStandard - extends MainFrame -{ - /** - * The logger. - */ - private final Logger logger = Logger.getLogger(MainFrameStandard.class); - - /** - * The main container. - */ - private final TransparentPanel mainPanel - = new TransparentPanel(new BorderLayout(0, 0)); - - /** - * The status bar panel. - */ - private final TransparentPanel statusBarPanel - = new TransparentPanel(new BorderLayout()); - - /** - * The center panel, containing the contact list. - */ - private final TransparentPanel centerPanel - = new TransparentPanel(new BorderLayout(0, 0)); - - /** - * The main menu. - */ - private MainMenu menu; - - /** - * The search field shown above the contact list. - */ - private final SearchField searchField; - - /** - * A mapping of ProtocolProviderServices and their indexes. - */ - private final HashMap protocolProviders - = new LinkedHashMap(); - - /** - * The panel containing the accounts status menu. - */ - private AccountStatusPanel accountStatusPanel; - - /** - * The panel replacing the contact list, shown when no matching is found - * for the search filter. - */ - private UnknownContactPanel unknownContactPanel; - - /** - * A mapping of ProtocolProviderServices and corresponding - * ContactEventHandlers. - */ - private final Map - providerContactHandlers = - new Hashtable(); - - /** - * A mapping of plug-in components and their corresponding native components. - */ - private final Map nativePluginsTable = - new Hashtable(); - - /** - * The north plug-in panel. - */ - private final JPanel pluginPanelNorth = new TransparentPanel(); - - /** - * The south plug-in panel. - */ - private final JPanel pluginPanelSouth = new TransparentPanel(); - - /** - * The west plug-in panel. - */ - private final JPanel pluginPanelWest = new TransparentPanel(); - - /** - * The east plug-in panel. - */ - private final JPanel pluginPanelEast = new TransparentPanel(); - - /** - * The container containing the contact list. - */ - private ContactListPane contactListPanel; - - /** - * Creates an instance of MainFrame. - */ - public MainFrameStandard() - { - if (!ConfigurationManager.isWindowDecorated()) - { - this.setUndecorated(true); - } - - this.searchField = new SearchField(this); - - this.contactListPanel = new ContactListPane(this); - - this.accountStatusPanel = new AccountStatusPanel(this); - - menu = new MainMenu(this); - - /* - * If the application is configured to quit when this frame is closed, - * do so. - */ - this.addWindowListener(new WindowAdapter() - { - /** - * Invoked when a window has been closed. - */ - public void windowClosed(WindowEvent event) - { - MainFrameStandard.this.windowClosed(event); - } - /** - * Invoked when a window has been opened. - */ - public void windowOpened(WindowEvent e) - { - GuiActivator.getContactList().requestFocusInWindow(); - } - }); - - this.initTitleFont(); - - ResourceManagementService resources = GuiActivator.getResources(); - String applicationName - = resources.getSettingsString("service.gui.APPLICATION_NAME"); - - this.setTitle(applicationName); - - this.mainPanel.setBackground(new Color( - GuiActivator.getResources() - .getColor("service.gui.MAIN_WINDOW_BACKGROUND"))); - - KeyboardFocusManager keyManager - = KeyboardFocusManager.getCurrentKeyboardFocusManager(); - keyManager.addKeyEventDispatcher(new MainKeyDispatcher(keyManager)); - - this.init(); - - this.initPluginComponents(); - } - - /** - * Requests the focus in the center panel, which contains either the - * contact list or the unknown contact panel. - */ - public void requestFocusInCenterPanel() - { - centerPanel.requestFocusInWindow(); - } - - /** - * Initiates the content of this frame. - */ - private void init() - { - setDefaultCloseOperation( - GuiActivator.getUIService().getExitOnMainWindowClose() - ? JFrame.DISPOSE_ON_CLOSE - : JFrame.HIDE_ON_CLOSE); - - this.setKeybindingInput(KeybindingSet.Category.MAIN); - this.addKeybindingAction("main-rename", - new RenameAction()); - - // Remove the default escape key mapping as its a special - // one for the main frame and the contactlist - getRootPane().getInputMap( - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) - .remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); - - TransparentPanel northPanel - = new TransparentPanel(new BorderLayout(0, 0)); - - this.setJMenuBar(menu); - - northPanel.add(accountStatusPanel, BorderLayout.CENTER); - - TransparentPanel searchPanel - = new TransparentPanel(new BorderLayout(2, 0)); - searchPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); - searchPanel.add(searchField); - searchPanel.add(new CallHistoryButton(), BorderLayout.EAST); - - centerPanel.add(searchPanel, BorderLayout.NORTH); - centerPanel.add(contactListPanel, BorderLayout.CENTER); - - this.mainPanel.add(northPanel, BorderLayout.NORTH); - this.mainPanel.add(centerPanel, BorderLayout.CENTER); - - java.awt.Container contentPane = getContentPane(); - contentPane.add(mainPanel, BorderLayout.CENTER); - contentPane.add(statusBarPanel, BorderLayout.SOUTH); - } - - /** - * Sets frame size and position. - */ - public void initBounds() - { - int width = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_WIDTH"); - - int height = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_HEIGHT"); - - int minWidth = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_MIN_WIDTH"); - - int minHeight = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_MIN_HEIGHT"); - - this.getContentPane().setMinimumSize(new Dimension(minWidth, minHeight)); - - this.setSize(width, height); - - this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width - - this.getWidth(), 50); - } - - /** - * Initialize main window font. - */ - private void initTitleFont() - { - JComponent layeredPane = this.getLayeredPane(); - - ResourceManagementService resources = GuiActivator.getResources(); - String fontName - = resources.getSettingsString("service.gui.FONT_NAME"); - - String titleFontSize - = resources.getSettingsString("service.gui.FONT_SIZE"); - - Font font = new Font( fontName, - Font.BOLD, - Integer.parseInt(titleFontSize)); - - final int componentCount = layeredPane.getComponentCount(); - for (int i = 0; i < componentCount; i++) - { - layeredPane.getComponent(i).setFont(font); - } - } - - /** - * Enters or exits the "unknown contact" view. This view will propose to - * the user some specific operations if the current filter doesn't match - * any contacts. - * @param isEnabled true to enable the "unknown contact" view, - * false - otherwise. - */ - public void enableUnknownContactView(boolean isEnabled) - { - if (isEnabled) - { - if (unknownContactPanel == null) - unknownContactPanel = new UnknownContactPanel(this); - - if (unknownContactPanel.getParent() != centerPanel) - { - contactListPanel.setVisible(false); - unknownContactPanel.setVisible(true); - centerPanel.remove(contactListPanel); - centerPanel.add(unknownContactPanel, BorderLayout.CENTER); - } - } - else - { - if (contactListPanel.getParent() != centerPanel) - { - if (unknownContactPanel != null) - { - unknownContactPanel.setVisible(false); - centerPanel.remove(unknownContactPanel); - } - contactListPanel.setVisible(true); - centerPanel.add(contactListPanel, BorderLayout.CENTER); - } - } - centerPanel.revalidate(); - centerPanel.repaint(); - } - - /** - * Initializes the contact list panel. - * - * @param contactList The MetaContactListService containing - * the contact list data. - */ - public void setContactList(MetaContactListService contactList) - { - contactListPanel.initList(contactList); - } - - /** - * Adds all protocol supported operation sets. - * - * @param protocolProvider The protocol provider. - */ - public void addProtocolSupportedOperationSets( - ProtocolProviderService protocolProvider) - { - Map supportedOperationSets - = protocolProvider.getSupportedOperationSets(); - - String ppOpSetClassName = OperationSetPersistentPresence - .class.getName(); - String pOpSetClassName = OperationSetPresence.class.getName(); - - // Obtain the presence operation set. - if (supportedOperationSets.containsKey(ppOpSetClassName) - || supportedOperationSets.containsKey(pOpSetClassName)) - { - OperationSetPresence presence = (OperationSetPresence) - supportedOperationSets.get(ppOpSetClassName); - - if(presence == null) { - presence = (OperationSetPresence) - supportedOperationSets.get(pOpSetClassName); - } - - presence.addProviderPresenceStatusListener( - new GUIProviderPresenceStatusListener()); - presence.addContactPresenceStatusListener( - GuiActivator.getContactList()); - } - - // Obtain the basic instant messaging operation set. - String imOpSetClassName = OperationSetBasicInstantMessaging - .class.getName(); - - if (supportedOperationSets.containsKey(imOpSetClassName)) - { - OperationSetBasicInstantMessaging im - = (OperationSetBasicInstantMessaging) - supportedOperationSets.get(imOpSetClassName); - - //Add to all instant messaging operation sets the Message - //listener implemented in the ContactListPanel, which handles - //all received messages. - im.addMessageListener(getContactListPanel()); - } - - // Obtain the typing notifications operation set. - String tnOpSetClassName = OperationSetTypingNotifications - .class.getName(); - - if (supportedOperationSets.containsKey(tnOpSetClassName)) - { - OperationSetTypingNotifications tn - = (OperationSetTypingNotifications) - supportedOperationSets.get(tnOpSetClassName); - - //Add to all typing notification operation sets the Message - //listener implemented in the ContactListPanel, which handles - //all received messages. - tn.addTypingNotificationsListener(this.getContactListPanel()); - } - - // Obtain the basic telephony operation set. - String telOpSetClassName = OperationSetBasicTelephony.class.getName(); - - if (supportedOperationSets.containsKey(telOpSetClassName)) - { - OperationSetBasicTelephony telephony - = (OperationSetBasicTelephony) - supportedOperationSets.get(telOpSetClassName); - - telephony.addCallListener(new CallManager.GuiCallListener()); - } - - // Obtain the multi user chat operation set. - String multiChatClassName = OperationSetMultiUserChat.class.getName(); - - if (supportedOperationSets.containsKey(multiChatClassName)) - { - OperationSetMultiUserChat multiUserChat - = (OperationSetMultiUserChat) - supportedOperationSets.get(multiChatClassName); - - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); - - multiUserChat.addInvitationListener(conferenceManager); - multiUserChat.addInvitationRejectionListener(conferenceManager); - multiUserChat.addPresenceListener(conferenceManager); - } - - // Obtain the ad-hoc multi user chat operation set. - OperationSetAdHocMultiUserChat adHocMultiChatOpSet - = protocolProvider - .getOperationSet(OperationSetAdHocMultiUserChat.class); - - if (adHocMultiChatOpSet != null) - { - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); - - adHocMultiChatOpSet.addInvitationListener(conferenceManager); - adHocMultiChatOpSet.addInvitationRejectionListener(conferenceManager); - adHocMultiChatOpSet.addPresenceListener(conferenceManager); - } - - // Obtain file transfer operation set. - OperationSetFileTransfer fileTransferOpSet - = protocolProvider.getOperationSet(OperationSetFileTransfer.class); - - if (fileTransferOpSet != null) - { - fileTransferOpSet.addFileTransferListener(getContactListPanel()); - } - } - - /** - * Returns a set of all protocol providers. - * - * @return a set of all protocol providers. - */ - public Iterator getProtocolProviders() - { - return new LinkedList( - protocolProviders.keySet()) - .iterator(); - } - - /** - * Returns the protocol provider associated to the account given - * by the account user identifier. - * - * @param accountName The account user identifier. - * @return The protocol provider associated to the given account. - */ - public ProtocolProviderService getProtocolProviderForAccount( - String accountName) - { - for (ProtocolProviderService pps : protocolProviders.keySet()) - { - if (pps.getAccountID().getUserID().equals(accountName)) - { - return pps; - } - } - return null; - } - - /** - * Adds a protocol provider. - * @param protocolProvider The protocol provider to add. - */ - public void addProtocolProvider(ProtocolProviderService protocolProvider) - { - if (logger.isTraceEnabled()) - logger.trace("Add the following protocol provider to the gui: " - + protocolProvider.getAccountID().getAccountAddress()); - - this.protocolProviders.put(protocolProvider, - initiateProviderIndex(protocolProvider)); - - this.addProtocolSupportedOperationSets(protocolProvider); - - this.addAccount(protocolProvider); - - ContactEventHandler contactHandler - = this.getContactHandlerForProvider(protocolProvider); - - if (contactHandler == null) - contactHandler = new DefaultContactEventHandler(this); - - this.addProviderContactHandler(protocolProvider, contactHandler); - } - - /** - * Returns the index of the given protocol provider. - * @param protocolProvider the protocol provider to search for - * @return the index of the given protocol provider - */ - public int getProviderIndex(ProtocolProviderService protocolProvider) - { - Integer o = protocolProviders.get(protocolProvider); - - return (o != null) ? o : 0; - } - - /** - * Adds an account to the application. - * - * @param protocolProvider The protocol provider of the account. - */ - public void addAccount(ProtocolProviderService protocolProvider) - { - if (!accountStatusPanel.containsAccount(protocolProvider)) - { - if (logger.isTraceEnabled()) - logger.trace("Add the following account to the status bar: " - + protocolProvider.getAccountID().getAccountAddress()); - - accountStatusPanel.addAccount(protocolProvider); - - //request the focus in the contact list panel, which - //permits to search in the contact list - this.contactListPanel.getContactList() - .requestFocus(); - } - } - - /** - * Adds an account to the application. - * - * @param protocolProvider The protocol provider of the account. - */ - public void removeProtocolProvider(ProtocolProviderService protocolProvider) - { - this.protocolProviders.remove(protocolProvider); - this.updateProvidersIndexes(protocolProvider); - - if (accountStatusPanel.containsAccount(protocolProvider)) - { - accountStatusPanel.removeAccount(protocolProvider); - } - } - - /** - * Returns the account user id for the given protocol provider. - * @param protocolProvider the protocol provider corresponding to the - * account to add - * @return The account user id for the given protocol provider. - */ - public String getAccount(ProtocolProviderService protocolProvider) - { - return protocolProvider.getAccountID().getUserID(); - } - - /** - * Returns the Web Contact Info operation set for the given - * protocol provider. - * - * @param protocolProvider The protocol provider for which the TN - * is searched. - * @return OperationSetWebContactInfo The Web Contact Info operation - * set for the given protocol provider. - */ - public OperationSetWebContactInfo getWebContactInfoOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetWebContactInfo.class); - - return (opSet instanceof OperationSetWebContactInfo) - ? (OperationSetWebContactInfo) opSet - : null; - } - - /** - * Returns the telephony operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the telephony - * operation set is about. - * @return OperationSetBasicTelephony The telephony operation - * set for the given protocol provider. - */ - public OperationSetBasicTelephony getTelephonyOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetBasicTelephony.class); - - return (opSet instanceof OperationSetBasicTelephony) - ? (OperationSetBasicTelephony) opSet - : null; - } - - /** - * Returns the multi user chat operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the multi user - * chat operation set is about. - * @return OperationSetAdHocMultiUserChat The telephony operation - * set for the given protocol provider. - */ - public OperationSetAdHocMultiUserChat getAdHocMultiUserChatOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet( - OperationSetAdHocMultiUserChat.class); - - return (opSet instanceof OperationSetAdHocMultiUserChat) - ? (OperationSetAdHocMultiUserChat) opSet - : null; - } - - /** - * Returns the multi user chat operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the multi user - * chat operation set is about. - * @return OperationSetMultiUserChat The telephony operation - * set for the given protocol provider. - */ - public OperationSetMultiUserChat getMultiUserChatOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetMultiUserChat.class); - - return (opSet instanceof OperationSetMultiUserChat) - ? (OperationSetMultiUserChat) opSet - : null; - } - - /** - * Listens for all providerStatusChanged and providerStatusMessageChanged - * events in order to refresh the account status panel, when a status is - * changed. - */ - private class GUIProviderPresenceStatusListener - implements ProviderPresenceStatusListener - { - public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) - { - ProtocolProviderService pps = evt.getProvider(); - - accountStatusPanel.updateStatus(pps, evt.getNewStatus()); - } - - public void providerStatusMessageChanged(PropertyChangeEvent evt) {} - } - - /** - * Returns the panel containing the ContactList. - * @return ContactListPanel the panel containing the ContactList - */ - public ContactListPane getContactListPanel() - { - return this.contactListPanel; - } - - /** - * Returns the text currently shown in the search field. - * @return the text currently shown in the search field - */ - public String getCurrentSearchText() - { - return searchField.getText(); - } - - /** - * Clears the current text in the search field. - */ - public void clearCurrentSearchText() - { - searchField.setText(""); - } - - /** - * Adds the given TextFieldChangeListener to listen for any changes - * that occur in the search field. - * @param l the TextFieldChangeListener to add - */ - public void addSearchFieldListener(TextFieldChangeListener l) - { - searchField.addTextChangeListener(l); - } - - /** - * Removes the given TextFieldChangeListener that listens for any - * changes that occur in the search field. - * @param l the TextFieldChangeListener to remove - */ - public void removeSearchFieldListener(TextFieldChangeListener l) - { - searchField.addTextChangeListener(l); - } - - /** - * Checks in the configuration xml if there is already stored index for - * this provider and if yes, returns it, otherwise creates a new account - * index and stores it. - * - * @param protocolProvider the protocol provider - * @return the protocol provider index - */ - private int initiateProviderIndex( - ProtocolProviderService protocolProvider) - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - String prefix = "net.java.sip.communicator.impl.gui.accounts"; - - List accounts = configService - .getPropertyNamesByPrefix(prefix, true); - - for (String accountRootPropName : accounts) { - String accountUID - = configService.getString(accountRootPropName); - - if(accountUID.equals(protocolProvider - .getAccountID().getAccountUniqueID())) - { - String index = configService.getString( - accountRootPropName + ".accountIndex"); - - if(index != null) { - //if we have found the accountIndex for this protocol provider - //return this index - return Integer.parseInt(index); - } - else - { - //if there's no stored accountIndex for this protocol - //provider, calculate the index, set it in the configuration - //service and return it. - - return createAccountIndex(protocolProvider, - accountRootPropName); - } - } - } - - String accNodeName - = "acc" + Long.toString(System.currentTimeMillis()); - - String accountPackage - = "net.java.sip.communicator.impl.gui.accounts." - + accNodeName; - - configService.setProperty(accountPackage, - protocolProvider.getAccountID().getAccountUniqueID()); - - return createAccountIndex(protocolProvider, - accountPackage); - } - - /** - * Creates and calculates the account index for the given protocol - * provider. - * @param protocolProvider the protocol provider - * @param accountRootPropName the path to where the index should be saved - * in the configuration xml - * @return the created index - */ - private int createAccountIndex(ProtocolProviderService protocolProvider, - String accountRootPropName) - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - int accountIndex = -1; - - for (ProtocolProviderService pps : protocolProviders.keySet()) - { - if (pps.getProtocolDisplayName().equals( - protocolProvider.getProtocolDisplayName()) - && !pps.equals(protocolProvider)) - { - - int index = protocolProviders.get(pps); - - if (accountIndex < index) - accountIndex = index; - } - } - accountIndex++; - configService.setProperty( - accountRootPropName + ".accountIndex", - accountIndex); - - return accountIndex; - } - - /** - * Updates the indexes in the configuration xml, when a provider has been - * removed. - * @param removedProvider the removed protocol provider - */ - private void updateProvidersIndexes(ProtocolProviderService removedProvider) - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - String prefix = "net.java.sip.communicator.impl.gui.accounts"; - - ProtocolProviderService currentProvider = null; - int sameProtocolProvidersCount = 0; - - for (ProtocolProviderService pps : protocolProviders.keySet()) { - if(pps.getProtocolDisplayName().equals( - removedProvider.getProtocolDisplayName())) { - - sameProtocolProvidersCount++; - if(sameProtocolProvidersCount > 1) { - break; - } - currentProvider = pps; - } - } - - if(sameProtocolProvidersCount < 2 && currentProvider != null) { - protocolProviders.put(currentProvider, 0); - - List accounts = configService - .getPropertyNamesByPrefix(prefix, true); - - for (String rootPropName : accounts) { - String accountUID - = configService.getString(rootPropName); - - if(accountUID.equals(currentProvider - .getAccountID().getAccountUniqueID())) { - - configService.setProperty( - rootPropName + ".accountIndex", - 0); - } - } - } - } - - /** - * If the protocol provider supports presence operation set searches the - * last status which was selected, otherwise returns null. - * - * @param protocolProvider the protocol provider we're interested in. - * @return the last protocol provider presence status, or null if this - * provider doesn't support presence operation set - */ - public Object getProtocolProviderLastStatus( - ProtocolProviderService protocolProvider) - { - if(getProtocolPresenceOpSet(protocolProvider) != null) - return accountStatusPanel.getLastPresenceStatus(protocolProvider); - else - return accountStatusPanel.getLastStatusString(protocolProvider); - } - - /** - * RenameAction is invoked when user presses the F2 key. Depending - * on the selection opens the appropriate form for renaming. - */ - private class RenameAction extends AbstractAction - { - private static final long serialVersionUID = 0L; - - public void actionPerformed(ActionEvent e) - { - Object selectedObject - = GuiActivator.getContactList().getSelectionPath() - .getLastPathComponent(); - - if(selectedObject instanceof MetaContact) { - RenameContactDialog dialog = new RenameContactDialog( - MainFrameStandard.this, (MetaContact)selectedObject); - - dialog.setLocation( - Toolkit.getDefaultToolkit().getScreenSize().width/2 - - 200, - Toolkit.getDefaultToolkit().getScreenSize().height/2 - - 50 - ); - - dialog.setVisible(true); - - dialog.requestFocusInFiled(); - } - else if(selectedObject instanceof MetaContactGroup) { - - RenameGroupDialog dialog = new RenameGroupDialog( - MainFrameStandard.this, (MetaContactGroup)selectedObject); - - Dimension screenSize = - Toolkit.getDefaultToolkit().getScreenSize(); - dialog.setLocation(screenSize.width / 2 - 200, - screenSize.height / 2 - 50); - - dialog.setVisible(true); - - dialog.requestFocusInFiled(); - } - } - } - - /** - * Overwrites the SIPCommFrame close method. This method is - * invoked when user presses the Escape key. - * @param isEscaped indicates if this window has been closed by pressing - * the escape key - */ - protected void close(boolean isEscaped) - { - TreeContactList contactList = GuiActivator.getContactList(); - - Component contactListRightMenu - = contactList.getRightButtonMenu(); - - CommonRightButtonMenu commonPopupMenu - = getContactListPanel().getCommonRightButtonMenu(); - - if(contactListRightMenu != null && contactListRightMenu.isVisible()) - { - contactListRightMenu.setVisible(false); - } - else if(commonPopupMenu != null && commonPopupMenu.isVisible()) - { - commonPopupMenu.setVisible(false); - } - else if(accountStatusPanel.hasSelectedMenus() - || menu.hasSelectedMenus()) - { - MenuSelectionManager selectionManager - = MenuSelectionManager.defaultManager(); - - selectionManager.clearSelectedPath(); - } - } - - /** - * Returns the main menu in the application window. - * @return the main menu in the application window - */ - public MainMenu getMainMenu() - { - return menu; - } - - /** - * - * @param protocolProvider - * @param contactHandler - */ - public void addProviderContactHandler( - ProtocolProviderService protocolProvider, - ContactEventHandler contactHandler) - { - providerContactHandlers.put(protocolProvider, contactHandler); - } - - /** - * Returns the ContactEventHandler registered for this protocol - * provider. - * - * @param protocolProvider the ProtocolProviderService for which - * we are searching a ContactEventHandler. - * @return the ContactEventHandler registered for this protocol - * provider - */ - public ContactEventHandler getContactHandler( - ProtocolProviderService protocolProvider) - { - return providerContactHandlers.get(protocolProvider); - } - - /** - * Returns the ContactEventHandler for contacts given by the - * protocolProvider. The ContactEventHandler is meant to - * be used from other bundles in order to change the default behavior of - * events generated when clicking a contact. - * @param protocolProvider the protocol provider for which we want to obtain - * a contact event handler - * @return the ContactEventHandler for contacts given by the - * protocolProvider - */ - private ContactEventHandler getContactHandlerForProvider( - ProtocolProviderService protocolProvider) - { - ServiceReference[] serRefs = null; - - String osgiFilter = "(" - + ProtocolProviderFactory.PROTOCOL - + "=" + protocolProvider.getProtocolName()+")"; - - try - { - serRefs = GuiActivator.bundleContext.getServiceReferences( - ContactEventHandler.class.getName(), osgiFilter); - } - catch (InvalidSyntaxException ex){ - logger.error("GuiActivator : " + ex); - } - - if(serRefs == null) - return null; - - return (ContactEventHandler) GuiActivator.bundleContext - .getService(serRefs[0]); - } - - /** - * Initialize plugin components already registered for this container. - */ - private void initPluginComponents() - { - pluginPanelSouth.setLayout( - new BoxLayout(pluginPanelSouth, BoxLayout.Y_AXIS)); - pluginPanelNorth.setLayout( - new BoxLayout(pluginPanelNorth, BoxLayout.Y_AXIS)); - pluginPanelEast.setLayout( - new BoxLayout(pluginPanelEast, BoxLayout.Y_AXIS)); - pluginPanelWest.setLayout( - new BoxLayout(pluginPanelWest, BoxLayout.Y_AXIS)); - - java.awt.Container contentPane = getContentPane(); - contentPane.add(pluginPanelNorth, BorderLayout.NORTH); - contentPane.add(pluginPanelEast, BorderLayout.EAST); - contentPane.add(pluginPanelWest, BorderLayout.WEST); - this.mainPanel.add(pluginPanelSouth, BorderLayout.SOUTH); - - // Search for plugin components registered through the OSGI bundle - // context. - ServiceReference[] serRefs = null; - - try - { - serRefs - = GuiActivator - .bundleContext - .getServiceReferences( - PluginComponent.class.getName(), - "(|(" - + Container.CONTAINER_ID - + "=" - + Container.CONTAINER_MAIN_WINDOW.getID() - + ")(" - + Container.CONTAINER_ID - + "=" - + Container.CONTAINER_STATUS_BAR.getID() - + "))"); - } - catch (InvalidSyntaxException exc) - { - logger.error("Could not obtain plugin reference.", exc); - } - - if (serRefs != null) - { - for (ServiceReference serRef : serRefs) - { - PluginComponent c - = (PluginComponent) - GuiActivator.bundleContext.getService(serRef); - - if (c.isNativeComponent()) - nativePluginsTable.put(c, new JPanel()); - else - { - String pluginConstraints = c.getConstraints(); - Object constraints; - - if (pluginConstraints != null) - constraints - = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - pluginConstraints); - else - constraints = BorderLayout.SOUTH; - - this.addPluginComponent((Component) c.getComponent(), c - .getContainer(), constraints); - } - } - } - - GuiActivator.getUIService().addPluginComponentListener(this); - } - - /** - * Adds the associated with this PluginComponentEvent component to - * the appropriate container. - * @param event the PluginComponentEvent that has notified us of - * the add of a plugin component - */ - public void pluginComponentAdded(PluginComponentEvent event) - { - PluginComponent pluginComponent = event.getPluginComponent(); - Container pluginContainer = pluginComponent.getContainer(); - - if (pluginContainer.equals(Container.CONTAINER_MAIN_WINDOW) - || pluginContainer.equals(Container.CONTAINER_STATUS_BAR)) - { - String pluginConstraints = pluginComponent.getConstraints(); - Object constraints; - - if (pluginConstraints != null) - constraints = - UIServiceImpl - .getBorderLayoutConstraintsFromContainer(pluginConstraints); - else - constraints = BorderLayout.SOUTH; - - if (pluginComponent.isNativeComponent()) - { - this.nativePluginsTable.put(pluginComponent, new JPanel()); - - if (isVisible()) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - addNativePlugins(); - } - }); - } - } - else - { - this.addPluginComponent((Component) pluginComponent - .getComponent(), pluginContainer, constraints); - } - } - } - - /** - * Removes the associated with this PluginComponentEvent component - * from this container. - * @param event the PluginComponentEvent that notified us of the - * remove of a plugin component - */ - public void pluginComponentRemoved(PluginComponentEvent event) - { - final PluginComponent pluginComponent = event.getPluginComponent(); - final Container containerID = pluginComponent.getContainer(); - - if (containerID.equals(Container.CONTAINER_MAIN_WINDOW)) - { - Object constraints = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - pluginComponent.getConstraints()); - - if (constraints == null) - constraints = BorderLayout.SOUTH; - - if (pluginComponent.isNativeComponent()) - { - if (nativePluginsTable.containsKey(pluginComponent)) - { - final Component c = nativePluginsTable.get(pluginComponent); - final Object finalConstraints = constraints; - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - removePluginComponent(c, containerID, - finalConstraints); - - getContentPane().repaint(); - } - }); - } - } - else - { - this.removePluginComponent((Component) pluginComponent - .getComponent(), containerID, constraints); - } - - nativePluginsTable.remove(pluginComponent); - } - } - - /** - * Removes all native plugins from this container. - */ - private void removeNativePlugins() - { - for (Map.Entry entry - : nativePluginsTable.entrySet()) - { - PluginComponent pluginComponent = entry.getKey(); - Component c = entry.getValue(); - - Object constraints - = UIServiceImpl - .getBorderLayoutConstraintsFromContainer(pluginComponent - .getConstraints()); - - if (constraints == null) - constraints = BorderLayout.SOUTH; - - this.removePluginComponent(c, pluginComponent.getContainer(), - constraints); - - this.getContentPane().repaint(); - } - } - - /** - * Adds all native plugins to this container. - */ - public void addNativePlugins() - { - this.removeNativePlugins(); - - for (Map.Entry pluginEntry - : nativePluginsTable.entrySet()) - { - PluginComponent plugin = pluginEntry.getKey(); - Object constraints - = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - plugin.getConstraints()); - - Component c = (Component) plugin.getComponent(); - - this.addPluginComponent(c, plugin.getContainer(), constraints); - - this.nativePluginsTable.put(plugin, c); - } - } - - /** - * Brings this window to front. - */ - public void bringToFront() - { - this.toFront(); - } - - /** - * Returns the identifier of this window. - * @return the identifier of this window - */ - public WindowID getIdentifier() - { - return ExportedWindow.MAIN_WINDOW; - } - - /** - * Returns this window. - * @return this window - */ - public Object getSource() - { - return this; - } - - /** - * Maximizes this window. - */ - public void maximize() - { - this.setExtendedState(JFrame.MAXIMIZED_BOTH); - } - - /** - * Minimizes this window. - */ - public void minimize() - { - this.setExtendedState(JFrame.ICONIFIED); - } - - /** - * Implements isVisible in the UIService interface. Checks if - * the main application window is visible. - * - * @return true if main application window is visible, - * false otherwise - * @see UIService#isVisible() - */ - public boolean isVisible() - { - return super.isVisible() - && (super.getExtendedState() != JFrame.ICONIFIED); - } - - /** - * Implements setVisible in the UIService interface. Shows or - * hides the main application window depending on the parameter - * visible. - * - * @param isVisible true if we are to show the main application frame and - * false otherwise. - * - * @see UIService#setVisible(boolean) - */ - public void setVisible(final boolean isVisible) - { - SwingUtilities.invokeLater(new Runnable(){ - public void run() - { - if(isVisible) - { - MainFrameStandard.this.addNativePlugins(); - MainFrameStandard.super.setVisible(isVisible); - MainFrameStandard.super.setExtendedState(MainFrameStandard.NORMAL); - MainFrameStandard.super.toFront(); - } - else - { - MainFrameStandard.super.setVisible(isVisible); - } - } - }); - } - - /** - * Adds the given component with to the container corresponding to the - * given constraints. - * - * @param c the component to add - * @param container the container to which to add the given component - * @param constraints the constraints determining the container - */ - private void addPluginComponent(Component c, - Container container, - Object constraints) - { - if (container.equals(Container.CONTAINER_MAIN_WINDOW)) - { - if (constraints.equals(BorderLayout.NORTH)) - { - pluginPanelNorth.add(c); - pluginPanelNorth.repaint(); - } - else if (constraints.equals(BorderLayout.SOUTH)) - { - pluginPanelSouth.add(c); - pluginPanelSouth.repaint(); - } - else if (constraints.equals(BorderLayout.WEST)) - { - pluginPanelWest.add(c); - pluginPanelWest.repaint(); - } - else if (constraints.equals(BorderLayout.EAST)) - { - pluginPanelEast.add(c); - pluginPanelEast.repaint(); - } - } - else if (container.equals(Container.CONTAINER_STATUS_BAR)) - { - statusBarPanel.add(c); - } - - this.getContentPane().repaint(); - this.getContentPane().validate(); - } - - /** - * Removes the given component from the container corresponding to the given - * constraints. - * - * @param c the component to remove - * @param container the container from which to remove the given component - * @param constraints the constraints determining the container - */ - private void removePluginComponent( Component c, - Container container, - Object constraints) - { - if (container.equals(Container.CONTAINER_MAIN_WINDOW)) - { - if (constraints.equals(BorderLayout.NORTH)) - pluginPanelNorth.remove(c); - else if (constraints.equals(BorderLayout.SOUTH)) - pluginPanelSouth.remove(c); - else if (constraints.equals(BorderLayout.WEST)) - pluginPanelWest.remove(c); - else if (constraints.equals(BorderLayout.EAST)) - pluginPanelEast.remove(c); - } - else if (container.equals(Container.CONTAINER_STATUS_BAR)) - { - this.statusBarPanel.remove(c); - } - } - - /** - * Returns the account status panel. - * @return the account status panel. - */ - public AccountStatusPanel getAccountStatusPanel() - { - return accountStatusPanel; - } - - /** - * Implementation of {@link ExportedWindow#setParams(Object[])}. - */ - public void setParams(Object[] windowParams) {} - - /** - * @param event Currently not used - */ - protected void windowClosed(WindowEvent event) - { - if(GuiActivator.getUIService().getExitOnMainWindowClose()) - { - try - { - GuiActivator.bundleContext.getBundle(0).stop(); - } - catch (BundleException ex) - { - logger.error("Failed to gently shutdown Felix", ex); - System.exit(0); - } - //stopping a bundle doesn't leave the time to the felix thread to - //properly end all bundles and call their Activator.stop() methods. - //if this causes problems don't uncomment the following line but - //try and see why felix isn't exiting (suggesting: is it running - //in embedded mode?) - //System.exit(0); - } - } - - /** - * Overrides SIPCommFrame#windowClosing(WindowEvent). Reflects the closed - * state of this MainFrame in the configuration in order to make it - * accessible to interested parties, displays the warning that the - * application will not quit. - * @param event the WindowEvent that notified us - */ - protected void windowClosing(WindowEvent event) - { - super.windowClosing(event); - - if (!GuiActivator.getUIService().getExitOnMainWindowClose()) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - if (ConfigurationManager.isQuitWarningShown()) - { - MessageDialog dialog = - new MessageDialog(null, - GuiActivator.getResources().getI18NString( - "service.gui.CLOSE"), - GuiActivator.getResources().getI18NString( - "service.gui.HIDE_MAIN_WINDOW"), false); - - if (dialog.showDialog() == MessageDialog.OK_DONT_ASK_CODE) - ConfigurationManager.setQuitWarningShown(false); - } - } - }); - - ConfigurationManager.setApplicationVisible(false); - } - } - - /** - * The MainKeyDispatcher is added to pre-listen KeyEvents before - * they're delivered to the current focus owner in order to introduce a - * specific behavior for the SearchField on top of the contact - * list. - */ - private class MainKeyDispatcher implements KeyEventDispatcher - { - private KeyboardFocusManager keyManager; - - /** - * Creates an instance of MainKeyDispatcher. - * @param keyManager the parent KeyboardFocusManager - */ - public MainKeyDispatcher(KeyboardFocusManager keyManager) - { - this.keyManager = keyManager; - } - - /** - * Dispatches the given KeyEvent. - * @param e the KeyEvent to dispatch - * @return true if the KeyboardFocusManager should take no - * further action with regard to the KeyEvent; false - * otherwise - */ - public boolean dispatchKeyEvent(KeyEvent e) - { - // If this window is not the focus window or if the event is not - // of type PRESSED we have nothing more to do here. - if (!isFocused() - || (e.getID() != KeyEvent.KEY_PRESSED - && e.getID() != KeyEvent.KEY_TYPED)) - return false; - - // Ctrl-Enter || Cmd-Enter typed when this window is the focused - // window. - // - // Tried to make this with key bindings first, but has a problem - // with enter key binding. When the popup menu containing call - // contacts was opened the default keyboard manager was prioritizing - // the window ENTER key, which will open a chat and we wanted that - // the enter starts a call with the selected contact from the menu. - // This is why we need to do it here and to check if the - // permanent focus owner is equal to the focus owner, which is not - // the case when a popup menu is opened. - if (e.getKeyCode() == KeyEvent.VK_ENTER - && (e.isControlDown() || e.isMetaDown())) - { - ctrlEnterKeyTyped(); - return false; - } - else if (e.getKeyCode() == KeyEvent.VK_ENTER - && keyManager.getFocusOwner() - .equals(keyManager.getPermanentFocusOwner())) - { - enterKeyTyped(); - return false; - } - - TreeContactList contactList - = getContactListPanel().getContactList(); - - // If the search field is the focus owner. - if (searchField.isFocusOwner() - && (e.getKeyCode() == KeyEvent.VK_UP - || e.getKeyCode() == KeyEvent.VK_DOWN - || e.getKeyCode() == KeyEvent.VK_PAGE_UP - || e.getKeyCode() == KeyEvent.VK_PAGE_DOWN)) - { - contactList.selectFirstContact(); - contactList.requestFocus(); - return false; - } - - // If the contact list is the focus owner. - if (contactList.isFocusOwner() - && e.getKeyCode() == KeyEvent.VK_ESCAPE) - { - // Removes all current selections. - contactList.removeSelectionRows(contactList.getSelectionRows()); - - if (searchField.getText() != null) - { - searchField.requestFocus(); - } - return false; - } - TreePath selectionPath = contactList.getSelectionPath(); - - // No matter who is the focus owner. - if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED - || e.getKeyCode() == KeyEvent.VK_ENTER - || e.getKeyCode() == KeyEvent.VK_DELETE - || e.getKeyCode() == KeyEvent.VK_BACK_SPACE - || e.getKeyCode() == KeyEvent.VK_TAB - || e.getKeyCode() == KeyEvent.VK_SPACE - || (selectionPath != null - && selectionPath.getLastPathComponent() instanceof GroupNode - && (e.getKeyChar() == '+' - || e.getKeyChar() == '-'))) - { - return false; - } - - if (!searchField.isFocusOwner() - && keyManager.getFocusOwner() != null - && keyManager.getFocusOwner() - .equals(keyManager.getPermanentFocusOwner())) - { - // Request the focus in the search field if a letter is typed. - searchField.requestFocusInWindow(); - - // We re-dispatch the event to search field. - keyManager.redispatchEvent(searchField, e); - - // We don't want to dispatch further this event. - return true; - } - return false; - } - } - - /** - * Called when the ENTER key was typed when this window was the focused - * window. Performs the appropriate actions depending on the current state - * of the contact list. - */ - private void enterKeyTyped() - { - if (unknownContactPanel != null && unknownContactPanel.isVisible()) - { - unknownContactPanel.addUnknownContact(); - } - else if (contactListPanel.isVisible()) - { - // Starts a chat with the currently selected contact. - GuiActivator.getContactList().startSelectedContactChat(); - } - } - - /** - * Called when the CTRL-ENTER or CMD-ENTER keys were typed when this window - * was the focused window. Performs the appropriate actions depending on the - * current state of the contact list. - */ - public void ctrlEnterKeyTyped() - { - if (unknownContactPanel != null && unknownContactPanel.isVisible()) - { - unknownContactPanel.startCall(); - } - else if (contactListPanel.isVisible()) - { - // Starts a chat with the currently selected contact. - GuiActivator.getContactList().startSelectedContactCall(); - } - } -} \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrameTouch.java b/src/net/java/sip/communicator/impl/gui/main/MainFrameTouch.java deleted file mode 100644 index 5679ebd..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrameTouch.java +++ /dev/null @@ -1,1688 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.main; - -import java.awt.*; -import java.awt.event.*; -import java.beans.PropertyChangeEvent; -import java.util.*; -import java.util.List; - -import javax.swing.*; -import javax.swing.tree.*; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.customcontrols.*; -import net.java.sip.communicator.impl.gui.event.*; -import net.java.sip.communicator.impl.gui.main.call.*; -import net.java.sip.communicator.impl.gui.main.chat.conference.*; -import net.java.sip.communicator.impl.gui.main.contactlist.*; -import net.java.sip.communicator.impl.gui.main.menus.*; -import net.java.sip.communicator.impl.gui.main.presence.*; -import net.java.sip.communicator.impl.gui.utils.*; -import net.java.sip.communicator.service.configuration.*; -import net.java.sip.communicator.service.contacteventhandler.*; -import net.java.sip.communicator.service.contactlist.*; -import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.gui.Container; -import net.java.sip.communicator.service.keybindings.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.service.resources.*; -import net.java.sip.communicator.util.*; -import net.java.sip.communicator.util.swing.*; -import net.java.sip.communicator.util.swing.event.*; - -import org.osgi.framework.*; - -/** - * The main application window. This class is the core of this UI - * implementation. It stores all available protocol providers and their - * operation sets, as well as all registered accounts, the - * MetaContactListService and all sent messages that aren't - * delivered yet. - * - * This class implements the GUI for touch screen only devices. In - * additiona to the standard interface class it uses a tabbed pane - * to display a dialpanel in the first tab and the contactlist in - * the second panel. - * - * @author Yana Stamcheva - * @author Lubomir Marinov - * @author Werner Dittmann - */ -public class MainFrameTouch - extends MainFrame -{ - /** - * The logger. - */ - private final Logger logger = Logger.getLogger(MainFrameTouch.class); - - /** - * The main container. - */ - private final TransparentPanel mainPanel - = new TransparentPanel(new BorderLayout(0, 0)); - - /** - * The status bar panel. - */ - private final TransparentPanel statusBarPanel - = new TransparentPanel(new BorderLayout()); - - /** - * The center panel, containing the contact list. - */ - private final TransparentPanel centerPanel - = new TransparentPanel(new BorderLayout(0, 0)); - - /** - * The dial panel. - */ - private final DialPanel dialPanel; - - private final JTabbedPane mainTabPanel = new JTabbedPane(); - /** - * The main menu. - */ - private MainMenu menu; - - /** - * The search field shown above the contact list. - */ - private final SearchField searchField; - - /** - * A mapping of ProtocolProviderServices and their indexes. - */ - private final HashMap protocolProviders - = new LinkedHashMap(); - - /** - * The panel containing the accounts status menu. - */ - private AccountStatusPanel accountStatusPanel; - - /** - * The panel replacing the contact list, shown when no matching is found - * for the search filter. - */ - private UnknownContactPanel unknownContactPanel; - - /** - * A mapping of ProtocolProviderServices and corresponding - * ContactEventHandlers. - */ - private final Map - providerContactHandlers = - new Hashtable(); - - /** - * A mapping of plug-in components and their corresponding native components. - */ - private final Map nativePluginsTable = - new Hashtable(); - - /** - * The north plug-in panel. - */ - private final JPanel pluginPanelNorth = new TransparentPanel(); - - /** - * The south plug-in panel. - */ - private final JPanel pluginPanelSouth = new TransparentPanel(); - - /** - * The west plug-in panel. - */ - private final JPanel pluginPanelWest = new TransparentPanel(); - - /** - * The east plug-in panel. - */ - private final JPanel pluginPanelEast = new TransparentPanel(); - - /** - * The container containing the contact list. - */ - private ContactListPane contactListPanel; - - /** - * Creates an instance of MainFrame. - */ - public MainFrameTouch() - { - if (!ConfigurationManager.isWindowDecorated()) - { - this.setUndecorated(true); - } - - this.searchField = new SearchField(this); - - this.contactListPanel = new ContactListPane(this); - - this.accountStatusPanel = new AccountStatusPanel(this); - - this.dialPanel = new DialPanel(this, searchField); - - menu = new MainMenu(this); - - /* - * If the application is configured to quit when this frame is closed, - * do so. - */ - this.addWindowListener(new WindowAdapter() - { - /** - * Invoked when a window has been closed. - */ - public void windowClosed(WindowEvent event) - { - MainFrameTouch.this.windowClosed(event); - } - /** - * Invoked when a window has been opened. - */ - public void windowOpened(WindowEvent e) - { - GuiActivator.getContactList().requestFocusInWindow(); - } - }); - - this.initTitleFont(); - - ResourceManagementService resources = GuiActivator.getResources(); - String applicationName - = resources.getSettingsString("service.gui.APPLICATION_NAME"); - - this.setTitle(applicationName); - - this.mainPanel.setBackground(new Color( - GuiActivator.getResources() - .getColor("service.gui.MAIN_WINDOW_BACKGROUND"))); - - KeyboardFocusManager keyManager - = KeyboardFocusManager.getCurrentKeyboardFocusManager(); - keyManager.addKeyEventDispatcher(new MainKeyDispatcher(keyManager)); - - this.init(); - - this.initPluginComponents(); - } - - /** - * Requests the focus in the center panel, which contains either the - * contact list or the unknown contact panel. - */ - public void requestFocusInCenterPanel() - { -// centerPanel.requestFocusInWindow(); - mainTabPanel.requestFocusInWindow(); - } - - /** - * Initiates the content of this frame. - */ - private void init() - { - setDefaultCloseOperation( - GuiActivator.getUIService().getExitOnMainWindowClose() - ? JFrame.DISPOSE_ON_CLOSE - : JFrame.HIDE_ON_CLOSE); - - this.setKeybindingInput(KeybindingSet.Category.MAIN); - this.addKeybindingAction("main-rename", - new RenameAction()); - - // Remove the default escape key mapping as its a special - // one for the main frame and the contactlist - getRootPane().getInputMap( - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) - .remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); - - TransparentPanel northPanel - = new TransparentPanel(new BorderLayout(0, 0)); - - this.setJMenuBar(menu); - - northPanel.add(accountStatusPanel, BorderLayout.CENTER); - - TransparentPanel searchPanel - = new TransparentPanel(new BorderLayout(2, 0)); - searchPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5)); - searchPanel.add(searchField); - searchPanel.add(new CallHistoryButton(), BorderLayout.EAST); - - northPanel.add(searchPanel, BorderLayout.SOUTH); - - centerPanel.add(contactListPanel, BorderLayout.CENTER); - - mainTabPanel.addTab( - GuiActivator.getResources().getI18NString("service.gui.CALL"), - dialPanel); - mainTabPanel.addTab( - GuiActivator.getResources().getI18NString( - "service.gui.CONTACTS"), centerPanel); - - this.mainPanel.add(northPanel, BorderLayout.NORTH); - this.mainPanel.add(mainTabPanel, BorderLayout.CENTER); - - java.awt.Container contentPane = getContentPane(); - contentPane.add(mainPanel, BorderLayout.CENTER); - contentPane.add(statusBarPanel, BorderLayout.SOUTH); - this.requestFocus(); - } - - /** - * Sets frame size and position. - */ - public void initBounds() - { - int width = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_WIDTH"); - - int height = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_HEIGHT"); - - int minWidth = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_MIN_WIDTH"); - - int minHeight = GuiActivator.getResources() - .getSettingsInt("impl.gui.MAIN_WINDOW_MIN_HEIGHT"); - - this.getContentPane().setMinimumSize(new Dimension(minWidth, minHeight)); - - this.setSize(width, height); - - this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width - - this.getWidth(), 50); - } - - /** - * Initialize main window font. - */ - private void initTitleFont() - { - JComponent layeredPane = this.getLayeredPane(); - - ResourceManagementService resources = GuiActivator.getResources(); - String fontName - = resources.getSettingsString("service.gui.FONT_NAME"); - - String titleFontSize - = resources.getSettingsString("service.gui.FONT_SIZE"); - - Font font = new Font( fontName, - Font.BOLD, - Integer.parseInt(titleFontSize)); - - final int componentCount = layeredPane.getComponentCount(); - for (int i = 0; i < componentCount; i++) - { - layeredPane.getComponent(i).setFont(font); - } - } - - /** - * Enters or exits the "unknown contact" view. This view will propose to - * the user some specific operations if the current filter doesn't match - * any contacts. - * @param isEnabled true to enable the "unknown contact" view, - * false - otherwise. - */ - public void enableUnknownContactView(boolean isEnabled) - { - if (isEnabled) - { - if (unknownContactPanel == null) - unknownContactPanel = new UnknownContactPanel(this); - - if (unknownContactPanel.getParent() != centerPanel) - { - contactListPanel.setVisible(false); - unknownContactPanel.setVisible(true); - centerPanel.remove(contactListPanel); - centerPanel.add(unknownContactPanel, BorderLayout.CENTER); - } - } - else - { - if (contactListPanel.getParent() != centerPanel) - { - if (unknownContactPanel != null) - { - unknownContactPanel.setVisible(false); - centerPanel.remove(unknownContactPanel); - } - contactListPanel.setVisible(true); - centerPanel.add(contactListPanel, BorderLayout.CENTER); - } - } - centerPanel.revalidate(); - centerPanel.repaint(); - } - - /** - * Initializes the contact list panel. - * - * @param contactList The MetaContactListService containing - * the contact list data. - */ - public void setContactList(MetaContactListService contactList) - { - contactListPanel.initList(contactList); - } - - /** - * Adds all protocol supported operation sets. - * - * @param protocolProvider The protocol provider. - */ - public void addProtocolSupportedOperationSets( - ProtocolProviderService protocolProvider) - { - Map supportedOperationSets - = protocolProvider.getSupportedOperationSets(); - - String ppOpSetClassName = OperationSetPersistentPresence - .class.getName(); - String pOpSetClassName = OperationSetPresence.class.getName(); - - // Obtain the presence operation set. - if (supportedOperationSets.containsKey(ppOpSetClassName) - || supportedOperationSets.containsKey(pOpSetClassName)) - { - OperationSetPresence presence = (OperationSetPresence) - supportedOperationSets.get(ppOpSetClassName); - - if(presence == null) { - presence = (OperationSetPresence) - supportedOperationSets.get(pOpSetClassName); - } - - presence.addProviderPresenceStatusListener( - new GUIProviderPresenceStatusListener()); - presence.addContactPresenceStatusListener( - GuiActivator.getContactList()); - } - - // Obtain the basic instant messaging operation set. - String imOpSetClassName = OperationSetBasicInstantMessaging - .class.getName(); - - if (supportedOperationSets.containsKey(imOpSetClassName)) - { - OperationSetBasicInstantMessaging im - = (OperationSetBasicInstantMessaging) - supportedOperationSets.get(imOpSetClassName); - - //Add to all instant messaging operation sets the Message - //listener implemented in the ContactListPanel, which handles - //all received messages. - im.addMessageListener(getContactListPanel()); - } - - // Obtain the typing notifications operation set. - String tnOpSetClassName = OperationSetTypingNotifications - .class.getName(); - - if (supportedOperationSets.containsKey(tnOpSetClassName)) - { - OperationSetTypingNotifications tn - = (OperationSetTypingNotifications) - supportedOperationSets.get(tnOpSetClassName); - - //Add to all typing notification operation sets the Message - //listener implemented in the ContactListPanel, which handles - //all received messages. - tn.addTypingNotificationsListener(this.getContactListPanel()); - } - - // Obtain the basic telephony operation set. - String telOpSetClassName = OperationSetBasicTelephony.class.getName(); - - if (supportedOperationSets.containsKey(telOpSetClassName)) - { - OperationSetBasicTelephony telephony - = (OperationSetBasicTelephony) - supportedOperationSets.get(telOpSetClassName); - - telephony.addCallListener(new CallManager.GuiCallListener()); - } - - // Obtain the multi user chat operation set. - String multiChatClassName = OperationSetMultiUserChat.class.getName(); - - if (supportedOperationSets.containsKey(multiChatClassName)) - { - OperationSetMultiUserChat multiUserChat - = (OperationSetMultiUserChat) - supportedOperationSets.get(multiChatClassName); - - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); - - multiUserChat.addInvitationListener(conferenceManager); - multiUserChat.addInvitationRejectionListener(conferenceManager); - multiUserChat.addPresenceListener(conferenceManager); - } - - // Obtain the ad-hoc multi user chat operation set. - OperationSetAdHocMultiUserChat adHocMultiChatOpSet - = protocolProvider - .getOperationSet(OperationSetAdHocMultiUserChat.class); - - if (adHocMultiChatOpSet != null) - { - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); - - adHocMultiChatOpSet.addInvitationListener(conferenceManager); - adHocMultiChatOpSet.addInvitationRejectionListener(conferenceManager); - adHocMultiChatOpSet.addPresenceListener(conferenceManager); - } - - // Obtain file transfer operation set. - OperationSetFileTransfer fileTransferOpSet - = protocolProvider.getOperationSet(OperationSetFileTransfer.class); - - if (fileTransferOpSet != null) - { - fileTransferOpSet.addFileTransferListener(getContactListPanel()); - } - } - - /** - * Returns a set of all protocol providers. - * - * @return a set of all protocol providers. - */ - public Iterator getProtocolProviders() - { - return new LinkedList( - protocolProviders.keySet()) - .iterator(); - } - - /** - * Returns the protocol provider associated to the account given - * by the account user identifier. - * - * @param accountName The account user identifier. - * @return The protocol provider associated to the given account. - */ - public ProtocolProviderService getProtocolProviderForAccount( - String accountName) - { - for (ProtocolProviderService pps : protocolProviders.keySet()) - { - if (pps.getAccountID().getUserID().equals(accountName)) - { - return pps; - } - } - return null; - } - - /** - * Adds a protocol provider. - * @param protocolProvider The protocol provider to add. - */ - public void addProtocolProvider(ProtocolProviderService protocolProvider) - { - if (logger.isTraceEnabled()) - logger.trace("Add the following protocol provider to the gui: " - + protocolProvider.getAccountID().getAccountAddress()); - - this.protocolProviders.put(protocolProvider, - initiateProviderIndex(protocolProvider)); - - this.addProtocolSupportedOperationSets(protocolProvider); - - this.addAccount(protocolProvider); - - ContactEventHandler contactHandler - = this.getContactHandlerForProvider(protocolProvider); - - if (contactHandler == null) - contactHandler = new DefaultContactEventHandler(this); - - this.addProviderContactHandler(protocolProvider, contactHandler); - } - - /** - * Returns the index of the given protocol provider. - * @param protocolProvider the protocol provider to search for - * @return the index of the given protocol provider - */ - public int getProviderIndex(ProtocolProviderService protocolProvider) - { - Integer o = protocolProviders.get(protocolProvider); - - return (o != null) ? o : 0; - } - - /** - * Adds an account to the application. - * - * @param protocolProvider The protocol provider of the account. - */ - public void addAccount(ProtocolProviderService protocolProvider) - { - if (!accountStatusPanel.containsAccount(protocolProvider)) - { - if (logger.isTraceEnabled()) - logger.trace("Add the following account to the status bar: " - + protocolProvider.getAccountID().getAccountAddress()); - - accountStatusPanel.addAccount(protocolProvider); - - //request the focus in the contact list panel, which - //permits to search in the contact list - this.contactListPanel.getContactList() - .requestFocus(); - } - } - - /** - * Adds an account to the application. - * - * @param protocolProvider The protocol provider of the account. - */ - public void removeProtocolProvider(ProtocolProviderService protocolProvider) - { - this.protocolProviders.remove(protocolProvider); - this.updateProvidersIndexes(protocolProvider); - - if (accountStatusPanel.containsAccount(protocolProvider)) - { - accountStatusPanel.removeAccount(protocolProvider); - } - } - - /** - * Returns the account user id for the given protocol provider. - * @param protocolProvider the protocol provider corresponding to the - * account to add - * @return The account user id for the given protocol provider. - */ - public String getAccount(ProtocolProviderService protocolProvider) - { - return protocolProvider.getAccountID().getUserID(); - } - - /** - * Returns the Web Contact Info operation set for the given - * protocol provider. - * - * @param protocolProvider The protocol provider for which the TN - * is searched. - * @return OperationSetWebContactInfo The Web Contact Info operation - * set for the given protocol provider. - */ - public OperationSetWebContactInfo getWebContactInfoOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetWebContactInfo.class); - - return (opSet instanceof OperationSetWebContactInfo) - ? (OperationSetWebContactInfo) opSet - : null; - } - - /** - * Returns the telephony operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the telephony - * operation set is about. - * @return OperationSetBasicTelephony The telephony operation - * set for the given protocol provider. - */ - public OperationSetBasicTelephony getTelephonyOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetBasicTelephony.class); - - return (opSet instanceof OperationSetBasicTelephony) - ? (OperationSetBasicTelephony) opSet - : null; - } - - /** - * Returns the multi user chat operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the multi user - * chat operation set is about. - * @return OperationSetAdHocMultiUserChat The telephony operation - * set for the given protocol provider. - */ - public OperationSetAdHocMultiUserChat getAdHocMultiUserChatOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet( - OperationSetAdHocMultiUserChat.class); - - return (opSet instanceof OperationSetAdHocMultiUserChat) - ? (OperationSetAdHocMultiUserChat) opSet - : null; - } - - /** - * Returns the multi user chat operation set for the given protocol provider. - * - * @param protocolProvider The protocol provider for which the multi user - * chat operation set is about. - * @return OperationSetMultiUserChat The telephony operation - * set for the given protocol provider. - */ - public OperationSetMultiUserChat getMultiUserChatOpSet( - ProtocolProviderService protocolProvider) - { - OperationSet opSet - = protocolProvider.getOperationSet(OperationSetMultiUserChat.class); - - return (opSet instanceof OperationSetMultiUserChat) - ? (OperationSetMultiUserChat) opSet - : null; - } - - /** - * Listens for all providerStatusChanged and providerStatusMessageChanged - * events in order to refresh the account status panel, when a status is - * changed. - */ - private class GUIProviderPresenceStatusListener - implements ProviderPresenceStatusListener - { - public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) - { - ProtocolProviderService pps = evt.getProvider(); - - accountStatusPanel.updateStatus(pps, evt.getNewStatus()); - } - - public void providerStatusMessageChanged(PropertyChangeEvent evt) {} - } - - /** - * Returns the panel containing the ContactList. - * @return ContactListPanel the panel containing the ContactList - */ - public ContactListPane getContactListPanel() - { - return this.contactListPanel; - } - - /** - * Returns the text currently shown in the search field. - * @return the text currently shown in the search field - */ - public String getCurrentSearchText() - { - return searchField.getText(); - } - - /** - * Clears the current text in the search field. - */ - public void clearCurrentSearchText() - { - searchField.setText(""); - } - - /** - * Adds the given TextFieldChangeListener to listen for any changes - * that occur in the search field. - * @param l the TextFieldChangeListener to add - */ - public void addSearchFieldListener(TextFieldChangeListener l) - { - searchField.addTextChangeListener(l); - } - - /** - * Removes the given TextFieldChangeListener that listens for any - * changes that occur in the search field. - * @param l the TextFieldChangeListener to remove - */ - public void removeSearchFieldListener(TextFieldChangeListener l) - { - searchField.addTextChangeListener(l); - } - - /** - * Checks in the configuration xml if there is already stored index for - * this provider and if yes, returns it, otherwise creates a new account - * index and stores it. - * - * @param protocolProvider the protocol provider - * @return the protocol provider index - */ - private int initiateProviderIndex( - ProtocolProviderService protocolProvider) - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - String prefix = "net.java.sip.communicator.impl.gui.accounts"; - - List accounts = configService - .getPropertyNamesByPrefix(prefix, true); - - for (String accountRootPropName : accounts) { - String accountUID - = configService.getString(accountRootPropName); - - if(accountUID.equals(protocolProvider - .getAccountID().getAccountUniqueID())) - { - String index = configService.getString( - accountRootPropName + ".accountIndex"); - - if(index != null) { - //if we have found the accountIndex for this protocol provider - //return this index - return Integer.parseInt(index); - } - else - { - //if there's no stored accountIndex for this protocol - //provider, calculate the index, set it in the configuration - //service and return it. - - return createAccountIndex(protocolProvider, - accountRootPropName); - } - } - } - - String accNodeName - = "acc" + Long.toString(System.currentTimeMillis()); - - String accountPackage - = "net.java.sip.communicator.impl.gui.accounts." - + accNodeName; - - configService.setProperty(accountPackage, - protocolProvider.getAccountID().getAccountUniqueID()); - - return createAccountIndex(protocolProvider, - accountPackage); - } - - /** - * Creates and calculates the account index for the given protocol - * provider. - * @param protocolProvider the protocol provider - * @param accountRootPropName the path to where the index should be saved - * in the configuration xml - * @return the created index - */ - private int createAccountIndex(ProtocolProviderService protocolProvider, - String accountRootPropName) - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - int accountIndex = -1; - - for (ProtocolProviderService pps : protocolProviders.keySet()) - { - if (pps.getProtocolDisplayName().equals( - protocolProvider.getProtocolDisplayName()) - && !pps.equals(protocolProvider)) - { - - int index = protocolProviders.get(pps); - - if (accountIndex < index) - accountIndex = index; - } - } - accountIndex++; - configService.setProperty( - accountRootPropName + ".accountIndex", - accountIndex); - - return accountIndex; - } - - /** - * Updates the indexes in the configuration xml, when a provider has been - * removed. - * @param removedProvider the removed protocol provider - */ - private void updateProvidersIndexes(ProtocolProviderService removedProvider) - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - String prefix = "net.java.sip.communicator.impl.gui.accounts"; - - ProtocolProviderService currentProvider = null; - int sameProtocolProvidersCount = 0; - - for (ProtocolProviderService pps : protocolProviders.keySet()) { - if(pps.getProtocolDisplayName().equals( - removedProvider.getProtocolDisplayName())) { - - sameProtocolProvidersCount++; - if(sameProtocolProvidersCount > 1) { - break; - } - currentProvider = pps; - } - } - - if(sameProtocolProvidersCount < 2 && currentProvider != null) { - protocolProviders.put(currentProvider, 0); - - List accounts = configService - .getPropertyNamesByPrefix(prefix, true); - - for (String rootPropName : accounts) { - String accountUID - = configService.getString(rootPropName); - - if(accountUID.equals(currentProvider - .getAccountID().getAccountUniqueID())) { - - configService.setProperty( - rootPropName + ".accountIndex", - 0); - } - } - } - } - - /** - * If the protocol provider supports presence operation set searches the - * last status which was selected, otherwise returns null. - * - * @param protocolProvider the protocol provider we're interested in. - * @return the last protocol provider presence status, or null if this - * provider doesn't support presence operation set - */ - public Object getProtocolProviderLastStatus( - ProtocolProviderService protocolProvider) - { - if(getProtocolPresenceOpSet(protocolProvider) != null) - return accountStatusPanel.getLastPresenceStatus(protocolProvider); - else - return accountStatusPanel.getLastStatusString(protocolProvider); - } - - /** - * RenameAction is invoked when user presses the F2 key. Depending - * on the selection opens the appropriate form for renaming. - */ - private class RenameAction extends AbstractAction - { - private static final long serialVersionUID = 0L; - - public void actionPerformed(ActionEvent e) - { - Object selectedObject - = GuiActivator.getContactList().getSelectionPath() - .getLastPathComponent(); - - if(selectedObject instanceof MetaContact) { - RenameContactDialog dialog = new RenameContactDialog( - MainFrameTouch.this, (MetaContact)selectedObject); - - dialog.setLocation( - Toolkit.getDefaultToolkit().getScreenSize().width/2 - - 200, - Toolkit.getDefaultToolkit().getScreenSize().height/2 - - 50 - ); - - dialog.setVisible(true); - - dialog.requestFocusInFiled(); - } - else if(selectedObject instanceof MetaContactGroup) { - - RenameGroupDialog dialog = new RenameGroupDialog( - MainFrameTouch.this, (MetaContactGroup)selectedObject); - - Dimension screenSize = - Toolkit.getDefaultToolkit().getScreenSize(); - dialog.setLocation(screenSize.width / 2 - 200, - screenSize.height / 2 - 50); - - dialog.setVisible(true); - - dialog.requestFocusInFiled(); - } - } - } - - /** - * Overwrites the SIPCommFrame close method. This method is - * invoked when user presses the Escape key. - * @param isEscaped indicates if this window has been closed by pressing - * the escape key - */ - protected void close(boolean isEscaped) - { - TreeContactList contactList = GuiActivator.getContactList(); - - Component contactListRightMenu - = contactList.getRightButtonMenu(); - - CommonRightButtonMenu commonPopupMenu - = getContactListPanel().getCommonRightButtonMenu(); - - if(contactListRightMenu != null && contactListRightMenu.isVisible()) - { - contactListRightMenu.setVisible(false); - } - else if(commonPopupMenu != null && commonPopupMenu.isVisible()) - { - commonPopupMenu.setVisible(false); - } - else if(accountStatusPanel.hasSelectedMenus() - || menu.hasSelectedMenus()) - { - MenuSelectionManager selectionManager - = MenuSelectionManager.defaultManager(); - - selectionManager.clearSelectedPath(); - } - } - - /** - * Returns the main menu in the application window. - * @return the main menu in the application window - */ - public MainMenu getMainMenu() - { - return menu; - } - - /** - * - * @param protocolProvider - * @param contactHandler - */ - public void addProviderContactHandler( - ProtocolProviderService protocolProvider, - ContactEventHandler contactHandler) - { - providerContactHandlers.put(protocolProvider, contactHandler); - } - - /** - * Returns the ContactEventHandler registered for this protocol - * provider. - * - * @param protocolProvider the ProtocolProviderService for which - * we are searching a ContactEventHandler. - * @return the ContactEventHandler registered for this protocol - * provider - */ - public ContactEventHandler getContactHandler( - ProtocolProviderService protocolProvider) - { - return providerContactHandlers.get(protocolProvider); - } - - /** - * Returns the ContactEventHandler for contacts given by the - * protocolProvider. The ContactEventHandler is meant to - * be used from other bundles in order to change the default behavior of - * events generated when clicking a contact. - * @param protocolProvider the protocol provider for which we want to obtain - * a contact event handler - * @return the ContactEventHandler for contacts given by the - * protocolProvider - */ - private ContactEventHandler getContactHandlerForProvider( - ProtocolProviderService protocolProvider) - { - ServiceReference[] serRefs = null; - - String osgiFilter = "(" - + ProtocolProviderFactory.PROTOCOL - + "=" + protocolProvider.getProtocolName()+")"; - - try - { - serRefs = GuiActivator.bundleContext.getServiceReferences( - ContactEventHandler.class.getName(), osgiFilter); - } - catch (InvalidSyntaxException ex){ - logger.error("GuiActivator : " + ex); - } - - if(serRefs == null) - return null; - - return (ContactEventHandler) GuiActivator.bundleContext - .getService(serRefs[0]); - } - - /** - * Initialize plugin components already registered for this container. - */ - private void initPluginComponents() - { - pluginPanelSouth.setLayout( - new BoxLayout(pluginPanelSouth, BoxLayout.Y_AXIS)); - pluginPanelNorth.setLayout( - new BoxLayout(pluginPanelNorth, BoxLayout.Y_AXIS)); - pluginPanelEast.setLayout( - new BoxLayout(pluginPanelEast, BoxLayout.Y_AXIS)); - pluginPanelWest.setLayout( - new BoxLayout(pluginPanelWest, BoxLayout.Y_AXIS)); - - java.awt.Container contentPane = getContentPane(); - contentPane.add(pluginPanelNorth, BorderLayout.NORTH); - contentPane.add(pluginPanelEast, BorderLayout.EAST); - contentPane.add(pluginPanelWest, BorderLayout.WEST); - this.mainPanel.add(pluginPanelSouth, BorderLayout.SOUTH); - - // Search for plugin components registered through the OSGI bundle - // context. - ServiceReference[] serRefs = null; - - try - { - serRefs - = GuiActivator - .bundleContext - .getServiceReferences( - PluginComponent.class.getName(), - "(|(" - + Container.CONTAINER_ID - + "=" - + Container.CONTAINER_MAIN_WINDOW.getID() - + ")(" - + Container.CONTAINER_ID - + "=" - + Container.CONTAINER_STATUS_BAR.getID() - + "))"); - } - catch (InvalidSyntaxException exc) - { - logger.error("Could not obtain plugin reference.", exc); - } - - if (serRefs != null) - { - for (ServiceReference serRef : serRefs) - { - PluginComponent c - = (PluginComponent) - GuiActivator.bundleContext.getService(serRef); - - if (c.isNativeComponent()) - nativePluginsTable.put(c, new JPanel()); - else - { - String pluginConstraints = c.getConstraints(); - Object constraints; - - if (pluginConstraints != null) - constraints - = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - pluginConstraints); - else - constraints = BorderLayout.SOUTH; - - this.addPluginComponent((Component) c.getComponent(), c - .getContainer(), constraints); - } - } - } - - GuiActivator.getUIService().addPluginComponentListener(this); - } - - /** - * Adds the associated with this PluginComponentEvent component to - * the appropriate container. - * @param event the PluginComponentEvent that has notified us of - * the add of a plugin component - */ - public void pluginComponentAdded(PluginComponentEvent event) - { - PluginComponent pluginComponent = event.getPluginComponent(); - Container pluginContainer = pluginComponent.getContainer(); - - if (pluginContainer.equals(Container.CONTAINER_MAIN_WINDOW) - || pluginContainer.equals(Container.CONTAINER_STATUS_BAR)) - { - String pluginConstraints = pluginComponent.getConstraints(); - Object constraints; - - if (pluginConstraints != null) - constraints = - UIServiceImpl - .getBorderLayoutConstraintsFromContainer(pluginConstraints); - else - constraints = BorderLayout.SOUTH; - - if (pluginComponent.isNativeComponent()) - { - this.nativePluginsTable.put(pluginComponent, new JPanel()); - - if (isVisible()) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - addNativePlugins(); - } - }); - } - } - else - { - this.addPluginComponent((Component) pluginComponent - .getComponent(), pluginContainer, constraints); - } - } - } - - /** - * Removes the associated with this PluginComponentEvent component - * from this container. - * @param event the PluginComponentEvent that notified us of the - * remove of a plugin component - */ - public void pluginComponentRemoved(PluginComponentEvent event) - { - final PluginComponent pluginComponent = event.getPluginComponent(); - final Container containerID = pluginComponent.getContainer(); - - if (containerID.equals(Container.CONTAINER_MAIN_WINDOW)) - { - Object constraints = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - pluginComponent.getConstraints()); - - if (constraints == null) - constraints = BorderLayout.SOUTH; - - if (pluginComponent.isNativeComponent()) - { - if (nativePluginsTable.containsKey(pluginComponent)) - { - final Component c = nativePluginsTable.get(pluginComponent); - final Object finalConstraints = constraints; - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - removePluginComponent(c, containerID, - finalConstraints); - - getContentPane().repaint(); - } - }); - } - } - else - { - this.removePluginComponent((Component) pluginComponent - .getComponent(), containerID, constraints); - } - - nativePluginsTable.remove(pluginComponent); - } - } - - /** - * Removes all native plugins from this container. - */ - private void removeNativePlugins() - { - for (Map.Entry entry - : nativePluginsTable.entrySet()) - { - PluginComponent pluginComponent = entry.getKey(); - Component c = entry.getValue(); - - Object constraints - = UIServiceImpl - .getBorderLayoutConstraintsFromContainer(pluginComponent - .getConstraints()); - - if (constraints == null) - constraints = BorderLayout.SOUTH; - - this.removePluginComponent(c, pluginComponent.getContainer(), - constraints); - - this.getContentPane().repaint(); - } - } - - /** - * Adds all native plugins to this container. - */ - public void addNativePlugins() - { - this.removeNativePlugins(); - - for (Map.Entry pluginEntry - : nativePluginsTable.entrySet()) - { - PluginComponent plugin = pluginEntry.getKey(); - Object constraints - = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - plugin.getConstraints()); - - Component c = (Component) plugin.getComponent(); - - this.addPluginComponent(c, plugin.getContainer(), constraints); - - this.nativePluginsTable.put(plugin, c); - } - } - - /** - * Brings this window to front. - */ - public void bringToFront() - { - this.toFront(); - } - - /** - * Returns the identifier of this window. - * @return the identifier of this window - */ - public WindowID getIdentifier() - { - return ExportedWindow.MAIN_WINDOW; - } - - /** - * Returns this window. - * @return this window - */ - public Object getSource() - { - return this; - } - - /** - * Maximizes this window. - */ - public void maximize() - { - this.setExtendedState(JFrame.MAXIMIZED_BOTH); - } - - /** - * Minimizes this window. - */ - public void minimize() - { - this.setExtendedState(JFrame.ICONIFIED); - } - - /** - * Implements isVisible in the UIService interface. Checks if - * the main application window is visible. - * - * @return true if main application window is visible, - * false otherwise - * @see UIService#isVisible() - */ - public boolean isVisible() - { - return super.isVisible() - && (super.getExtendedState() != JFrame.ICONIFIED); - } - - /** - * Implements setVisible in the UIService interface. Shows or - * hides the main application window depending on the parameter - * visible. - * - * @param isVisible true if we are to show the main application frame and - * false otherwise. - * - * @see UIService#setVisible(boolean) - */ - public void setVisible(final boolean isVisible) - { - SwingUtilities.invokeLater(new Runnable(){ - public void run() - { - if(isVisible) - { - MainFrameTouch.this.addNativePlugins(); - MainFrameTouch.super.setVisible(isVisible); - MainFrameTouch.super.setExtendedState(MainFrameTouch.NORMAL); - MainFrameTouch.super.toFront(); - } - else - { - MainFrameTouch.super.setVisible(isVisible); - } - } - }); - } - - /** - * Adds the given component with to the container corresponding to the - * given constraints. - * - * @param c the component to add - * @param container the container to which to add the given component - * @param constraints the constraints determining the container - */ - private void addPluginComponent(Component c, - Container container, - Object constraints) - { - if (container.equals(Container.CONTAINER_MAIN_WINDOW)) - { - if (constraints.equals(BorderLayout.NORTH)) - { - pluginPanelNorth.add(c); - pluginPanelNorth.repaint(); - } - else if (constraints.equals(BorderLayout.SOUTH)) - { - pluginPanelSouth.add(c); - pluginPanelSouth.repaint(); - } - else if (constraints.equals(BorderLayout.WEST)) - { - pluginPanelWest.add(c); - pluginPanelWest.repaint(); - } - else if (constraints.equals(BorderLayout.EAST)) - { - pluginPanelEast.add(c); - pluginPanelEast.repaint(); - } - } - else if (container.equals(Container.CONTAINER_STATUS_BAR)) - { - statusBarPanel.add(c); - } - - this.getContentPane().repaint(); - this.getContentPane().validate(); - } - - /** - * Removes the given component from the container corresponding to the given - * constraints. - * - * @param c the component to remove - * @param container the container from which to remove the given component - * @param constraints the constraints determining the container - */ - private void removePluginComponent( Component c, - Container container, - Object constraints) - { - if (container.equals(Container.CONTAINER_MAIN_WINDOW)) - { - if (constraints.equals(BorderLayout.NORTH)) - pluginPanelNorth.remove(c); - else if (constraints.equals(BorderLayout.SOUTH)) - pluginPanelSouth.remove(c); - else if (constraints.equals(BorderLayout.WEST)) - pluginPanelWest.remove(c); - else if (constraints.equals(BorderLayout.EAST)) - pluginPanelEast.remove(c); - } - else if (container.equals(Container.CONTAINER_STATUS_BAR)) - { - this.statusBarPanel.remove(c); - } - } - - /** - * Returns the account status panel. - * @return the account status panel. - */ - public AccountStatusPanel getAccountStatusPanel() - { - return accountStatusPanel; - } - - /** - * Implementation of {@link ExportedWindow#setParams(Object[])}. - */ - public void setParams(Object[] windowParams) {} - - /** - * @param event Currently not used - */ - protected void windowClosed(WindowEvent event) - { - if(GuiActivator.getUIService().getExitOnMainWindowClose()) - { - try - { - GuiActivator.bundleContext.getBundle(0).stop(); - } - catch (BundleException ex) - { - logger.error("Failed to gently shutdown Felix", ex); - System.exit(0); - } - //stopping a bundle doesn't leave the time to the felix thread to - //properly end all bundles and call their Activator.stop() methods. - //if this causes problems don't uncomment the following line but - //try and see why felix isn't exiting (suggesting: is it running - //in embedded mode?) - //System.exit(0); - } - } - - /** - * Overrides SIPCommFrame#windowClosing(WindowEvent). Reflects the closed - * state of this MainFrame in the configuration in order to make it - * accessible to interested parties, displays the warning that the - * application will not quit. - * @param event the WindowEvent that notified us - */ - protected void windowClosing(WindowEvent event) - { - super.windowClosing(event); - - if (!GuiActivator.getUIService().getExitOnMainWindowClose()) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - if (ConfigurationManager.isQuitWarningShown()) - { - MessageDialog dialog = - new MessageDialog(null, - GuiActivator.getResources().getI18NString( - "service.gui.CLOSE"), - GuiActivator.getResources().getI18NString( - "service.gui.HIDE_MAIN_WINDOW"), false); - - if (dialog.showDialog() == MessageDialog.OK_DONT_ASK_CODE) - ConfigurationManager.setQuitWarningShown(false); - } - } - }); - - ConfigurationManager.setApplicationVisible(false); - } - } - - /** - * The MainKeyDispatcher is added to pre-listen KeyEvents before - * they're delivered to the current focus owner in order to introduce a - * specific behavior for the SearchField on top of the contact - * list. - */ - private class MainKeyDispatcher implements KeyEventDispatcher - { - private KeyboardFocusManager keyManager; - - /** - * Creates an instance of MainKeyDispatcher. - * @param keyManager the parent KeyboardFocusManager - */ - public MainKeyDispatcher(KeyboardFocusManager keyManager) - { - this.keyManager = keyManager; - } - - /** - * Dispatches the given KeyEvent. - * @param e the KeyEvent to dispatch - * @return true if the KeyboardFocusManager should take no - * further action with regard to the KeyEvent; false - * otherwise - */ - public boolean dispatchKeyEvent(KeyEvent e) - { - // If this window is not the focus window or if the event is not - // of type PRESSED we have nothing more to do here. - if (!isFocused() - || (e.getID() != KeyEvent.KEY_PRESSED - && e.getID() != KeyEvent.KEY_TYPED)) - return false; - - // Ctrl-Enter || Cmd-Enter typed when this window is the focused - // window. - // - // Tried to make this with key bindings first, but has a problem - // with enter key binding. When the popup menu containing call - // contacts was opened the default keyboard manager was prioritizing - // the window ENTER key, which will open a chat and we wanted that - // the enter starts a call with the selected contact from the menu. - // This is why we need to do it here and to check if the - // permanent focus owner is equal to the focus owner, which is not - // the case when a popup menu is opened. - if (e.getKeyCode() == KeyEvent.VK_ENTER - && (e.isControlDown() || e.isMetaDown())) - { - ctrlEnterKeyTyped(); - return false; - } - else if (e.getKeyCode() == KeyEvent.VK_ENTER - && keyManager.getFocusOwner() - .equals(keyManager.getPermanentFocusOwner())) - { - enterKeyTyped(); - return false; - } - - TreeContactList contactList - = getContactListPanel().getContactList(); - // If the search field is the focus owner. - if (searchField.isFocusOwner() - && (e.getKeyCode() == KeyEvent.VK_UP - || e.getKeyCode() == KeyEvent.VK_DOWN - || e.getKeyCode() == KeyEvent.VK_PAGE_UP - || e.getKeyCode() == KeyEvent.VK_PAGE_DOWN)) - { - contactList.selectFirstContact(); - contactList.requestFocus(); - return false; - } - - // If the contact list is the focus owner. - if (contactList.isFocusOwner() - && e.getKeyCode() == KeyEvent.VK_ESCAPE) - { - // Removes all current selections. - contactList.removeSelectionRows(contactList.getSelectionRows()); - - if (searchField.getText() != null) - { - searchField.requestFocus(); - } - return false; - } - TreePath selectionPath = contactList.getSelectionPath(); - // No matter who is the focus owner. - if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED - || e.getKeyCode() == KeyEvent.VK_ENTER - || e.getKeyCode() == KeyEvent.VK_DELETE - || e.getKeyCode() == KeyEvent.VK_BACK_SPACE - || e.getKeyCode() == KeyEvent.VK_TAB - || e.getKeyCode() == KeyEvent.VK_SPACE - || (selectionPath != null - && selectionPath.getLastPathComponent() instanceof GroupNode - && (e.getKeyChar() == '+' - || e.getKeyChar() == '-'))) - { - return false; - } - - if (!searchField.isFocusOwner() - && keyManager.getFocusOwner() != null - && keyManager.getFocusOwner() - .equals(keyManager.getPermanentFocusOwner())) - { - // Request the focus in the search field if a letter is typed. - searchField.requestFocusInWindow(); - - // We re-dispatch the event to search field. - keyManager.redispatchEvent(searchField, e); - - // We don't want to dispatch further this event. - return true; - } - return false; - } - } - - /** - * Called when the ENTER key was typed when this window was the focused - * window. Performs the appropriate actions depending on the current state - * of the contact list. - */ - private void enterKeyTyped() - { - if (unknownContactPanel != null && unknownContactPanel.isVisible()) - { - unknownContactPanel.addUnknownContact(); - } - else if (contactListPanel.isVisible()) - { - // Starts a chat with the currently selected contact. - GuiActivator.getContactList().startSelectedContactChat(); - } - } - - /** - * Called when the CTRL-ENTER or CMD-ENTER keys were typed when this window - * was the focused window. Performs the appropriate actions depending on the - * current state of the contact list. - */ - public void ctrlEnterKeyTyped() - { - if (unknownContactPanel != null && unknownContactPanel.isVisible()) - { - unknownContactPanel.startCall(); - } - else if (contactListPanel.isVisible()) - { - // Starts a chat with the currently selected contact. - GuiActivator.getContactList().startSelectedContactCall(); - } - } -} \ No newline at end of file -- cgit v1.1