6280057: I have audited SystemTray and TrayIcon code

Small refactoring

Reviewed-by: dcherepanov
This commit is contained in:
Anton Tarasov 2008-06-04 12:32:05 +04:00
parent da21254012
commit ac0b8d6ebe
2 changed files with 12 additions and 26 deletions

View File

@ -125,6 +125,8 @@ public class SystemTray {
transient private SystemTrayPeer peer; transient private SystemTrayPeer peer;
private static final TrayIcon[] EMPTY_TRAY_ARRAY = new TrayIcon[0];
/** /**
* Private <code>SystemTray</code> constructor. * Private <code>SystemTray</code> constructor.
* *
@ -203,13 +205,12 @@ public class SystemTray {
public static boolean isSupported() { public static boolean isSupported() {
initializeSystemTrayIfNeeded(); initializeSystemTrayIfNeeded();
if (Toolkit.getDefaultToolkit() instanceof SunToolkit) { Toolkit toolkit = Toolkit.getDefaultToolkit();
return ((SunToolkit)Toolkit.getDefaultToolkit()).isTraySupported(); if (toolkit instanceof SunToolkit) {
return ((SunToolkit)toolkit).isTraySupported();
} else if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit) { } else if (toolkit instanceof HeadlessToolkit) {
return ((HeadlessToolkit)toolkit).isTraySupported();
return ((HeadlessToolkit)Toolkit.getDefaultToolkit()).isTraySupported();
} }
return false; return false;
} }
@ -323,7 +324,7 @@ public class SystemTray {
if (icons != null) { if (icons != null) {
return (TrayIcon[])icons.toArray(new TrayIcon[icons.size()]); return (TrayIcon[])icons.toArray(new TrayIcon[icons.size()]);
} }
return new TrayIcon[0]; return EMPTY_TRAY_ARRAY;
} }
/** /**

View File

@ -142,9 +142,6 @@ public class TrayIcon {
*/ */
public TrayIcon(Image image) { public TrayIcon(Image image) {
this(); this();
if (image == null) {
throw new IllegalArgumentException("creating TrayIcon with null Image");
}
setImage(image); setImage(image);
} }
@ -433,7 +430,7 @@ public class TrayIcon {
* @see java.awt.event.MouseListener * @see java.awt.event.MouseListener
*/ */
public synchronized MouseListener[] getMouseListeners() { public synchronized MouseListener[] getMouseListeners() {
return (MouseListener[])(getListeners(MouseListener.class)); return AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
} }
/** /**
@ -494,7 +491,7 @@ public class TrayIcon {
* @see java.awt.event.MouseMotionListener * @see java.awt.event.MouseMotionListener
*/ */
public synchronized MouseMotionListener[] getMouseMotionListeners() { public synchronized MouseMotionListener[] getMouseMotionListeners() {
return (MouseMotionListener[]) (getListeners(MouseMotionListener.class)); return AWTEventMulticaster.getListeners(mouseMotionListener, MouseMotionListener.class);
} }
/** /**
@ -581,7 +578,7 @@ public class TrayIcon {
* @see java.awt.event.ActionListener * @see java.awt.event.ActionListener
*/ */
public synchronized ActionListener[] getActionListeners() { public synchronized ActionListener[] getActionListeners() {
return (ActionListener[])(getListeners(ActionListener.class)); return AWTEventMulticaster.getListeners(actionListener, ActionListener.class);
} }
/** /**
@ -635,7 +632,7 @@ public class TrayIcon {
TrayIconPeer peer = this.peer; TrayIconPeer peer = this.peer;
if (peer != null) { if (peer != null) {
peer.displayMessage(caption, text, messageType.toString()); peer.displayMessage(caption, text, messageType.name());
} }
} }
@ -657,18 +654,6 @@ public class TrayIcon {
// **************************************************************** // ****************************************************************
// **************************************************************** // ****************************************************************
<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() void addNotify()
throws AWTException throws AWTException
{ {