changeset 648:80a4ace80c31

6280057: I have audited SystemTray and TrayIcon code Summary: small refactoring Reviewed-by: dcherepanov
author ant
date Wed, 04 Jun 2008 12:32:05 +0400
parents d8f9efc21477
children adebdf3701a4
files src/share/classes/java/awt/SystemTray.java src/share/classes/java/awt/TrayIcon.java
diffstat 2 files changed, 12 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/SystemTray.java	Thu May 29 13:48:51 2008 +0400
+++ b/src/share/classes/java/awt/SystemTray.java	Wed Jun 04 12:32:05 2008 +0400
@@ -125,6 +125,8 @@
 
     transient private SystemTrayPeer peer;
 
+    private static final TrayIcon[] EMPTY_TRAY_ARRAY = new TrayIcon[0];
+
     /**
      * Private <code>SystemTray</code> constructor.
      *
@@ -203,13 +205,12 @@
     public static boolean isSupported() {
         initializeSystemTrayIfNeeded();
 
-        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
 
-            return ((SunToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
-
-        } else if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit) {
-
-            return ((HeadlessToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
+        if (toolkit instanceof SunToolkit) {
+            return ((SunToolkit)toolkit).isTraySupported();
+        } else if (toolkit instanceof HeadlessToolkit) {
+            return ((HeadlessToolkit)toolkit).isTraySupported();
         }
         return false;
     }
@@ -323,7 +324,7 @@
         if (icons != null) {
             return (TrayIcon[])icons.toArray(new TrayIcon[icons.size()]);
         }
-        return new TrayIcon[0];
+        return EMPTY_TRAY_ARRAY;
     }
 
     /**
--- a/src/share/classes/java/awt/TrayIcon.java	Thu May 29 13:48:51 2008 +0400
+++ b/src/share/classes/java/awt/TrayIcon.java	Wed Jun 04 12:32:05 2008 +0400
@@ -142,9 +142,6 @@
      */
     public TrayIcon(Image image) {
         this();
-        if (image == null) {
-            throw new IllegalArgumentException("creating TrayIcon with null Image");
-        }
         setImage(image);
     }
 
@@ -433,7 +430,7 @@
      * @see      java.awt.event.MouseListener
      */
     public synchronized MouseListener[] getMouseListeners() {
-        return (MouseListener[])(getListeners(MouseListener.class));
+        return AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
     }
 
     /**
@@ -494,7 +491,7 @@
      * @see      java.awt.event.MouseMotionListener
      */
     public synchronized MouseMotionListener[] getMouseMotionListeners() {
-        return (MouseMotionListener[]) (getListeners(MouseMotionListener.class));
+        return AWTEventMulticaster.getListeners(mouseMotionListener, MouseMotionListener.class);
     }
 
     /**
@@ -581,7 +578,7 @@
      * @see      java.awt.event.ActionListener
      */
     public synchronized ActionListener[] getActionListeners() {
-        return (ActionListener[])(getListeners(ActionListener.class));
+        return AWTEventMulticaster.getListeners(actionListener, ActionListener.class);
     }
 
     /**
@@ -635,7 +632,7 @@
 
         TrayIconPeer peer = this.peer;
         if (peer != null) {
-            peer.displayMessage(caption, text, messageType.toString());
+            peer.displayMessage(caption, text, messageType.name());
         }
     }
 
@@ -657,18 +654,6 @@
     // ****************************************************************
     // ****************************************************************
 
-    <T extends EventListener> T[] getListeners(Class<T> listenerType) {
-        EventListener l = null;
-        if (listenerType == MouseListener.class) {
-            l = mouseListener;
-        } else if (listenerType == MouseMotionListener.class) {
-            l = mouseMotionListener;
-        } else if (listenerType == ActionListener.class) {
-            l = actionListener;
-        }
-        return AWTEventMulticaster.getListeners(l, listenerType);
-    }
-
     void addNotify()
       throws AWTException
     {