 |
java.awt.TrayIcon: isSupported vs isAvailable
Posted by ixmal on November 17, 2006 at 12:01 AM | Comments (4)
Description of the problem
When the java.awt.SystemTray class was first introduced in JDK 6.0, there was only one method to check if the system tray and tray icons can be used: isSupported(). The value returned by this method is constant for the given desktop/environment, for example, on Windows platform it always return true.
Another thing that can help the developers with the system tray is AWTException thrown by SystemTray.add(TrayIcon icon) method. According to the JavaDoc for this method, this exception is thrown "if the desktop system tray is missing". One of the common cases when the system tray is missing is when the notification area applet is removed from the GNOME desktop manually by user.
Recently I have faced another problem, on Windows. There are several projects that make possible to install a Java application as a Windows NT/2K/XP service. Some of such Java applications may interact with the user using SystemTray and TrayIcons. Here the problem lies: Windows services may start before any user is logged in, so no taskbar and system tray are present.
Introducing isAvailable method
Obviously, the isSupported() method is not enough. Developers should be able to detect not only whether Java supports the system tray on the given platform, but also whether the system tray is currently present and tray icons can be added into it.
The most probable name for the new method will be isAvailable. Additionally, it may be useful to have another method in the SystemTray class that works the following way: if the system tray is available, adds the given tray icon into it, if not - waits until the tray becomes available and then adds the icon. AWTException is not required for this case.
Introducing a new property
There is another problem to be resolved to make the using of tray icons easier. Consider an application like an instant messenger that is run as an icon in the system tray, without any other visible window. If the system tray is removed or made unavailable this application may lose some of its functionality.
Alternatively, using a property that changes its value when the system tray becomes available/unavailable, enables an application to listen for that property change and behave correspondingly. For example, an application can show some toplevel window.
There is already a property called 'trayIcons' in the SystemTray class. The new property will be accessible as a parameter of the java.beans.PropertyChangeListener interface instance by using the same methods: addPropertyChangeListener and removePropertyChangeListener.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
is this in Java 6? :)
leouser
Posted by: leouser on November 17, 2006 at 06:32 AM
-
I think it is too late for 6.0 to introduce new property, so it is the suggestion for 7.0
Posted by: ixmal on November 17, 2006 at 08:36 AM
-
Im trying to decide from reading this if having a method that would do an "defer adding Icon until SystemTray is available" would be sufficient. I suspect that a user would want to be able to see the scheduled icons and also the ability to remove them as well. Maybe they wouldn't?
leouser
Posted by: leouser on November 17, 2006 at 09:47 AM
-
The property may be useful not only for listening when the scheduled icons are added, but also when the tray becomes unavailable. So I think having one new method about deferred icons adding is not enough
Posted by: ixmal on November 20, 2006 at 01:01 AM
|