From ccc3a6f458847249ceddc1b11f0bcf963f4fa435 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Thu, 26 Apr 2007 21:35:34 +0000 Subject: [PATCH] a method was created which is charged with the gui loading --- .../communicator/impl/gui/GuiActivator.java | 68 +++++-------- .../impl/gui/PopupDialogImpl.java | 34 +++---- .../communicator/impl/gui/UIServiceImpl.java | 99 +++++++++++++++++-- .../impl/gui/main/CommunicatorMain.java | 68 ------------- .../communicator/impl/gui/main/MainFrame.java | 8 +- 5 files changed, 137 insertions(+), 140 deletions(-) delete mode 100755 src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index 95f5ae7ed..6ca04b0ba 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -35,17 +35,15 @@ public class GuiActivator implements BundleActivator { private static Logger logger = Logger.getLogger(GuiActivator.class.getName()); private static UIServiceImpl uiService = null; - - private CommunicatorMain communicatorMain; - private LoginManager loginManager; - public static BundleContext bundleContext; private static ConfigurationService configService; private static MessageHistoryService msgHistoryService; + private static MetaContactListService metaCListService; + private static CallHistoryService callHistoryService; private static AudioNotifierService audioNotifierService; @@ -64,41 +62,21 @@ public void start(BundleContext bundleContext) throws Exception { GuiActivator.bundleContext = bundleContext; ConfigurationManager.loadGuiConfigurations(); - - this.communicatorMain = new CommunicatorMain(); - - MainFrame mainFrame = communicatorMain.getMainFrame(); - - this.loginManager = new LoginManager(mainFrame); - + try { - ServiceReference clistReference = bundleContext - .getServiceReference(MetaContactListService.class.getName()); - - MetaContactListService contactListService - = (MetaContactListService) bundleContext - .getService(clistReference); - - mainFrame.setContactList(contactListService); - - logger.logEntry(); - - //Create the ui service - this.uiService = new UIServiceImpl(mainFrame); + // Create the ui service + this.uiService = new UIServiceImpl(); logger.info("UI Service...[ STARTED ]"); bundleContext.registerService(UIService.class.getName(), this.uiService, null); - - logger.info("UI Service ...[REGISTERED]"); - if(ConfigurationManager.isApplicationVisible()) - mainFrame.setVisible(true); - - SwingUtilities.invokeLater(new RunLogin()); + logger.info("UI Service ...[REGISTERED]"); + + this.uiService.loadApplicationGui(); - uiService.initExportedWindows(); + logger.logEntry(); } finally { logger.logExit(); @@ -119,16 +97,6 @@ public void stop(BundleContext bundleContext) throws Exception { logger.info("UI Service ...[STOPPED]"); } - /** - * The RunLogin implements the Runnable interface and is used to - * shows the login windows in new thread. - */ - private class RunLogin implements Runnable { - public void run() { - loginManager.runLogin(communicatorMain.getMainFrame()); - } - } - /** * Returns all ProtocolProviderFactorys obtained from the bundle * context. @@ -224,6 +192,24 @@ public static MessageHistoryService getMsgHistoryService() { return msgHistoryService; } + /** + * Returns the MetaContactListService obtained from the bundle + * context. + * @return the MetaContactListService obtained from the bundle + * context + */ + public static MetaContactListService getMetaContactListService() { + if (metaCListService == null) { + ServiceReference clistReference = bundleContext + .getServiceReference(MetaContactListService.class.getName()); + + metaCListService = (MetaContactListService) bundleContext + .getService(clistReference); + } + + return metaCListService; + } + /** * Returns the CallHistoryService obtained from the bundle * context. diff --git a/src/net/java/sip/communicator/impl/gui/PopupDialogImpl.java b/src/net/java/sip/communicator/impl/gui/PopupDialogImpl.java index 32e183c7c..b58416bca 100644 --- a/src/net/java/sip/communicator/impl/gui/PopupDialogImpl.java +++ b/src/net/java/sip/communicator/impl/gui/PopupDialogImpl.java @@ -16,17 +16,15 @@ * * @author Yana Stamcheva */ -public class PopupDialogImpl extends JOptionPane - implements PopupDialog { - - private MainFrame parentWindow; - +public class PopupDialogImpl + extends JOptionPane + implements PopupDialog +{ /** * Creates an instance of PopupDialogImpl. - * @param parentWindow The main application window. */ - public PopupDialogImpl(MainFrame parentWindow) { - this.parentWindow = parentWindow; + public PopupDialogImpl() + { } /** @@ -34,7 +32,7 @@ public PopupDialogImpl(MainFrame parentWindow) { * Invokes the corresponding JOptionPane.showInputDialog method. */ public String showInputPopupDialog(Object message) { - return showInputDialog(parentWindow, message); + return showInputDialog(message); } /** @@ -44,8 +42,7 @@ public String showInputPopupDialog(Object message) { */ public String showInputPopupDialog(Object message, String initialSelectionValue) { - return showInputDialog(parentWindow, message, - initialSelectionValue); + return showInputDialog(message, initialSelectionValue); } /** @@ -72,8 +69,7 @@ else if (messageType == PopupDialog.WARNING_MESSAGE) { else { type = JOptionPane.PLAIN_MESSAGE; } - return (String)showInputDialog(parentWindow, message, - title, type); + return (String)showInputDialog(null, message, title, type); } /** @@ -103,7 +99,7 @@ else if (messageType == PopupDialog.WARNING_MESSAGE) { type = JOptionPane.PLAIN_MESSAGE; } - return showInputDialog(parentWindow, message, title, type, + return showInputDialog(null, message, title, type, null, selectionValues, initialSelectionValue); } @@ -113,7 +109,7 @@ else if (messageType == PopupDialog.WARNING_MESSAGE) { * JOptionPane.showMessageDialog method. */ public void showMessagePopupDialog(Object message) { - showMessageDialog(parentWindow, message); + showMessageDialog(null, message); } /** @@ -140,7 +136,7 @@ else if (messageType == PopupDialog.WARNING_MESSAGE) { type = JOptionPane.PLAIN_MESSAGE; } - showMessageDialog(parentWindow, message, title, type); + showMessageDialog(null, message, title, type); } /** @@ -149,7 +145,7 @@ else if (messageType == PopupDialog.WARNING_MESSAGE) { * JOptionPane.showConfirmDialog method. */ public int showConfirmPopupDialog(Object message) { - return showConfirmDialog(parentWindow, message); + return showConfirmDialog(null, message); } /** @@ -173,7 +169,7 @@ else if (optionType == PopupDialog.YES_NO_CANCEL_OPTION) { type = JOptionPane.DEFAULT_OPTION; } - return showConfirmDialog(parentWindow, message, title, type); + return showConfirmDialog(null, message, title, type); } /** @@ -215,7 +211,7 @@ else if (messageType == PopupDialog.WARNING_MESSAGE) { msgType = JOptionPane.PLAIN_MESSAGE; } - return showConfirmDialog(parentWindow, message, title, + return showConfirmDialog(null, message, title, optType, msgType); } diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index 4a6cd4915..0cab5d85a 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -15,8 +15,11 @@ import java.util.Map; import java.util.Vector; +import javax.swing.*; import javax.swing.JFrame; +import net.java.sip.communicator.impl.gui.GuiActivator.*; +import net.java.sip.communicator.impl.gui.lookandfeel.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.account.AccountRegWizardContainerImpl; import net.java.sip.communicator.impl.gui.main.chat.*; @@ -24,6 +27,7 @@ import net.java.sip.communicator.impl.gui.main.contactlist.ContactListPanel; import net.java.sip.communicator.impl.gui.main.contactlist.addcontact.*; import net.java.sip.communicator.impl.gui.main.login.*; +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.event.PluginComponentEvent; @@ -57,12 +61,15 @@ public class UIServiceImpl supportedContainers.add(UIService.CONTAINER_MAIN_TOOL_BAR); supportedContainers.add(UIService.CONTAINER_CONTACT_RIGHT_BUTTON_MENU); supportedContainers.add(UIService.CONTAINER_GROUP_RIGHT_BUTTON_MENU); + supportedContainers.add(UIService.CONTAINER_TOOLS_MENU); } private static final Hashtable exportedWindows = new Hashtable(); private MainFrame mainFrame; + private LoginManager loginManager; + private ContactListPanel contactListPanel; private ConfigurationFrame configurationFrame; @@ -74,17 +81,36 @@ public class UIServiceImpl * * @param mainFrame The main application window. */ - public UIServiceImpl(MainFrame mainFrame) + public UIServiceImpl() + {} + + /** + * Initializes all frames and panels and shows the gui. + */ + public void loadApplicationGui() { - this.mainFrame = mainFrame; + this.setDefaultThemePack(); + + this.mainFrame = new MainFrame(); + + this.loginManager = new LoginManager(mainFrame); this.contactListPanel = mainFrame.getContactListPanel(); - this.popupDialog = new PopupDialogImpl(mainFrame); + this.popupDialog = new PopupDialogImpl(); this.wizardContainer = new AccountRegWizardContainerImpl(mainFrame); - this.configurationFrame = new ConfigurationFrame(mainFrame); + this.configurationFrame = new ConfigurationFrame(mainFrame); + + mainFrame.setContactList(GuiActivator.getMetaContactListService()); + + if(ConfigurationManager.isApplicationVisible()) + SwingUtilities.invokeLater(new RunApplicationGui()); + + SwingUtilities.invokeLater(new RunLoginGui()); + + this.initExportedWindows(); } /** @@ -100,10 +126,8 @@ public UIServiceImpl(MainFrame mainFrame) public void addComponent(ContainerID containerID, Object component) throws ClassCastException, IllegalArgumentException { - if (!supportedContainers.contains(containerID)) { - throw new IllegalArgumentException( "The constraint that you specified is not" + " supported by this UIService implementation."); @@ -116,15 +140,12 @@ else if (!(component instanceof Component)) } else { - if (registeredPlugins.containsKey(containerID)) { - ((Vector) registeredPlugins.get(containerID)).add(component); } else { - Vector plugins = new Vector(); plugins.add(component); registeredPlugins.put(containerID, plugins); @@ -132,7 +153,6 @@ else if (!(component instanceof Component)) this.firePluginEvent(component, containerID, PluginComponentEvent.PLUGIN_COMPONENT_ADDED); } - } /** @@ -556,4 +576,63 @@ public ExportedWindow getAuthenticationWindow( return new AuthenticationWindow(mainFrame, protocolProvider, realm, userCredentials); } + + /** + * Returns the LoginManager. + * @return the LoginManager + */ + public LoginManager getLoginManager() + { + return loginManager; + } + + /** + * Returns the MainFrame. This is the class defining the main + * application window. + * + * @return the MainFrame + */ + public MainFrame getMainFrame() + { + return mainFrame; + } + + /** + * The RunLogin implements the Runnable interface and is used to + * shows the login windows in a seperate thread. + */ + private class RunLoginGui implements Runnable { + public void run() { + loginManager.runLogin(mainFrame); + } + } + + /** + * The RunApplication implements the Runnable interface and is used to + * shows the main application window in a separate thread. + */ + private class RunApplicationGui implements Runnable { + public void run() { + mainFrame.setVisible(true); + } + } + + /** + * Sets the look&feel and the theme. + */ + private void setDefaultThemePack() { + + SIPCommLookAndFeel lf = new SIPCommLookAndFeel(); + SIPCommLookAndFeel.setCurrentTheme(new SIPCommDefaultTheme()); + + // we need to set the UIDefaults class loader so that it may access + // resources packed inside OSGI bundles + UIManager.put("ClassLoader", getClass().getClassLoader()); + try { + UIManager.setLookAndFeel(lf); + } catch (UnsupportedLookAndFeelException e) { + logger.error("The provided Look & Feel is not supported.", e); + } + } + } diff --git a/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java b/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java deleted file mode 100755 index 28dd2f256..000000000 --- a/src/net/java/sip/communicator/impl/gui/main/CommunicatorMain.java +++ /dev/null @@ -1,68 +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 javax.swing.*; - -import net.java.sip.communicator.impl.gui.lookandfeel.*; -import net.java.sip.communicator.impl.gui.utils.*; -import net.java.sip.communicator.util.*; - -/** - * Starts the GUI application using the SIPCommLookAndFeel with the - * SIPCommDefaultTheme. - * - * @author Yana Stamcheva - */ -public class CommunicatorMain { - - private MainFrame mainFrame; - - private Logger logger = Logger.getLogger(CommunicatorMain.class.getName()); - - /** - * Creates an instance of CommunicatorMain. Creates the - * MainFrame. - */ - public CommunicatorMain() { - - this.setDefaultThemePack(); - - mainFrame = new MainFrame(); - - // In order to have the same icon when using option panes - JOptionPane.getRootFrame().setIconImage( - ImageLoader.getImage(ImageLoader.SIP_COMMUNICATOR_LOGO)); - } - - /** - * Sets the look&feel and the theme. - */ - public void setDefaultThemePack() { - - SIPCommLookAndFeel lf = new SIPCommLookAndFeel(); - SIPCommLookAndFeel.setCurrentTheme(new SIPCommDefaultTheme()); - - // we need to set the UIDefaults class loader so that it may access - // resources packed inside OSGI bundles - UIManager.put("ClassLoader", getClass().getClassLoader()); - try { - UIManager.setLookAndFeel(lf); - } catch (UnsupportedLookAndFeelException e) { - logger.error("The provided Look & Feel is not supported.", e); - } - } - - /** - * Returns the main application window. - * @return the main application window. - */ - public MainFrame getMainFrame() { - return mainFrame; - } -} 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 9901fc71c..0525bcc1d 100755 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java +++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java @@ -18,6 +18,7 @@ import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.i18n.*; +import net.java.sip.communicator.impl.gui.lookandfeel.*; import net.java.sip.communicator.impl.gui.main.call.*; import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.impl.gui.main.chat.conference.*; @@ -100,13 +101,16 @@ public MainFrame() this.addWindowListener(new MainFrameWindowAdapter()); - //this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setInitialBounds(); this.setTitle(Messages.getI18NString("sipCommunicator").getText()); this.setIconImage( ImageLoader.getImage(ImageLoader.SIP_COMMUNICATOR_LOGO)); + + // In order to have the same icon when using option panes + JOptionPane.getRootFrame().setIconImage( + ImageLoader.getImage(ImageLoader.SIP_COMMUNICATOR_LOGO)); this.init(); } @@ -138,7 +142,7 @@ private void init() this.getContentPane().add(mainPanel); } - + /** * Sets frame size and position. */