diff options
Diffstat (limited to 'src/net/java/sip')
26 files changed, 609 insertions, 456 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index 33fa243..c5915ce 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -214,15 +214,15 @@ public class UIServiceImpl * <tt>ContainerPluginListener</tt>s that a plugin component is added or * removed from the container. * - * @param pluginComponent the plugin component that is added to the + * @param factory the plugin component factory that is added to the * container. * @param eventID one of the PLUGIN_COMPONENT_XXX static fields indicating * the nature of the event. */ - private void firePluginEvent(PluginComponent pluginComponent, int eventID) + private void firePluginEvent(PluginComponentFactory factory, + int eventID) { - PluginComponentEvent evt = - new PluginComponentEvent(pluginComponent, eventID); + PluginComponentEvent evt = new PluginComponentEvent(factory, eventID); if (logger.isDebugEnabled()) logger.debug("Will dispatch the following plugin component event: " @@ -661,7 +661,7 @@ public class UIServiceImpl * contact exists already, returns it; otherwise, creates a new one. * * @param contact the contact that we'd like to retrieve a chat window for. - * @param escapedMessageID the message ID of the message that should be + * @param escapedMessageUID the message ID of the message that should be * excluded from the history when the last one is loaded in the chat * @return the <tt>Chat</tt> corresponding to the specified contact. * @see UIService#getChat(Contact) @@ -1060,10 +1060,10 @@ public class UIServiceImpl event.getServiceReference()); // we don't care if the source service is not a plugin component - if (! (sService instanceof PluginComponent)) + if (! (sService instanceof PluginComponentFactory)) return; - PluginComponent pluginComponent = (PluginComponent) sService; + PluginComponentFactory factory = (PluginComponentFactory) sService; switch (event.getType()) { @@ -1071,27 +1071,12 @@ public class UIServiceImpl if (logger.isInfoEnabled()) logger.info("Handling registration of a new Plugin Component."); - /* - // call getComponent for the first time when the component is - // needed to be created and add to a container - // skip early creating of components - Object component = pluginComponent.getComponent(); - if (!(component instanceof Component)) - { - logger.error("Plugin Component type is not supported." - + "Should provide a plugin in AWT, SWT or Swing."); - if (logger.isDebugEnabled()) - logger.debug("Logging exception to show the calling plugin", - new Exception("")); - return; - }*/ - - this.firePluginEvent(pluginComponent, + this.firePluginEvent(factory, PluginComponentEvent.PLUGIN_COMPONENT_ADDED); break; case ServiceEvent.UNREGISTERING: - this.firePluginEvent(pluginComponent, + this.firePluginEvent(factory, PluginComponentEvent.PLUGIN_COMPONENT_REMOVED); break; } diff --git a/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java b/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java index 8b22db4..dfe27bd 100644 --- a/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java +++ b/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java @@ -41,17 +41,17 @@ public class PluginComponentEvent * notify about a specific <tt>PluginComponent</tt> and which is to be of a * nature indicated by a specific ID. * - * @param pluginComponent the <tt>PluginComponent</tt> about which the new - * instance is to notify + * @param pluginComponentProvider the <tt>PluginComponentFactory</tt> about + * which the new instance is to notify * @param eventID one of the <tt>PLUGIN_COMPONENT_XXX</tt> constants defined * by the <tt>PluginComponentEvent</tt> class which indicates the very * nature of the event that the new instance is to represent */ public PluginComponentEvent( - PluginComponent pluginComponent, + PluginComponentFactory pluginComponentProvider, int eventID) { - super(pluginComponent); + super(pluginComponentProvider); this.eventID = eventID; } @@ -70,12 +70,12 @@ public class PluginComponentEvent } /** - * Returns the <tt>PluginComponent</tt> associated with this event. + * Returns the <tt>PluginComponentFactory</tt> associated with this event. * - * @return the <tt>PluginComponent</tt> associated with this event + * @return the <tt>PluginComponentFactory</tt> associated with this event */ - public PluginComponent getPluginComponent() + public PluginComponentFactory getPluginComponentFactory() { - return (PluginComponent) getSource(); + return (PluginComponentFactory) getSource(); } } 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 db6dd5b..6a981ec 100644 --- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java +++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java @@ -126,8 +126,8 @@ public class MainFrame /** * A mapping of plug-in components and their corresponding native components. */ - private final Map<PluginComponent, Component> nativePluginsTable = - new Hashtable<PluginComponent, Component>(); + private final List<PluginComponentFactory> nativePluginsTable = + new ArrayList<PluginComponentFactory>(); /** * The north plug-in panel. @@ -1441,7 +1441,7 @@ public class MainFrame = GuiActivator .bundleContext .getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), "(|(" + Container.CONTAINER_ID + "=" @@ -1461,15 +1461,15 @@ public class MainFrame { for (ServiceReference serRef : serRefs) { - PluginComponent c - = (PluginComponent) - GuiActivator.bundleContext.getService(serRef); + PluginComponentFactory factory + = (PluginComponentFactory) + GuiActivator.bundleContext.getService(serRef); - if (c.isNativeComponent()) - nativePluginsTable.put(c, new JPanel()); + if (factory.isNativeComponent()) + nativePluginsTable.add(factory); else { - String pluginConstraints = c.getConstraints(); + String pluginConstraints = factory.getConstraints(); Object constraints; if (pluginConstraints != null) @@ -1480,8 +1480,11 @@ public class MainFrame else constraints = BorderLayout.SOUTH; - this.addPluginComponent((Component) c.getComponent(), c - .getContainer(), constraints); + this.addPluginComponent( + (Component)factory.getPluginComponentInstance(this) + .getComponent(), + factory.getContainer(), + constraints); } } } @@ -1497,13 +1500,13 @@ public class MainFrame */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent pluginComponent = event.getPluginComponent(); - Container pluginContainer = pluginComponent.getContainer(); + PluginComponentFactory factory = event.getPluginComponentFactory(); + Container pluginContainer = factory.getContainer(); if (pluginContainer.equals(Container.CONTAINER_MAIN_WINDOW) || pluginContainer.equals(Container.CONTAINER_STATUS_BAR)) { - String pluginConstraints = pluginComponent.getConstraints(); + String pluginConstraints = factory.getConstraints(); Object constraints; if (pluginConstraints != null) @@ -1513,9 +1516,9 @@ public class MainFrame else constraints = BorderLayout.SOUTH; - if (pluginComponent.isNativeComponent()) + if (factory.isNativeComponent()) { - this.nativePluginsTable.put(pluginComponent, new JPanel()); + this.nativePluginsTable.add(factory); if (isFrameVisible()) { @@ -1530,8 +1533,12 @@ public class MainFrame } else { - this.addPluginComponent((Component) pluginComponent - .getComponent(), pluginContainer, constraints); + this.addPluginComponent( + (Component)factory + .getPluginComponentInstance(MainFrame.this) + .getComponent(), + pluginContainer, + constraints); } } } @@ -1544,30 +1551,33 @@ public class MainFrame */ public void pluginComponentRemoved(PluginComponentEvent event) { - final PluginComponent pluginComponent = event.getPluginComponent(); - final Container containerID = pluginComponent.getContainer(); + final PluginComponentFactory factory = + event.getPluginComponentFactory(); + final Container containerID = factory.getContainer(); if (containerID.equals(Container.CONTAINER_MAIN_WINDOW)) { Object constraints = UIServiceImpl .getBorderLayoutConstraintsFromContainer( - pluginComponent.getConstraints()); + factory.getConstraints()); if (constraints == null) constraints = BorderLayout.SOUTH; - if (pluginComponent.isNativeComponent()) + if (factory.isNativeComponent()) { - if (nativePluginsTable.containsKey(pluginComponent)) + if (nativePluginsTable.contains(factory)) { - final Component c = nativePluginsTable.get(pluginComponent); final Object finalConstraints = constraints; SwingUtilities.invokeLater(new Runnable() { public void run() { - removePluginComponent(c, containerID, + removePluginComponent( + (Component)factory.getPluginComponentInstance( + MainFrame.this).getComponent(), + containerID, finalConstraints); getContentPane().repaint(); @@ -1577,11 +1587,15 @@ public class MainFrame } else { - this.removePluginComponent((Component) pluginComponent - .getComponent(), containerID, constraints); + this.removePluginComponent( + (Component) factory + .getPluginComponentInstance(MainFrame.this) + .getComponent(), + containerID, + constraints); } - nativePluginsTable.remove(pluginComponent); + nativePluginsTable.remove(factory); } } @@ -1590,21 +1604,20 @@ public class MainFrame */ private void removeNativePlugins() { - for (Map.Entry<PluginComponent, Component> entry - : nativePluginsTable.entrySet()) + for (PluginComponentFactory factory: nativePluginsTable) { - PluginComponent pluginComponent = entry.getKey(); - Component c = entry.getValue(); - Object constraints = UIServiceImpl - .getBorderLayoutConstraintsFromContainer(pluginComponent + .getBorderLayoutConstraintsFromContainer(factory .getConstraints()); if (constraints == null) constraints = BorderLayout.SOUTH; - this.removePluginComponent(c, pluginComponent.getContainer(), + this.removePluginComponent( + (Component)factory.getPluginComponentInstance(MainFrame.this) + .getComponent(), + factory.getContainer(), constraints); this.getContentPane().repaint(); @@ -1618,20 +1631,20 @@ public class MainFrame { this.removeNativePlugins(); - for (Map.Entry<PluginComponent, Component> pluginEntry - : nativePluginsTable.entrySet()) + for (PluginComponentFactory factory: nativePluginsTable) { - PluginComponent plugin = pluginEntry.getKey(); Object constraints = UIServiceImpl .getBorderLayoutConstraintsFromContainer( - plugin.getConstraints()); + factory.getConstraints()); - Component c = (Component) plugin.getComponent(); + Component c = (Component) factory + .getPluginComponentInstance(MainFrame.this) + .getComponent(); - this.addPluginComponent(c, plugin.getContainer(), constraints); + this.addPluginComponent(c, factory.getContainer(), constraints); - this.nativePluginsTable.put(plugin, c); + this.nativePluginsTable.add(factory); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java index 892762b..16851ce 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java @@ -1272,7 +1272,7 @@ public class CallPanel { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException ise) @@ -1284,10 +1284,13 @@ public class CallPanel { for (ServiceReference serRef : serRefs) { - PluginComponent component - = (PluginComponent) + PluginComponentFactory factory + = (PluginComponentFactory) GuiActivator.bundleContext.getService(serRef); + PluginComponent component = + factory.getPluginComponentInstance(CallPanel.this); + component.setCurrentContact( CallManager.getPeerMetaContact( callConference.getCallPeers().get(0))); @@ -1685,25 +1688,26 @@ public class CallPanel */ protected void onPluginComponentEvent(PluginComponentEvent ev) { - PluginComponent pc = ev.getPluginComponent(); - Object c; + PluginComponentFactory pc = ev.getPluginComponentFactory(); if (pc.getContainer().equals( net.java.sip.communicator.service.gui.Container - .CONTAINER_CALL_DIALOG) - && ((c = pc.getComponent()) instanceof Component)) + .CONTAINER_CALL_DIALOG)) { - pc.setCurrentContact( + PluginComponent plugin = + pc.getPluginComponentInstance(CallPanel.this); + Component c = (Component)plugin.getComponent(); + plugin.setCurrentContact( CallManager.getPeerMetaContact( callConference.getCallPeers().get(0))); switch (ev.getEventID()) { case PluginComponentEvent.PLUGIN_COMPONENT_ADDED: - settingsPanel.add((Component) c); + settingsPanel.add(c); break; case PluginComponentEvent.PLUGIN_COMPONENT_REMOVED: - settingsPanel.remove((Component) c); + settingsPanel.remove(c); break; } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java index 467ced0..55fd0d6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java @@ -818,7 +818,7 @@ public class ChatWindow try { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) @@ -830,11 +830,12 @@ public class ChatWindow { for (ServiceReference serRef : serRefs) { - PluginComponent c - = (PluginComponent) + PluginComponentFactory factory + = (PluginComponentFactory) GuiActivator .bundleContext.getService(serRef); - Component comp = (Component) c.getComponent(); + Component comp = (Component)factory.getPluginComponentInstance( + ChatWindow.this).getComponent(); // If this component has been already added, we have nothing // more to do here. @@ -842,10 +843,11 @@ public class ChatWindow return; Object borderLayoutConstraint = UIServiceImpl - .getBorderLayoutConstraintsFromContainer(c.getConstraints()); + .getBorderLayoutConstraintsFromContainer( + factory.getConstraints()); this.addPluginComponent(comp, - c.getContainer(), + factory.getContainer(), borderLayoutConstraint); } } @@ -858,23 +860,26 @@ public class ChatWindow */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - Component comp = (Component) c.getComponent(); + Component comp = (Component)factory.getPluginComponentInstance( + ChatWindow.this).getComponent(); // If this component has been already added, we have nothing more to do // here. if (comp.getParent() != null) return; - if (c.getContainer().equals(Container.CONTAINER_CHAT_WINDOW) - || c.getContainer().equals(Container.CONTAINER_CHAT_STATUS_BAR)) + if (factory.getContainer().equals(Container.CONTAINER_CHAT_WINDOW) + || factory.getContainer().equals( + Container.CONTAINER_CHAT_STATUS_BAR)) { Object borderLayoutConstraints = UIServiceImpl - .getBorderLayoutConstraintsFromContainer(c.getConstraints()); + .getBorderLayoutConstraintsFromContainer( + factory.getConstraints()); - this.addPluginComponent((Component) c.getComponent(), - c.getContainer(), + this.addPluginComponent(comp, + factory.getContainer(), borderLayoutConstraints); } } @@ -886,17 +891,21 @@ public class ChatWindow */ public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if (c.getContainer().equals(Container.CONTAINER_CHAT_WINDOW) - || c.getContainer().equals(Container.CONTAINER_CHAT_STATUS_BAR)) + if (factory.getContainer().equals(Container.CONTAINER_CHAT_WINDOW) + || factory.getContainer().equals( + Container.CONTAINER_CHAT_STATUS_BAR)) { Object borderLayoutConstraint = UIServiceImpl - .getBorderLayoutConstraintsFromContainer(c.getConstraints()); - - this.removePluginComponent( (Component) c.getComponent(), - c.getContainer(), - borderLayoutConstraint); + .getBorderLayoutConstraintsFromContainer( + factory.getConstraints()); + + this.removePluginComponent( + (Component)factory.getPluginComponentInstance( + ChatWindow.this).getComponent(), + factory.getContainer(), + borderLayoutConstraint); this.pack(); } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java b/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java index 8671d91..b77c33a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/menus/HelpMenu.java @@ -78,7 +78,7 @@ public class HelpMenu try { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) @@ -90,8 +90,11 @@ public class HelpMenu { for (int i = 0; i < serRefs.length; i ++) { - PluginComponent component = (PluginComponent) GuiActivator - .bundleContext.getService(serRefs[i]);; + PluginComponentFactory factory = + (PluginComponentFactory) GuiActivator + .bundleContext.getService(serRefs[i]); + PluginComponent component = + factory.getPluginComponentInstance(HelpMenu.this); this.add((Component)component.getComponent()); } @@ -110,11 +113,13 @@ public class HelpMenu public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if (c.getContainer().equals(Container.CONTAINER_CHAT_HELP_MENU)) + if (factory.getContainer().equals(Container.CONTAINER_CHAT_HELP_MENU)) { - this.add((Component) c.getComponent()); + this.add( + (Component)factory.getPluginComponentInstance(HelpMenu.this) + .getComponent()); this.revalidate(); this.repaint(); @@ -123,12 +128,13 @@ public class HelpMenu public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if (c.getContainer().equals(Container.CONTAINER_CHAT_HELP_MENU)) + if (factory.getContainer().equals(Container.CONTAINER_CHAT_HELP_MENU)) { - this.remove((Component) c.getComponent()); + this.remove( + (Component)factory.getPluginComponentInstance(HelpMenu.this) + .getComponent()); } } - } diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomCommonRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomCommonRightButtonMenu.java index 1d69446..4cd02de 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomCommonRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomCommonRightButtonMenu.java @@ -109,7 +109,7 @@ public class ChatRoomCommonRightButtonMenu try { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) @@ -121,8 +121,11 @@ public class ChatRoomCommonRightButtonMenu { for (int i = 0; i < serRefs.length; i ++) { - PluginComponent component = (PluginComponent) GuiActivator - .bundleContext.getService(serRefs[i]);; + PluginComponentFactory factory = + (PluginComponentFactory) GuiActivator + .bundleContext.getService(serRefs[i]); + PluginComponent component = + factory.getPluginComponentInstance(this); if (component.getComponent() == null) continue; @@ -169,9 +172,10 @@ public class ChatRoomCommonRightButtonMenu */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - this.add((Component) c.getComponent()); + this.add( + (Component)factory.getPluginComponentInstance(this).getComponent()); this.repaint(); } @@ -184,9 +188,10 @@ public class ChatRoomCommonRightButtonMenu */ public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - this.remove((Component) c.getComponent()); + this.remove( + (Component)factory.getPluginComponentInstance(this).getComponent()); } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java index 63ab880..f933b1a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java @@ -712,7 +712,7 @@ public class ContactListPane try { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) @@ -724,9 +724,11 @@ public class ContactListPane { for (ServiceReference serRef : serRefs) { - PluginComponent component - = (PluginComponent) + PluginComponentFactory factory = + (PluginComponentFactory) GuiActivator.bundleContext.getService(serRef); + PluginComponent component = + factory.getPluginComponentInstance(this); Object selectedValue = getContactList().getSelectedValue(); @@ -740,8 +742,8 @@ public class ContactListPane .setCurrentContactGroup((MetaContactGroup)selectedValue); } - String pluginConstraints = component.getConstraints(); - Object constraints = null; + String pluginConstraints = factory.getConstraints(); + Object constraints; if (pluginConstraints != null) constraints = UIServiceImpl @@ -766,22 +768,22 @@ public class ContactListPane */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent pluginComponent = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); // If the container id doesn't correspond to the id of the plugin // container we're not interested. - if(!pluginComponent.getContainer() - .equals(Container.CONTAINER_CONTACT_LIST)) + if(!factory.getContainer().equals(Container.CONTAINER_CONTACT_LIST)) return; Object constraints = UIServiceImpl - .getBorderLayoutConstraintsFromContainer( - pluginComponent.getConstraints()); + .getBorderLayoutConstraintsFromContainer(factory.getConstraints()); if (constraints == null) constraints = BorderLayout.SOUTH; - this.add((Component) pluginComponent.getComponent(), constraints); + PluginComponent pluginComponent = + factory.getPluginComponentInstance(this); + this.add((Component)pluginComponent.getComponent(), constraints); Object selectedValue = getContactList().getSelectedValue(); @@ -807,14 +809,15 @@ public class ContactListPane */ public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); // If the container id doesn't correspond to the id of the plugin // container we're not interested. - if(!c.getContainer() + if(!factory.getContainer() .equals(Container.CONTAINER_CONTACT_LIST)) return; - this.remove((Component) c.getComponent()); + this.remove( + (Component)factory.getPluginComponentInstance(this).getComponent()); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupRightButtonMenu.java index dc7ef5e..86be7cb 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupRightButtonMenu.java @@ -117,7 +117,7 @@ public class GroupRightButtonMenu { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), osgiFilter); + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) { @@ -128,10 +128,11 @@ public class GroupRightButtonMenu { for (int i = 0; i < serRefs.length; i++) { - PluginComponent component = - (PluginComponent) GuiActivator.bundleContext + PluginComponentFactory factory = + (PluginComponentFactory) GuiActivator.bundleContext .getService(serRefs[i]); - ; + PluginComponent component = + factory.getPluginComponentInstance(this); component.setCurrentContactGroup(group); @@ -198,12 +199,14 @@ public class GroupRightButtonMenu */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if (!c.getContainer().equals( - Container.CONTAINER_GROUP_RIGHT_BUTTON_MENU)) + if (!factory.getContainer().equals( + Container.CONTAINER_GROUP_RIGHT_BUTTON_MENU)) return; + PluginComponent c = factory.getPluginComponentInstance(this); + this.add((Component) c.getComponent()); c.setCurrentContactGroup(group); @@ -219,12 +222,13 @@ public class GroupRightButtonMenu */ public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if (c.getContainer() + if (factory.getContainer() .equals(Container.CONTAINER_GROUP_RIGHT_BUTTON_MENU)) { - this.remove((Component) c.getComponent()); + this.remove((Component)factory.getPluginComponentInstance(this) + .getComponent()); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java index 40f63e2..64b9183 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java @@ -887,7 +887,7 @@ public class MetaContactRightButtonMenu try { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) @@ -899,17 +899,21 @@ public class MetaContactRightButtonMenu { for (int i = 0; i < serRefs.length; i ++) { - PluginComponent component = (PluginComponent) GuiActivator - .bundleContext.getService(serRefs[i]); + PluginComponentFactory factory = + (PluginComponentFactory) GuiActivator + .bundleContext.getService(serRefs[i]); + + PluginComponent component = + factory.getPluginComponentInstance(this); component.setCurrentContact(metaContact); if (component.getComponent() == null) continue; - if(component.getPositionIndex() != -1) + if(factory.getPositionIndex() != -1) this.add((Component)component.getComponent(), - component.getPositionIndex()); + factory.getPositionIndex()); else this.add((Component)component.getComponent()); @@ -1359,20 +1363,21 @@ public class MetaContactRightButtonMenu */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if(!c.getContainer() + if(!factory.getContainer() .equals(Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU)) return; Object constraints = UIServiceImpl.getBorderLayoutConstraintsFromContainer( - c.getConstraints()); + factory.getConstraints()); + PluginComponent c = factory.getPluginComponentInstance(this); if (c.getComponent() == null) return; - int ix = c.getPositionIndex(); + int ix = factory.getPositionIndex(); if (constraints == null) { @@ -1401,12 +1406,13 @@ public class MetaContactRightButtonMenu */ public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent c = event.getPluginComponent(); + PluginComponentFactory factory = event.getPluginComponentFactory(); - if(c.getContainer() + if(factory.getContainer() .equals(Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU)) { - this.remove((Component) c.getComponent()); + this.remove((Component)factory.getPluginComponentInstance(this) + .getComponent()); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java index 43efa38..d117738 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java @@ -158,7 +158,7 @@ public class ToolsMenu try { serRefs = GuiActivator.bundleContext.getServiceReferences( - PluginComponent.class.getName(), + PluginComponentFactory.class.getName(), osgiFilter); } catch (InvalidSyntaxException exc) @@ -170,14 +170,15 @@ public class ToolsMenu { for (ServiceReference serRef : serRefs) { - final PluginComponent component = (PluginComponent) GuiActivator + final PluginComponentFactory f = (PluginComponentFactory) GuiActivator .bundleContext.getService(serRef); SwingUtilities.invokeLater(new Runnable() { public void run() { - add((Component) component.getComponent()); + add((Component) f.getPluginComponentInstance( + ToolsMenu.this).getComponent()); } }); } @@ -293,7 +294,7 @@ public class ToolsMenu */ public void pluginComponentAdded(PluginComponentEvent event) { - final PluginComponent c = event.getPluginComponent(); + final PluginComponentFactory c = event.getPluginComponentFactory(); if(c.getContainer().equals(Container.CONTAINER_TOOLS_MENU)) { @@ -301,7 +302,7 @@ public class ToolsMenu { public void run() { - add((Component) c.getComponent()); + add((Component) c.getPluginComponentInstance(ToolsMenu.this)); } }); @@ -317,7 +318,7 @@ public class ToolsMenu */ public void pluginComponentRemoved(PluginComponentEvent event) { - final PluginComponent c = event.getPluginComponent(); + final PluginComponentFactory c = event.getPluginComponentFactory(); if(c.getContainer().equals(Container.CONTAINER_TOOLS_MENU)) { @@ -325,7 +326,7 @@ public class ToolsMenu { public void run() { - remove((Component) c.getComponent()); + remove((Component) c.getPluginComponentInstance(ToolsMenu.this).getComponent()); } }); } diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java b/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java index e2408b3..9b39b5d 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/AccountStatusPanel.java @@ -399,7 +399,8 @@ public class AccountStatusPanel */ public void pluginComponentAdded(PluginComponentEvent event) { - PluginComponent pluginComponent = event.getPluginComponent(); + PluginComponentFactory pluginComponent = + event.getPluginComponentFactory(); Container containerID = pluginComponent.getContainer(); /* // avoid early creating of components by calling getComponent @@ -425,7 +426,8 @@ public class AccountStatusPanel */ public void pluginComponentRemoved(PluginComponentEvent event) { - PluginComponent pluginComponent = event.getPluginComponent(); + PluginComponentFactory pluginComponent = + event.getPluginComponentFactory(); Container pluginContainer = pluginComponent.getContainer(); /*Object component = pluginComponent.getComponent(); diff --git a/src/net/java/sip/communicator/impl/gui/utils/PluginContainer.java b/src/net/java/sip/communicator/impl/gui/utils/PluginContainer.java index e36d4f4..134369b 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/PluginContainer.java +++ b/src/net/java/sip/communicator/impl/gui/utils/PluginContainer.java @@ -104,12 +104,15 @@ public class PluginContainer * Adds the component of a specific <tt>PluginComponent</tt> to the
* associated <tt>Container</tt>.
*
- * @param c the <tt>PluginComponent</tt> which is to have its component
- * added to the <tt>Container</tt> associated with this
- * <tt>PluginContainer</tt>
+ * @param factory the <tt>PluginComponentFactory</tt> which is to have its
+ * component added to the <tt>Container</tt> associated with this
+ * <tt>PluginContainer</tt>
*/
- private synchronized void addPluginComponent(PluginComponent c)
+ private synchronized void addPluginComponent(PluginComponentFactory factory)
{
+ PluginComponent c =
+ factory.getPluginComponentInstance(PluginContainer.this);
+
if (logger.isInfoEnabled())
logger.info("Will add plugin component: " + c);
@@ -119,7 +122,7 @@ public class PluginContainer * these with positionIndex equal to -1 follow them and then go these
* with positionIndex greater than 0.
*/
- int cIndex = c.getPositionIndex();
+ int cIndex = factory.getPositionIndex();
int index = -1;
int i = 0;
@@ -130,7 +133,7 @@ public class PluginContainer if (-1 == index)
{
- int pluginComponentIndex = pluginComponent.getPositionIndex();
+ int pluginComponentIndex = factory.getPositionIndex();
if ((0 == cIndex) || (-1 == cIndex))
{
@@ -238,7 +241,7 @@ public class PluginContainer = GuiActivator
.bundleContext
.getServiceReferences(
- PluginComponent.class.getName(),
+ PluginComponentFactory.class.getName(),
"("
+ Container.CONTAINER_ID
+ "="
@@ -254,11 +257,11 @@ public class PluginContainer {
for (ServiceReference serRef : serRefs)
{
- PluginComponent component
- = (PluginComponent)
+ PluginComponentFactory factory
+ = (PluginComponentFactory)
GuiActivator.bundleContext.getService(serRef);
- addPluginComponent(component);
+ addPluginComponent(factory);
}
}
}
@@ -272,10 +275,10 @@ public class PluginContainer */
public void pluginComponentAdded(PluginComponentEvent event)
{
- PluginComponent c = event.getPluginComponent();
+ PluginComponentFactory factory = event.getPluginComponentFactory();
- if (c.getContainer().equals(containerId))
- addPluginComponent(c);
+ if (factory.getContainer().equals(containerId))
+ addPluginComponent(factory);
}
/**
@@ -287,23 +290,27 @@ public class PluginContainer */
public void pluginComponentRemoved(PluginComponentEvent event)
{
- PluginComponent c = event.getPluginComponent();
+ PluginComponentFactory factory = event.getPluginComponentFactory();
- if (c.getContainer().equals(containerId))
- removePluginComponent(c);
+ if (factory.getContainer().equals(containerId))
+ removePluginComponent(factory);
}
/**
* Removes the component of a specific <code>PluginComponent</code> from
* this <code>PluginContainer</code>.
*
- * @param c
+ * @param factory
* the <code>PluginComponent</code> which is to have its
* component removed from this <code>PluginContainer</code>
*/
- private synchronized void removePluginComponent(PluginComponent c)
+ private synchronized void removePluginComponent(
+ PluginComponentFactory factory)
{
- container.remove((Component) c.getComponent());
- pluginComponents.remove(c);
+ PluginComponent p =
+ factory.getPluginComponentInstance(PluginContainer.this);
+ Component c = (Component)factory.getPluginComponentInstance(p);
+ container.remove(c);
+ pluginComponents.remove(p);
}
}
diff --git a/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java b/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java index e19340c..6a874cf 100644 --- a/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java +++ b/src/net/java/sip/communicator/plugin/branding/BrandingActivator.java @@ -221,10 +221,18 @@ public class BrandingActivator helpMenuFilter.put( Container.CONTAINER_ID, Container.CONTAINER_HELP_MENU.getID()); - bundleContext.registerService( PluginComponent.class.getName(), - new AboutWindowPluginComponent( - Container.CONTAINER_HELP_MENU), - helpMenuFilter); + bundleContext.registerService( + PluginComponentFactory.class.getName(), + new PluginComponentFactory( + Container.CONTAINER_HELP_MENU) + { + @Override + protected PluginComponent getPluginInstance() + { + return new AboutWindowPluginComponent(getContainer()); + } + }, + helpMenuFilter); if (logger.isInfoEnabled()) logger.info("ABOUT WINDOW ... [REGISTERED]"); @@ -235,10 +243,18 @@ public class BrandingActivator chatHelpMenuFilter.put( Container.CONTAINER_ID, Container.CONTAINER_CHAT_HELP_MENU.getID()); - bundleContext.registerService( PluginComponent.class.getName(), - new AboutWindowPluginComponent( - Container.CONTAINER_CHAT_HELP_MENU), - chatHelpMenuFilter); + bundleContext.registerService( + PluginComponentFactory.class.getName(), + new PluginComponentFactory( + Container.CONTAINER_CHAT_HELP_MENU) + { + @Override + protected PluginComponent getPluginInstance() + { + return new AboutWindowPluginComponent(getContainer()); + } + }, + chatHelpMenuFilter); if (logger.isInfoEnabled()) logger.info("CHAT ABOUT WINDOW ... [REGISTERED]"); diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java index 2412bf2..200dddb 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java @@ -55,17 +55,17 @@ public class ContactInfoActivator implements BundleActivator {
bundleContext = bc;
- ContactInfoMenuItem cinfoMenuItem = new ContactInfoMenuItem();
-
Hashtable<String, String> containerFilter
= new Hashtable<String, String>();
containerFilter.put(
Container.CONTAINER_ID,
Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID());
- bundleContext.registerService( PluginComponent.class.getName(),
- cinfoMenuItem,
- containerFilter);
+ bundleContext.registerService(
+ PluginComponentFactory.class.getName(),
+ new ContactInfoPluginComponentFactory(
+ Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU),
+ containerFilter);
if(getConfigService().getBoolean(ENABLED_IN_CHAT_WINDOW_PROP, false))
{
@@ -75,8 +75,9 @@ public class ContactInfoActivator implements BundleActivator Container.CONTAINER_CHAT_TOOL_BAR.getID());
bundleContext.registerService(
- PluginComponent.class.getName(),
- new ContactInfoMenuItem(Container.CONTAINER_CHAT_TOOL_BAR),
+ PluginComponentFactory.class.getName(),
+ new ContactInfoPluginComponentFactory(
+ Container.CONTAINER_CHAT_TOOL_BAR),
containerFilter);
}
@@ -88,8 +89,9 @@ public class ContactInfoActivator implements BundleActivator Container.CONTAINER_CALL_DIALOG.getID());
bundleContext.registerService(
- PluginComponent.class.getName(),
- new ContactInfoMenuItem(Container.CONTAINER_CALL_DIALOG),
+ PluginComponentFactory.class.getName(),
+ new ContactInfoPluginComponentFactory(
+ Container.CONTAINER_CALL_DIALOG),
containerFilter);
}
@@ -169,4 +171,21 @@ public class ContactInfoActivator implements BundleActivator ConfigurationService.class);
}
+ /**
+ * Contact info create factory.
+ */
+ private class ContactInfoPluginComponentFactory
+ extends PluginComponentFactory
+ {
+ ContactInfoPluginComponentFactory(Container c)
+ {
+ super(c);
+ }
+
+ @Override
+ protected PluginComponent getPluginInstance()
+ {
+ return new ContactInfoMenuItem(getContainer());
+ }
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/exampleplugin/ExamplePluginActivator.java b/src/net/java/sip/communicator/plugin/exampleplugin/ExamplePluginActivator.java index d58f2f8..7d1992b 100644 --- a/src/net/java/sip/communicator/plugin/exampleplugin/ExamplePluginActivator.java +++ b/src/net/java/sip/communicator/plugin/exampleplugin/ExamplePluginActivator.java @@ -33,7 +33,7 @@ public class ExamplePluginActivator public void start(BundleContext bc) throws Exception { - ExamplePluginMenuItem examplePlugin = new ExamplePluginMenuItem(); + final ExamplePluginMenuItem examplePlugin = new ExamplePluginMenuItem(); Hashtable<String, String> containerFilter = new Hashtable<String, String>(); @@ -41,9 +41,18 @@ public class ExamplePluginActivator Container.CONTAINER_ID, Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID()); - bc.registerService( PluginComponent.class.getName(), - examplePlugin, - containerFilter); + bc.registerService( + PluginComponentFactory.class.getName(), + new PluginComponentFactory( + Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU) + { + @Override + protected PluginComponent getPluginInstance() + { + return examplePlugin; + } + }, + containerFilter); if (logger.isInfoEnabled()) logger.info("CONTACT INFO... [REGISTERED]"); diff --git a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java index 5898f86..6038d9f 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java @@ -340,18 +340,20 @@ public class OtrActivator containerFilter.put(Container.CONTAINER_ID, Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID()); - bundleContext - .registerService(PluginComponent.class.getName(), - new OtrMetaContactMenu( - Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU), - containerFilter); + bundleContext.registerService( + PluginComponentFactory.class.getName(), + new OtrPluginComponentFactory( + Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU), + containerFilter); // Register the chat window menu bar item. containerFilter.put(Container.CONTAINER_ID, Container.CONTAINER_CHAT_MENU_BAR.getID()); - bundleContext.registerService(PluginComponent.class.getName(), - new OtrMetaContactMenu(Container.CONTAINER_CHAT_MENU_BAR), + bundleContext.registerService( + PluginComponentFactory.class.getName(), + new OtrPluginComponentFactory( + Container.CONTAINER_CHAT_MENU_BAR), containerFilter); // Register the chat button bar default-action-button. @@ -359,8 +361,9 @@ public class OtrActivator Container.CONTAINER_CHAT_TOOL_BAR.getID()); bundleContext.registerService( - PluginComponent.class.getName(), - new OtrMetaContactButton(Container.CONTAINER_CHAT_TOOL_BAR), + PluginComponentFactory.class.getName(), + new OtrPluginComponentFactory( + Container.CONTAINER_CHAT_TOOL_BAR), containerFilter); // Register Swing OTR action handler @@ -369,8 +372,6 @@ public class OtrActivator new SwingOtrActionHandler(), null); } - - // If the general configuration form is disabled don't register it. if (!configService.getBoolean(OTR_CHAT_CONFIG_DISABLED_PROP, false) && !OSUtils.IS_ANDROID) @@ -446,4 +447,23 @@ public class OtrActivator } return metaCListService; } + + /** + * The factory that will be registered in OSGi and will create + * otr menu instances. + */ + private class OtrPluginComponentFactory + extends PluginComponentFactory + { + OtrPluginComponentFactory(Container c) + { + super(c); + } + + @Override + protected PluginComponent getPluginInstance() + { + return new OtrMetaContactMenu(getContainer()); + } + } } diff --git a/src/net/java/sip/communicator/plugin/profiler4j/ProfilerActivator.java b/src/net/java/sip/communicator/plugin/profiler4j/ProfilerActivator.java index 76b0824..8ae5fb4 100644 --- a/src/net/java/sip/communicator/plugin/profiler4j/ProfilerActivator.java +++ b/src/net/java/sip/communicator/plugin/profiler4j/ProfilerActivator.java @@ -32,7 +32,7 @@ public class ProfilerActivator implements BundleActivator { public void start(BundleContext bc) throws Exception { bundleContext = bc; - SettingsWindowMenuEntry menuEntry = new SettingsWindowMenuEntry( + final SettingsWindowMenuEntry menuEntry = new SettingsWindowMenuEntry( Container.CONTAINER_TOOLS_MENU); Hashtable<String, String> toolsMenuFilter = @@ -40,8 +40,17 @@ public class ProfilerActivator implements BundleActivator { toolsMenuFilter.put(Container.CONTAINER_ID, Container.CONTAINER_TOOLS_MENU.getID()); - menuRegistration = bc.registerService(PluginComponent.class - .getName(), menuEntry, toolsMenuFilter); + menuRegistration = bc.registerService( + PluginComponentFactory.class.getName(), + new PluginComponentFactory(Container.CONTAINER_TOOLS_MENU) + { + @Override + protected PluginComponent getPluginInstance() + { + return menuEntry; + } + }, + toolsMenuFilter); if (logger.isInfoEnabled()) logger.info("PROFILER4J [REGISTERED]"); diff --git a/src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java b/src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java deleted file mode 100644 index 79fcc80..0000000 --- a/src/net/java/sip/communicator/plugin/spellcheck/CheckerToggleButton.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. See terms of license at gnu.org. - */ -package net.java.sip.communicator.plugin.spellcheck; - -import java.awt.event.*; - -import javax.swing.*; - -import net.java.sip.communicator.service.contactlist.*; -import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.protocol.*; - -/** - * Toggle-able button that sets the spell checker to be either enabled or - * disabled. - * - * @author Damian Johnson - */ -public class CheckerToggleButton - implements PluginComponent -{ - private final JToggleButton toggleButton; - - CheckerToggleButton(final SpellChecker checker) - { - this.toggleButton = - new JToggleButton(Resources.getImage("plugin.spellcheck.DISABLE")); - this.toggleButton.setSelectedIcon(Resources - .getImage("plugin.spellcheck.ENABLE")); - this.toggleButton.setSelected(checker.isEnabled()); - this.toggleButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent event) - { - checker.setEnabled(toggleButton.isSelected()); - } - }); - } - - public Object getComponent() - { - return this.toggleButton; - } - - public String getConstraints() - { - return Container.RIGHT; - } - - public Container getContainer() - { - return Container.CONTAINER_CHAT_TOOL_BAR; - } - - public String getName() - { - return "Spell Checker Toggle"; - } - - public int getPositionIndex() - { - return -1; - } - - public boolean isNativeComponent() - { - return false; - } - - public void setCurrentContact(MetaContact metaContact) - { - - } - - public void setCurrentContactGroup(MetaContactGroup metaGroup) - { - - } - - public void setCurrentContact(Contact contact) - { - - } -} diff --git a/src/net/java/sip/communicator/plugin/spellcheck/LanguageMenuBar.java b/src/net/java/sip/communicator/plugin/spellcheck/LanguageMenuBar.java index 4a19731..a27c02e 100644 --- a/src/net/java/sip/communicator/plugin/spellcheck/LanguageMenuBar.java +++ b/src/net/java/sip/communicator/plugin/spellcheck/LanguageMenuBar.java @@ -43,10 +43,6 @@ public class LanguageMenuBar */ private static final long serialVersionUID = 0L; - private static final HashMap<SpellChecker, LanguageMenuBar> - CLASS_INSTANCES = - new HashMap<SpellChecker, LanguageMenuBar>(); - // parallel maps containing cached instances of country flags private static final HashMap<Parameters.Locale, ImageIcon> AVAILABLE_FLAGS = new HashMap<Parameters.Locale, ImageIcon>(); @@ -77,30 +73,7 @@ public class LanguageMenuBar public final JList list; - /** - * Provides instance of this class associated with a spell checker. If ones - * already been created then this instance is used. - * - * @param checker spell checker field is to be associated with - * @return spell checker locale selection field - */ - public synchronized static LanguageMenuBar makeSelectionField( - SpellChecker checker) - { - // singleton constructor to ensure only one combo box is associated with - // each checker - if (CLASS_INSTANCES.containsKey(checker)) - return CLASS_INSTANCES.get(checker); - else - { - LanguageMenuBar instance = - new LanguageMenuBar(checker); - CLASS_INSTANCES.put(checker, instance); - return instance; - } - } - - private LanguageMenuBar(SpellChecker checker) + LanguageMenuBar(SpellChecker checker) { this.spellChecker = checker; @@ -264,42 +237,12 @@ public class LanguageMenuBar }); } - /** - * Clears any cached data used by the field so it reflects the current state - * of its associated spell checker. - */ - // public void revalidate() - // { - // this.localeAvailabilityCache.clear(); - // this.field.setSelectedItem(this.spellChecker.getLocale()); - // } - - public String getConstraints() - { - return Container.RIGHT; - } - - public Container getContainer() - { - return Container.CONTAINER_CHAT_TOOL_BAR; - } - @Override public String getName() { return "Spell Checker Toggle"; } - public int getPositionIndex() - { - return -1; - } - - public boolean isNativeComponent() - { - return false; - } - public void setCurrentContact(MetaContact metaContact) { diff --git a/src/net/java/sip/communicator/plugin/spellcheck/SpellCheckActivator.java b/src/net/java/sip/communicator/plugin/spellcheck/SpellCheckActivator.java index cb68963..84c8a2d 100644 --- a/src/net/java/sip/communicator/plugin/spellcheck/SpellCheckActivator.java +++ b/src/net/java/sip/communicator/plugin/spellcheck/SpellCheckActivator.java @@ -9,6 +9,7 @@ import java.util.*; import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.util.*; import org.jitsi.service.configuration.*; import org.jitsi.service.fileaccess.*; import org.osgi.framework.*; @@ -21,11 +22,11 @@ import javax.swing.*; * @author Damian Johnson */ public class SpellCheckActivator - implements BundleActivator + extends AbstractServiceDependentActivator { static BundleContext bundleContext; - private SpellChecker checker = new SpellChecker(); + private SpellChecker checker = null; private static UIService uiService; @@ -36,40 +37,100 @@ public class SpellCheckActivator /** * Called when this bundle is started. * - * @param context The execution context of the bundle being started. + * @param dependentService the service we depend on. */ - public void start(BundleContext context) throws Exception + @Override + public void start(Object dependentService) + { + // UI-Service started. + + // adds button to toggle spell checker + Hashtable<String, String> containerFilter = + new Hashtable<String, String>(); + containerFilter.put(Container.CONTAINER_ID, + Container.CONTAINER_CHAT_TOOL_BAR.getID()); + + // adds field to change language + bundleContext.registerService( + PluginComponentFactory.class.getName(), + new PluginComponentFactory(Container.CONTAINER_CHAT_TOOL_BAR, + Container.RIGHT, + -1, + false) + { + @Override + protected PluginComponent getPluginInstance() + { + LanguageMenuBarCreator creator = + new LanguageMenuBarCreator(); + + try + { + if(!SwingUtilities.isEventDispatchThread()) + SwingUtilities.invokeAndWait(creator); + else + creator.run(); + + return creator.menuBar; + } + catch(Throwable t) + { + t.printStackTrace(); + } + + return null; + } + }, + containerFilter); + + } + + /** + * Setting context to the activator, as soon as we have one. + * + * @param context the context to set. + */ + @Override + public void setBundleContext(BundleContext context) { bundleContext = context; + } - this.checker.start(context); + /** + * This activator depends on UIService. + * @return the class name of uiService. + */ + @Override + public Class<?> getDependentServiceClass() + { + return UIService.class; + } - SwingUtilities.invokeLater(new Runnable() + /** + * Creates and loads everything when needed. + */ + private class LanguageMenuBarCreator + implements Runnable + { + LanguageMenuBar menuBar; + public void run() { - public void run() + if(SpellCheckActivator.this.checker == null) { - final LanguageMenuBar menuBar = - LanguageMenuBar.makeSelectionField(checker); - - new Thread(new Runnable() + SpellCheckActivator.this.checker = new SpellChecker(); + try { - public void run() - { - // adds button to toggle spell checker - Hashtable<String, String> containerFilter = - new Hashtable<String, String>(); - containerFilter.put(Container.CONTAINER_ID, - Container.CONTAINER_CHAT_TOOL_BAR.getID()); - - // adds field to change language - bundleContext.registerService( - PluginComponent.class.getName(), - menuBar, - containerFilter); - } - }).start(); + SpellCheckActivator.this.checker.start(bundleContext); + } + catch(Exception ex) + { + ex.printStackTrace(); + } } - }); + menuBar = new LanguageMenuBar(checker); + menuBar.createSpellCheckerWorker( + SpellCheckActivator.this.checker.getLocale()).start(); + } } /** @@ -135,6 +196,7 @@ public class SpellCheckActivator */ public void stop(BundleContext arg0) throws Exception { - this.checker.stop(); + if(this.checker != null) + this.checker.stop(); } } diff --git a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java index 34bebb2..d6bb2b0 100644 --- a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java +++ b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java @@ -151,14 +151,7 @@ class SpellChecker { public void run() { - // initializes dictionary and saves locale config - // use the worker to set the locale if it fails - // will still show spellcheck and will not fail - // starting spell check plugin - LanguageMenuBar.makeSelectionField(SpellChecker.this) - .createSpellCheckerWorker(locale).start(); - - // attaches to uiService so this'll be attached to future chats + // attaches to uiService so we'll be attached to future chats SpellCheckActivator.getUIService() .addChatListener(SpellChecker.this); diff --git a/src/net/java/sip/communicator/plugin/update/UpdateActivator.java b/src/net/java/sip/communicator/plugin/update/UpdateActivator.java index 67881d6..7e2e30d 100644 --- a/src/net/java/sip/communicator/plugin/update/UpdateActivator.java +++ b/src/net/java/sip/communicator/plugin/update/UpdateActivator.java @@ -190,10 +190,6 @@ public class UpdateActivator if(!cfg.getBoolean(CHECK_FOR_UPDATES_MENU_DISABLED_PROP, false))
{
// Register the "Check for Updates" menu item.
- CheckForUpdatesMenuItemComponent
- checkForUpdatesMenuItemComponent
- = new CheckForUpdatesMenuItemComponent(
- Container.CONTAINER_HELP_MENU);
Hashtable<String, String> toolsMenuFilter
= new Hashtable<String, String>();
@@ -202,9 +198,17 @@ public class UpdateActivator Container.CONTAINER_HELP_MENU.getID());
bundleContext.registerService(
- PluginComponent.class.getName(),
- checkForUpdatesMenuItemComponent,
- toolsMenuFilter);
+ PluginComponentFactory.class.getName(),
+ new PluginComponentFactory(Container.CONTAINER_HELP_MENU)
+ {
+ @Override
+ protected PluginComponent getPluginInstance()
+ {
+ return new CheckForUpdatesMenuItemComponent(
+ getContainer());
+ }
+ },
+ toolsMenuFilter);
}
// Check for software update upon startup if enabled.
diff --git a/src/net/java/sip/communicator/plugin/whiteboard/WhiteboardActivator.java b/src/net/java/sip/communicator/plugin/whiteboard/WhiteboardActivator.java index a4f711d..6dc6c35 100644 --- a/src/net/java/sip/communicator/plugin/whiteboard/WhiteboardActivator.java +++ b/src/net/java/sip/communicator/plugin/whiteboard/WhiteboardActivator.java @@ -44,7 +44,7 @@ public class WhiteboardActivator implements BundleActivator session = new WhiteboardSessionManager (); - WhiteboardMenuItem whiteboardPlugin = new WhiteboardMenuItem (session); + final WhiteboardMenuItem whiteboardPlugin = new WhiteboardMenuItem (session); Hashtable<String, String> containerFilter = new Hashtable<String, String>(); @@ -52,9 +52,18 @@ public class WhiteboardActivator implements BundleActivator Container.CONTAINER_ID, Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU.getID()); - bundleContext.registerService( PluginComponent.class.getName(), - whiteboardPlugin, - containerFilter); + bundleContext.registerService( + PluginComponentFactory.class.getName(), + new PluginComponentFactory( + Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU) + { + @Override + protected PluginComponent getPluginInstance() + { + return whiteboardPlugin; + } + }, + containerFilter); if (logger.isInfoEnabled()) logger.info("WHITEBOARD... [REGISTERED]"); diff --git a/src/net/java/sip/communicator/service/gui/PluginComponent.java b/src/net/java/sip/communicator/service/gui/PluginComponent.java index 6813f3d..7266a87 100644 --- a/src/net/java/sip/communicator/service/gui/PluginComponent.java +++ b/src/net/java/sip/communicator/service/gui/PluginComponent.java @@ -14,7 +14,7 @@ import net.java.sip.communicator.service.protocol.*; * all plugins that would like to add a user interface component to a particular * container in the graphical user interface (GUI). In order to appear in the * GUI all implementations of this interface should be registered through the - * OSGI bundle context. + * OSGI bundle context using <tt>PluginComponentFactory</tt>. * <p> * All components interested in the current contact or group that they're * dealing with (i.g. the one selected in the contact list for example), should @@ -38,37 +38,6 @@ public interface PluginComponent public String getName(); /** - * Returns the identifier of the container, where we would like to add - * our control. All possible container identifiers are defined in the - * <tt>Container</tt> class. If the <tt>Container</tt> returned by this - * method is not supported by the current UI implementation the plugin won't - * be added. - * - * @return the container, where we would like to add our control. - */ - public Container getContainer(); - - /** - * Returns the constraints, which will indicate to the container, where this - * component should be added. All constraints are defined in the Container - * class and are as follows: START, END, TOP, BOTTOM, LEFT, RIGHT. - * - * @return the constraints, which will indicate to the container, where this - * component should be added. - */ - public String getConstraints(); - - /** - * Returns the index position of this component in the container, where it - * will be added. An index of 0 would mean that this component should be - * added before all other components. An index of -1 would mean that the - * position of this component is not important. - * @return the index position of this component in the container, where it - * will be added. - */ - public int getPositionIndex(); - - /** * Returns the component that should be added. This method should return a * valid AWT, SWT or Swing object in order to appear properly in the user * interface. @@ -106,14 +75,4 @@ public interface PluginComponent * @param metaGroup the current meta contact group */ public void setCurrentContactGroup(MetaContactGroup metaGroup); - - /** - * Returns <code>true</code> to indicate that this component is a native - * component and <code>false</code> otherwise. This method is meant to be - * used by containers if a special treatment is needed for native components. - * - * @return <code>true</code> to indicate that this component is a native - * component and <code>false</code> otherwise. - */ - public boolean isNativeComponent(); } diff --git a/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java b/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java new file mode 100644 index 0000000..2cb5379 --- /dev/null +++ b/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java @@ -0,0 +1,152 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.gui; + +import java.util.*; + +/** + * The <tt>PluginComponentFactory</tt> is the factory that will be used by the + * <tt>PluginComponents</tt> to register in OSGI bundle context and will be + * used by containers of the plugins to create Plugin component instances. + * + * @author Damian Minkov + */ +public abstract class PluginComponentFactory +{ + /** + * The container id for this plugin. + */ + private Container container; + + /** + * Any special constraints if needed for placing the plugin instances. + */ + private String constraints; + + /** + * The position of the plugin, where to be added. + */ + private int position; + + /** + * Is it a native component. + */ + private boolean nativeComponent; + + /** + * Weak hash map holding plugins if the parent (container) is garbage + * collected free and the plugin instance that corresponds it. + */ + private WeakHashMap<Object,PluginComponent> pluginInstances = + new WeakHashMap<Object, PluginComponent>(); + + /** + * Creates a default factory for a <tt>container</tt>. + * @param container the container id for the plugins to be created. + */ + public PluginComponentFactory(Container container) + { + this(container, null, -1, false); + + } + + /** + * Creates factory. + * @param container the container id + * @param constraints the constraints + * @param position a position for the plugin component. + * @param nativeComponent is it native one. + */ + public PluginComponentFactory(Container container, + String constraints, + int position, + boolean nativeComponent) + { + this.container = container; + this.constraints = constraints; + this.position = position; + this.nativeComponent = nativeComponent; + } + + /** + * Returns the identifier of the container, where we would like to add + * our control. All possible container identifiers are defined in the + * <tt>Container</tt> class. If the <tt>Container</tt> returned by this + * method is not supported by the current UI implementation the plugin won't + * be added. + * + * @return the container, where we would like to add our control. + */ + public Container getContainer() + { + return container; + } + + /** + * Returns the constraints, which will indicate to the container, where this + * component should be added. All constraints are defined in the Container + * class and are as follows: START, END, TOP, BOTTOM, LEFT, RIGHT. + * + * @return the constraints, which will indicate to the container, where this + * component should be added. + */ + public String getConstraints() + { + return constraints; + } + + /** + * Returns the index position of this component in the container, where it + * will be added. An index of 0 would mean that this component should be + * added before all other components. An index of -1 would mean that the + * position of this component is not important. + * @return the index position of this component in the container, where it + * will be added. + */ + public int getPositionIndex() + { + return position; + } + + /** + * Returns <code>true</code> to indicate that this component is a native + * component and <code>false</code> otherwise. This method is meant to be + * used by containers if a special treatment is needed for native components. + * + * @return <code>true</code> to indicate that this component is a native + * component and <code>false</code> otherwise. + */ + public boolean isNativeComponent() + { + return nativeComponent; + } + + /** + * Returns the component that should be added. This method should return a + * valid AWT, SWT or Swing object in order to appear properly in the user + * interface. + * @param parent the parent that will contain this plugin + * + * @return the component that should be added. + */ + public PluginComponent getPluginComponentInstance(Object parent) + { + PluginComponent p = pluginInstances.get(parent); + if(p == null) + { + p = getPluginInstance(); + } + + return p; + } + + /** + * Implementers use it to create plugin component instances. + * @return the plugin component instance. + */ + abstract protected PluginComponent getPluginInstance(); +} |