0N/A/*
3909N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt;
0N/A
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.peer.TrayIconPeer;
0N/Aimport sun.awt.AppContext;
0N/Aimport sun.awt.SunToolkit;
5255N/Aimport sun.awt.AWTAccessor;
563N/Aimport sun.awt.HeadlessToolkit;
0N/Aimport java.util.EventObject;
3787N/Aimport java.security.AccessControlContext;
3787N/Aimport java.security.AccessController;
0N/A
0N/A/**
0N/A * A <code>TrayIcon</code> object represents a tray icon that can be
0N/A * added to the {@link SystemTray system tray}. A
0N/A * <code>TrayIcon</code> can have a tooltip (text), an image, a popup
0N/A * menu, and a set of listeners associated with it.
0N/A *
0N/A * <p>A <code>TrayIcon</code> can generate various {@link MouseEvent
0N/A * MouseEvents} and supports adding corresponding listeners to receive
0N/A * notification of these events. <code>TrayIcon</code> processes some
0N/A * of the events by itself. For example, by default, when the
0N/A * right-mouse click is performed on the <code>TrayIcon</code> it
0N/A * displays the specified popup menu. When the mouse hovers
0N/A * over the <code>TrayIcon</code> the tooltip is displayed.
0N/A *
0N/A * <p><strong>Note:</strong> When the <code>MouseEvent</code> is
0N/A * dispatched to its registered listeners its <code>component</code>
0N/A * property will be set to <code>null</code>. (See {@link
0N/A * java.awt.event.ComponentEvent#getComponent}) The
0N/A * <code>source</code> property will be set to this
0N/A * <code>TrayIcon</code>. (See {@link
0N/A * java.util.EventObject#getSource})
0N/A *
0N/A * <p><b>Note:</b> A well-behaved {@link TrayIcon} implementation
0N/A * will assign different gestures to showing a popup menu and
0N/A * selecting a tray icon.
0N/A *
0N/A * <p>A <code>TrayIcon</code> can generate an {@link ActionEvent
0N/A * ActionEvent}. On some platforms, this occurs when the user selects
0N/A * the tray icon using either the mouse or keyboard.
0N/A *
0N/A * <p>If a SecurityManager is installed, the AWTPermission
0N/A * {@code accessSystemTray} must be granted in order to create
0N/A * a {@code TrayIcon}. Otherwise the constructor will throw a
0N/A * SecurityException.
0N/A *
0N/A * <p> See the {@link SystemTray} class overview for an example on how
0N/A * to use the <code>TrayIcon</code> API.
0N/A *
0N/A * @since 1.6
0N/A * @see SystemTray#add
0N/A * @see java.awt.event.ComponentEvent#getComponent
0N/A * @see java.util.EventObject#getSource
0N/A *
0N/A * @author Bino George
0N/A * @author Denis Mikhalkin
0N/A * @author Sharon Zakhour
0N/A * @author Anton Tarasov
0N/A */
0N/Apublic class TrayIcon {
3787N/A
0N/A private Image image;
0N/A private String tooltip;
0N/A private PopupMenu popup;
0N/A private boolean autosize;
0N/A private int id;
0N/A private String actionCommand;
0N/A
0N/A transient private TrayIconPeer peer;
0N/A
0N/A transient MouseListener mouseListener;
0N/A transient MouseMotionListener mouseMotionListener;
0N/A transient ActionListener actionListener;
0N/A
3787N/A /*
3787N/A * The tray icon's AccessControlContext.
3787N/A *
3787N/A * Unlike the acc in Component, this field is made final
3787N/A * because TrayIcon is not serializable.
3787N/A */
3787N/A private final AccessControlContext acc = AccessController.getContext();
3787N/A
3787N/A /*
3787N/A * Returns the acc this tray icon was constructed with.
3787N/A */
3787N/A final AccessControlContext getAccessControlContext() {
3787N/A if (acc == null) {
3787N/A throw new SecurityException("TrayIcon is missing AccessControlContext");
3787N/A }
3787N/A return acc;
3787N/A }
3787N/A
0N/A static {
0N/A Toolkit.loadLibraries();
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
5255N/A
5255N/A AWTAccessor.setTrayIconAccessor(
5255N/A new AWTAccessor.TrayIconAccessor() {
5255N/A public void addNotify(TrayIcon trayIcon) throws AWTException {
5255N/A trayIcon.addNotify();
5255N/A }
5255N/A public void removeNotify(TrayIcon trayIcon) {
5255N/A trayIcon.removeNotify();
5255N/A }
5255N/A });
0N/A }
0N/A
0N/A private TrayIcon()
0N/A throws UnsupportedOperationException, HeadlessException, SecurityException
0N/A {
0N/A SystemTray.checkSystemTrayAllowed();
0N/A if (GraphicsEnvironment.isHeadless()) {
0N/A throw new HeadlessException();
0N/A }
0N/A if (!SystemTray.isSupported()) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A SunToolkit.insertTargetMapping(this, AppContext.getAppContext());
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>TrayIcon</code> with the specified image.
0N/A *
0N/A * @param image the <code>Image</code> to be used
0N/A * @throws IllegalArgumentException if <code>image</code> is
0N/A * <code>null</code>
0N/A * @throws UnsupportedOperationException if the system tray isn't
0N/A * supported by the current platform
0N/A * @throws HeadlessException if
0N/A * {@code GraphicsEnvironment.isHeadless()} returns {@code true}
0N/A * @throws SecurityException if {@code accessSystemTray} permission
0N/A * is not granted
0N/A * @see SystemTray#add(TrayIcon)
0N/A * @see TrayIcon#TrayIcon(Image, String, PopupMenu)
0N/A * @see TrayIcon#TrayIcon(Image, String)
0N/A * @see SecurityManager#checkPermission
0N/A * @see AWTPermission
0N/A */
0N/A public TrayIcon(Image image) {
0N/A this();
1399N/A if (image == null) {
1399N/A throw new IllegalArgumentException("creating TrayIcon with null Image");
1399N/A }
0N/A setImage(image);
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>TrayIcon</code> with the specified image and
0N/A * tooltip text.
0N/A *
0N/A * @param image the <code>Image</code> to be used
0N/A * @param tooltip the string to be used as tooltip text; if the
0N/A * value is <code>null</code> no tooltip is shown
0N/A * @throws IllegalArgumentException if <code>image</code> is
0N/A * <code>null</code>
0N/A * @throws UnsupportedOperationException if the system tray isn't
0N/A * supported by the current platform
0N/A * @throws HeadlessException if
0N/A * {@code GraphicsEnvironment.isHeadless()} returns {@code true}
0N/A * @throws SecurityException if {@code accessSystemTray} permission
0N/A * is not granted
0N/A * @see SystemTray#add(TrayIcon)
0N/A * @see TrayIcon#TrayIcon(Image)
0N/A * @see TrayIcon#TrayIcon(Image, String, PopupMenu)
0N/A * @see SecurityManager#checkPermission
0N/A * @see AWTPermission
0N/A */
0N/A public TrayIcon(Image image, String tooltip) {
0N/A this(image);
0N/A setToolTip(tooltip);
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>TrayIcon</code> with the specified image,
0N/A * tooltip and popup menu.
0N/A *
0N/A * @param image the <code>Image</code> to be used
0N/A * @param tooltip the string to be used as tooltip text; if the
0N/A * value is <code>null</code> no tooltip is shown
0N/A * @param popup the menu to be used for the tray icon's popup
0N/A * menu; if the value is <code>null</code> no popup menu is shown
0N/A * @throws IllegalArgumentException if <code>image</code> is <code>null</code>
0N/A * @throws UnsupportedOperationException if the system tray isn't
0N/A * supported by the current platform
0N/A * @throws HeadlessException if
0N/A * {@code GraphicsEnvironment.isHeadless()} returns {@code true}
0N/A * @throws SecurityException if {@code accessSystemTray} permission
0N/A * is not granted
0N/A * @see SystemTray#add(TrayIcon)
0N/A * @see TrayIcon#TrayIcon(Image, String)
0N/A * @see TrayIcon#TrayIcon(Image)
0N/A * @see PopupMenu
0N/A * @see MouseListener
0N/A * @see #addMouseListener(MouseListener)
0N/A * @see SecurityManager#checkPermission
0N/A * @see AWTPermission
0N/A */
0N/A public TrayIcon(Image image, String tooltip, PopupMenu popup) {
0N/A this(image, tooltip);
0N/A setPopupMenu(popup);
0N/A }
0N/A
0N/A /**
0N/A * Sets the image for this <code>TrayIcon</code>. The previous
0N/A * tray icon image is discarded without calling the {@link
0N/A * java.awt.Image#flush} method &#151; you will need to call it
0N/A * manually.
0N/A *
0N/A * <p> If the image represents an animated image, it will be
0N/A * animated automatically.
0N/A *
0N/A * <p> See the {@link #setImageAutoSize(boolean)} property for
0N/A * details on the size of the displayed image.
0N/A *
0N/A * <p> Calling this method with the same image that is currently
0N/A * being used has no effect.
0N/A *
0N/A * @throws NullPointerException if <code>image</code> is <code>null</code>
0N/A * @param image the non-null <code>Image</code> to be used
0N/A * @see #getImage
0N/A * @see Image
0N/A * @see SystemTray#add(TrayIcon)
0N/A * @see TrayIcon#TrayIcon(Image, String)
0N/A */
0N/A public void setImage(Image image) {
0N/A if (image == null) {
0N/A throw new NullPointerException("setting null Image");
0N/A }
0N/A this.image = image;
0N/A
0N/A TrayIconPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.updateImage();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the current image used for this <code>TrayIcon</code>.
0N/A *
0N/A * @return the image
0N/A * @see #setImage(Image)
0N/A * @see Image
0N/A */
0N/A public Image getImage() {
0N/A return image;
0N/A }
0N/A
0N/A /**
0N/A * Sets the popup menu for this <code>TrayIcon</code>. If
0N/A * <code>popup</code> is <code>null</code>, no popup menu will be
0N/A * associated with this <code>TrayIcon</code>.
0N/A *
0N/A * <p>Note that this <code>popup</code> must not be added to any
0N/A * parent before or after it is set on the tray icon. If you add
0N/A * it to some parent, the <code>popup</code> may be removed from
0N/A * that parent.
0N/A *
0N/A * <p>The {@code popup} can be set on one {@code TrayIcon} only.
0N/A * Setting the same popup on multiple {@code TrayIcon}s will cause
0N/A * an {@code IllegalArgumentException}.
0N/A *
0N/A * <p><strong>Note:</strong> Some platforms may not support
0N/A * showing the user-specified popup menu component when the user
0N/A * right-clicks the tray icon. In this situation, either no menu
0N/A * will be displayed or, on some systems, a native version of the
0N/A * menu may be displayed.
0N/A *
0N/A * @throws IllegalArgumentException if the {@code popup} is already
0N/A * set for another {@code TrayIcon}
0N/A * @param popup a <code>PopupMenu</code> or <code>null</code> to
0N/A * remove any popup menu
0N/A * @see #getPopupMenu
0N/A */
0N/A public void setPopupMenu(PopupMenu popup) {
0N/A if (popup == this.popup) {
0N/A return;
0N/A }
0N/A synchronized (TrayIcon.class) {
0N/A if (popup != null) {
0N/A if (popup.isTrayIconPopup) {
0N/A throw new IllegalArgumentException("the PopupMenu is already set for another TrayIcon");
0N/A }
0N/A popup.isTrayIconPopup = true;
0N/A }
0N/A if (this.popup != null) {
0N/A this.popup.isTrayIconPopup = false;
0N/A }
0N/A this.popup = popup;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the popup menu associated with this <code>TrayIcon</code>.
0N/A *
0N/A * @return the popup menu or <code>null</code> if none exists
0N/A * @see #setPopupMenu(PopupMenu)
0N/A */
0N/A public PopupMenu getPopupMenu() {
0N/A return popup;
0N/A }
0N/A
0N/A /**
0N/A * Sets the tooltip string for this <code>TrayIcon</code>. The
0N/A * tooltip is displayed automatically when the mouse hovers over
0N/A * the icon. Setting the tooltip to <code>null</code> removes any
0N/A * tooltip text.
0N/A *
0N/A * When displayed, the tooltip string may be truncated on some platforms;
0N/A * the number of characters that may be displayed is platform-dependent.
0N/A *
0N/A * @param tooltip the string for the tooltip; if the value is
0N/A * <code>null</code> no tooltip is shown
0N/A * @see #getToolTip
0N/A */
0N/A public void setToolTip(String tooltip) {
0N/A this.tooltip = tooltip;
0N/A
0N/A TrayIconPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.setToolTip(tooltip);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the tooltip string associated with this
0N/A * <code>TrayIcon</code>.
0N/A *
0N/A * @return the tooltip string or <code>null</code> if none exists
0N/A * @see #setToolTip(String)
0N/A */
0N/A public String getToolTip() {
0N/A return tooltip;
0N/A }
0N/A
0N/A /**
0N/A * Sets the auto-size property. Auto-size determines whether the
0N/A * tray image is automatically sized to fit the space allocated
0N/A * for the image on the tray. By default, the auto-size property
0N/A * is set to <code>false</code>.
0N/A *
0N/A * <p> If auto-size is <code>false</code>, and the image size
0N/A * doesn't match the tray icon space, the image is painted as-is
0N/A * inside that space &#151; if larger than the allocated space, it will
0N/A * be cropped.
0N/A *
0N/A * <p> If auto-size is <code>true</code>, the image is stretched or shrunk to
0N/A * fit the tray icon space.
0N/A *
0N/A * @param autosize <code>true</code> to auto-size the image,
0N/A * <code>false</code> otherwise
0N/A * @see #isImageAutoSize
0N/A */
0N/A public void setImageAutoSize(boolean autosize) {
0N/A this.autosize = autosize;
0N/A
0N/A TrayIconPeer peer = this.peer;
0N/A if (peer != null) {
0N/A peer.updateImage();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the value of the auto-size property.
0N/A *
0N/A * @return <code>true</code> if the image will be auto-sized,
0N/A * <code>false</code> otherwise
0N/A * @see #setImageAutoSize(boolean)
0N/A */
0N/A public boolean isImageAutoSize() {
0N/A return autosize;
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified mouse listener to receive mouse events from
0N/A * this <code>TrayIcon</code>. Calling this method with a
0N/A * <code>null</code> value has no effect.
0N/A *
0N/A * <p><b>Note</b>: The {@code MouseEvent}'s coordinates (received
0N/A * from the {@code TrayIcon}) are relative to the screen, not the
0N/A * {@code TrayIcon}.
0N/A *
0N/A * <p> <b>Note: </b>The <code>MOUSE_ENTERED</code> and
0N/A * <code>MOUSE_EXITED</code> mouse events are not supported.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param listener the mouse listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseListener
0N/A * @see #removeMouseListener(MouseListener)
0N/A * @see #getMouseListeners
0N/A */
0N/A public synchronized void addMouseListener(MouseListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A mouseListener = AWTEventMulticaster.add(mouseListener, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified mouse listener. Calling this method with
0N/A * <code>null</code> or an invalid value has no effect.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param listener the mouse listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseListener
0N/A * @see #addMouseListener(MouseListener)
0N/A * @see #getMouseListeners
0N/A */
0N/A public synchronized void removeMouseListener(MouseListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A mouseListener = AWTEventMulticaster.remove(mouseListener, listener);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the mouse listeners
0N/A * registered on this <code>TrayIcon</code>.
0N/A *
0N/A * @return all of the <code>MouseListeners</code> registered on
0N/A * this <code>TrayIcon</code> or an empty array if no mouse
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addMouseListener(MouseListener)
0N/A * @see #removeMouseListener(MouseListener)
0N/A * @see java.awt.event.MouseListener
0N/A */
0N/A public synchronized MouseListener[] getMouseListeners() {
540N/A return AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified mouse listener to receive mouse-motion
0N/A * events from this <code>TrayIcon</code>. Calling this method
0N/A * with a <code>null</code> value has no effect.
0N/A *
0N/A * <p><b>Note</b>: The {@code MouseEvent}'s coordinates (received
0N/A * from the {@code TrayIcon}) are relative to the screen, not the
0N/A * {@code TrayIcon}.
0N/A *
0N/A * <p> <b>Note: </b>The <code>MOUSE_DRAGGED</code> mouse event is not supported.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param listener the mouse listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseMotionListener
0N/A * @see #removeMouseMotionListener(MouseMotionListener)
0N/A * @see #getMouseMotionListeners
0N/A */
0N/A public synchronized void addMouseMotionListener(MouseMotionListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified mouse-motion listener. Calling this method with
0N/A * <code>null</code> or an invalid value has no effect.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param listener the mouse listener
0N/A * @see java.awt.event.MouseEvent
0N/A * @see java.awt.event.MouseMotionListener
0N/A * @see #addMouseMotionListener(MouseMotionListener)
0N/A * @see #getMouseMotionListeners
0N/A */
0N/A public synchronized void removeMouseMotionListener(MouseMotionListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the mouse-motion listeners
0N/A * registered on this <code>TrayIcon</code>.
0N/A *
0N/A * @return all of the <code>MouseInputListeners</code> registered on
0N/A * this <code>TrayIcon</code> or an empty array if no mouse
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addMouseMotionListener(MouseMotionListener)
0N/A * @see #removeMouseMotionListener(MouseMotionListener)
0N/A * @see java.awt.event.MouseMotionListener
0N/A */
0N/A public synchronized MouseMotionListener[] getMouseMotionListeners() {
540N/A return AWTEventMulticaster.getListeners(mouseMotionListener, MouseMotionListener.class);
0N/A }
0N/A
0N/A /**
0N/A * Returns the command name of the action event fired by this tray icon.
0N/A *
0N/A * @return the action command name, or <code>null</code> if none exists
0N/A * @see #addActionListener(ActionListener)
0N/A * @see #setActionCommand(String)
0N/A */
0N/A public String getActionCommand() {
0N/A return actionCommand;
0N/A }
0N/A
0N/A /**
0N/A * Sets the command name for the action event fired by this tray
0N/A * icon. By default, this action command is set to
0N/A * <code>null</code>.
0N/A *
0N/A * @param command a string used to set the tray icon's
0N/A * action command.
0N/A * @see java.awt.event.ActionEvent
0N/A * @see #addActionListener(ActionListener)
0N/A * @see #getActionCommand
0N/A */
0N/A public void setActionCommand(String command) {
0N/A actionCommand = command;
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified action listener to receive
0N/A * <code>ActionEvent</code>s from this <code>TrayIcon</code>.
0N/A * Action events usually occur when a user selects the tray icon,
0N/A * using either the mouse or keyboard. The conditions in which
0N/A * action events are generated are platform-dependent.
0N/A *
0N/A * <p>Calling this method with a <code>null</code> value has no
0N/A * effect.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param listener the action listener
0N/A * @see #removeActionListener
0N/A * @see #getActionListeners
0N/A * @see java.awt.event.ActionListener
0N/A * @see #setActionCommand(String)
0N/A */
0N/A public synchronized void addActionListener(ActionListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A actionListener = AWTEventMulticaster.add(actionListener, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes the specified action listener. Calling this method with
0N/A * <code>null</code> or an invalid value has no effect.
0N/A * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
0N/A * >AWT Threading Issues</a> for details on AWT's threading model.
0N/A *
0N/A * @param listener the action listener
0N/A * @see java.awt.event.ActionEvent
0N/A * @see java.awt.event.ActionListener
0N/A * @see #addActionListener(ActionListener)
0N/A * @see #getActionListeners
0N/A * @see #setActionCommand(String)
0N/A */
0N/A public synchronized void removeActionListener(ActionListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A actionListener = AWTEventMulticaster.remove(actionListener, listener);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the action listeners
0N/A * registered on this <code>TrayIcon</code>.
0N/A *
0N/A * @return all of the <code>ActionListeners</code> registered on
0N/A * this <code>TrayIcon</code> or an empty array if no action
0N/A * listeners are currently registered
0N/A *
0N/A * @see #addActionListener(ActionListener)
0N/A * @see #removeActionListener(ActionListener)
0N/A * @see java.awt.event.ActionListener
0N/A */
0N/A public synchronized ActionListener[] getActionListeners() {
540N/A return AWTEventMulticaster.getListeners(actionListener, ActionListener.class);
0N/A }
0N/A
0N/A /**
0N/A * The message type determines which icon will be displayed in the
0N/A * caption of the message, and a possible system sound a message
0N/A * may generate upon showing.
0N/A *
0N/A * @see TrayIcon
0N/A * @see TrayIcon#displayMessage(String, String, MessageType)
0N/A * @since 1.6
0N/A */
0N/A public enum MessageType {
0N/A /** An error message */
0N/A ERROR,
0N/A /** A warning message */
0N/A WARNING,
0N/A /** An information message */
0N/A INFO,
0N/A /** Simple message */
0N/A NONE
0N/A };
0N/A
0N/A /**
0N/A * Displays a popup message near the tray icon. The message will
0N/A * disappear after a time or if the user clicks on it. Clicking
0N/A * on the message may trigger an {@code ActionEvent}.
0N/A *
0N/A * <p>Either the caption or the text may be <code>null</code>, but an
0N/A * <code>NullPointerException</code> is thrown if both are
0N/A * <code>null</code>.
0N/A *
0N/A * When displayed, the caption or text strings may be truncated on
0N/A * some platforms; the number of characters that may be displayed is
0N/A * platform-dependent.
0N/A *
0N/A * <p><strong>Note:</strong> Some platforms may not support
0N/A * showing a message.
0N/A *
0N/A * @param caption the caption displayed above the text, usually in
0N/A * bold; may be <code>null</code>
0N/A * @param text the text displayed for the particular message; may be
0N/A * <code>null</code>
0N/A * @param messageType an enum indicating the message type
0N/A * @throws NullPointerException if both <code>caption</code>
0N/A * and <code>text</code> are <code>null</code>
0N/A */
0N/A public void displayMessage(String caption, String text, MessageType messageType) {
0N/A if (caption == null && text == null) {
0N/A throw new NullPointerException("displaying the message with both caption and text being null");
0N/A }
0N/A
0N/A TrayIconPeer peer = this.peer;
0N/A if (peer != null) {
540N/A peer.displayMessage(caption, text, messageType.name());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the size, in pixels, of the space that the tray icon
0N/A * occupies in the system tray. For the tray icon that is not yet
0N/A * added to the system tray, the returned size is equal to the
0N/A * result of the {@link SystemTray#getTrayIconSize}.
0N/A *
0N/A * @return the size of the tray icon, in pixels
0N/A * @see TrayIcon#setImageAutoSize(boolean)
0N/A * @see java.awt.Image
0N/A * @see TrayIcon#getSize()
0N/A */
0N/A public Dimension getSize() {
0N/A return SystemTray.getSystemTray().getTrayIconSize();
0N/A }
0N/A
0N/A // ****************************************************************
0N/A // ****************************************************************
0N/A
0N/A void addNotify()
0N/A throws AWTException
0N/A {
0N/A synchronized (this) {
0N/A if (peer == null) {
563N/A Toolkit toolkit = Toolkit.getDefaultToolkit();
563N/A if (toolkit instanceof SunToolkit) {
563N/A peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
563N/A } else if (toolkit instanceof HeadlessToolkit) {
563N/A peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
563N/A }
0N/A }
0N/A }
0N/A peer.setToolTip(tooltip);
0N/A }
0N/A
0N/A void removeNotify() {
0N/A TrayIconPeer p = null;
0N/A synchronized (this) {
0N/A p = peer;
0N/A peer = null;
0N/A }
0N/A if (p != null) {
0N/A p.dispose();
0N/A }
0N/A }
0N/A
0N/A void setID(int id) {
0N/A this.id = id;
0N/A }
0N/A
0N/A int getID(){
0N/A return id;
0N/A }
0N/A
0N/A void dispatchEvent(AWTEvent e) {
0N/A EventQueue.setCurrentEventAndMostRecentTime(e);
0N/A Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
0N/A processEvent(e);
0N/A }
0N/A
0N/A void processEvent(AWTEvent e) {
0N/A if (e instanceof MouseEvent) {
0N/A switch(e.getID()) {
0N/A case MouseEvent.MOUSE_PRESSED:
0N/A case MouseEvent.MOUSE_RELEASED:
0N/A case MouseEvent.MOUSE_CLICKED:
0N/A processMouseEvent((MouseEvent)e);
0N/A break;
0N/A case MouseEvent.MOUSE_MOVED:
0N/A processMouseMotionEvent((MouseEvent)e);
0N/A break;
0N/A default:
0N/A return;
0N/A }
0N/A } else if (e instanceof ActionEvent) {
0N/A processActionEvent((ActionEvent)e);
0N/A }
0N/A }
0N/A
0N/A void processMouseEvent(MouseEvent e) {
0N/A MouseListener listener = mouseListener;
0N/A
0N/A if (listener != null) {
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case MouseEvent.MOUSE_PRESSED:
0N/A listener.mousePressed(e);
0N/A break;
0N/A case MouseEvent.MOUSE_RELEASED:
0N/A listener.mouseReleased(e);
0N/A break;
0N/A case MouseEvent.MOUSE_CLICKED:
0N/A listener.mouseClicked(e);
0N/A break;
0N/A default:
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A
0N/A void processMouseMotionEvent(MouseEvent e) {
0N/A MouseMotionListener listener = mouseMotionListener;
0N/A if (listener != null &&
0N/A e.getID() == MouseEvent.MOUSE_MOVED)
0N/A {
0N/A listener.mouseMoved(e);
0N/A }
0N/A }
0N/A
0N/A void processActionEvent(ActionEvent e) {
0N/A ActionListener listener = actionListener;
0N/A if (listener != null) {
0N/A listener.actionPerformed(e);
0N/A }
0N/A }
0N/A
0N/A private static native void initIDs();
0N/A}