提交 f53e7cfa 编写于 作者: A ant

6280057: I have audited SystemTray and TrayIcon code

Summary: small refactoring
Reviewed-by: dcherepanov
上级 f5178c7c
...@@ -125,6 +125,8 @@ public class SystemTray { ...@@ -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 { ...@@ -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();
} 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; return false;
} }
...@@ -323,7 +324,7 @@ public class SystemTray { ...@@ -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;
} }
/** /**
......
...@@ -142,9 +142,6 @@ public class TrayIcon { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册