Java 类java.awt.TrayIcon 实例源码

项目:litiengine    文件:Program.java   
private static void initSystemTray() {
  // add system tray icon with popup menu
  if (SystemTray.isSupported()) {
    SystemTray tray = SystemTray.getSystemTray();
    PopupMenu menu = new PopupMenu();
    MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
    exitItem.addActionListener(a -> Game.terminate());
    menu.add(exitItem);

    trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
    trayIcon.setImageAutoSize(true);
    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
}
项目:AgentWorkbench    文件:AgentGUITrayIcon.java   
/**
 * Starts the TrayIcon, if this is supported. If not, it should start a
 * simple JDialog, doing the same as independent Window.
 */
private void initialize() {

    switch (this.getTrayIconUsage()) {
    case TrayIcon:
        try {
            // --- System-Tray is supported ---------------------
            this.getSystemTray().add(this.getTrayIcon(true));

        } catch (AWTException e) {
            System.err.println("TrayIcon supported, but could not be added. => Use TrayDialog instead !");
            this.getAgentGUITrayDialog(true).setVisible(true);          
        }
        break;

    case TrayDialog:
        this.getAgentGUITrayDialog(true).setVisible(true);
        break;

    default:
        break;
    }

    // --- Refresh tray icon ------------------------------------
    this.getAgentGUITrayPopUp().refreshView();
}
项目:dracoon-dropzone    文件:Dropzone.java   
/**
 * Init Swing UI
 */
private void initUI() {
    URL url = null;
    if (ConfigIO.getInstance().isUseDarkIcon()) {
        url = Dropzone.class.getResource("/images/sds_logo_dark.png");
    } else {
        url = Dropzone.class.getResource("/images/sds_logo_light.png");

    }
    if (Util.getOSType() == OSType.MACOS) {

    }

    trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(url), I18n.get("tray.appname"),
            new TrayPopupMenu());
    trayIcon.setImageAutoSize(true);

    final SystemTray tray = SystemTray.getSystemTray();
    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        LOG.error("TrayIcon could not be added.");
        System.exit(1);
    }
}
项目:OpenJSharp    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:OpenJSharp    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:jdk8u-jdk    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:jdk8u-jdk    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:openjdk-jdk10    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, () -> {
        PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
        if (popup != newPopup) {
            if (popup != null) {
                popupParent.remove(popup);
            }
            if (newPopup != null) {
                popupParent.add(newPopup);
            }
            popup = newPopup;
        }
        if (popup != null) {
            WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
                                             .getPeer(popup);
            peer.show(popupParent, new Point(x, y));
        }
    });
}
项目:openjdk-jdk10    文件:UpdatePopupMenu.java   
private PopupMenu createPopupMenu(final TrayIcon trayIcon,
        final int menuCount) {

    final PopupMenu trayIconPopupMenu = new PopupMenu();

    for (int i = 1; i <= menuCount; ++i) {
        final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);

        popupMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
                trayIcon.setPopupMenu(createPopupMenu(trayIcon,
                        menuCount + 1));
            }
        });

        trayIconPopupMenu.add(popupMenuItem);
    }

    return trayIconPopupMenu;
}
项目:openjdk-jdk10    文件:ActionEventTest.java   
private void initializeGUI() {

        icon = new TrayIcon(
            new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "ti");
        icon.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                actionPerformed = true;
                int md = ae.getModifiers();
                int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                        | ActionEvent.SHIFT_MASK;

                if ((md & expectedMask) != expectedMask) {
                    clear();
                    throw new RuntimeException("Action Event modifiers are not"
                        + " set correctly.");
                }
            }
        });

        try {
            SystemTray.getSystemTray().add(icon);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
项目:sbc-qsystem    文件:QTray.java   
/**
 * Показать сообщение в системном трее
 *
 * @param message текст сообщения
 * @param type тип сообщения
 */
synchronized public void showMessageTray(String caption, String message, MessageType type) {
    TrayIcon.MessageType t = TrayIcon.MessageType.NONE;
    switch (type) {
        case ERROR: {
            t = TrayIcon.MessageType.ERROR;
            break;
        }
        case WARNING: {
            t = TrayIcon.MessageType.WARNING;
            break;
        }
        case INFO: {
            t = TrayIcon.MessageType.INFO;
            break;
        }
    }
    trayIcon.displayMessage(caption, message, t);
}
项目:openjdk9    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, () -> {
        PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
        if (popup != newPopup) {
            if (popup != null) {
                popupParent.remove(popup);
            }
            if (newPopup != null) {
                popupParent.add(newPopup);
            }
            popup = newPopup;
        }
        if (popup != null) {
            WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
                                             .getPeer(popup);
            peer.show(popupParent, new Point(x, y));
        }
    });
}
项目:openjdk9    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:openjdk9    文件:UpdatePopupMenu.java   
private PopupMenu createPopupMenu(final TrayIcon trayIcon,
        final int menuCount) {

    final PopupMenu trayIconPopupMenu = new PopupMenu();

    for (int i = 1; i <= menuCount; ++i) {
        final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);

        popupMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
                trayIcon.setPopupMenu(createPopupMenu(trayIcon,
                        menuCount + 1));
            }
        });

        trayIconPopupMenu.add(popupMenuItem);
    }

    return trayIconPopupMenu;
}
项目:openjdk9    文件:ActionEventTest.java   
private void initializeGUI() {

        icon = new TrayIcon(
            new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB), "ti");
        icon.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                actionPerformed = true;
                int md = ae.getModifiers();
                int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                        | ActionEvent.SHIFT_MASK;

                if ((md & expectedMask) != expectedMask) {
                    clear();
                    throw new RuntimeException("Action Event modifiers are not"
                        + " set correctly.");
                }
            }
        });

        try {
            SystemTray.getSystemTray().add(icon);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
项目:yajsw    文件:HelloWorld.java   
private static void startTray()
{
    SystemTray tray = SystemTray.getSystemTray();
    int w = 80;
    int[] pix = new int[w * w];
    for (int i = 0; i < w * w; i++)
        pix[i] = (int) (Math.random() * 255);
    ImageProducer producer = new MemoryImageSource(w, w, pix, 0, w);
    Image image = Toolkit.getDefaultToolkit().createImage(producer);
    TrayIcon trayIcon = new TrayIcon(image);
    trayIcon.setImageAutoSize(true);
    startWindow();
    try
    {
        tray.add(trayIcon);
        System.out.println("installed tray");
    }
    catch (AWTException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
项目:timetray    文件:TimeTray.java   
/**
 * TimeTray Constructor
 */
public TimeTray() {
    // retrieve iconSize of SystemTray
    SystemTray systemTray = SystemTray.getSystemTray();
    iconSize = systemTray.getTrayIconSize();

    // set presets
    presets = new Presets(iconSize.height);

    calendar = Calendar.getInstance();

    // create TrayIcon according to iconSize
    trayIcon = new TrayIcon(getTrayImage(), "TimeTray", menu);
    try {
        systemTray.add(trayIcon);
    } catch (AWTException ex) {
        ex.printStackTrace();
    }

    // run thread and set timer tooltip to update every second
    run();

    Timer timer = new Timer();
    timer.schedule(this, 1000, 1000);
}
项目:jdk8u_jdk    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:jdk8u_jdk    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:runelite    文件:Notifier.java   
private void sendNotification(
    final String title,
    final String message,
    final TrayIcon.MessageType type,
    final String subtitle)
{
    final String escapedTitle = SHELL_ESCAPE.escape(title);
    final String escapedMessage = SHELL_ESCAPE.escape(message);
    final String escapedSubtitle = subtitle != null ? SHELL_ESCAPE.escape(subtitle) : null;

    switch (DETECTED_OS)
    {
        case Linux:
            sendLinuxNotification(escapedTitle, escapedMessage, type);
            break;
        case MacOS:
            sendMacNotification(escapedTitle, escapedMessage, escapedSubtitle);
            break;
        default:
            sendTrayNotification(title, message, type);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:lookaside_java-1.8.0-openjdk    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:DuckDNSClient    文件:duckdns.java   
private void startProcess() {

Thread thread = new Thread(new Runnable() {

 @Override public void run() {
 Preferences prefs = Preferences.userNodeForPackage(duckdns.class);

 // first start message (on empty settings)
 if ((prefs.get("domain", "").length() < 1) || (prefs.get("token", "").length() < 1)) {
 processTrayIcon.displayMessage(DuckDNSVersion, "Right click on the tray icon to change the settings!", TrayIcon.MessageType.INFO);
 }

 Timer timer = new Timer("Repeater");
 MyTask t = new MyTask();
 timer.schedule(t, 0, 1000);

 timercount = (Integer.parseInt(prefs.get("refresh", "5")) * 60);

 }
});

thread.start();
}
项目:deskshare-public    文件:SmallUI.java   
private void initTray() {
    final SystemTray systemTray = SystemTray.getSystemTray();
    final TrayIcon trayIcon = new TrayIcon(getImage("icon.gif"), "Deskshare is running");
    trayIcon.setImageAutoSize(true); // Autosize icon base on space
                                     // available on tray
    MouseAdapter mouseAdapter = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            // This will display small popup message from System Tray
            trayIcon.displayMessage("BigMarker Deskshare", "This is an info message", TrayIcon.MessageType.INFO);
            if (!app.isVisible()) {
                app.setVisible(true);
            }
        }
    };
    trayIcon.addMouseListener(mouseAdapter);
    try {
        systemTray.add(trayIcon);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:deskshare-public    文件:DebugUI.java   
private void initTray() {
    final SystemTray systemTray = SystemTray.getSystemTray();
    final TrayIcon trayIcon = new TrayIcon(getImage("icon.gif"), "Deskshare is running");
    trayIcon.setImageAutoSize(true); // Autosize icon base on space available on tray
    MouseAdapter mouseAdapter = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            System.out.println("icon clicked: " + evt.getClickCount());
            // This will display small popup message from System Tray
            trayIcon.displayMessage("BigMarker Deskshare", "This is an info message", TrayIcon.MessageType.INFO);
            if (!app.isVisible()) {
                app.setVisible(true);
            }
        }
    };
    trayIcon.addMouseListener(mouseAdapter);
    try {
        systemTray.add(trayIcon);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:MIDI-Automator    文件:Tray.java   
/**
 * Initializes the tray
 */
public void init() {

    if (SystemTray.isSupported()) {

        SystemTray tray = SystemTray.getSystemTray();

        if (tray.getTrayIcons().length == 0) {

            String iconFileName = resources.getImagePath() + File.separator
                    + "MidiAutomatorIcon16.png";
            image = Toolkit.getDefaultToolkit().getImage(iconFileName);
            trayPopupMenu.init();
            trayIcon = new TrayIcon(image, NAME);
            trayIcon.addMouseListener(trayMouseListener);

            try {
                tray.add(trayIcon);
            } catch (AWTException e) {
                log.error("Error on adding tray icon.", e);
            }
        }
    }
}
项目:TodoLazyList    文件:Tray.java   
private void hookTray() {
    if (!SystemTray.isSupported()) {
        System.out.println("SystemTray is not supported");
    } else {
        try {
            Todo.icon = new TrayIcon(ImageIO.read(Todo.class.getResourceAsStream("/todo/res/logoTray.png")), "TODO application",
                    createPopupMenu());
            Todo.icon.addActionListener((ActionEvent e) -> {
                Platform.runLater(() -> {
                    stage.setIconified(false);
                });
                //some popup test
            });
            SystemTray.getSystemTray().add(Todo.icon);
            //Thread.sleep(3000);
            Todo.icon.displayMessage("TODO", "Listener enabled",
                    TrayIcon.MessageType.INFO);

        } catch (AWTException | IOException ex) {
            ex.printStackTrace();
        }

    }
}
项目:infobip-open-jdk-8    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:infobip-open-jdk-8    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:jdk8u-dev-jdk    文件:WTrayIconPeer.java   
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:jdk8u-dev-jdk    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:neembuu-uploader    文件:QueueManager.java   
/**
 * Start next upload if any.. Decrements the current uploads averageProgress and
 * updates the queuing mechanism.
 */
public void startNextUploadIfAny() {
    currentlyUploading--;
    //If no more uploads in queue and no more uploads currently running, reset the title
    if (getQueuedUploadCount() == 0 && currentlyUploading == 0){
        setFrameTitle();

        try{
            //If the tray icon is activated, then display message
            if(SystemTray.getSystemTray().getTrayIcons().length > 0) {
                SystemTray.getSystemTray().getTrayIcons()[0].displayMessage(Translation.T().neembuuuploader(), Translation.T().allUploadsCompleted(), TrayIcon.MessageType.INFO);
            }
        }catch(UnsupportedOperationException a){
            //ignore
        }
    } else {
        updateQueue();
    }
}
项目:neembuu-uploader    文件:NeembuuUploader.java   
private void setUpTrayIcon() {
    if (SystemTray.isSupported()) {
        //trayIcon.setImageAutoSize(true); It renders the icon very poorly.
        //So we render the icon ourselves with smooth settings.
        {
            Dimension d = SystemTray.getSystemTray().getTrayIconSize();
            trayIcon = new TrayIcon(getIconImage().getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH));
        }
        //trayIcon = new TrayIcon(getIconImage());
        //trayIcon.setImageAutoSize(true);
        trayIcon.setToolTip(Translation.T().trayIconToolTip());
        trayIcon.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                NULogger.getLogger().info("System tray double clicked");

                setExtendedState(JFrame.NORMAL);
                setVisible(true);
                repaint();
                SystemTray.getSystemTray().remove(trayIcon);
            }
        });
    }
}
项目:jdk7-jdk    文件:WTrayIconPeer.java   
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:jdk7-jdk    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:FutureSonic-Server    文件:SubsonicController.java   
private void createComponents() {
    PopupMenu menu = new PopupMenu();
    menu.add(createMenuItem(openAction));
    menu.add(createMenuItem(controlPanelAction));
    menu.addSeparator();
    menu.add(createMenuItem(quitAction));

    URL url = getClass().getResource("/images/futuresonic-21.png");
    Image image = Toolkit.getDefaultToolkit().createImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "FutureSonic Music Streamer", menu);
    trayIcon.setImageAutoSize(false);

    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (Throwable x) {
        System.err.println("Failed to add tray icon.");
    }
}
项目:openjdk-source-code-learn    文件:WTrayIconPeer.java   
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
项目:openjdk-source-code-learn    文件:WTrayIconPeer.java   
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
项目:timey    文件:AlarmControllerTest.java   
/**
 * Testet die Verarbeitung eines Ereignisses.
 */
@Test
public final void testHandleEvent() {
    final AlarmController controller = (AlarmController) getController();
    final GuiHelper guiHelper = controller.getGuiHelper();

    final Alarm alarm = new Alarm(LocalDateTime.now(), "alarm", "sound", true);

    final MessageHelper messageHelper = mock(MessageHelper.class);
    guiHelper.setMessageHelper(messageHelper);

    final AudioPlayer audioPlayer = mock(AudioPlayer.class);
    guiHelper.setAudioPlayer(audioPlayer);

    // Ereignis auslösen
    controller.handleEvent(new AlarmExpiredEvent(AlarmDescriptorConverter.getAsAlarmDescriptor(alarm)));
    waitForThreads();

    // sicherstellen, dass Ereignis verarbeitet wird
    verify(messageHelper).showTrayMessageWithFallbackToDialog(anyString(), eq(alarm.getDescription()), isNull(TrayIcon.class),
            isA(ResourceBundle.class));
    verify(audioPlayer).playInThread(isA(ThreadHelper.class), eq(alarm.getSound()), isA(Thread.UncaughtExceptionHandler.class));
}
项目:timey    文件:AlarmControllerTest.java   
/**
 * Testet die Verarbeitung eines unwichtigen Ereignisses.
 */
@Test
public final void testIgnoreEvent() {
    final AlarmController controller = (AlarmController) getController();
    final GuiHelper guiHelper = controller.getGuiHelper();

    final MessageHelper messageHelper = mock(MessageHelper.class);
    guiHelper.setMessageHelper(messageHelper);

    final AudioPlayer audioPlayer = mock(AudioPlayer.class);
    guiHelper.setAudioPlayer(audioPlayer);

    // unwichtiges Ereignis auslösen
    controller.handleEvent(mock(TimeyEvent.class));
    waitForThreads();

    // sicherstellen, dass Ereignis ignoriert wird
    verify(messageHelper, never()).showTrayMessageWithFallbackToDialog(anyString(), anyString(), isNull(TrayIcon.class),
            isA(ResourceBundle.class));
    verify(audioPlayer, never()).playInThread(isA(ThreadHelper.class), anyString(), isA(Thread.UncaughtExceptionHandler.class));
}