From 834eabfa774027207c735af86c40aac1fdc8e3c2 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Tue, 18 Mar 2008 15:24:30 +0000 Subject: [PATCH] - plugin component listener and events were used only in the implementation, so I have moved them there - Introduced PluginComponent interface to be implemented by all modules that would like add a component( button, menu item, etc.) in the gui. --- .../impl/gui/event/PluginComponentEvent.java | 70 +++++++++++++++ .../gui/event/PluginComponentListener.java | 33 +++++++ .../branding/AboutWindowPluginComponent.java | 61 +++++++++++++ .../service/gui/PluginComponent.java | 89 +++++++++++++++++++ 4 files changed, 253 insertions(+) create mode 100644 src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java create mode 100644 src/net/java/sip/communicator/impl/gui/event/PluginComponentListener.java create mode 100644 src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java create mode 100644 src/net/java/sip/communicator/service/gui/PluginComponent.java diff --git a/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java b/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java new file mode 100644 index 000000000..771d4c66d --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/event/PluginComponentEvent.java @@ -0,0 +1,70 @@ +/* + * 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.event; + +import java.awt.*; +import java.util.*; + +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.gui.Container; + +/** + * The PluginComponentEvent + * @author Yana Stamcheva + */ +public class PluginComponentEvent + extends EventObject +{ + + private int eventID = -1; + + /** + * Indicates that the PluginComponentEvent instance was triggered by + * adding a plugin component. + */ + public static final int PLUGIN_COMPONENT_ADDED = 1; + + /** + * Indicates that the MetaContactEvent instance was triggered by the + * removal of an existing MetaContact. + */ + public static final int PLUGIN_COMPONENT_REMOVED = 2; + + /** + * Creates a new PluginComponentEvent according to the specified + * parameters. + * @param pluginComponent The pluginComponent that is added to the container. + * @param eventID one of the PLUGIN_COMPONENT_XXX static fields indicating + * the nature of the event. + */ + public PluginComponentEvent(PluginComponent pluginComponent, + int eventID) + { + super(pluginComponent); + this.eventID = eventID; + } + + /** + * Returns the PluginComponent associated with this event. + * @return the PluginComponent associated with this event + */ + public PluginComponent getPluginComponent() + { + return (PluginComponent) getSource(); + } + + /** + * Returns an event id specifying whether the type of this event + * (PLUGIN_COMPONENT_ADDED or PLUGIN_COMPONENT_REMOVED) + * + * @return one of the PLUGIN_COMPONENT_XXX int fields of this class. + */ + public int getEventID() + { + return eventID; + } +} diff --git a/src/net/java/sip/communicator/impl/gui/event/PluginComponentListener.java b/src/net/java/sip/communicator/impl/gui/event/PluginComponentListener.java new file mode 100644 index 000000000..fc4d2c4f3 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/event/PluginComponentListener.java @@ -0,0 +1,33 @@ +/* + * 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.event; + +import java.util.*; +/** + * Listens for all events caused by adding or removing of a plugin component. + * + * @author Yana Stamcheva + */ +public interface PluginComponentListener + extends EventListener { + + /** + * Indicates that a plugin component has been successfully added + * to the container. + * @param event the PluginComponentEvent containing the corresponding + * plugin component + */ + public void pluginComponentAdded(PluginComponentEvent event); + + /** + * Indicates that a plugin component has been successfully removed + * from the container. + * @param event the PluginComponentEvent containing the corresponding + * plugin component + */ + public void pluginComponentRemoved(PluginComponentEvent event); +} diff --git a/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java b/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java new file mode 100644 index 000000000..c60206ee9 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/branding/AboutWindowPluginComponent.java @@ -0,0 +1,61 @@ +/* + * 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.plugin.branding; + +import java.awt.event.*; + +import javax.swing.*; + +import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.gui.*; + +public class AboutWindowPluginComponent + implements PluginComponent +{ + private JMenuItem aboutMenuItem + = new JMenuItem(Resources.getString("aboutMenuEntry")); + + public AboutWindowPluginComponent() + { + aboutMenuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + AboutWindow aboutWindow = new AboutWindow(null); + aboutWindow.setVisible(true); + } + }); + } + + public Object getComponent() + { + return aboutMenuItem; + } + + public String getConstraints() + { + return null; + } + + public Container getContainer() + { + return Container.CONTAINER_HELP_MENU; + } + + public String getName() + { + return Resources.getString("aboutMenuEntry"); + } + + public void setCurrentContact(MetaContact metaContact) + { + } + + public void setCurrentContactGroup(MetaContactGroup metaGroup) + { + } +} diff --git a/src/net/java/sip/communicator/service/gui/PluginComponent.java b/src/net/java/sip/communicator/service/gui/PluginComponent.java new file mode 100644 index 000000000..9cf537b32 --- /dev/null +++ b/src/net/java/sip/communicator/service/gui/PluginComponent.java @@ -0,0 +1,89 @@ +/* + * 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.service.gui; + +import net.java.sip.communicator.service.contactlist.*; + +/** + * The PluginComponent is an interface meant to be implemented by + * 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. + *

+ * 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 + * implement the setCurrentContact and + * setCurrentContactGroup methods. + *

+ * Note that getComponent should return a valid AWT, SWT or Swing + * control in order to appear properly in the GUI. + * + * @author Yana Stamcheva + */ +public interface PluginComponent +{ + /** + * Returns the name of this plugin component. This name could be used as a + * label when the component is added to a container, which requires a title. + * A container that could request a name is for example a tabbed pane. + * + * @return the name of this plugin component + */ + 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 + * Container class. If the Container 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 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. + * + * @return the component that should be added. + */ + public Object getComponent(); + + /** + * Sets the current meta contact. Meant to be used by plugin components that + * are interested of the current contact. The current contact could be the + * contact currently selected in the contact list or the contact for the + * currently selected chat, etc. It depends on the container, where this + * component is meant to be added. + * + * @param metaContact the current meta contact + */ + public void setCurrentContact(MetaContact metaContact); + + /** + * Sets the current meta group. Meant to be used by plugin components that + * are interested of the current meta group. The current group is always + * the currently selected group in the contact list. If the group passed + * here is null, this means that no group is selected. + * + * @param metaGroup the current meta contact group + */ + public void setCurrentContactGroup(MetaContactGroup metaGroup); +}