aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2010-03-25 05:57:26 +0000
committerYana Stamcheva <yana@jitsi.org>2010-03-25 05:57:26 +0000
commitc36d3dc187e9baf869ac2f965e985e3f1f5fa198 (patch)
treee693bb1fb5d08b8e20fa628b45a1f1e3801741cd
parentceb8e40d146bd387e986d1ba4f54afbb07a300c1 (diff)
downloadjitsi-c36d3dc187e9baf869ac2f965e985e3f1f5fa198.zip
jitsi-c36d3dc187e9baf869ac2f965e985e3f1f5fa198.tar.gz
jitsi-c36d3dc187e9baf869ac2f965e985e3f1f5fa198.tar.bz2
Adds the possibility to hide/show the main application window from the systray menu. Handles window events coming from the window X button or the operating system specific hide/show operations in order to update the systray menu item state.
Adds javadoc to TrayMenuFactory.
-rw-r--r--resources/languages/resources.properties2
-rw-r--r--src/net/java/sip/communicator/impl/gui/UIServiceImpl.java19
-rw-r--r--src/net/java/sip/communicator/impl/osdependent/jdic/TrayMenuFactory.java135
-rw-r--r--src/net/java/sip/communicator/service/gui/UIService.java20
4 files changed, 175 insertions, 1 deletions
diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties
index 7c5f741..17fd53a 100644
--- a/resources/languages/resources.properties
+++ b/resources/languages/resources.properties
@@ -193,6 +193,7 @@ service.gui.GRANT_VOICE=Grant voice
service.gui.GUEST=visitor
service.gui.HANG_UP=Hang up
service.gui.HELP=&Help
+service.gui.HIDE=Hide
service.gui.HIDE_OFFLINE_CONTACTS=Hide offline contacts
service.gui.HIDE_MAIN_WINDOW=<DIV>Clicking the X window button will not exit the application, \
but only <BR> hide it. If you wish to exit the application choose File/Quit.</DIV>
@@ -351,6 +352,7 @@ service.gui.SENT=sent
service.gui.SET_GLOBAL_STATUS=Set global status
service.gui.SET_STATUS_MESSAGE=Set status message
service.gui.SETTINGS=&Options
+service.gui.SHOW=Show
service.gui.SHOW_OFFLINE_CONTACTS=Show offline contacts
service.gui.SIGN_IN=Sign in
service.gui.SMS_SUCCESSFULLY_SENT=SMS message successfully sent!
diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java
index 3542f75..a23be39 100644
--- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java
@@ -1172,4 +1172,23 @@ public class UIServiceImpl
else
return null;
}
+
+ /**
+ * Adds the given <tt>WindowListener</tt> to the main application window.
+ * @param l the <tt>WindowListener</tt> to add
+ */
+ public void addWindowListener(WindowListener l)
+ {
+ mainFrame.addWindowListener(l);
+ }
+
+ /**
+ * Removes the given <tt>WindowListener</tt> from the main application
+ * window.
+ * @param l the <tt>WindowListener</tt> to remove
+ */
+ public void removeWindowListener(WindowListener l)
+ {
+ mainFrame.removeWindowListener(l);
+ }
}
diff --git a/src/net/java/sip/communicator/impl/osdependent/jdic/TrayMenuFactory.java b/src/net/java/sip/communicator/impl/osdependent/jdic/TrayMenuFactory.java
index e55e2ba..8c69688 100644
--- a/src/net/java/sip/communicator/impl/osdependent/jdic/TrayMenuFactory.java
+++ b/src/net/java/sip/communicator/impl/osdependent/jdic/TrayMenuFactory.java
@@ -22,10 +22,10 @@ import net.java.sip.communicator.util.*;
*
* @author Nicolas Chamouard
* @author Lubomir Marinov
+ * @author Yana Stamcheva
*/
public final class TrayMenuFactory
{
-
/**
* Handles the <tt>ActionEvent</tt> when one of the menu items is selected.
*
@@ -68,8 +68,27 @@ public final class TrayMenuFactory
.showMessagePopupDialog(Resources.getString(
"impl.systray.FAILED_TO_OPEN_ADD_CONTACT_DIALOG"));
}
+ else if (itemName.equals("service.gui.SHOW"))
+ {
+ OsDependentActivator.getUIService().setVisible(true);
+
+ changeTrayMenuItem(source, "service.gui.HIDE",
+ "service.gui.HIDE", "service.gui.icons.SEARCH_ICON_16x16");
+ }
+ else if (itemName.equals("service.gui.HIDE"))
+ {
+ OsDependentActivator.getUIService().setVisible(false);
+
+ changeTrayMenuItem(source, "service.gui.SHOW",
+ "service.gui.SHOW", "service.gui.icons.SEARCH_ICON_16x16");
+ }
}
+ /**
+ * Adds the given <tt>trayMenuItem</tt> to the given <tt>trayMenu</tt>.
+ * @param trayMenu the tray menu to which to add the item
+ * @param trayMenuItem the item to add
+ */
private static void add(Object trayMenu, Object trayMenuItem)
{
if (trayMenu instanceof JPopupMenu)
@@ -78,6 +97,11 @@ public final class TrayMenuFactory
((PopupMenu) trayMenu).add((MenuItem) trayMenuItem);
}
+ /**
+ * Adds a <tt>PopupMenuListener</tt> to the given <tt>trayMenu</tt>.
+ * @param trayMenu the tray menu to which to add a popup listener
+ * @param listener the listener to add
+ */
public static void addPopupMenuListener(Object trayMenu,
PopupMenuListener listener)
{
@@ -85,6 +109,10 @@ public final class TrayMenuFactory
((JPopupMenu) trayMenu).addPopupMenuListener(listener);
}
+ /**
+ * Adds a separator to the given <tt>trayMenu</tt>.
+ * @param trayMenu the tray menu to which to add a separator
+ */
private static void addSeparator(Object trayMenu)
{
if (trayMenu instanceof JPopupMenu)
@@ -93,6 +121,12 @@ public final class TrayMenuFactory
((PopupMenu) trayMenu).addSeparator();
}
+ /**
+ * Creates a tray menu for the given system tray.
+ * @param tray the system tray for which we're creating a menu
+ * @param swing indicates if we should create a Swing or an AWT menu
+ * @return a tray menu for the given system tray
+ */
public static Object createTrayMenu(SystrayServiceJdicImpl tray,
boolean swing)
{
@@ -117,13 +151,76 @@ public final class TrayMenuFactory
addSeparator(trayMenu);
add(trayMenu, new StatusSubMenu(tray, swing).getMenu());
addSeparator(trayMenu);
+
+ String showHideName;
+ String showHideTextId;
+ String showHideIconId;
+
+ if (OsDependentActivator.getUIService().isVisible())
+ {
+ showHideName = "service.gui.HIDE";
+ showHideTextId = "service.gui.HIDE";
+ showHideIconId = "service.gui.icons.SEARCH_ICON_16x16";
+ }
+ else
+ showHideName = "service.gui.SHOW";
+ showHideTextId = "service.gui.SHOW";
+ showHideIconId = "service.gui.icons.SEARCH_ICON_16x16";
+
+ final Object showHideMenuItem = createTrayMenuItem( showHideName,
+ showHideTextId,
+ showHideIconId,
+ listener,
+ swing);
+
+ add(trayMenu, showHideMenuItem);
+
add(trayMenu, createTrayMenuItem("service.gui.CLOSE",
"service.gui.CLOSE", "service.systray.CLOSE_MENU_ICON", listener,
swing));
+ OsDependentActivator.getUIService().addWindowListener(
+ new WindowAdapter()
+ {
+ /**
+ * Invoked when a window is activated.
+ */
+ public void windowActivated(WindowEvent e)
+ {
+ changeTrayMenuItem( showHideMenuItem,
+ "service.gui.HIDE",
+ "service.gui.HIDE",
+ "service.gui.icons.SEARCH_ICON_16x16");
+ }
+
+ /**
+ * Invoked when a window is de-activated.
+ */
+ public void windowDeactivated(WindowEvent e)
+ {
+ changeTrayMenuItem( showHideMenuItem,
+ "service.gui.SHOW",
+ "service.gui.SHOW",
+ "service.gui.icons.SEARCH_ICON_16x16");
+ }
+ });
+
return trayMenu;
}
+ /**
+ * Creates a tray menu with the given <tt>name</tt>, text given by
+ * <tt>textID</tt> and icon given by <tt>iconID</tt>. The <tt>listener</tt>
+ * is handling item events and the <tt>swing</tt> value indicates if we
+ * should create a Swing menu item or and an AWT item.
+ * @param name the name of the item
+ * @param textID the identifier of the text in the localization resources
+ * @param iconID the identifier of the icon in the image resources
+ * @param listener the <tt>ActionListener</tt> handling action events
+ * @param swing indicates if we should create a Swing menu item or an AWT
+ * item
+ * @return a reference to the newly created item
+ */
private static Object createTrayMenuItem( String name,
String textID,
String iconID,
@@ -150,6 +247,42 @@ public final class TrayMenuFactory
return trayMenuItem;
}
+ /**
+ * Changes the tray menu item properties, like name, text and icon.
+ * @param trayItem the tray menu item to change
+ * @param name the new name of the item
+ * @param textID the new text identifier
+ * @param iconID the new icon string identifier
+ */
+ private static void changeTrayMenuItem( Object trayItem,
+ String name,
+ String textID,
+ String iconID)
+ {
+ String text = Resources.getString(textID);
+
+ if (trayItem instanceof JMenuItem)
+ {
+ JMenuItem jmenuItem = (JMenuItem) trayItem;
+ jmenuItem.setName(name);
+ jmenuItem.setText(text);
+ jmenuItem.setIcon(Resources.getImage(iconID));
+ }
+ else if (trayItem instanceof MenuItem)
+ {
+ MenuItem menuItem = (MenuItem) trayItem;
+ menuItem.setName(name);
+ menuItem.setLabel(text);
+ }
+ }
+
+ /**
+ * Returns <tt>true</tt> if the given <tt>trayMenu</tt> is visible,
+ * otherwise returns <tt>false</tt>.
+ * @param trayMenu the <tt>TrayMenu</tt> to check
+ * @return <tt>true</tt> if the given <tt>trayMenu</tt> is visible,
+ * otherwise returns <tt>false</tt>
+ */
public static boolean isVisible(Object trayMenu)
{
if (trayMenu instanceof JPopupMenu)
diff --git a/src/net/java/sip/communicator/service/gui/UIService.java b/src/net/java/sip/communicator/service/gui/UIService.java
index 78f4834..d4b2e91 100644
--- a/src/net/java/sip/communicator/service/gui/UIService.java
+++ b/src/net/java/sip/communicator/service/gui/UIService.java
@@ -7,6 +7,7 @@
package net.java.sip.communicator.service.gui;
import java.awt.*;
+import java.awt.event.*;
import java.util.*;
import java.util.List;
@@ -387,4 +388,23 @@ public interface UIService
* configuration window; <tt>false</tt> to hide it
*/
public void setConfigurationWindowVisible(boolean visible);
+
+ /**
+ * Adds the given <tt>WindowListener</tt> listening for events triggered
+ * by the main UIService component. This is normally the main application
+ * window component, the one containing the contact list. This listener
+ * would also receive events when this window is shown or hidden.
+ * @param l the <tt>WindowListener</tt> to add
+ */
+ public void addWindowListener(WindowListener l);
+
+ /**
+ * Removes the given <tt>WindowListener</tt> from the list of registered
+ * listener. The <tt>WindowListener</tt> is listening for events
+ * triggered by the main UIService component. This is normally the main
+ * application window component, the one containing the contact list. This
+ * listener would also receive events when this window is shown or hidden.
+ * @param l the <tt>WindowListener</tt> to remove
+ */
+ public void removeWindowListener(WindowListener l);
}