From dcc3f8dd4f75977d6d654b424e08b96633e8fb0b Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Fri, 9 Feb 2007 08:51:05 +0000 Subject: [PATCH] request focus in chat window configurable property --- .../communicator/impl/gui/GuiActivator.java | 2 + .../impl/gui/i18n/messages.properties | 1 + .../main/contactlist/ContactListPanel.java | 92 ++++++++++--------- .../gui/main/message/menus/SettingsMenu.java | 33 ++++++- .../impl/gui/utils/ConfigurationManager.java | 54 +++++++++++ .../impl/gui/utils/Constants.java | 7 +- 6 files changed, 138 insertions(+), 51 deletions(-) create mode 100644 src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index 177337a25..152b8193a 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -12,6 +12,7 @@ import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.login.*; +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.audionotifier.*; import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.service.callhistory.*; @@ -90,6 +91,7 @@ public void start(BundleContext bundleContext) throws Exception { logger.info("UI Service ...[REGISTERED]"); + ConfigurationManager.loadGuiConfigurations(); communicatorMain.showCommunicator(true); SwingUtilities.invokeLater(new RunLogin()); } diff --git a/src/net/java/sip/communicator/impl/gui/i18n/messages.properties b/src/net/java/sip/communicator/impl/gui/i18n/messages.properties index 581969100..b3c85d71c 100644 --- a/src/net/java/sip/communicator/impl/gui/i18n/messages.properties +++ b/src/net/java/sip/communicator/impl/gui/i18n/messages.properties @@ -30,6 +30,7 @@ authorizationRequested=Authorization requested authorizationRequestedInfo=The ? contact requests your authorization. authenticationFailed=The authentication for account ? failed. The password you entered is not valid. authorizationResponse=Authorization response +autoPopup=Autopopup new message back=&Back call=Call callVia=Call via: diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java index ac217497d..b5644a085 100755 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java @@ -377,18 +377,20 @@ public void messageReceived(MessageReceivedEvent evt) if (chatWindow.getState() == JFrame.ICONIFIED) { chatWindow.setTitle("*" + chatWindow.getTitle()); } - - if (Constants.AUTO_POPUP_NEW_MESSAGE) { - if(chatWindow.isVisible()) { - + + if(chatWindow.isVisible()) + { + if (ConfigurationManager.isAutoPopupNewMessage()) + { if(chatWindow.getState() == JFrame.ICONIFIED) chatWindow.setState(JFrame.NORMAL); chatWindow.toFront(); } - else - chatWindow.setVisible(true); } + else + chatWindow.setVisible(true); + } else { ChatWindow msgWindow = new ChatWindow(mainFrame); @@ -405,7 +407,7 @@ public void messageReceived(MessageReceivedEvent evt) * If there's no chat window for the contact create it and show * it. */ - if (Constants.AUTO_POPUP_NEW_MESSAGE) { + if (ConfigurationManager.isAutoPopupNewMessage()) { msgWindow.addChat(chatPanel); msgWindow.pack(); @@ -445,26 +447,28 @@ public void messageReceived(MessageReceivedEvent evt) chatPanel.processMessage(protocolContact.getDisplayName(), date, Constants.INCOMING_MESSAGE, message.getContent()); - if (Constants.AUTO_POPUP_NEW_MESSAGE) { - chatWindow.addChatTab(chatPanel); - - if(chatWindow.isVisible()) { + chatWindow.addChatTab(chatPanel); + + if(chatWindow.isVisible()) + { + if (ConfigurationManager.isAutoPopupNewMessage()) + { if(chatWindow.getState() == JFrame.ICONIFIED) chatWindow.setState(JFrame.NORMAL); chatWindow.toFront(); } - else - chatWindow.setVisible(true); + } + else + chatWindow.setVisible(true); - chatPanel.setCaretToEnd(); + chatPanel.setCaretToEnd(); - chatWindow.getCurrentChatPanel() - .requestFocusInWriteArea(); + chatWindow.getCurrentChatPanel() + .requestFocusInWriteArea(); - if (chatWindow.getTabCount() > 1) { - chatWindow.highlightTab(metaContact); - } + if (chatWindow.getTabCount() > 1) { + chatWindow.highlightTab(metaContact); } } else { @@ -478,7 +482,7 @@ public void messageReceived(MessageReceivedEvent evt) chatPanel.processMessage(protocolContact.getDisplayName(), date, Constants.INCOMING_MESSAGE, message.getContent()); - + if (chatWindow.getState() == JFrame.ICONIFIED) { if (chatWindow.getTabCount() > 1) { chatWindow.setSelectedContactTab(metaContact); @@ -495,10 +499,13 @@ public void messageReceived(MessageReceivedEvent evt) } if(chatWindow.isVisible()) - chatWindow.toFront(); + { + if(ConfigurationManager.isAutoPopupNewMessage()) + chatWindow.toFront(); + } else chatWindow.setVisible(true); - } + } } } @@ -618,18 +625,19 @@ else if (evt.getErrorCode() if (chatWindow.getState() == JFrame.ICONIFIED) { chatWindow.setTitle("*" + chatWindow.getTitle()); } - - if (Constants.AUTO_POPUP_NEW_MESSAGE) { - if(chatWindow.isVisible()) { - + + if(chatWindow.isVisible()) { + + if (ConfigurationManager.isAutoPopupNewMessage()) + { if(chatWindow.getState() == JFrame.ICONIFIED) chatWindow.setState(JFrame.NORMAL); chatWindow.toFront(); } - else - chatWindow.setVisible(true); } + else + chatWindow.setVisible(true); } else { ChatWindow msgWindow = new ChatWindow(mainFrame); @@ -656,7 +664,7 @@ else if (evt.getErrorCode() * If there's no chat window for the contact create it and show * it. */ - if (Constants.AUTO_POPUP_NEW_MESSAGE) { + if (ConfigurationManager.isAutoPopupNewMessage()) { msgWindow.addChat(chatPanel); msgWindow.pack(); @@ -733,28 +741,30 @@ else if (evt.getErrorCode() Constants.ERROR_MESSAGE, errorMsg); - if (Constants.AUTO_POPUP_NEW_MESSAGE) { - chatWindow.addChatTab(chatPanel); + + chatWindow.addChatTab(chatPanel); - if(chatWindow.isVisible()) { + if(chatWindow.isVisible()) { + if (ConfigurationManager.isAutoPopupNewMessage()) + { if(chatWindow.getState() == JFrame.ICONIFIED) chatWindow.setState(JFrame.NORMAL); chatWindow.toFront(); } - else - chatWindow.setVisible(true); + } + else + chatWindow.setVisible(true); - chatPanel.setCaretToEnd(); + chatPanel.setCaretToEnd(); - chatWindow.getCurrentChatPanel() - .requestFocusInWriteArea(); + chatWindow.getCurrentChatPanel() + .requestFocusInWriteArea(); - if (chatWindow.getTabCount() > 1) { - chatWindow.highlightTab(metaContact); - } + if (chatWindow.getTabCount() > 1) { + chatWindow.highlightTab(metaContact); } - } + } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/message/menus/SettingsMenu.java b/src/net/java/sip/communicator/impl/gui/main/message/menus/SettingsMenu.java index da0dd0aef..75a9982a4 100644 --- a/src/net/java/sip/communicator/impl/gui/main/message/menus/SettingsMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/message/menus/SettingsMenu.java @@ -7,6 +7,7 @@ import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.i18n.*; import net.java.sip.communicator.impl.gui.main.message.*; +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.configuration.*; /** @@ -27,12 +28,18 @@ public class SettingsMenu extends SIPCommMenu private I18NString useCtrlEnterString = Messages.getI18NString("useCtrlEnterToSend"); + private I18NString autoPopupString + = Messages.getI18NString("autoPopup"); + private JCheckBoxMenuItem typingNotificationsItem = new JCheckBoxMenuItem(typingNotifString.getText()); private JCheckBoxMenuItem sendingMessageCommandItem = new JCheckBoxMenuItem(useCtrlEnterString.getText()); + private JCheckBoxMenuItem autoPopupItem + = new JCheckBoxMenuItem(autoPopupString.getText()); + private ChatWindow chatWindow; /** @@ -48,6 +55,7 @@ public SettingsMenu(ChatWindow chatWindow){ typingNotificationsItem.setName("typingNotifications"); sendingMessageCommandItem.setName("sendingMessageCommand"); + autoPopupItem.setName("autopopup"); this.setMnemonic(Messages.getI18NString("settings").getMnemonic()); @@ -57,17 +65,28 @@ public SettingsMenu(ChatWindow chatWindow){ this.sendingMessageCommandItem.setMnemonic( useCtrlEnterString.getMnemonic()); + this.autoPopupItem.setMnemonic( + autoPopupString.getMnemonic()); + ConfigurationService configService = GuiActivator.getConfigurationService(); String messageCommand = configService.getString( "net.java.sip.communicator.impl.gui.sendMessageCommand"); + String autoPopup = configService.getString( + "net.java.sip.communicator.impl.gui.autoPopupNewMessage"); + if(messageCommand == null || messageCommand.equalsIgnoreCase("enter")) this.sendingMessageCommandItem.setSelected(false); else this.sendingMessageCommandItem.setSelected(true); + if(autoPopup == null || autoPopup.equalsIgnoreCase("yes")) + this.autoPopupItem.setSelected(true); + else + this.autoPopupItem.setSelected(false); + this.init(); } @@ -77,9 +96,11 @@ public SettingsMenu(ChatWindow chatWindow){ private void init(){ this.add(typingNotificationsItem); this.add(sendingMessageCommandItem); + this.add(autoPopupItem); this.typingNotificationsItem.addActionListener(this); this.sendingMessageCommandItem.addActionListener(this); + this.autoPopupItem.addActionListener(this); } /** @@ -88,8 +109,8 @@ private void init(){ public void actionPerformed(ActionEvent e) { JCheckBoxMenuItem item = (JCheckBoxMenuItem)e.getSource(); - if(item.getName().equals("typingNotifications")) { - + if (item.getName().equals("typingNotifications")) + { if (item.isSelected()) { chatWindow.enableTypingNotification(true); } @@ -97,9 +118,13 @@ public void actionPerformed(ActionEvent e) { chatWindow.enableTypingNotification(false); } } - else if(item.getName().equals("sendingMessageCommand")) { - + else if (item.getName().equals("sendingMessageCommand")) + { chatWindow.changeSendCommand(!item.isSelected()); } + else if (item.getName().equals("autopopup")) + { + ConfigurationManager.setAutoPopupNewMessage(item.isSelected()); + } } } diff --git a/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java new file mode 100644 index 000000000..ee788e2c3 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java @@ -0,0 +1,54 @@ +/* + * 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.utils; + +import net.java.sip.communicator.impl.gui.*; +import net.java.sip.communicator.service.configuration.*; + +public class ConfigurationManager +{ + /** + * Indicates whether the message automatic popup is enabled. + */ + private static boolean autoPopupNewMessage; + + public static void loadGuiConfigurations() + { + ConfigurationService configService + = GuiActivator.getConfigurationService(); + + String autoPopup = configService.getString( + "net.java.sip.communicator.impl.gui.autoPopupNewMessage"); + + if(autoPopup == null || autoPopup.equalsIgnoreCase("yes")) + autoPopupNewMessage = true; + else + autoPopupNewMessage = false; + } + + public static boolean isAutoPopupNewMessage() + { + return autoPopupNewMessage; + } + + public static void setAutoPopupNewMessage(boolean autoPopupNewMessage) + { + ConfigurationManager.autoPopupNewMessage = autoPopupNewMessage; + + ConfigurationService configService + = GuiActivator.getConfigurationService(); + + if(autoPopupNewMessage) + configService.setProperty( + "net.java.sip.communicator.impl.gui.autoPopupNewMessage", + "yes"); + else + configService.setProperty( + "net.java.sip.communicator.impl.gui.autoPopupNewMessage", + "no"); + } +} diff --git a/src/net/java/sip/communicator/impl/gui/utils/Constants.java b/src/net/java/sip/communicator/impl/gui/utils/Constants.java index 82af97ca2..0ea4f8a69 100755 --- a/src/net/java/sip/communicator/impl/gui/utils/Constants.java +++ b/src/net/java/sip/communicator/impl/gui/utils/Constants.java @@ -54,12 +54,7 @@ public class Constants { * a contact. */ public static boolean REMOVE_GROUP_ASK = true; - - /** - * Indicates whether the message automatic popup is enabled. - */ - public static boolean AUTO_POPUP_NEW_MESSAGE = true; - + /** * Indicates the number of messages to show in the chat area when a new * chat is opened.