6280057: I have audited SystemTray and TrayIcon code
authorant
Wed, 04 Jun 2008 12:32:05 +0400
changeset 1168 5f1d2fcfcd3e
parent 638 69a80895db21
child 1169 23b1850f7d73
6280057: I have audited SystemTray and TrayIcon code Summary: small refactoring Reviewed-by: dcherepanov
jdk/src/share/classes/java/awt/SystemTray.java
jdk/src/share/classes/java/awt/TrayIcon.java
--- a/jdk/src/share/classes/java/awt/SystemTray.java	Thu May 29 13:48:51 2008 +0400
+++ b/jdk/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) {
-
-            return ((SunToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
 
-        } 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/jdk/src/share/classes/java/awt/TrayIcon.java	Thu May 29 13:48:51 2008 +0400
+++ b/jdk/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
     {