aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2008-12-11 23:16:05 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2008-12-11 23:16:05 +0000
commitaf2587049ca5cfa8b143559adb9d1d71398f837a (patch)
tree6f56189d6403ac0660fa82710e8810c31a9b8b8f
parente782599a05759ecdafc0d514bfdd488c56936eac (diff)
downloadjitsi-af2587049ca5cfa8b143559adb9d1d71398f837a.zip
jitsi-af2587049ca5cfa8b143559adb9d1d71398f837a.tar.gz
jitsi-af2587049ca5cfa8b143559adb9d1d71398f837a.tar.bz2
Hopes to fix issue #502: Do not use jdic when running Java 6.
-rw-r--r--build.xml2
-rw-r--r--src/net/java/sip/communicator/impl/systray/StatusMessageMenu.java88
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java145
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java115
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java115
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/SystemTray.java218
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java15
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/TrayIcon.java333
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java124
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/TrayMenuFactory.java179
10 files changed, 1017 insertions, 317 deletions
diff --git a/build.xml b/build.xml
index 3f9ed01..e2270c7 100644
--- a/build.xml
+++ b/build.xml
@@ -656,7 +656,7 @@
<sysproperty key="java.library.path"
path="${ld.library.path}:${path}:${dyld.library.path}"/>
<sysproperty key="jna.library.path"
- path="${ld.library.path}:${path}:${dyld.library.path}"/>
+ path="${ld.library.path}:${path}:${dyld.library.path}"/>
<!-- pass l10n properties from ant call for
easy translation debugging -->
diff --git a/src/net/java/sip/communicator/impl/systray/StatusMessageMenu.java b/src/net/java/sip/communicator/impl/systray/StatusMessageMenu.java
index 678019f..ce0f595 100644
--- a/src/net/java/sip/communicator/impl/systray/StatusMessageMenu.java
+++ b/src/net/java/sip/communicator/impl/systray/StatusMessageMenu.java
@@ -15,10 +15,9 @@ import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
public class StatusMessageMenu
- extends JMenu
implements ActionListener
{
- private Logger logger = Logger.getLogger(StatusMessageMenu.class);
+ private final Logger logger = Logger.getLogger(StatusMessageMenu.class);
private static final String BRB_MESSAGE
= Resources.getString("service.gui.BRB_MESSAGE");
@@ -26,55 +25,82 @@ public class StatusMessageMenu
private static final String BUSY_MESSAGE
= Resources.getString("service.gui.BUSY_MESSAGE");
- private JMenuItem noMessageItem
- = new JMenuItem(Resources.getString("service.gui.NO_MESSAGE"));
+ private final Object newMessageItem;
- private JMenuItem newMessageItem
- = new JMenuItem(Resources.getString("service.gui.NEW_MESSAGE"));
+ private final Object busyMessageItem;
- private JMenuItem busyMessageItem = new JMenuItem(BUSY_MESSAGE);
+ private final Object brbMessageItem;
- private JMenuItem brbMessageItem = new JMenuItem(BRB_MESSAGE);
+ private final ProtocolProviderService protocolProvider;
- private ProtocolProviderService protocolProvider;
+ private final Object menu;
- public StatusMessageMenu( ProtocolProviderService protocolProvider)
+ public StatusMessageMenu(ProtocolProviderService protocolProvider,
+ boolean swing)
{
- super(Resources.getString("service.gui.SET_STATUS_MESSAGE"));
-
this.protocolProvider = protocolProvider;
- this.noMessageItem.addActionListener(this);
- this.newMessageItem.addActionListener(this);
- this.busyMessageItem.addActionListener(this);
- this.brbMessageItem.addActionListener(this);
+ String text = Resources.getString("service.gui.SET_STATUS_MESSAGE");
+ if (swing)
+ menu = new JMenu(text);
+ else
+ menu = new Menu(text);
+
+ createMenuItem(Resources.getString("service.gui.NO_MESSAGE"));
+ newMessageItem =
+ createMenuItem(Resources.getString("service.gui.NEW_MESSAGE"));
- this.add(noMessageItem);
- this.add(newMessageItem);
+ addSeparator();
- this.addSeparator();
+ busyMessageItem = createMenuItem(BUSY_MESSAGE);
+ brbMessageItem = createMenuItem(BRB_MESSAGE);
+ }
- this.add(busyMessageItem);
- this.add(brbMessageItem);
+ private Object createMenuItem(String text)
+ {
+ if (menu instanceof Container)
+ {
+ JMenuItem menuItem = new JMenuItem(text);
+ menuItem.addActionListener(this);
+ ((Container) menu).add(menuItem);
+ return menuItem;
+ }
+ else
+ {
+ MenuItem menuItem = new MenuItem(text);
+ menuItem.addActionListener(this);
+ ((Menu) menu).add(menuItem);
+ return menuItem;
+ }
+ }
+
+ private void addSeparator()
+ {
+ if (menu instanceof JMenu)
+ ((JMenu) menu).addSeparator();
+ else
+ ((Menu) menu).addSeparator();
+ }
+
+ public Object getMenu()
+ {
+ return menu;
}
public void actionPerformed(ActionEvent e)
{
- JMenuItem menuItem = (JMenuItem) e.getSource();
+ Object menuItem = e.getSource();
String statusMessage = "";
if (menuItem.equals(newMessageItem))
{
- NewStatusMessageDialog dialog
- = new NewStatusMessageDialog(protocolProvider);
-
- dialog.setLocation(
- Toolkit.getDefaultToolkit().getScreenSize().width/2
- - dialog.getWidth()/2,
- Toolkit.getDefaultToolkit().getScreenSize().height/2
- - dialog.getHeight()/2
- );
+ NewStatusMessageDialog dialog =
+ new NewStatusMessageDialog(protocolProvider);
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+
+ dialog.setLocation(screenSize.width / 2 - dialog.getWidth() / 2,
+ screenSize.height / 2 - dialog.getHeight() / 2);
dialog.setVisible(true);
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java
index 3897c4a..062210e 100644
--- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java
+++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSelector.java
@@ -4,10 +4,9 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
-
package net.java.sip.communicator.impl.systray.jdic;
-
+import java.awt.*;
import java.awt.event.*;
import java.util.*;
@@ -17,38 +16,35 @@ import net.java.sip.communicator.impl.systray.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
-
/**
* The <tt>StatusSelector</tt> is a submenu which allows to select a status for
* a protocol provider which supports the OperationSetPresence.
*
* @author Nicolas Chamouard
- *
+ * @author Lubomir Marinov
*/
public class StatusSelector
- extends JMenu
implements ActionListener
{
/**
* A reference of <tt>Systray</tt>
*/
- private SystrayServiceJdicImpl parentSystray;
+ private final SystrayServiceJdicImpl parentSystray;
/**
* The protocol provider
*/
- private ProtocolProviderService provider;
+ private final ProtocolProviderService provider;
/**
* The presence status
*/
- private OperationSetPresence presence;
+ private final OperationSetPresence presence;
/**
* The logger for this class.
*/
- private Logger logger = Logger.getLogger(
- StatusSelector.class.getName());
+ private final Logger logger = Logger.getLogger(StatusSelector.class);
- private StatusMessageMenu statusMessageMenu;
+ private final Object menu;
/**
* Creates an instance of StatusSelector
@@ -57,96 +53,125 @@ public class StatusSelector
* @param provider the protocol provider
* @param presence the presence status
*/
- public StatusSelector( SystrayServiceJdicImpl jdicSystray,
- ProtocolProviderService provider,
- OperationSetPresence presence)
+ public StatusSelector(SystrayServiceJdicImpl jdicSystray,
+ ProtocolProviderService provider, OperationSetPresence presence,
+ boolean swing)
{
this.parentSystray = jdicSystray;
this.provider = provider;
this.presence = presence;
- this.statusMessageMenu = new StatusMessageMenu(provider);
/* the parent item */
+ {
+ String text = provider.getAccountID().getUserID();
+ if (swing)
+ {
+ JMenu menu = new JMenu(text);
+ menu.setIcon(new ImageIcon(presence.getPresenceStatus()
+ .getStatusIcon()));
- this.setText(provider.getAccountID().getUserID());
- this.setIcon(new ImageIcon(
- presence.getPresenceStatus().getStatusIcon()));
+ this.menu = menu;
+ }
+ else
+ {
+ this.menu = new Menu(text);
+ }
+ }
/* the submenu itself */
Iterator statusIterator = this.presence.getSupportedStatusSet();
- while(statusIterator.hasNext())
+ while (statusIterator.hasNext())
{
PresenceStatus status = (PresenceStatus) statusIterator.next();
+ String text = status.getStatusName();
- ImageIcon icon = new ImageIcon(status.getStatusIcon());
- JMenuItem item = new JMenuItem(status.getStatusName(),icon);
+ if (menu instanceof Container)
+ {
+ ImageIcon icon = new ImageIcon(status.getStatusIcon());
+ JMenuItem item = new JMenuItem(text, icon);
- item.addActionListener(this);
+ item.addActionListener(this);
- this.add(item);
+ ((Container) menu).add(item);
+ }
+ else
+ {
+ MenuItem item = new MenuItem(text);
+ item.addActionListener(this);
+ ((Menu) menu).add(item);
+ }
}
- this.addSeparator();
+ addSeparator();
+
+ StatusSubMenu.addMenuItem(menu, new StatusMessageMenu(provider, swing)
+ .getMenu());
+ }
- this.add(statusMessageMenu);
+ private void addSeparator()
+ {
+ if (menu instanceof JMenu)
+ ((JMenu) menu).addSeparator();
+ else
+ ((Menu) menu).addSeparator();
+ }
+
+ public Object getMenu()
+ {
+ return menu;
}
/**
- * Change the status of the protocol according to
- * the menu item selected
+ * Change the status of the protocol according to the menu item selected
+ *
* @param evt the event containing the menu item name
*/
public void actionPerformed(ActionEvent evt)
{
- JMenuItem menuItem = (JMenuItem) evt.getSource();
+ Object source = evt.getSource();
+ String menuItemText;
+ if (source instanceof AbstractButton)
+ menuItemText = ((AbstractButton) source).getText();
+ else
+ menuItemText = ((MenuItem) source).getLabel();
Iterator statusSet = presence.getSupportedStatusSet();
- while (statusSet.hasNext())
+ while (statusSet.hasNext())
{
- PresenceStatus status = ((PresenceStatus) statusSet.next());
+ PresenceStatus status = (PresenceStatus) statusSet.next();
- if (status.getStatusName().equals(menuItem.getText()))
+ if (status.getStatusName().equals(menuItemText))
{
-
- if (this.provider.getRegistrationState()
- == RegistrationState.REGISTERED
+ RegistrationState registrationState =
+ provider.getRegistrationState();
+
+ if (registrationState == RegistrationState.REGISTERED
&& !presence.getPresenceStatus().equals(status))
{
- if (status.isOnline())
- {
+ if (status.isOnline())
new PublishPresenceStatusThread(status).start();
- }
else
- {
new ProviderUnRegistration(this.provider).start();
- }
}
- else if (this.provider.getRegistrationState()
- != RegistrationState.REGISTERED
- && this.provider.getRegistrationState()
- != RegistrationState.REGISTERING
- && this.provider.getRegistrationState()
- != RegistrationState.AUTHENTICATING
- && status.isOnline())
+ else if (registrationState != RegistrationState.REGISTERED
+ && registrationState != RegistrationState.REGISTERING
+ && registrationState != RegistrationState.AUTHENTICATING
+ && status.isOnline())
{
new ProviderRegistration(provider).start();
}
- else
+ else if (!status.isOnline()
+ && !(registrationState == RegistrationState.UNREGISTERING))
{
- if(!status.isOnline()
- && !(this.provider.getRegistrationState()
- == RegistrationState.UNREGISTERING))
- {
- new ProviderUnRegistration(this.provider).start();
- }
- }
-
- parentSystray.saveStatusInformation(
- provider, status.getStatusName());
-
+ new ProviderUnRegistration(this.provider).start();
+ }
+
+ parentSystray.saveStatusInformation(provider, status
+ .getStatusName());
+
break;
}
}
@@ -161,7 +186,9 @@ public class StatusSelector
+ provider.getAccountID().getAccountAddress()
+ ". The new status will be: " + presenceStatus.getStatusName());
- this.setIcon(new ImageIcon(presenceStatus.getStatusIcon()));
+ if (menu instanceof AbstractButton)
+ ((AbstractButton) menu).setIcon(new ImageIcon(presenceStatus
+ .getStatusIcon()));
}
/**
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java
index 0ad5226..0d4cdbb 100644
--- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java
+++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSimpleSelector.java
@@ -4,10 +4,9 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
-
package net.java.sip.communicator.impl.systray.jdic;
-
+import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@@ -16,87 +15,90 @@ import net.java.sip.communicator.impl.systray.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
-
/**
- * The <tt>StatusSimpleSelector</tt> is a submenu which allow
- * to select a status for a protocol provider which does not
- * support the OperationSetPresence
+ * The <tt>StatusSimpleSelector</tt> is a submenu which allow to select a status
+ * for a protocol provider which does not support the OperationSetPresence
*
* @author Nicolas Chamouard
- *
+ * @author Lubomir Marinov
*/
public class StatusSimpleSelector
- extends JMenu
implements ActionListener
{
- /**
- * A reference of <tt>Systray</tt>
- */
- private SystrayServiceJdicImpl parentSystray;
+
/**
* The protocol provider
*/
- private ProtocolProviderService provider;
+ private final ProtocolProviderService provider;
/**
* The logger for this class.
*/
- private Logger logger = Logger.getLogger(
- StatusSimpleSelector.class.getName());
-
- /**
- * The menu item for the online status
- */
- private JMenuItem onlineItem = new JMenuItem(
- Resources.getString("impl.systray.ONLINE_STATUS"));
- /**
- * The menu item for the offline status
- */
- private JMenuItem offlineItem = new JMenuItem(
- Resources.getString("impl.systray.OFFLINE_STATUS"));
-
+ private final Logger logger = Logger.getLogger(StatusSimpleSelector.class);
+
+ private final Object menu;
+
/**
* Creates an instance of <tt>StatusSimpleSelector</tt>
*
- * @param jdicSystray a reference of the parent <tt>Systray</tt>
* @param protocolProvider the protocol provider
*/
- public StatusSimpleSelector(SystrayServiceJdicImpl jdicSystray,
- ProtocolProviderService protocolProvider)
+ public StatusSimpleSelector(ProtocolProviderService protocolProvider,
+ boolean swing)
{
-
this.provider = protocolProvider;
- this.parentSystray = jdicSystray;
/* the parent item */
+ String text = provider.getAccountID().getUserID();
+ if (swing)
+ {
+ JMenu menu = new JMenu(text);
- ImageIcon icon;
+ ImageIcon icon =
+ new ImageIcon(protocolProvider.getProtocolIcon().getIcon(
+ ProtocolIcon.ICON_SIZE_16x16));
+ if (!provider.isRegistered())
+ {
+ icon =
+ new ImageIcon(LightGrayFilter.createDisabledImage(icon
+ .getImage()));
+ }
+ menu.setIcon(icon);
- if(provider.isRegistered())
- {
- icon = new ImageIcon(protocolProvider.getProtocolIcon()
- .getIcon(ProtocolIcon.ICON_SIZE_16x16));
+ this.menu = menu;
}
else
{
- icon = new ImageIcon(LightGrayFilter.createDisabledImage(
- new ImageIcon(protocolProvider.getProtocolIcon()
- .getIcon(ProtocolIcon.ICON_SIZE_16x16)).getImage()));
+ this.menu = new Menu(text);
}
- this.setText(provider.getAccountID().getUserID());
- this.setIcon(icon);
-
/* the menu itself */
+ createMenuItem("impl.systray.ONLINE_STATUS", "online");
+ createMenuItem("impl.systray.OFFLINE_STATUS", "offline");
+ }
- this.onlineItem.addActionListener(this);
- this.offlineItem.addActionListener(this);
-
- this.onlineItem.setName("online");
- this.offlineItem.setName("offline");
+ private void createMenuItem(String textKey, String name)
+ {
+ String text = Resources.getString(textKey);
+ if (menu instanceof JMenu)
+ {
+ JMenuItem menuItem = new JMenuItem(text);
+ menuItem.setName(name);
+ menuItem.addActionListener(this);
+ ((JMenu) menu).add(menuItem);
+ }
+ else
+ {
+ MenuItem menuItem = new MenuItem(text);
+ menuItem.setName(name);
+ menuItem.addActionListener(this);
+ ((Menu) menu).add(menuItem);
+ }
+ }
- this.add(onlineItem);
- this.add(offlineItem);
+ public Object getMenu()
+ {
+ return menu;
}
/**
@@ -106,9 +108,12 @@ public class StatusSimpleSelector
*/
public void actionPerformed(ActionEvent evt)
{
-
- JMenuItem menuItem = (JMenuItem) evt.getSource();
- String itemName = menuItem.getName();
+ Object source = evt.getSource();
+ String itemName;
+ if (source instanceof Component)
+ itemName = ((Component) source).getName();
+ else
+ itemName = ((MenuComponent) source).getName();
if(itemName.equals("online"))
{
@@ -138,6 +143,8 @@ public class StatusSimpleSelector
+ provider.getAccountID().getAccountAddress()
+ ". The new status will be: " + presenceStatus.getStatusName());
- this.setIcon(new ImageIcon(presenceStatus.getStatusIcon()));
+ if (menu instanceof AbstractButton)
+ ((AbstractButton) menu).setIcon(new ImageIcon(presenceStatus
+ .getStatusIcon()));
}
}
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
index ac5ae5b..5375365 100644
--- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
+++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
@@ -20,84 +20,112 @@ import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
- * The <tt>StatusSubMenu</tt> provides a menu which allow
- * to select the status for each of the protocol providers
- * registered when the menu appears
+ * The <tt>StatusSubMenu</tt> provides a menu which allow to select the status
+ * for each of the protocol providers registered when the menu appears
*
* @author Nicolas Chamouard
- *
+ * @author Lubomir Marinov
*/
-
public class StatusSubMenu
- extends JMenu
{
/**
* A reference of <tt>Systray</tt>
*/
- private SystrayServiceJdicImpl parentSystray;
+ private final SystrayServiceJdicImpl parentSystray;
/**
* Contains all accounts and corresponding menus.
*/
- private Hashtable accountSelectors = new Hashtable();
+ private final Map<AccountID, Object> accountSelectors =
+ new Hashtable<AccountID, Object>();
+
+ private final Logger logger = Logger.getLogger(StatusSubMenu.class);
- private Logger logger = Logger.getLogger(StatusSubMenu.class);
+ private final Object menu;
/**
* Creates an instance of <tt>StatusSubMenu</tt>.
+ *
* @param tray a reference of the parent <tt>Systray</tt>
+ * @param swing <tt>true</tt> to represent this instance with a Swing
+ * <code>JMenu</code>; <tt>false</tt> to use an AWT
+ * <code>Menu</code>
*/
- public StatusSubMenu(SystrayServiceJdicImpl tray)
+ public StatusSubMenu(SystrayServiceJdicImpl tray, boolean swing)
{
-
parentSystray = tray;
- this.setText(Resources.getString("impl.systray.SET_STATUS"));
- this.setIcon(Resources.getImage("service.systray.STATUS_MENU_ICON"));
+ String text = Resources.getString("impl.systray.SET_STATUS");
+ if (swing)
+ {
+ JMenu menu = new JMenu(text);
+ menu
+ .setIcon(Resources.getImage("service.systray.STATUS_MENU_ICON"));
- /* makes the menu look better */
- this.setPreferredSize(new java.awt.Dimension(28, 24));
+ /* makes the menu look better */
+ menu.setPreferredSize(new java.awt.Dimension(28, 24));
+
+ this.menu = menu;
+ }
+ else
+ {
+ this.menu = new Menu(text);
+ }
this.init();
}
+ public Object getMenu()
+ {
+ return menu;
+ }
+
/**
* Adds the account corresponding to the given protocol provider to this
* menu.
*
* @param protocolProvider the protocol provider corresponding to the
- * account to add
+ * account to add
*/
private void addAccount(ProtocolProviderService protocolProvider)
{
- OperationSetPresence presence = (OperationSetPresence)
- protocolProvider.getOperationSet(OperationSetPresence.class);
+ OperationSetPresence presence =
+ (OperationSetPresence) protocolProvider
+ .getOperationSet(OperationSetPresence.class);
+ boolean swing = (menu instanceof JComponent);
if (presence == null)
{
- StatusSimpleSelector simpleSelector =
- new StatusSimpleSelector(parentSystray, protocolProvider);
+ StatusSimpleSelector simpleSelector =
+ new StatusSimpleSelector(protocolProvider, swing);
- this.accountSelectors.put( protocolProvider.getAccountID(),
- simpleSelector);
- this.add(simpleSelector);
+ this.accountSelectors.put(protocolProvider.getAccountID(),
+ simpleSelector);
+ addMenuItem(menu, simpleSelector.getMenu());
}
else
{
- StatusSelector statusSelector =
- new StatusSelector( parentSystray,
- protocolProvider,
- presence);
+ StatusSelector statusSelector =
+ new StatusSelector(parentSystray, protocolProvider, presence,
+ swing);
- this.accountSelectors.put( protocolProvider.getAccountID(),
- statusSelector);
- this.add(statusSelector);
+ this.accountSelectors.put(protocolProvider.getAccountID(),
+ statusSelector);
+ addMenuItem(menu, statusSelector.getMenu());
- presence.addProviderPresenceStatusListener(
- new SystrayProviderPresenceStatusListener());
+ presence
+ .addProviderPresenceStatusListener(new SystrayProviderPresenceStatusListener());
}
}
+ static void addMenuItem(Object menu, Object menuItem)
+ {
+ if (menu instanceof Container)
+ ((Container) menu).add((Component) menuItem);
+ else
+ ((Menu) menu).add((MenuItem) menuItem);
+ }
+
/**
* Removes the account corresponding to the given protocol provider from
* this menu.
@@ -107,10 +135,13 @@ public class StatusSubMenu
*/
private void removeAccount(ProtocolProviderService protocolProvider)
{
- Component c = (Component) this.accountSelectors
- .get(protocolProvider.getAccountID());
+ Object selector =
+ this.accountSelectors.get(protocolProvider.getAccountID());
- this.remove(c);
+ if (menu instanceof Container)
+ ((Container) menu).remove((Component) selector);
+ else
+ ((MenuContainer) menu).remove((MenuComponent) selector);
}
/**
@@ -190,11 +221,16 @@ public class StatusSubMenu
ProtocolProviderService provider = (ProtocolProviderService)service;
- if (event.getType() == ServiceEvent.REGISTERED)
+ switch (event.getType())
+ {
+ case ServiceEvent.REGISTERED:
addAccount(provider);
+ break;
- if (event.getType() == ServiceEvent.UNREGISTERING)
- removeAccount(provider);
+ case ServiceEvent.UNREGISTERING:
+ removeAccount(provider);
+ break;
+ }
}
}
@@ -227,5 +263,4 @@ public class StatusSubMenu
{
}
}
-
-} \ No newline at end of file
+}
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/SystemTray.java b/src/net/java/sip/communicator/impl/systray/jdic/SystemTray.java
new file mode 100644
index 0000000..0463345
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/systray/jdic/SystemTray.java
@@ -0,0 +1,218 @@
+/*
+ * 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.systray.jdic;
+
+import java.awt.*;
+import java.lang.reflect.*;
+
+import javax.swing.*;
+
+import net.java.sip.communicator.impl.systray.jdic.TrayIcon.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * @author Lubomir Marinov
+ */
+public class SystemTray
+{
+ private static final Logger logger = Logger.getLogger(SystemTray.class);
+
+ private static SystemTray defaultSystemTray;
+
+ public static SystemTray getDefaultSystemTray()
+ throws UnsupportedOperationException,
+ HeadlessException,
+ SecurityException
+ {
+ if (defaultSystemTray != null)
+ return defaultSystemTray;
+
+ Class<?> awtSystemTrayClass = null;
+ try
+ {
+ awtSystemTrayClass = Class.forName("java.awt.SystemTray");
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // We'll try org.jdesktop.jdic.tray then.
+ }
+ SystemTrayPeer peer = null;
+ if (awtSystemTrayClass != null)
+ try
+ {
+ peer = new AWTSystemTrayPeer(awtSystemTrayClass);
+ }
+ catch (Exception ex)
+ {
+ logger
+ .error(
+ "Failed to initialize the java.awt.SystemTray implementation.",
+ ex);
+
+ // We'll try org.jdesktop.jdic.tray then.
+ }
+ if (peer == null)
+ peer = new JdicSystemTrayPeer();
+
+ return (defaultSystemTray = new SystemTray(peer));
+ }
+
+ private final SystemTrayPeer peer;
+
+ private SystemTray(SystemTrayPeer peer)
+ {
+ this.peer = peer;
+ }
+
+ public void addTrayIcon(TrayIcon trayIcon)
+ throws NullPointerException,
+ IllegalArgumentException
+ {
+ getPeer().addTrayIcon(trayIcon.getPeer());
+ }
+
+ SystemTrayPeer getPeer()
+ {
+ return peer;
+ }
+
+ public boolean isSwing()
+ {
+ return getPeer().isSwing();
+ }
+
+ static interface SystemTrayPeer
+ {
+ void addTrayIcon(TrayIconPeer trayIconPeer)
+ throws NullPointerException,
+ IllegalArgumentException;
+
+ TrayIconPeer createTrayIcon(ImageIcon icon, String tooltip, Object popup)
+ throws IllegalArgumentException,
+ UnsupportedOperationException,
+ HeadlessException,
+ SecurityException;
+
+ boolean isSwing();
+ }
+
+ private static class AWTSystemTrayPeer
+ implements SystemTrayPeer
+ {
+ private final Method addTrayIcon;
+
+ private final Object impl;
+
+ private final Class<?> trayIconClass;
+
+ public AWTSystemTrayPeer(Class<?> clazz)
+ throws UnsupportedOperationException,
+ HeadlessException,
+ SecurityException
+ {
+ Method getDefaultSystemTray;
+ try
+ {
+ getDefaultSystemTray =
+ clazz.getMethod("getSystemTray", (Class<?>[]) null);
+ trayIconClass = Class.forName("java.awt.TrayIcon");
+ addTrayIcon = clazz.getMethod("add", new Class<?>[]
+ { trayIconClass });
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+ catch (NoSuchMethodException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+
+ try
+ {
+ impl = getDefaultSystemTray.invoke(null, (Object[]) null);
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+ }
+
+ public void addTrayIcon(TrayIconPeer trayIconPeer)
+ throws NullPointerException,
+ IllegalArgumentException
+ {
+ try
+ {
+ addTrayIcon.invoke(impl, new Object[]
+ { ((AWTTrayIconPeer) trayIconPeer).getImpl() });
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UndeclaredThrowableException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable cause = ex.getCause();
+ if (cause == null)
+ throw new UndeclaredThrowableException(ex);
+ if (cause instanceof NullPointerException)
+ throw (NullPointerException) cause;
+ if (cause instanceof IllegalArgumentException)
+ throw (IllegalArgumentException) cause;
+ throw new UndeclaredThrowableException(cause);
+ }
+ }
+
+ public TrayIconPeer createTrayIcon(ImageIcon icon, String tooltip,
+ Object popup)
+ throws IllegalArgumentException,
+ UnsupportedOperationException,
+ HeadlessException,
+ SecurityException
+ {
+ return new AWTTrayIconPeer(trayIconClass, (icon == null) ? null
+ : icon.getImage(), tooltip, (PopupMenu) popup);
+ }
+
+ public boolean isSwing()
+ {
+ return false;
+ }
+ }
+
+ private static class JdicSystemTrayPeer
+ implements SystemTrayPeer
+ {
+ private final org.jdesktop.jdic.tray.SystemTray impl;
+
+ public JdicSystemTrayPeer()
+ {
+ impl = org.jdesktop.jdic.tray.SystemTray.getDefaultSystemTray();
+ }
+
+ public void addTrayIcon(TrayIconPeer trayIconPeer)
+ {
+ impl.addTrayIcon(((JdicTrayIconPeer) trayIconPeer).getImpl());
+ }
+
+ public TrayIconPeer createTrayIcon(ImageIcon icon, String tooltip,
+ Object popup)
+ {
+ return new JdicTrayIconPeer(icon, tooltip, (JPopupMenu) popup);
+ }
+
+ public boolean isSwing()
+ {
+ return true;
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java b/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java
index 26216e1..eb4163f 100644
--- a/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java
+++ b/src/net/java/sip/communicator/impl/systray/jdic/SystrayServiceJdicImpl.java
@@ -4,7 +4,6 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
-
package net.java.sip.communicator.impl.systray.jdic;
import java.awt.Toolkit;
@@ -25,8 +24,6 @@ import net.java.sip.communicator.service.systray.*;
import net.java.sip.communicator.service.systray.event.*;
import net.java.sip.communicator.util.*;
-import org.jdesktop.jdic.tray.*;
-
/**
* The <tt>Systray</tt> provides a Icon and the associated <tt>TrayMenu</tt>
* in the system tray using the Jdic library.
@@ -50,7 +47,7 @@ public class SystrayServiceJdicImpl
/**
* The menu that spring with a right click.
*/
- private TrayMenu menu;
+ private Object menu;
/**
* The list of all added popup message listeners.
@@ -140,7 +137,7 @@ public class SystrayServiceJdicImpl
final int doubleClickSpeed = (o instanceof Integer ? ((Integer) o)
.intValue() : 500);
- menu = new TrayMenu(this);
+ menu = TrayMenuFactory.createTrayMenu(this, systray.isSwing());
String osName = System.getProperty("os.name");
// If we're running under Windows, we use a special icon without
@@ -245,7 +242,7 @@ public class SystrayServiceJdicImpl
// menu appears
if (osName.startsWith("Mac OS X"))
{
- menu.addPopupMenuListener(new PopupMenuListener()
+ TrayMenuFactory.addPopupMenuListener(menu, new PopupMenuListener()
{
public void popupMenuWillBecomeVisible(PopupMenuEvent e)
{
@@ -473,7 +470,8 @@ public class SystrayServiceJdicImpl
if (imageType == SystrayService.SC_IMG_TYPE)
{
- if (osName.startsWith("Mac OS X") && this.menu.isVisible())
+ if (osName.startsWith("Mac OS X")
+ && TrayMenuFactory.isVisible(menu))
{
toChangeSystrayIcon = logoIconWhite;
}
@@ -505,7 +503,8 @@ public class SystrayServiceJdicImpl
}
else if (imageType == SystrayService.ENVELOPE_IMG_TYPE)
{
- if (osName.startsWith("Mac OS X") && this.menu.isVisible())
+ if (osName.startsWith("Mac OS X")
+ && TrayMenuFactory.isVisible(menu))
{
toChangeSystrayIcon = envelopeIconWhite;
}
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/TrayIcon.java b/src/net/java/sip/communicator/impl/systray/jdic/TrayIcon.java
new file mode 100644
index 0000000..35e0b42
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/systray/jdic/TrayIcon.java
@@ -0,0 +1,333 @@
+/*
+ * 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.systray.jdic;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.reflect.*;
+
+import javax.swing.*;
+
+/**
+ * @author Lubomir Marinov
+ */
+public class TrayIcon
+{
+ public static final int ERROR_MESSAGE_TYPE =
+ org.jdesktop.jdic.tray.TrayIcon.ERROR_MESSAGE_TYPE;
+
+ public static final int INFO_MESSAGE_TYPE =
+ org.jdesktop.jdic.tray.TrayIcon.INFO_MESSAGE_TYPE;
+
+ public static final int NONE_MESSAGE_TYPE =
+ org.jdesktop.jdic.tray.TrayIcon.NONE_MESSAGE_TYPE;
+
+ public static final int WARNING_MESSAGE_TYPE =
+ org.jdesktop.jdic.tray.TrayIcon.WARNING_MESSAGE_TYPE;
+
+ private final TrayIconPeer peer;
+
+ public TrayIcon(ImageIcon icon, String tooltip, Object popup)
+ throws IllegalArgumentException,
+ UnsupportedOperationException,
+ HeadlessException,
+ SecurityException
+ {
+ peer =
+ SystemTray.getDefaultSystemTray().getPeer().createTrayIcon(icon,
+ tooltip, popup);
+ }
+
+ public void addActionListener(ActionListener listener)
+ {
+ getPeer().addActionListener(listener);
+ }
+
+ public void addBalloonActionListener(ActionListener listener)
+ {
+ getPeer().addBalloonActionListener(listener);
+ }
+
+ public void displayMessage(String caption, String text, int messageType)
+ throws NullPointerException
+ {
+ getPeer().displayMessage(caption, text, messageType);
+ }
+
+ TrayIconPeer getPeer()
+ {
+ return peer;
+ }
+
+ public void setIcon(ImageIcon icon) throws NullPointerException
+ {
+ getPeer().setIcon(icon);
+ }
+
+ public void setIconAutoSize(boolean autoSize)
+ {
+ getPeer().setIconAutoSize(autoSize);
+ }
+
+ static interface TrayIconPeer
+ {
+ void addActionListener(ActionListener listener);
+
+ void addBalloonActionListener(ActionListener listener);
+
+ void displayMessage(String caption, String text, int messageType)
+ throws NullPointerException;
+
+ void setIcon(ImageIcon icon) throws NullPointerException;
+
+ void setIconAutoSize(boolean autoSize);
+ }
+
+ static class AWTTrayIconPeer
+ implements TrayIconPeer
+ {
+ private final Method addActionListener;
+
+ private final Method displayMessage;
+
+ private final Object impl;
+
+ private final Class<?> messageTypeClass;
+
+ private final Method setIcon;
+
+ private final Method setIconAutoSize;
+
+ public AWTTrayIconPeer(Class<?> clazz, Image image, String tooltip,
+ PopupMenu popup)
+ throws IllegalArgumentException,
+ UnsupportedOperationException,
+ HeadlessException,
+ SecurityException
+ {
+ Constructor<?> constructor;
+ try
+ {
+ constructor = clazz.getConstructor(new Class<?>[]
+ { Image.class, String.class, PopupMenu.class });
+ addActionListener =
+ clazz.getMethod("addActionListener", new Class<?>[]
+ { ActionListener.class });
+ messageTypeClass =
+ Class.forName("java.awt.TrayIcon$MessageType");
+ displayMessage =
+ clazz.getMethod("displayMessage", new Class<?>[]
+ { String.class, String.class, messageTypeClass });
+ setIcon = clazz.getMethod("setImage", new Class<?>[]
+ { Image.class });
+ setIconAutoSize =
+ clazz.getMethod("setImageAutoSize", new Class<?>[]
+ { boolean.class });
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+ catch (NoSuchMethodException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+
+ try
+ {
+ impl = constructor.newInstance(new Object[]
+ { image, tooltip, popup });
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+ catch (InstantiationException ex)
+ {
+ throw new UnsupportedOperationException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable cause = ex.getCause();
+ if (cause == null)
+ throw new UnsupportedOperationException(ex);
+ if (cause instanceof IllegalArgumentException)
+ throw (IllegalArgumentException) cause;
+ if (cause instanceof UnsupportedOperationException)
+ throw (UnsupportedOperationException) cause;
+ if (cause instanceof HeadlessException)
+ throw (HeadlessException) cause;
+ if (cause instanceof SecurityException)
+ throw (SecurityException) cause;
+ throw new UnsupportedOperationException(cause);
+ }
+ }
+
+ public void addActionListener(ActionListener listener)
+ {
+ try
+ {
+ addActionListener.invoke(getImpl(), new Object[]
+ { listener });
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UndeclaredThrowableException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable cause = ex.getCause();
+ throw new UndeclaredThrowableException((cause == null) ? ex
+ : cause);
+ }
+ }
+
+ public void addBalloonActionListener(ActionListener listener)
+ {
+ // java.awt.TrayIcon doesn't support addBalloonActionListener()
+ }
+
+ public void displayMessage(String caption, String text, int messageType)
+ throws NullPointerException
+ {
+ try
+ {
+ displayMessage.invoke(getImpl(), new Object[]
+ { caption, text, getMessageType(messageType) });
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UndeclaredThrowableException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable cause = ex.getCause();
+ if (cause instanceof NullPointerException)
+ throw (NullPointerException) cause;
+ throw new UndeclaredThrowableException((cause == null) ? ex
+ : cause);
+ }
+ }
+
+ public Object getImpl()
+ {
+ return impl;
+ }
+
+ private Object getMessageType(int messageType)
+ {
+ Object[] constants = messageTypeClass.getEnumConstants();
+ String name;
+ switch (messageType)
+ {
+ case ERROR_MESSAGE_TYPE:
+ name = "ERROR";
+ break;
+ case INFO_MESSAGE_TYPE:
+ name = "INFO";
+ break;
+ case NONE_MESSAGE_TYPE:
+ name = "NONE";
+ break;
+ case WARNING_MESSAGE_TYPE:
+ name = "WARNING";
+ break;
+ default:
+ throw new IllegalArgumentException("messageType");
+ }
+ for (int i = 0; i < constants.length; i++)
+ {
+ Object constant = constants[i];
+ if (name.equals(constant.toString()))
+ return constant;
+ }
+ throw new IllegalArgumentException("messageType");
+ }
+
+ public void setIcon(ImageIcon icon) throws NullPointerException
+ {
+ try
+ {
+ setIcon.invoke(getImpl(), new Object[]
+ { (icon == null) ? null : icon.getImage() });
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UndeclaredThrowableException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable cause = ex.getCause();
+ if (cause instanceof NullPointerException)
+ throw (NullPointerException) cause;
+ throw new UndeclaredThrowableException((cause == null) ? ex
+ : cause);
+ }
+ }
+
+ public void setIconAutoSize(boolean autoSize)
+ {
+ try
+ {
+ setIconAutoSize.invoke(getImpl(), new Object[]
+ { autoSize });
+ }
+ catch (IllegalAccessException ex)
+ {
+ throw new UndeclaredThrowableException(ex);
+ }
+ catch (InvocationTargetException ex)
+ {
+ Throwable cause = ex.getCause();
+ throw new UndeclaredThrowableException((cause == null) ? ex
+ : cause);
+ }
+ }
+ }
+
+ static class JdicTrayIconPeer
+ implements TrayIconPeer
+ {
+ private final org.jdesktop.jdic.tray.TrayIcon impl;
+
+ public JdicTrayIconPeer(ImageIcon icon, String tooltip, JPopupMenu popup)
+ {
+ impl = new org.jdesktop.jdic.tray.TrayIcon(icon, tooltip, popup);
+ }
+
+ public void addActionListener(ActionListener listener)
+ {
+ getImpl().addActionListener(listener);
+ }
+
+ public void addBalloonActionListener(ActionListener listener)
+ {
+ getImpl().addBalloonActionListener(listener);
+ }
+
+ public void displayMessage(String caption, String text, int messageType)
+ throws NullPointerException
+ {
+ getImpl().displayMessage(caption, text, messageType);
+ }
+
+ org.jdesktop.jdic.tray.TrayIcon getImpl()
+ {
+ return impl;
+ }
+
+ public void setIcon(ImageIcon icon)
+ {
+ getImpl().setIcon(icon);
+ }
+
+ public void setIconAutoSize(boolean autoSize)
+ {
+ getImpl().setIconAutoSize(autoSize);
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java b/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java
deleted file mode 100644
index 5bc48b2..0000000
--- a/src/net/java/sip/communicator/impl/systray/jdic/TrayMenu.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package net.java.sip.communicator.impl.systray.jdic;
-
-import java.awt.event.*;
-
-import javax.swing.*;
-
-import net.java.sip.communicator.impl.systray.*;
-import net.java.sip.communicator.service.gui.*;
-import net.java.sip.communicator.util.*;
-
-import org.osgi.framework.*;
-
-/**
- * The <tt>TrayMenu</tt> is the menu that appears when the user right-click
- * on the Systray icon.
- *
- * @author Nicolas Chamouard
- */
-public class TrayMenu
- extends JPopupMenu
- implements ActionListener
-{
- /**
- * The logger for this class.
- */
- private Logger logger = Logger.getLogger(TrayMenu.class.getName());
-
- /**
- * A reference of <tt>Systray</tt>
- */
- private SystrayServiceJdicImpl parentSystray;
-
- private JMenuItem settingsItem = new JMenuItem(
- Resources.getString("service.gui.SETTINGS"),
- Resources.getImage("service.gui.icons.QUICK_MENU_CONFIGURE_ICON"));
-
- private JMenuItem closeItem = new JMenuItem(
- Resources.getString("service.gui.CLOSE"),
- Resources.getImage("service.systray.CLOSE_MENU_ICON"));
-
- private JMenuItem addContactMenuItem = new JMenuItem(
- Resources.getString("service.gui.ADD_CONTACT"),
- Resources.getImage("service.gui.icons.ADD_CONTACT_16x16_ICON"));
-
- private StatusSubMenu statusMenu;
-
- /**
- * Creates an instance of <tt>TrayMenu</tt>.
- * @param tray a reference of the parent <tt>Systray</tt>
- */
- public TrayMenu(SystrayServiceJdicImpl tray)
- {
- parentSystray = tray;
-
- statusMenu = new StatusSubMenu(tray);
-
- this.add(settingsItem);
- this.add(addContactMenuItem);
- this.addSeparator();
- this.add(statusMenu);
- this.addSeparator();
- this.add(closeItem);
-
- this.settingsItem.setName("settings");
- this.closeItem.setName("service.gui.CLOSE");
- this.addContactMenuItem.setName("addContact");
-
- this.settingsItem.addActionListener(this);
- this.closeItem.addActionListener(this);
- this.addContactMenuItem.addActionListener(this);
- }
-
- /**
- * Handles the <tt>ActionEvent</tt> when one of the menu items is selected.
- * @param evt the event containing the menu item name
- */
- public void actionPerformed(ActionEvent evt)
- {
-
- JMenuItem menuItem = (JMenuItem) evt.getSource();
- String itemName = menuItem.getName();
-
- if(itemName.equals("settings"))
- {
- ExportedWindow configWindow
- = SystrayActivator.getUIService()
- .getExportedWindow(ExportedWindow.CONFIGURATION_WINDOW);
-
- configWindow.setVisible(true);
- }
- else if(itemName.equals("service.gui.CLOSE"))
- {
- try
- {
- SystrayActivator.bundleContext.getBundle(0).stop();
- } catch (BundleException ex)
- {
- logger.error("Failed to gently shutdown Felix", ex);
- System.exit(0);
- }
-
- }
- else if(itemName.equals("addContact"))
- {
- ExportedWindow dialog
- = SystrayActivator.getUIService().getExportedWindow(
- ExportedWindow.ADD_CONTACT_WINDOW);
-
- if(dialog != null)
- dialog.setVisible(true);
- else
- SystrayActivator.getUIService().getPopupDialog()
- .showMessagePopupDialog(Resources.getString(
- "impl.systray.FAILED_TO_OPEN_ADD_CONTACT_DIALOG"));
- }
- }
-} \ No newline at end of file
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/TrayMenuFactory.java b/src/net/java/sip/communicator/impl/systray/jdic/TrayMenuFactory.java
new file mode 100644
index 0000000..8bc4dc2
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/systray/jdic/TrayMenuFactory.java
@@ -0,0 +1,179 @@
+/*
+ * 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.systray.jdic;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.swing.*;
+import javax.swing.event.*;
+
+import net.java.sip.communicator.impl.systray.*;
+import net.java.sip.communicator.service.gui.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
+
+/**
+ * The <tt>TrayMenu</tt> is the menu that appears when the user right-click
+ * on the Systray icon.
+ *
+ * @author Nicolas Chamouard
+ * @author Lubomir Marinov
+ */
+public final class TrayMenuFactory
+{
+
+ /**
+ * The logger for this class.
+ */
+ private static final Logger logger =
+ Logger.getLogger(TrayMenuFactory.class.getName());
+
+ /**
+ * Handles the <tt>ActionEvent</tt> when one of the menu items is selected.
+ *
+ * @param evt the event containing the menu item name
+ */
+ private static void actionPerformed(ActionEvent evt)
+ {
+ Object source = evt.getSource();
+ String itemName;
+ if (source instanceof JMenuItem)
+ {
+ JMenuItem menuItem = (JMenuItem) source;
+ itemName = menuItem.getName();
+ }
+ else
+ {
+ MenuItem menuItem = (MenuItem) source;
+ itemName = menuItem.getName();
+ }
+
+ if (itemName.equals("settings"))
+ {
+ ExportedWindow configWindow =
+ SystrayActivator.getUIService().getExportedWindow(
+ ExportedWindow.CONFIGURATION_WINDOW);
+
+ configWindow.setVisible(true);
+ }
+ else if (itemName.equals("service.gui.CLOSE"))
+ {
+
+ /*
+ * TODO Quitting the application has evolved to resolve additional
+ * issues such as storing the configuration prior to disposing the
+ * MainFrame so this old copy here doesn't have them.
+ */
+ try
+ {
+ SystrayActivator.bundleContext.getBundle(0).stop();
+ }
+ catch (BundleException ex)
+ {
+ logger.error("Failed to gently shutdown Felix", ex);
+ System.exit(0);
+ }
+
+ }
+ else if (itemName.equals("addContact"))
+ {
+ ExportedWindow dialog =
+ SystrayActivator.getUIService().getExportedWindow(
+ ExportedWindow.ADD_CONTACT_WINDOW);
+
+ if (dialog != null)
+ dialog.setVisible(true);
+ else
+ SystrayActivator
+ .getUIService()
+ .getPopupDialog()
+ .showMessagePopupDialog(
+ Resources
+ .getString("impl.systray.FAILED_TO_OPEN_ADD_CONTACT_DIALOG"));
+ }
+ }
+
+ private static void add(Object trayMenu, Object trayMenuItem)
+ {
+ if (trayMenu instanceof JPopupMenu)
+ ((JPopupMenu) trayMenu).add((JMenuItem) trayMenuItem);
+ else
+ ((PopupMenu) trayMenu).add((MenuItem) trayMenuItem);
+ }
+
+ public static void addPopupMenuListener(Object trayMenu,
+ PopupMenuListener listener)
+ {
+ if (trayMenu instanceof JPopupMenu)
+ ((JPopupMenu) trayMenu).addPopupMenuListener(listener);
+ }
+
+ private static void addSeparator(Object trayMenu)
+ {
+ if (trayMenu instanceof JPopupMenu)
+ ((JPopupMenu) trayMenu).addSeparator();
+ else
+ ((PopupMenu) trayMenu).addSeparator();
+ }
+
+ public static Object createTrayMenu(SystrayServiceJdicImpl tray, boolean swing)
+ {
+ Object trayMenu = swing ? new JPopupMenu() : new PopupMenu();
+ ActionListener listener = new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ TrayMenuFactory.actionPerformed(event);
+ }
+ };
+
+ add(trayMenu, createTrayMenuItem("settings", "service.gui.SETTINGS",
+ "service.gui.icons.QUICK_MENU_CONFIGURE_ICON", listener, swing));
+ add(trayMenu, createTrayMenuItem("addContact",
+ "service.gui.ADD_CONTACT",
+ "service.gui.icons.ADD_CONTACT_16x16_ICON", listener, swing));
+ addSeparator(trayMenu);
+ add(trayMenu, new StatusSubMenu(tray, swing).getMenu());
+ addSeparator(trayMenu);
+ add(trayMenu, createTrayMenuItem("service.gui.CLOSE",
+ "service.gui.CLOSE", "service.systray.CLOSE_MENU_ICON", listener,
+ swing));
+
+ return trayMenu;
+ }
+
+ private static Object createTrayMenuItem(String name, String textID, String iconID,
+ ActionListener listener, boolean swing)
+ {
+ String text = Resources.getString(textID);
+ Object trayMenuItem;
+ if (swing)
+ {
+ JMenuItem menuItem = new JMenuItem(text, Resources.getImage(iconID));
+ menuItem.setName(name);
+ menuItem.addActionListener(listener);
+ trayMenuItem = menuItem;
+ }
+ else
+ {
+ MenuItem menuItem = new MenuItem(text);
+ menuItem.setName(name);
+ menuItem.addActionListener(listener);
+ trayMenuItem = menuItem;
+ }
+ return trayMenuItem;
+ }
+
+ public static boolean isVisible(Object trayMenu)
+ {
+ if (trayMenu instanceof JPopupMenu)
+ return ((JPopupMenu) trayMenu).isVisible();
+ return false;
+ }
+}