KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > TrayIcon


1 /*
2  * Copyright (C) 2006 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  */

5
6 package java.awt;
7
8 import java.awt.Point JavaDoc;
9 import java.awt.Toolkit JavaDoc;
10 import java.awt.GraphicsEnvironment JavaDoc;
11 import java.awt.event.*;
12 import java.awt.AWTEvent JavaDoc;
13 import java.awt.AWTEventMulticaster JavaDoc;
14 import java.awt.EventQueue JavaDoc;
15 import java.awt.PopupMenu JavaDoc;
16 import java.awt.Image JavaDoc;
17 import java.util.EventListener JavaDoc;
18 import java.awt.peer.TrayIconPeer;
19 import sun.awt.AppContext;
20 import sun.awt.SunToolkit;
21 import java.util.EventObject JavaDoc;
22
23 /**
24  * A <code>TrayIcon</code> object represents a tray icon that can be
25  * added to the {@link SystemTray system tray}. A
26  * <code>TrayIcon</code> can have a tooltip (text), an image, a popup
27  * menu, and a set of listeners associated with it.
28  *
29  * <p>A <code>TrayIcon</code> can generate various {@link MouseEvent
30  * MouseEvents} and supports adding corresponding listeners to receive
31  * notification of these events. <code>TrayIcon</code> processes some
32  * of the events by itself. For example, by default, when the
33  * right-mouse click is performed on the <code>TrayIcon</code> it
34  * displays the specified popup menu. When the mouse hovers
35  * over the <code>TrayIcon</code> the tooltip is displayed.
36  *
37  * <p><strong>Note:</strong> When the <code>MouseEvent</code> is
38  * dispatched to its registered listeners its <code>component</code>
39  * property will be set to <code>null</code>. (See {@link
40  * java.awt.event.ComponentEvent#getComponent}) The
41  * <code>source</code> property will be set to this
42  * <code>TrayIcon</code>. (See {@link
43  * java.util.EventObject#getSource})
44  *
45  * <p><b>Note:</b> A well-behaved {@link TrayIcon} implementation
46  * will assign different gestures to showing a popup menu and
47  * selecting a tray icon.
48  *
49  * <p>A <code>TrayIcon</code> can generate an {@link ActionEvent
50  * ActionEvent}. On some platforms, this occurs when the user selects
51  * the tray icon using either the mouse or keyboard.
52  *
53  * <p>If a SecurityManager is installed, the AWTPermission
54  * {@code accessSystemTray} must be granted in order to create
55  * a {@code TrayIcon}. Otherwise the constructor will throw a
56  * SecurityException.
57  *
58  * <p> See the {@link SystemTray} class overview for an example on how
59  * to use the <code>TrayIcon</code> API.
60  *
61  * @since 1.6
62  * @see SystemTray#add
63  * @see java.awt.event.ComponentEvent#getComponent
64  * @see java.util.EventObject#getSource
65  *
66  * @author Bino George
67  * @author Denis Mikhalkin
68  * @author Sharon Zakhour
69  * @author Anton Tarasov
70  */

71 public class TrayIcon {
72     private Image JavaDoc image;
73     private String JavaDoc tooltip;
74     private PopupMenu JavaDoc popup;
75     private boolean autosize;
76     private int id;
77     private String JavaDoc actionCommand;
78
79     transient private TrayIconPeer peer;
80
81     transient MouseListener mouseListener;
82     transient MouseMotionListener mouseMotionListener;
83     transient ActionListener actionListener;
84
85     /**
86      * This object is used as a key for internal hashtables.
87      */

88     transient private Object JavaDoc privateKey = new Object JavaDoc();
89
90     static {
91         Toolkit.loadLibraries();
92         if (!GraphicsEnvironment.isHeadless()) {
93             initIDs();
94         }
95     }
96
97     private TrayIcon()
98       throws UnsupportedOperationException JavaDoc, HeadlessException JavaDoc, SecurityException JavaDoc
99     {
100         SystemTray.checkSystemTrayAllowed();
101         if (GraphicsEnvironment.isHeadless()) {
102             throw new HeadlessException JavaDoc();
103         }
104         if (!SystemTray.isSupported()) {
105             throw new UnsupportedOperationException JavaDoc();
106         }
107         SunToolkit.insertTargetMapping(this, AppContext.getAppContext());
108     }
109
110     /**
111      * Creates a <code>TrayIcon</code> with the specified image.
112      *
113      * @param image the <code>Image</code> to be used
114      * @throws IllegalArgumentException if <code>image</code> is
115      * <code>null</code>
116      * @throws UnsupportedOperationException if the system tray isn't
117      * supported by the current platform
118      * @throws HeadlessException if
119      * {@code GraphicsEnvironment.isHeadless()} returns {@code true}
120      * @throws SecurityException if {@code accessSystemTray} permission
121      * is not granted
122      * @see SystemTray#add(TrayIcon)
123      * @see TrayIcon#TrayIcon(Image, String, PopupMenu)
124      * @see TrayIcon#TrayIcon(Image, String)
125      * @see SecurityManager#checkPermission
126      * @see AWTPermission
127      */

128     public TrayIcon(Image JavaDoc image) {
129         this();
130         if (image == null) {
131             throw new IllegalArgumentException JavaDoc("creating TrayIcon with null Image");
132         }
133         setImage(image);
134     }
135
136     /**
137      * Creates a <code>TrayIcon</code> with the specified image and
138      * tooltip text.
139      *
140      * @param image the <code>Image</code> to be used
141      * @param tooltip the string to be used as tooltip text; if the
142      * value is <code>null</code> no tooltip is shown
143      * @throws IllegalArgumentException if <code>image</code> is
144      * <code>null</code>
145      * @throws UnsupportedOperationException if the system tray isn't
146      * supported by the current platform
147      * @throws HeadlessException if
148      * {@code GraphicsEnvironment.isHeadless()} returns {@code true}
149      * @throws SecurityException if {@code accessSystemTray} permission
150      * is not granted
151      * @see SystemTray#add(TrayIcon)
152      * @see TrayIcon#TrayIcon(Image)
153      * @see TrayIcon#TrayIcon(Image, String, PopupMenu)
154      * @see SecurityManager#checkPermission
155      * @see AWTPermission
156      */

157     public TrayIcon(Image JavaDoc image, String JavaDoc tooltip) {
158         this(image);
159         setToolTip(tooltip);
160     }
161
162     /**
163      * Creates a <code>TrayIcon</code> with the specified image,
164      * tooltip and popup menu.
165      *
166      * @param image the <code>Image</code> to be used
167      * @param tooltip the string to be used as tooltip text; if the
168      * value is <code>null</code> no tooltip is shown
169      * @param popup the menu to be used for the tray icon's popup
170      * menu; if the value is <code>null</code> no popup menu is shown
171      * @throws IllegalArgumentException if <code>image</code> is <code>null</code>
172      * @throws UnsupportedOperationException if the system tray isn't
173      * supported by the current platform
174      * @throws HeadlessException if
175      * {@code GraphicsEnvironment.isHeadless()} returns {@code true}
176      * @throws SecurityException if {@code accessSystemTray} permission
177      * is not granted
178      * @see SystemTray#add(TrayIcon)
179      * @see TrayIcon#TrayIcon(Image, String)
180      * @see TrayIcon#TrayIcon(Image)
181      * @see PopupMenu
182      * @see MouseListener
183      * @see #addMouseListener(MouseListener)
184      * @see SecurityManager#checkPermission
185      * @see AWTPermission
186      */

187     public TrayIcon(Image JavaDoc image, String JavaDoc tooltip, PopupMenu JavaDoc popup) {
188         this(image, tooltip);
189         setPopupMenu(popup);
190     }
191
192     /**
193      * Sets the image for this <code>TrayIcon</code>. The previous
194      * tray icon image is discarded without calling the {@link
195      * java.awt.Image#flush} method &#151; you will need to call it
196      * manually.
197      *
198      * <p> If the image represents an animated image, it will be
199      * animated automatically.
200      *
201      * <p> See the {@link #setImageAutoSize(boolean)} property for
202      * details on the size of the displayed image.
203      *
204      * <p> Calling this method with the same image that is currently
205      * being used has no effect.
206      *
207      * @throws NullPointerException if <code>image</code> is <code>null</code>
208      * @param image the non-null <code>Image</code> to be used
209      * @see #getImage
210      * @see Image
211      * @see SystemTray#add(TrayIcon)
212      * @see TrayIcon#TrayIcon(Image, String)
213      */

214     public void setImage(Image JavaDoc image) {
215         if (image == null) {
216             throw new NullPointerException JavaDoc("setting null Image");
217         }
218         this.image = image;
219         
220         TrayIconPeer peer = this.peer;
221         if (peer != null) {
222             peer.updateImage();
223         }
224     }
225
226     /**
227      * Returns the current image used for this <code>TrayIcon</code>.
228      *
229      * @return the image
230      * @see #setImage(Image)
231      * @see Image
232      */

233     public Image JavaDoc getImage() {
234         return image;
235     }
236
237     /**
238      * Sets the popup menu for this <code>TrayIcon</code>. If
239      * <code>popup</code> is <code>null</code>, no popup menu will be
240      * associated with this <code>TrayIcon</code>.
241      *
242      * <p>Note that this <code>popup</code> must not be added to any
243      * parent before or after it is set on the tray icon. If you add
244      * it to some parent, the <code>popup</code> may be removed from
245      * that parent.
246      *
247      * <p>The {@code popup} can be set on one {@code TrayIcon} only.
248      * Setting the same popup on multiple {@code TrayIcon}s will cause
249      * an {@code IllegalArgumentException}.
250      *
251      * <p><strong>Note:</strong> Some platforms may not support
252      * showing the user-specified popup menu component when the user
253      * right-clicks the tray icon. In this situation, either no menu
254      * will be displayed or, on some systems, a native version of the
255      * menu may be displayed.
256      *
257      * @throws IllegalArgumentException if the {@code popup} is already
258      * set for another {@code TrayIcon}
259      * @param popup a <code>PopupMenu</code> or <code>null</code> to
260      * remove any popup menu
261      * @see #getPopupMenu
262      */

263     public void setPopupMenu(PopupMenu JavaDoc popup) {
264         if (popup == this.popup) {
265             return;
266         }
267         synchronized (TrayIcon JavaDoc.class) {
268             if (popup != null) {
269                 if (popup.isTrayIconPopup) {
270                     throw new IllegalArgumentException JavaDoc("the PopupMenu is already set for another TrayIcon");
271                 }
272                 popup.isTrayIconPopup = true;
273             }
274             if (this.popup != null) {
275                 this.popup.isTrayIconPopup = false;
276             }
277             this.popup = popup;
278         }
279     }
280
281     /**
282      * Returns the popup menu associated with this <code>TrayIcon</code>.
283      *
284      * @return the popup menu or <code>null</code> if none exists
285      * @see #setPopupMenu(PopupMenu)
286      */

287     public PopupMenu JavaDoc getPopupMenu() {
288         return popup;
289     }
290
291     /**
292      * Sets the tooltip string for this <code>TrayIcon</code>. The
293      * tooltip is displayed automatically when the mouse hovers over
294      * the icon. Setting the tooltip to <code>null</code> removes any
295      * tooltip text.
296      *
297      * When displayed, the tooltip string may be truncated on some platforms;
298      * the number of characters that may be displayed is platform-dependent.
299      *
300      * @param tooltip the string for the tooltip; if the value is
301      * <code>null</code> no tooltip is shown
302      * @see #getToolTip
303      */

304     public void setToolTip(String JavaDoc tooltip) {
305         this.tooltip = tooltip;
306
307         TrayIconPeer peer = this.peer;
308         if (peer != null) {
309             peer.setToolTip(tooltip);
310         }
311     }
312
313     /**
314      * Returns the tooltip string associated with this
315      * <code>TrayIcon</code>.
316      *
317      * @return the tooltip string or <code>null</code> if none exists
318      * @see #setToolTip(String)
319      */

320     public String JavaDoc getToolTip() {
321         return tooltip;
322     }
323
324     /**
325      * Sets the auto-size property. Auto-size determines whether the
326      * tray image is automatically sized to fit the space allocated
327      * for the image on the tray. By default, the auto-size property
328      * is set to <code>false</code>.
329      *
330      * <p> If auto-size is <code>false</code>, and the image size
331      * doesn't match the tray icon space, the image is painted as-is
332      * inside that space &#151; if larger than the allocated space, it will
333      * be cropped.
334      *
335      * <p> If auto-size is <code>true</code>, the image is stretched or shrunk to
336      * fit the tray icon space.
337      *
338      * @param autosize <code>true</code> to auto-size the image,
339      * <code>false</code> otherwise
340      * @see #isImageAutoSize
341      */

342     public void setImageAutoSize(boolean autosize) {
343         this.autosize = autosize;
344
345         TrayIconPeer peer = this.peer;
346         if (peer != null) {
347             peer.updateImage();
348         }
349     }
350
351     /**
352      * Returns the value of the auto-size property.
353      *
354      * @return <code>true</code> if the image will be auto-sized,
355      * <code>false</code> otherwise
356      * @see #setImageAutoSize(boolean)
357      */

358     public boolean isImageAutoSize() {
359         return autosize;
360     }
361
362     /**
363      * Adds the specified mouse listener to receive mouse events from
364      * this <code>TrayIcon</code>. Calling this method with a
365      * <code>null</code> value has no effect.
366      *
367      * <p><b>Note</b>: The {@code MouseEvent}'s coordinates (received
368      * from the {@code TrayIcon}) are relative to the screen, not the
369      * {@code TrayIcon}.
370      *
371      * <p> <b>Note: </b>The <code>MOUSE_ENTERED</code> and
372      * <code>MOUSE_EXITED</code> mouse events are not supported.
373      * <p>Refer to <a HREF="doc-files/AWTThreadIssues.html#ListenersThreads"
374      * >AWT Threading Issues</a> for details on AWT's threading model.
375      *
376      * @param listener the mouse listener
377      * @see java.awt.event.MouseEvent
378      * @see java.awt.event.MouseListener
379      * @see #removeMouseListener(MouseListener)
380      * @see #getMouseListeners
381      */

382     public synchronized void addMouseListener(MouseListener listener) {
383         if (listener == null) {
384             return;
385         }
386         mouseListener = AWTEventMulticaster.add(mouseListener, listener);
387     }
388
389     /**
390      * Removes the specified mouse listener. Calling this method with
391      * <code>null</code> or an invalid value has no effect.
392      * <p>Refer to <a HREF="doc-files/AWTThreadIssues.html#ListenersThreads"
393      * >AWT Threading Issues</a> for details on AWT's threading model.
394      *
395      * @param listener the mouse listener
396      * @see java.awt.event.MouseEvent
397      * @see java.awt.event.MouseListener
398      * @see #addMouseListener(MouseListener)
399      * @see #getMouseListeners
400      */

401     public synchronized void removeMouseListener(MouseListener listener) {
402         if (listener == null) {
403             return;
404         }
405         mouseListener = AWTEventMulticaster.remove(mouseListener, listener);
406     }
407
408     /**
409      * Returns an array of all the mouse listeners
410      * registered on this <code>TrayIcon</code>.
411      *
412      * @return all of the <code>MouseListeners</code> registered on
413      * this <code>TrayIcon</code> or an empty array if no mouse
414      * listeners are currently registered
415      *
416      * @see #addMouseListener(MouseListener)
417      * @see #removeMouseListener(MouseListener)
418      * @see java.awt.event.MouseListener
419      */

420     public synchronized MouseListener[] getMouseListeners() {
421         return (MouseListener[])(getListeners(MouseListener.class));
422     }
423  
424     /**
425      * Adds the specified mouse listener to receive mouse-motion
426      * events from this <code>TrayIcon</code>. Calling this method
427      * with a <code>null</code> value has no effect.
428      *
429      * <p><b>Note</b>: The {@code MouseEvent}'s coordinates (received
430      * from the {@code TrayIcon}) are relative to the screen, not the
431      * {@code TrayIcon}.
432      *
433      * <p> <b>Note: </b>The <code>MOUSE_DRAGGED</code> mouse event is not supported.
434      * <p>Refer to <a HREF="doc-files/AWTThreadIssues.html#ListenersThreads"
435      * >AWT Threading Issues</a> for details on AWT's threading model.
436      *
437      * @param listener the mouse listener
438      * @see java.awt.event.MouseEvent
439      * @see java.awt.event.MouseMotionListener
440      * @see #removeMouseMotionListener(MouseMotionListener)
441      * @see #getMouseMotionListeners
442      */

443     public synchronized void addMouseMotionListener(MouseMotionListener listener) {
444         if (listener == null) {
445             return;
446         }
447         mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener);
448     }
449
450     /**
451      * Removes the specified mouse-motion listener. Calling this method with
452      * <code>null</code> or an invalid value has no effect.
453      * <p>Refer to <a HREF="doc-files/AWTThreadIssues.html#ListenersThreads"
454      * >AWT Threading Issues</a> for details on AWT's threading model.
455      *
456      * @param listener the mouse listener
457      * @see java.awt.event.MouseEvent
458      * @see java.awt.event.MouseMotionListener
459      * @see #addMouseMotionListener(MouseMotionListener)
460      * @see #getMouseMotionListeners
461      */

462     public synchronized void removeMouseMotionListener(MouseMotionListener listener) {
463         if (listener == null) {
464             return;
465         }
466         mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener);
467     }
468
469     /**
470      * Returns an array of all the mouse-motion listeners
471      * registered on this <code>TrayIcon</code>.
472      *
473      * @return all of the <code>MouseInputListeners</code> registered on
474      * this <code>TrayIcon</code> or an empty array if no mouse
475      * listeners are currently registered
476      *
477      * @see #addMouseMotionListener(MouseMotionListener)
478      * @see #removeMouseMotionListener(MouseMotionListener)
479      * @see java.awt.event.MouseMotionListener
480      */

481     public synchronized MouseMotionListener[] getMouseMotionListeners() {
482         return (MouseMotionListener[]) (getListeners(MouseMotionListener.class));
483     }
484
485     /**
486      * Returns the command name of the action event fired by this tray icon.
487      *
488      * @return the action command name, or <code>null</code> if none exists
489      * @see #addActionListener(ActionListener)
490      * @see #setActionCommand(String)
491      */

492     public String JavaDoc getActionCommand() {
493         return actionCommand;
494     }
495
496     /**
497      * Sets the command name for the action event fired by this tray
498      * icon. By default, this action command is set to
499      * <code>null</code>.
500      *
501      * @param command a string used to set the tray icon's
502      * action command.
503      * @see java.awt.event.ActionEvent
504      * @see #addActionListener(ActionListener)
505      * @see #getActionCommand
506      */

507     public void setActionCommand(String JavaDoc command) {
508         actionCommand = command;
509     }
510
511     /**
512      * Adds the specified action listener to receive
513      * <code>ActionEvent</code>s from this <code>TrayIcon</code>.
514      * Action events usually occur when a user selects the tray icon,
515      * using either the mouse or keyboard. The conditions in which
516      * action events are generated are platform-dependent.
517      *
518      * <p>Calling this method with a <code>null</code> value has no
519      * effect.
520      * <p>Refer to <a HREF="doc-files/AWTThreadIssues.html#ListenersThreads"
521      * >AWT Threading Issues</a> for details on AWT's threading model.
522      *
523      * @param listener the action listener
524      * @see #removeActionListener
525      * @see #getActionListeners
526      * @see java.awt.event.ActionListener
527      * @see #setActionCommand(String)
528      */

529     public synchronized void addActionListener(ActionListener listener) {
530         if (listener == null) {
531             return;
532         }
533         actionListener = AWTEventMulticaster.add(actionListener, listener);
534     }
535
536     /**
537      * Removes the specified action listener. Calling this method with
538      * <code>null</code> or an invalid value has no effect.
539      * <p>Refer to <a HREF="doc-files/AWTThreadIssues.html#ListenersThreads"
540      * >AWT Threading Issues</a> for details on AWT's threading model.
541      *
542      * @param listener the action listener
543      * @see java.awt.event.ActionEvent
544      * @see java.awt.event.ActionListener
545      * @see #addActionListener(ActionListener)
546      * @see #getActionListeners
547      * @see #setActionCommand(String)
548      */

549     public synchronized void removeActionListener(ActionListener listener) {
550         if (listener == null) {
551             return;
552         }
553         actionListener = AWTEventMulticaster.remove(actionListener, listener);
554     }
555
556     /**
557      * Returns an array of all the action listeners
558      * registered on this <code>TrayIcon</code>.
559      *
560      * @return all of the <code>ActionListeners</code> registered on
561      * this <code>TrayIcon</code> or an empty array if no action
562      * listeners are currently registered
563      *
564      * @see #addActionListener(ActionListener)
565      * @see #removeActionListener(ActionListener)
566      * @see java.awt.event.ActionListener
567      */

568     public synchronized ActionListener[] getActionListeners() {
569         return (ActionListener[])(getListeners(ActionListener.class));
570     }
571
572     /**
573      * The message type determines which icon will be displayed in the
574      * caption of the message, and a possible system sound a message
575      * may generate upon showing.
576      *
577      * @see TrayIcon
578      * @see TrayIcon#displayMessage(String, String, MessageType)
579      * @since 1.6
580      */

581     public enum MessageType {
582         /** An error message */
583         ERROR,
584         /** A warning message */
585         WARNING,
586         /** An information message */
587         INFO,
588         /** Simple message */
589         NONE
590     };
591
592     /**
593      * Displays a popup message near the tray icon. The message will
594      * disappear after a time or if the user clicks on it. Clicking
595      * on the message may trigger an {@code ActionEvent}.
596      *
597      * <p>Either the caption or the text may be <code>null</code>, but an
598      * <code>NullPointerException</code> is thrown if both are
599      * <code>null</code>.
600      *
601      * When displayed, the caption or text strings may be truncated on
602      * some platforms; the number of characters that may be displayed is
603      * platform-dependent.
604      *
605      * <p><strong>Note:</strong> Some platforms may not support
606      * showing a message.
607      *
608      * @param caption the caption displayed above the text, usually in
609      * bold; may be <code>null</code>
610      * @param text the text displayed for the particular message; may be
611      * <code>null</code>
612      * @param messageType an enum indicating the message type
613      * @throws NullPointerException if both <code>caption</code>
614      * and <code>text</code> are <code>null</code>
615      */

616     public void displayMessage(String JavaDoc caption, String JavaDoc text, MessageType messageType) {
617         if (caption == null && text == null) {
618             throw new NullPointerException JavaDoc("displaying the message with both caption and text being null");
619         }
620
621         TrayIconPeer peer = this.peer;
622         if (peer != null) {
623             peer.displayMessage(caption, text, messageType.toString());
624         }
625     }
626
627     /**
628      * Returns the size, in pixels, of the space that the tray icon
629      * occupies in the system tray. For the tray icon that is not yet
630      * added to the system tray, the returned size is equal to the
631      * result of the {@link SystemTray#getTrayIconSize}.
632      *
633      * @return the size of the tray icon, in pixels
634      * @see TrayIcon#setImageAutoSize(boolean)
635      * @see java.awt.Image
636      * @see TrayIcon#getSize()
637      */

638     public Dimension JavaDoc getSize() {
639         return SystemTray.getSystemTray().getTrayIconSize();
640     }
641
642     // ****************************************************************
643
// ****************************************************************
644

645     <T extends EventListener JavaDoc> T[] getListeners(Class JavaDoc<T> listenerType) {
646         EventListener JavaDoc l = null;
647         if (listenerType == MouseListener.class) {
648             l = mouseListener;
649         } else if (listenerType == MouseMotionListener.class) {
650             l = mouseMotionListener;
651         } else if (listenerType == ActionListener.class) {
652             l = actionListener;
653         }
654         return AWTEventMulticaster.getListeners(l, listenerType);
655     }
656     
657     void addNotify()
658       throws AWTException JavaDoc
659     {
660         synchronized (this) {
661             if (peer == null) {
662                 peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
663             }
664         }
665         peer.setToolTip(tooltip);
666     }
667
668     void removeNotify() {
669         TrayIconPeer p = null;
670         synchronized (this) {
671             p = peer;
672             peer = null;
673         }
674         if (p != null) {
675             p.dispose();
676         }
677     }
678
679     void setID(int id) {
680         this.id = id;
681     }
682
683     int getID(){
684         return id;
685     }
686
687     void dispatchEvent(AWTEvent JavaDoc e) {
688         EventQueue.setCurrentEventAndMostRecentTime(e);
689         Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
690         processEvent(e);
691     }
692
693     void processEvent(AWTEvent JavaDoc e) {
694         if (e instanceof MouseEvent) {
695             switch(e.getID()) {
696             case MouseEvent.MOUSE_PRESSED:
697             case MouseEvent.MOUSE_RELEASED:
698             case MouseEvent.MOUSE_CLICKED:
699                 processMouseEvent((MouseEvent)e);
700                 break;
701             case MouseEvent.MOUSE_MOVED:
702                 processMouseMotionEvent((MouseEvent)e);
703                 break;
704             default:
705                 return;
706             }
707         } else if (e instanceof ActionEvent) {
708             processActionEvent((ActionEvent)e);
709         }
710     }
711
712     void processMouseEvent(MouseEvent e) {
713         MouseListener listener = mouseListener;
714
715         TrayIconPeer peer = this.peer;
716         if (e.isPopupTrigger() && peer != null) {
717             peer.showPopupMenu(e.getPoint().x, e.getPoint().y);
718         }
719
720         if (listener != null) {
721             int id = e.getID();
722             switch(id) {
723             case MouseEvent.MOUSE_PRESSED:
724                 listener.mousePressed(e);
725                 break;
726             case MouseEvent.MOUSE_RELEASED:
727                 listener.mouseReleased(e);
728                 break;
729             case MouseEvent.MOUSE_CLICKED:
730                 listener.mouseClicked(e);
731                 break;
732             default:
733                 return;
734             }
735         }
736     }
737
738     void processMouseMotionEvent(MouseEvent e) {
739         MouseMotionListener listener = mouseMotionListener;
740         if (listener != null &&
741             e.getID() == MouseEvent.MOUSE_MOVED)
742         {
743             listener.mouseMoved(e);
744         }
745     }
746
747     void processActionEvent(ActionEvent e) {
748         ActionListener listener = actionListener;
749         if (listener != null) {
750             listener.actionPerformed(e);
751         }
752     }
753
754     private static native void initIDs();
755 }
756
Popular Tags