List of usage examples for java.awt TrayIcon TrayIcon
public TrayIcon(Image image, String tooltip, PopupMenu popup)
From source file:de.tbuchloh.kiskis.gui.systray.Java6SystemTray.java
/** * @see de.tbuchloh.kiskis.gui.systray.ISystemTray#show() *///from w w w .j a va2s .c o m public void show() { if (!SystemTray.isSupported()) { LOG.error("System tray is not supported!"); return; } final SystemTray tray = SystemTray.getSystemTray(); final Image image = Toolkit.getDefaultToolkit().getImage(_main.getTrayIconURL()); final MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() >= 2) { _main.setVisible(!_main.isVisible()); } } }; final PopupMenu popup = _main.getPopupMenu(); _trayIcon = new TrayIcon(image, BuildProperties.getFullTitle(), popup); _trayIcon.setImageAutoSize(true); _trayIcon.addMouseListener(mouseListener); try { tray.add(_trayIcon); } catch (final AWTException e) { e.printStackTrace(); } }
From source file:com.github.cmisbox.ui.UI.java
private UI() { this.log = LogFactory.getLog(this.getClass()); try {/*from ww w . jav a2 s .com*/ this.available = !GraphicsEnvironment.isHeadless(); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); if (SystemTray.isSupported()) { this.tray = SystemTray.getSystemTray(); Image image = ImageIO.read(this.getClass().getResource("images/cmisbox.png")); ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { Main.exit(0); } }; this.popup = new PopupMenu(); MenuItem defaultItem = new MenuItem(Messages.exit); defaultItem.addActionListener(exitListener); this.popup.add(defaultItem); MenuItem loginItem = new MenuItem(Messages.login); loginItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { new LoginDialog(); } }); this.popup.add(loginItem); MenuItem treeItem = new MenuItem(Messages.showTree); treeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { new TreeSelect(); } }); this.popup.add(treeItem); final TrayIcon trayIcon = new TrayIcon(image, UI.NOTIFY_TITLE, this.popup); trayIcon.setImageAutoSize(true); this.tray.add(trayIcon); this.notify(Messages.startupComplete); } } catch (Exception e) { this.log.error(e); } }
From source file:org.cryptomator.ui.ExitUtil.java
private TrayIcon createTrayIcon(Runnable exitCommand) { final PopupMenu popup = new PopupMenu(); final MenuItem showItem = new MenuItem(localization.getString("tray.menu.open")); showItem.addActionListener(this::restoreFromTray); popup.add(showItem);// w w w . j av a 2 s .c o m final MenuItem exitItem = new MenuItem(localization.getString("tray.menu.quit")); exitItem.addActionListener(e -> exitCommand.run()); popup.add(exitItem); final Image image; if (SystemUtils.IS_OS_MAC_OSX && isMacMenuBarDarkMode()) { image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_white.png")); } else if (SystemUtils.IS_OS_MAC_OSX) { image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_black.png")); } else { image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon.png")); } return new TrayIcon(image, localization.getString("app.name"), popup); }
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup System Tray Icon./* ww w. j a va 2 s .c o m*/ * * @param frame owner frame */ private void setupTrayIcon(final JFrame frame) { idleIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/node_inactive.png")); activeIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/node_active.png")); frame.setIconImage(idleIcon); // If system tray is supported by OS if (SystemTray.isSupported()) { trayIcon = new TrayIcon(idleIcon, "Nebula Grid Node", createTrayPopup()); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (!frame.isVisible()) { frame.setVisible(true); } frame.setExtendedState(JFrame.NORMAL); frame.requestFocus(); frame.toFront(); } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException ae) { log.debug("[UI] Unable to Initialize Tray Icon"); return; } frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { // Hide (can be shown using tray icon) frame.setVisible(false); } }); } }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * System Tray Icon setup// w w w. jav a 2 s .c o m * @param frame owner JFrame */ private void setupTrayIcon(final JFrame frame) { // Idle Icon idleIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_inactive.png")); // Active Icon activeIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_active.png")); frame.setIconImage(idleIcon); // If system tray is supported by OS if (SystemTray.isSupported()) { // Set Icon trayIcon = new TrayIcon(idleIcon, "Nebula Grid Cluster", createTrayPopup()); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (!frame.isVisible()) { frame.setVisible(true); } frame.setExtendedState(JFrame.NORMAL); frame.requestFocus(); frame.toFront(); } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException ae) { log.debug("[UI] Unable to Initialize Tray Icon"); return; } frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { // Hide (can be shown using tray icon) frame.setVisible(false); } }); } }
From source file:org.duracloud.syncui.SyncUIDriver.java
private static void createSysTray(final String url, final Server srv) { final TrayIcon trayIcon; try {/*from w w w . j a v a 2 s . com*/ if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); InputStream is = org.duracloud.syncui.SyncUIDriver.class.getClassLoader() .getResourceAsStream("tray.png"); Image image = ImageIO.read(is); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { log.debug("Tray Icon - Mouse clicked!"); } public void mouseEntered(MouseEvent e) { log.debug("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { log.debug("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { log.debug("Tray Icon - Mouse pressed!"); } public void mouseReleased(MouseEvent e) { log.debug("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { log.info("Exiting..."); try { srv.stop(); while (!srv.isStopped()) { WaitUtil.wait(1); } } catch (Exception e1) { e1.printStackTrace(); } System.exit(0); } }; PopupMenu popup = new PopupMenu(); MenuItem view = new MenuItem("View Status"); view.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { launchBrowser(url); } }); popup.add(view); MenuItem exit = new MenuItem("Exit"); exit.addActionListener(exitListener); popup.add(exit); trayIcon = new TrayIcon(image, "DuraCloud Sync Tool", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { trayIcon.displayMessage("Action Event", "An Action Event Has Been Performed!", TrayIcon.MessageType.INFO); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { log.error("TrayIcon could not be added."); } } else { log.warn("System Tray is not supported."); } } catch (Exception ex) { log.error(ex.getMessage(), ex); } }
From source file:com.darkenedsky.reddit.traders.RedditTraders.java
/** * Construct a new RedditTraders instance. * /*from www. j a v a2 s.c o m*/ * */ public RedditTraders() { // Load XML configuration file, connect to DB and connect to Reddit API try { config = new Configuration(); addListener(new Help(this)); addListener(new About(this)); addListener(new Confirm(this)); addListener(new Activate(this)); listeners.put("DEACTIVATE", new Activate(this)); addListener(new CountAllSubs(this)); addListener(new ModHelp(this)); addListener(new AcceptModInvite(this)); addListener(new Install(this)); addListener(new Cake(this)); addListener(new Trade(this)); addListener(new TopTraders(this, "TOP20", 20)); addListener(new Lookup(this)); addListener(new SetLegacy(this)); addListener(new SetTextFlair(this)); addListener(new ViewFlair(this)); addListener(new Resolve(this)); listeners.put("BLAME", new Resolve(this)); listeners.put("CLOSE", new Resolve(this)); addListener(new SetFlair(this)); listeners.put("REMOVEFLAIR", new SetFlair(this)); addListener(new SetModFlair(this)); listeners.put("REMOVEMODFLAIR", new SetModFlair(this)); addListener(new SetBlameBan(this)); addListener(new SetList(this)); listeners.put("SETHAVELIST", new SetList(this)); addListener(new GetList(this)); listeners.put("HAVELIST", new GetList(this)); addListener(new SetAccountAgeRequirement(this)); addListener(new SetVerifiedEmail(this)); addListener(new Undo(this)); addListener(new LastTrades(this, "LAST10", 10)); addListener(new SetCheckBan(this)); addListener(new SetDaysBetween(this)); // Build a system tray icon SystemTray tray = SystemTray.getSystemTray(); PopupMenu popup = new PopupMenu(); MenuItem todaysLog = new MenuItem("Today's Log"); todaysLog.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { new TextFrame("logs/RedditTraders.log").setVisible(true); } catch (Exception e1) { LOG.error(e1); } } }); popup.add(todaysLog); MenuItem exit = new MenuItem("Exit"); ActionListener exitListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }; exit.addActionListener(exitListener); popup.add(exit); Image image = Toolkit.getDefaultToolkit().getImage("reddit.png"); TrayIcon trayIcon = new TrayIcon(image, "RedditTraders " + config.getVersion(), popup); trayIcon.setImageAutoSize(true); tray.add(trayIcon); LOG.debug("RedditTraders launched OK."); } catch (Exception x) { x.printStackTrace(); System.exit(0); } }
From source file:press.gfw.Windows.java
private void initTray() { logo = Toolkit.getDefaultToolkit().getImage("logo.png"); setIconImage(logo);/*from w ww. j a va 2s . c o m*/ if (!SystemTray.isSupported()) { return; } icon = new TrayIcon(logo, null, null); icon.setImageAutoSize(true); icon.addActionListener(new TrayListener()); tray = SystemTray.getSystemTray(); try { tray.add(icon); } catch (AWTException ex) { log(""); ex.printStackTrace(); } }
From source file:application.Main.java
public void createTrayIcon(final Stage stage) { // if the operating system // supports the system tray if (SystemTray.isSupported()) { // get the SystemTray instance SystemTray tray = SystemTray.getSystemTray(); // load an image java.awt.Image image = null; try {/* ww w. jav a2 s .co m*/ // File file = new File(iconLocation); // image = ImageIO.read(file); URL urlIcon = Main.class.getResource(iconLocation); image = ImageIO.read(urlIcon); } catch (IOException ex) { System.out.println(ex); } stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent t) { hide(stage); } }); // create an action listener to listen for default action executed on the tray icon final ActionListener closeListener = new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { stage.close(); controller.terminate(); // // fileWatcher.setTerminateWatching(Boolean.TRUE); System.out.println(applicationTitle + " terminated!"); Platform.exit(); System.exit(0); } }); } }; ActionListener showListener = new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { stage.show(); } }); } }; // create a pop-up menu PopupMenu popupMenu = new PopupMenu(); MenuItem nameItem = new MenuItem(applicationTitle); nameItem.addActionListener(showListener); popupMenu.add(nameItem); popupMenu.addSeparator(); MenuItem showItem = new MenuItem("Show"); showItem.addActionListener(showListener); popupMenu.add(showItem); MenuItem closeItem = new MenuItem("Close"); closeItem.addActionListener(closeListener); popupMenu.add(closeItem); /// ... add other menu items // construct a TrayIcon, scaling the image to 16x16 (the default dimensions of a tray icon) trayIcon = new TrayIcon(image.getScaledInstance(24, 24, Image.SCALE_DEFAULT), applicationTitle, popupMenu); // set the TrayIcon properties trayIcon.addActionListener(showListener); // add the tray image try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } } }
From source file:com.loy.MainFrame.java
private void systemTray() { if (SystemTray.isSupported()) { ImageIcon icon = new ImageIcon(image); PopupMenu popupMenu = new PopupMenu(); MenuItem itemShow = new MenuItem("Show"); MenuItem itemExit = new MenuItem("Exit"); itemExit.addActionListener(new ActionListener() { @Override/*w w w. j ava 2 s . c o m*/ public void actionPerformed(ActionEvent e) { killProcess(); System.exit(0); } }); itemShow.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(true); } }); popupMenu.add(itemShow); popupMenu.add(itemExit); TrayIcon trayIcon = new TrayIcon(icon.getImage(), "E-MICRO-SERVICE-START", popupMenu); SystemTray sysTray = SystemTray.getSystemTray(); try { sysTray.add(trayIcon); } catch (AWTException e1) { } } }