mirror of https://github.com/sipwise/jitsi.git
Hopes to fix issue #502: Do not use jdic when running Java 6.
parent
e782599a05
commit
af2587049c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue