From 90be1c5c5838d63c47f3c9a737cd3f538c7980cf Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Fri, 13 Apr 2007 14:03:59 +0000 Subject: [PATCH] 1) Save the "isMinimized" property. Issue N 344 2) some enhancements on the way the ConfigurationService is accessed from the gui --- .../communicator/impl/gui/GuiActivator.java | 7 +- .../impl/gui/main/CommunicatorMain.java | 12 --- .../communicator/impl/gui/main/MainFrame.java | 57 ++---------- .../impl/gui/main/call/CallManager.java | 87 +++++++------------ .../gui/main/chat/menus/SettingsMenu.java | 5 +- .../gui/main/contactlist/ContactList.java | 19 ++-- .../impl/gui/main/menus/QuickMenu.java | 5 +- .../impl/gui/main/menus/ViewMenu.java | 15 +--- .../impl/gui/utils/ConfigurationManager.java | 85 ++++++++++++++++-- .../impl/systray/SystrayActivator.java | 23 +++++ 10 files changed, 156 insertions(+), 159 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index d6123f687..95f5ae7ed 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -63,6 +63,8 @@ public void start(BundleContext bundleContext) throws Exception { GuiActivator.bundleContext = bundleContext; + ConfigurationManager.loadGuiConfigurations(); + this.communicatorMain = new CommunicatorMain(); MainFrame mainFrame = communicatorMain.getMainFrame(); @@ -91,8 +93,9 @@ public void start(BundleContext bundleContext) throws Exception { logger.info("UI Service ...[REGISTERED]"); - ConfigurationManager.loadGuiConfigurations(); - communicatorMain.showCommunicator(true); + if(ConfigurationManager.isApplicationVisible()) + mainFrame.setVisible(true); + SwingUtilities.invokeLater(new RunLogin()); uiService.initExportedWindows(); diff --git a/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java b/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java index 1e5fc17e0..28dd2f256 100755 --- a/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java +++ b/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java @@ -57,18 +57,6 @@ public void setDefaultThemePack() { logger.error("The provided Look & Feel is not supported.", e); } } - - /** - * Shows or hides the main application window. - * - * @param isVisible true to show the main application - * window, false to hide it. - */ - public void showCommunicator(boolean isVisible) { - - this.mainFrame.loadConfigurationSettings(); - this.mainFrame.setVisible(isVisible); - } /** * Returns the main application window. 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 42510268a..bb92ece88 100755 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java +++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java @@ -102,7 +102,7 @@ public MainFrame() this.addWindowListener(new MainFrameWindowAdapter()); - this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + //this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setInitialBounds(); this.setTitle(Messages.getI18NString("sipCommunicator").getText()); @@ -645,29 +645,15 @@ public MetaContactGroup getGroupByID(String metaUID) * through the ConfigurationService. */ public class MainFrameWindowAdapter extends WindowAdapter - { - public void windowClosing(WindowEvent e) { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - try { - configService.setProperty( - "net.java.sip.communicator.impl.gui.showCallPanel", - new Boolean(callManager.isShown())); - - - configService.setProperty( - "net.java.sip.communicator.impl.gui.showOffline", - new Boolean(getContactListPanel() - .getContactList().isShowOffline())); - - } - catch (PropertyVetoException e1) { - logger.error("The proposed property change " - + "represents an unacceptable value"); + { + public void windowClosing(WindowEvent e) + { + if(!GuiActivator.getUIService().getExitOnMainWindowClose()) + { + ConfigurationManager.setApplicationVisible(false); } } - + public void windowClosed(WindowEvent e) { if(GuiActivator.getUIService().getExitOnMainWindowClose()) @@ -688,33 +674,6 @@ public void windowClosed(WindowEvent e) } } - /** - * Sets the window size and position. - */ - public void loadConfigurationSettings() { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - String isCallPanelShown = configService.getString( - "net.java.sip.communicator.impl.gui.showCallPanel"); - - String isShowOffline = configService.getString( - "net.java.sip.communicator.impl.gui.showOffline"); - - if(isCallPanelShown != null && isCallPanelShown != "") - { - callManager.setShown(new Boolean(isCallPanelShown).booleanValue()); - } - else { - callManager.setShown(true); - } - - if(isShowOffline != null && isShowOffline != "") { - getContactListPanel().getContactList() - .setShowOffline(new Boolean(isShowOffline).booleanValue()); - } - } - /** * Saves the last status for all accounts. This information is used * on loging. Each time user logs in he's logged with the same status diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index d22e24f58..687ca18c1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -84,8 +84,6 @@ public class CallManager private Hashtable activeCalls = new Hashtable(); - private boolean isShown; - private boolean isCallMetaContact; private Hashtable removeCallTimers = new Hashtable(); @@ -148,7 +146,9 @@ private void init() this.hangupButton.setEnabled(false); - this.add(minimizeButtonPanel, BorderLayout.SOUTH); + this.add(minimizeButtonPanel, BorderLayout.SOUTH); + + this.setCallPanelVisible(ConfigurationManager.isCallPanelShown()); } @@ -319,7 +319,7 @@ else if (buttonName.equalsIgnoreCase("minimize")) { if(!hideCallPanelItem.isSelected()) hideCallPanelItem.setSelected(true); - this.hideCallPanel(); + this.setCallPanelVisible(false); } else if (buttonName.equalsIgnoreCase("restore")) { @@ -329,43 +329,42 @@ else if (buttonName.equalsIgnoreCase("restore")) { if(hideCallPanelItem.isSelected()) hideCallPanelItem.setSelected(false); - this.showCallPanel(); + this.setCallPanelVisible(true); } } /** * Hides the panel containing call and hangup buttons. */ - public void hideCallPanel() + public void setCallPanelVisible(boolean isVisible) { - this.remove(comboPanel); - this.remove(buttonsPanel); + if(isVisible) + { + this.add(comboPanel, BorderLayout.NORTH); + this.add(buttonsPanel, BorderLayout.CENTER); - this.minimizeButtonPanel.removeAll(); - this.minimizeButtonPanel.add(restoreButton); - this.isShown = false; - - this.mainFrame.getContactListPanel() - .getContactList().requestFocus(); + this.minimizeButtonPanel.removeAll(); + this.minimizeButtonPanel.add(minimizeButton); + } + else + { + this.remove(comboPanel); + this.remove(buttonsPanel); + this.minimizeButtonPanel.removeAll(); + this.minimizeButtonPanel.add(restoreButton); + + if(mainFrame.isVisible()) + this.mainFrame.getContactListPanel() + .getContactList().requestFocus(); + } + + if(ConfigurationManager.isCallPanelShown() != isVisible) + ConfigurationManager.setShowCallPanel(isVisible); + this.mainFrame.validate(); } - /** - * Shows the panel containing call and hangup buttons. - */ - public void showCallPanel() - { - this.add(comboPanel, BorderLayout.NORTH); - this.add(buttonsPanel, BorderLayout.CENTER); - - this.minimizeButtonPanel.removeAll(); - this.minimizeButtonPanel.add(minimizeButton); - this.isShown = true; - - this.mainFrame.validate(); - } - /** * Adds the given call account to the list of call via accounts. * @param pps the protocol provider service corresponding to the account @@ -468,7 +467,7 @@ public void incomingCallReceived(CallEvent event) activeCalls.put(sourceCall, callPanel); - this.showCallPanel(); + this.setCallPanelVisible(true); } /** @@ -617,34 +616,6 @@ public JComboBox getCallComboBox() return phoneNumberCombo; } - /** - * Returns TRUE if this panel is visible, FALSE otherwise. - * @return TRUE if this panel is visible, FALSE otherwise - */ - public boolean isShown() - { - return this.isShown; - } - - /** - * When TRUE shows this panel, when FALSE hides it. - * @param isShown - */ - public void setShown(boolean isShown) - { - this.isShown = isShown; - - if(isShown) { - this.add(comboPanel, BorderLayout.NORTH); - this.add(buttonsPanel, BorderLayout.CENTER); - - this.minimizeButtonPanel.add(minimizeButton); - } - else { - this.minimizeButtonPanel.add(restoreButton); - } - } - /** * Answers the given call. * @param call the call to answer diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/menus/SettingsMenu.java b/src/net/java/sip/communicator/impl/gui/main/chat/menus/SettingsMenu.java index 7aeb54c7c..c2669f21f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/menus/SettingsMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/menus/SettingsMenu.java @@ -72,11 +72,14 @@ public SettingsMenu(ChatWindow chatWindow){ = GuiActivator.getConfigurationService(); String messageCommand = configService.getString( - "net.java.sip.communicator.impl.gui.sendMessageCommand"); + "net.java.sip.communicator.impl.gui.sendMessageCommand"); String autoPopup = configService.getString( "net.java.sip.communicator.impl.gui.autoPopupNewMessage"); + String typingNotif = configService.getString( + "net.java.sip.communicator.impl.gui.autoPopupNewMessage"); + if(messageCommand == null || messageCommand.equalsIgnoreCase("enter")) this.sendingMessageCommandItem.setSelected(false); else diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java index 3b5c9b779..a65429f59 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactList.java @@ -16,8 +16,8 @@ import javax.swing.text.*; import net.java.sip.communicator.impl.gui.main.*; -import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.impl.gui.main.chat.history.*; +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.contactlist.event.*; import net.java.sip.communicator.service.protocol.*; @@ -75,7 +75,6 @@ public class ContactList */ public ContactList(MainFrame mainFrame) { - this.mainFrame = mainFrame; this.contactList = mainFrame.getContactList(); @@ -109,6 +108,8 @@ public void valueChanged(ListSelectionEvent e) } }); + this.setShowOffline(ConfigurationManager.isShowOffline()); + new ContactListRefresh().start(); } @@ -1093,16 +1094,6 @@ public GroupRightButtonMenu getGroupRightButtonMenu() return groupRightButtonMenu; } - /** - * Returns TRUE if the list shows offline contacts, FALSE otherwise. - * - * @return TRUE if the list shows offline contacts, FALSE otherwise - */ - public boolean isShowOffline() - { - return listModel.isShowOffline(); - } - /** * Sets the showOffline property. * @@ -1115,6 +1106,8 @@ public void setShowOffline(boolean isShowOffline) listModel.setShowOffline(isShowOffline); + ConfigurationManager.setShowOffline(isShowOffline); + int newListSize = listModel.getSize(); //hide offline users @@ -1138,7 +1131,7 @@ else if(isShowOffline && newListSize > 0) } else listModel.contentAdded(0, newListSize - 1); - } + } } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java index 3b09e652e..d80d0ef01 100755 --- a/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/QuickMenu.java @@ -196,7 +196,6 @@ else if (buttonName.equals("config")) } else if (buttonName.equals("search")) { - ContactList contactList = mainFrame.getContactListPanel() .getContactList(); @@ -209,8 +208,8 @@ else if (buttonName.equals("search")) selectedObject = listModel.getElementAt(currentlySelectedIndex); } - - contactList.setShowOffline(!contactList.isShowOffline()); + + contactList.setShowOffline(!ConfigurationManager.isShowOffline()); if (selectedObject != null) { if (selectedObject instanceof MetaContact) { diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java index 098b52204..556ac4d28 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ViewMenu.java @@ -55,14 +55,8 @@ public ViewMenu(MainFrame mainFrame) { this.mainFrame = mainFrame; - ConfigurationService configService - = GuiActivator.getConfigurationService(); - - String isCallPanelShown = configService.getString( - "net.java.sip.communicator.impl.gui.showCallPanel"); - this.hideCallPanelItem.setSelected( - !new Boolean(isCallPanelShown).booleanValue()); + !ConfigurationManager.isCallPanelShown()); this.add(hideCallPanelItem); @@ -90,12 +84,7 @@ public void actionPerformed(ActionEvent e) { if (itemName.equals("hideCallPanel")) { CallManager callManager = mainFrame.getCallManager(); - if (hideCallPanelItem.isSelected()) { - callManager.hideCallPanel(); - } - else { - callManager.showCallPanel(); - } + callManager.setCallPanelVisible(!hideCallPanelItem.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 index ee788e2c3..65106e338 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java @@ -16,32 +16,74 @@ public class ConfigurationManager */ private static boolean autoPopupNewMessage; + private static boolean isCallPanelShown; + + private static boolean isShowOffline; + + private static boolean isApplicationVisible; + + private static ConfigurationService configService + = GuiActivator.getConfigurationService(); + public static void loadGuiConfigurations() - { - ConfigurationService configService - = GuiActivator.getConfigurationService(); - + { String autoPopup = configService.getString( "net.java.sip.communicator.impl.gui.autoPopupNewMessage"); + + String callPanelShown = configService.getString( + "net.java.sip.communicator.impl.gui.showCallPanel"); + + String showOffline = configService.getString( + "net.java.sip.communicator.impl.gui.showOffline"); + + String isVisible = configService.getString( + "net.java.sip.communicator.impl.systray.showApplication"); if(autoPopup == null || autoPopup.equalsIgnoreCase("yes")) autoPopupNewMessage = true; else autoPopupNewMessage = false; + + if(callPanelShown != null && callPanelShown != "") + { + isCallPanelShown = new Boolean(callPanelShown).booleanValue(); + } + + if(showOffline != null && showOffline != "") + { + isShowOffline = new Boolean(showOffline).booleanValue(); + } + + if(isVisible != null && isVisible != "") + { + isApplicationVisible = new Boolean(isVisible).booleanValue(); + } } public static boolean isAutoPopupNewMessage() { return autoPopupNewMessage; } + + public static boolean isCallPanelShown() + { + return isCallPanelShown; + } + + public static boolean isShowOffline() + { + return isShowOffline; + } + + public static boolean isApplicationVisible() + { + return isApplicationVisible; + } public static void setAutoPopupNewMessage(boolean autoPopupNewMessage) { ConfigurationManager.autoPopupNewMessage = autoPopupNewMessage; - - ConfigurationService configService - = GuiActivator.getConfigurationService(); - + if(autoPopupNewMessage) configService.setProperty( "net.java.sip.communicator.impl.gui.autoPopupNewMessage", @@ -51,4 +93,31 @@ public static void setAutoPopupNewMessage(boolean autoPopupNewMessage) "net.java.sip.communicator.impl.gui.autoPopupNewMessage", "no"); } + + public static void setShowOffline(boolean isShowOffline) + { + ConfigurationManager.isShowOffline = isShowOffline; + + configService.setProperty( + "net.java.sip.communicator.impl.gui.showOffline", + new Boolean(isShowOffline)); + } + + public static void setShowCallPanel(boolean isCallPanelShown) + { + ConfigurationManager.isCallPanelShown = isCallPanelShown; + + configService.setProperty( + "net.java.sip.communicator.impl.gui.showCallPanel", + new Boolean(isCallPanelShown)); + } + + public static void setApplicationVisible(boolean isVisible) + { + isApplicationVisible = isVisible; + + configService.setProperty( + "net.java.sip.communicator.impl.systray.showApplication", + new Boolean(isVisible)); + } } diff --git a/src/net/java/sip/communicator/impl/systray/SystrayActivator.java b/src/net/java/sip/communicator/impl/systray/SystrayActivator.java index a36e9c9a7..87693023b 100644 --- a/src/net/java/sip/communicator/impl/systray/SystrayActivator.java +++ b/src/net/java/sip/communicator/impl/systray/SystrayActivator.java @@ -7,6 +7,7 @@ package net.java.sip.communicator.impl.systray; import net.java.sip.communicator.impl.systray.jdic.*; +import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.util.*; @@ -27,6 +28,8 @@ public class SystrayActivator public static UIService uiService; + private static ConfigurationService configService; + private static Logger logger = Logger.getLogger( SystrayActivator.class.getName()); @@ -60,4 +63,24 @@ public void start(BundleContext bc) throws Exception */ public void stop(BundleContext bc) throws Exception { } + + + /** + * Returns the ConfigurationService obtained from the bundle + * context. + * @return the ConfigurationService obtained from the bundle + * context + */ + public static ConfigurationService getConfigurationService() + { + if(configService == null) { + ServiceReference configReference = bundleContext + .getServiceReference(ConfigurationService.class.getName()); + + configService = (ConfigurationService) bundleContext + .getService(configReference); + } + + return configService; + } }