aboutsummaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorpaweldomas <pawel.domas@jitsi.org>2013-07-02 13:57:19 +0200
committerpaweldomas <pawel.domas@jitsi.org>2013-07-02 13:57:19 +0200
commit433c5df32e803a6d1758c86803c08bc9c76c2551 (patch)
treed5ba63eec3ef203caaa7bdf0fad26b1e063116cd /src/net
parenta9725da99aa55eca61f5bcdc3b106bc4da492b0c (diff)
downloadjitsi-433c5df32e803a6d1758c86803c08bc9c76c2551.zip
jitsi-433c5df32e803a6d1758c86803c08bc9c76c2551.tar.gz
jitsi-433c5df32e803a6d1758c86803c08bc9c76c2551.tar.bz2
Extracts AbstractSystrayService.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/java/sip/communicator/impl/osdependent/jdic/SystrayServiceJdicImpl.java152
-rw-r--r--src/net/java/sip/communicator/service/systray/AbstractSystrayService.java201
-rw-r--r--src/net/java/sip/communicator/service/systray/systray.manifest.mf1
3 files changed, 220 insertions, 134 deletions
diff --git a/src/net/java/sip/communicator/impl/osdependent/jdic/SystrayServiceJdicImpl.java b/src/net/java/sip/communicator/impl/osdependent/jdic/SystrayServiceJdicImpl.java
index 782a84c..2b32f42 100644
--- a/src/net/java/sip/communicator/impl/osdependent/jdic/SystrayServiceJdicImpl.java
+++ b/src/net/java/sip/communicator/impl/osdependent/jdic/SystrayServiceJdicImpl.java
@@ -9,8 +9,6 @@ package net.java.sip.communicator.impl.osdependent.jdic;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
-import java.util.*;
-import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
@@ -38,9 +36,10 @@ import com.apple.eawt.*;
* @author Yana Stamcheva
* @author Lyubomir Marinov
* @author Symphorien Wanko
+ * @author Pawel Domas
*/
public class SystrayServiceJdicImpl
- implements SystrayService
+ extends AbstractSystrayService
{
/**
@@ -59,17 +58,6 @@ public class SystrayServiceJdicImpl
private Object menu;
/**
- * The popup handler currently used to show popup messages
- */
- private PopupMessageHandler activePopupHandler;
-
- /**
- * A set of usable <tt>PopupMessageHandler</tt>
- */
- private final Hashtable<String, PopupMessageHandler> popupHandlerSet
- = new Hashtable<String, PopupMessageHandler>();
-
- /**
* The <tt>ConfigurationService</tt> obtained from the associated
* <tt>BundleActivator</tt>.
*/
@@ -129,12 +117,6 @@ public class SystrayServiceJdicImpl
= new SystrayPopupMessageListenerImpl();
/**
- * List of listeners from early received calls to addPopupMessageListener.
- * Calls to addPopupMessageListener before the UIService is registered.
- */
- private List<SystrayPopupMessageListener> earlyAddedListeners = null;
-
- /**
* Initializes a new <tt>SystrayServiceJdicImpl</tt> instance.
*/
public SystrayServiceJdicImpl()
@@ -332,7 +314,7 @@ public class SystrayServiceJdicImpl
if (!isMac)
{
pmh = new PopupMessageHandlerTrayIconImpl(trayIcon);
- popupHandlerSet.put(pmh.getClass().getName(), pmh);
+ addPopupHandler(pmh);
OsDependentActivator.bundleContext.registerService(
PopupMessageHandler.class.getName(),
pmh,
@@ -379,9 +361,9 @@ public class SystrayServiceJdicImpl
handlerRef);
String handlerName = handler.getClass().getName();
- if (!popupHandlerSet.containsKey(handlerName))
+ if (!containsHandler(handlerName))
{
- popupHandlerSet.put(handlerName, handler);
+ addPopupHandler(handler);
if (logger.isInfoEnabled())
{
logger.info(
@@ -408,7 +390,7 @@ public class SystrayServiceJdicImpl
* becomes available. We will be aware of it since we listen for new
* registered services in the BundleContext.
*/
- if ((activePopupHandler == null) && (pmh != null))
+ if ((getActivePopupMessageHandler() == null) && (pmh != null))
setActivePopupMessageHandler(pmh);
SwingUtilities.invokeLater(new Runnable()
@@ -425,51 +407,6 @@ public class SystrayServiceJdicImpl
}
/**
- * Implements <tt>SystraService#showPopupMessage()</tt>
- *
- * @param popupMessage the message we will show
- */
- public void showPopupMessage(PopupMessage popupMessage)
- {
- // since popup handler could be loaded and unloader on the fly,
- // we have to check if we currently have a valid one.
- if (activePopupHandler != null)
- activePopupHandler.showPopupMessage(popupMessage);
- }
-
- /**
- * Implements the <tt>SystrayService.addPopupMessageListener</tt> method.
- * If <tt>activePopupHandler</tt> is still not available record the listener
- * so we can add him later.
- *
- * @param listener the listener to add
- */
- public void addPopupMessageListener(SystrayPopupMessageListener listener)
- {
- if (activePopupHandler != null)
- activePopupHandler.addPopupMessageListener(listener);
- else
- {
- if(earlyAddedListeners == null)
- earlyAddedListeners =
- new ArrayList<SystrayPopupMessageListener>();
-
- earlyAddedListeners.add(listener);
- }
- }
-
- /**
- * Implements the <tt>SystrayService.removePopupMessageListener</tt> method.
- *
- * @param listener the listener to remove
- */
- public void removePopupMessageListener(SystrayPopupMessageListener listener)
- {
- if (activePopupHandler != null)
- activePopupHandler.removePopupMessageListener(listener);
- }
-
- /**
* Sets a new Systray icon.
*
* @param imageType the type of the image to set.
@@ -594,67 +531,14 @@ public class SystrayServiceJdicImpl
public PopupMessageHandler setActivePopupMessageHandler(
PopupMessageHandler newHandler)
{
- PopupMessageHandler oldHandler = activePopupHandler;
+ PopupMessageHandler oldHandler = getActivePopupHandler();
if (oldHandler != null)
oldHandler.removePopupMessageListener(popupMessageListener);
if (newHandler != null)
newHandler.addPopupMessageListener(popupMessageListener);
- if (logger.isInfoEnabled())
- {
- logger.info(
- "setting the following popup handler as active: "
- + newHandler);
- }
- activePopupHandler = newHandler;
- // if we have received calls to addPopupMessageListener before
- // the UIService is registered we should add those listeners
- if(earlyAddedListeners != null)
- {
- for(SystrayPopupMessageListener l : earlyAddedListeners)
- activePopupHandler.addPopupMessageListener(l);
-
- earlyAddedListeners.clear();
- earlyAddedListeners = null;
- }
-
- return oldHandler;
- }
- /**
- * Get the handler currently used by this implementation to popup message
- * @return the current handler
- */
- public PopupMessageHandler getActivePopupMessageHandler()
- {
- return activePopupHandler;
- }
-
- /**
- * Sets activePopupHandler to be the one with the highest preference index.
- */
- public void selectBestPopupMessageHandler()
- {
- PopupMessageHandler preferedHandler = null;
- int highestPrefIndex = 0;
-
- if (!popupHandlerSet.isEmpty())
- {
- Enumeration<String> keys = popupHandlerSet.keys();
-
- while (keys.hasMoreElements())
- {
- String handlerName = keys.nextElement();
- PopupMessageHandler h = popupHandlerSet.get(handlerName);
-
- if (h.getPreferenceIndex() > highestPrefIndex)
- {
- highestPrefIndex = h.getPreferenceIndex();
- preferedHandler = h;
- }
- }
- setActivePopupMessageHandler(preferedHandler);
- }
+ return super.setActivePopupMessageHandler(newHandler);
}
/** our listener for popup message click */
@@ -700,14 +584,12 @@ public class SystrayServiceJdicImpl
if (serviceEvent.getType() == ServiceEvent.REGISTERED)
{
- if (!popupHandlerSet.containsKey(
- handler.getClass().getName()))
+ if (!containsHandler(handler.getClass().getName()))
{
if (logger.isInfoEnabled())
logger.info(
"adding the following popup handler : " + handler);
- popupHandlerSet.put(
- handler.getClass().getName(), handler);
+ addPopupHandler(handler);
}
else
logger.warn("the following popup handler has not " +
@@ -717,9 +599,10 @@ public class SystrayServiceJdicImpl
= (String) cfg.getProperty("systray.POPUP_HANDLER");
if ((configuredHandler == null)
- && ((activePopupHandler == null)
+ && ((getActivePopupHandler() == null)
|| (handler.getPreferenceIndex()
- > activePopupHandler.getPreferenceIndex())))
+ > getActivePopupHandler()
+ .getPreferenceIndex())))
{
// The user doesn't have a preferred handler set and new
// handler with better preference index has arrived,
@@ -740,12 +623,13 @@ public class SystrayServiceJdicImpl
if (logger.isInfoEnabled())
logger.info(
"removing the following popup handler : " + handler);
- popupHandlerSet.remove(handler.getClass().getName());
- if (activePopupHandler == handler)
+ removePopupHandler(handler);
+ PopupMessageHandler activeHandler = getActivePopupHandler();
+ if (activeHandler == handler)
{
- activePopupHandler.removePopupMessageListener(
+ activeHandler.removePopupMessageListener(
popupMessageListener);
- activePopupHandler = null;
+ setActivePopupMessageHandler(null);
// We just lost our default handler, so we replace it
// with the one that has the highest preference index.
diff --git a/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java b/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java
new file mode 100644
index 0000000..637ec05
--- /dev/null
+++ b/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java
@@ -0,0 +1,201 @@
+/*
+ * 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.systray;
+
+import net.java.sip.communicator.service.systray.event.*;
+import net.java.sip.communicator.util.*;
+
+import java.util.*;
+
+/**
+ * Base implementation of {@link SystrayService}. Manages
+ * <tt>PopupMessageHandler</tt>s and <tt>SystrayPopupMessageListener</tt>s.
+ *
+ * @author Nicolas Chamouard
+ * @author Yana Stamcheva
+ * @author Lyubomir Marinov
+ * @author Symphorien Wanko
+ * @author Pawel Domas
+ */
+public abstract class AbstractSystrayService
+ implements SystrayService
+{
+
+ /**
+ * The logger
+ */
+ private final Logger logger
+ = Logger.getLogger(AbstractSystrayService.class);
+
+ /**
+ * The popup handler currently used to show popup messages
+ */
+ private PopupMessageHandler activePopupHandler;
+
+ /**
+ * A set of usable <tt>PopupMessageHandler</tt>
+ */
+ private final Hashtable<String, PopupMessageHandler> popupHandlerSet
+ = new Hashtable<String, PopupMessageHandler>();
+
+ /**
+ * List of listeners from early received calls to addPopupMessageListener.
+ * Calls to addPopupMessageListener before the UIService is registered.
+ */
+ private List<SystrayPopupMessageListener> earlyAddedListeners = null;
+
+ /**
+ * Registers given <tt>PopupMessageHandler</tt>.
+ * @param handler the <tt>PopupMessageHandler</tt> to be registered.
+ */
+ protected void addPopupHandler(PopupMessageHandler handler)
+ {
+ popupHandlerSet.put(handler.getClass().getName(), handler);
+ }
+
+ /**
+ * Removes given <tt>PopupMessageHandler</tt>.
+ * @param handler the <tt>PopupMessageHandler</tt> to be removed.
+ */
+ protected void removePopupHandler(PopupMessageHandler handler)
+ {
+ popupHandlerSet.remove(handler.getClass().getName());
+ }
+
+ /**
+ * Checks if given <tt>handlerClass</tt> is registered as a handler.
+ * @param handlerClass the class name to be checked.
+ * @return <tt>true</tt> if given <tt>handlerClass</tt> is already
+ * registered as a handler.
+ */
+ protected boolean containsHandler(String handlerClass)
+ {
+ return popupHandlerSet.contains(handlerClass);
+ }
+
+ /**
+ * Returns active <tt>PopupMessageHandler</tt>.
+ * @return active <tt>PopupMessageHandler</tt>.
+ */
+ protected PopupMessageHandler getActivePopupHandler()
+ {
+ return activePopupHandler;
+ }
+
+ /**
+ * Implements <tt>SystraService#showPopupMessage()</tt>
+ *
+ * @param popupMessage the message we will show
+ */
+ public void showPopupMessage(PopupMessage popupMessage)
+ {
+ // since popup handler could be loaded and unloader on the fly,
+ // we have to check if we currently have a valid one.
+ if (activePopupHandler != null)
+ activePopupHandler.showPopupMessage(popupMessage);
+ }
+
+ /**
+ * Implements the <tt>SystrayService.addPopupMessageListener</tt> method.
+ * If <tt>activePopupHandler</tt> is still not available record the listener
+ * so we can add him later.
+ *
+ * @param listener the listener to add
+ */
+ public void addPopupMessageListener(SystrayPopupMessageListener listener)
+ {
+ if (activePopupHandler != null)
+ activePopupHandler.addPopupMessageListener(listener);
+ else
+ {
+ if(earlyAddedListeners == null)
+ earlyAddedListeners =
+ new ArrayList<SystrayPopupMessageListener>();
+
+ earlyAddedListeners.add(listener);
+ }
+ }
+
+ /**
+ * Implements the <tt>SystrayService.removePopupMessageListener</tt> method.
+ *
+ * @param listener the listener to remove
+ */
+ public void removePopupMessageListener(SystrayPopupMessageListener listener)
+ {
+ if (activePopupHandler != null)
+ activePopupHandler.removePopupMessageListener(listener);
+ }
+
+ /**
+ * Set the handler which will be used for popup message
+ * @param newHandler the handler to set. providing a null handler is like
+ * disabling popup.
+ * @return the previously used popup handler
+ */
+ public PopupMessageHandler setActivePopupMessageHandler(
+ PopupMessageHandler newHandler)
+ {
+ PopupMessageHandler oldHandler = activePopupHandler;
+
+ if (logger.isInfoEnabled())
+ {
+ logger.info(
+ "setting the following popup handler as active: "
+ + newHandler);
+ }
+ activePopupHandler = newHandler;
+ // if we have received calls to addPopupMessageListener before
+ // the UIService is registered we should add those listeners
+ if(earlyAddedListeners != null)
+ {
+ for(SystrayPopupMessageListener l : earlyAddedListeners)
+ activePopupHandler.addPopupMessageListener(l);
+
+ earlyAddedListeners.clear();
+ earlyAddedListeners = null;
+ }
+
+ return oldHandler;
+ }
+
+ /**
+ * Get the handler currently used by this implementation to popup message
+ * @return the current handler
+ */
+ public PopupMessageHandler getActivePopupMessageHandler()
+ {
+ return activePopupHandler;
+ }
+
+ /**
+ * Sets activePopupHandler to be the one with the highest preference index.
+ */
+ public void selectBestPopupMessageHandler()
+ {
+ PopupMessageHandler preferredHandler = null;
+ int highestPrefIndex = 0;
+
+ if (!popupHandlerSet.isEmpty())
+ {
+ Enumeration<String> keys = popupHandlerSet.keys();
+
+ while (keys.hasMoreElements())
+ {
+ String handlerName = keys.nextElement();
+ PopupMessageHandler h = popupHandlerSet.get(handlerName);
+
+ if (h.getPreferenceIndex() > highestPrefIndex)
+ {
+ highestPrefIndex = h.getPreferenceIndex();
+ preferredHandler = h;
+ }
+ }
+ setActivePopupMessageHandler(preferredHandler);
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/service/systray/systray.manifest.mf b/src/net/java/sip/communicator/service/systray/systray.manifest.mf
index 7ff6ff8..1bc52f7 100644
--- a/src/net/java/sip/communicator/service/systray/systray.manifest.mf
+++ b/src/net/java/sip/communicator/service/systray/systray.manifest.mf
@@ -3,5 +3,6 @@ Bundle-Description: Systray service
Bundle-Vendor: jitsi.org
Bundle-Version: 0.0.1
System-Bundle: yes
+Import-Package: net.java.sip.communicator.util
Export-Package: net.java.sip.communicator.service.systray,
net.java.sip.communicator.service.systray.event