diff options
Diffstat (limited to 'src/net/java/sip/communicator/plugin')
11 files changed, 224 insertions, 227 deletions
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]"); |