List of usage examples for java.awt SystemTray isSupported
public static boolean isSupported()
From source file:org.kootox.episodesmanager.ui.systray.EpisodesTrayIcon.java
public void create() { //Check the SystemTray support if (!SystemTray.isSupported()) { if (log.isInfoEnabled()) { log.info("SystemTray is not supported"); }//from w w w . j ava 2 s .com return; } if (loaded) { return; } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("systray.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem display = new MenuItem("Display"); MenuItem exit = new MenuItem("Exit"); //Add components to popup menu popup.add(display); popup.addSeparator(); popup.add(exit); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { if (log.isDebugEnabled()) { log.debug("TrayIcon could not be added."); } return; } trayIcon.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent mouseEvent) { if (mouseEvent.getButton() == MouseEvent.BUTTON1) { showHide(); } } @Override public void mousePressed(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseReleased(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseEntered(MouseEvent mouseEvent) { //Do nothing } @Override public void mouseExited(MouseEvent mouseEvent) { //Do nothing } }); display.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showHide(); } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EpisodesManagerMainUI mainUI = EpisodesManagerContext.MAIN_UI_ENTRY_DEF.getContextValue(context); mainUI.close(); } }); loaded = true; if (log.isDebugEnabled()) { log.debug("Systray loaded"); } }
From source file:com.github.cmisbox.ui.UI.java
private UI() { this.log = LogFactory.getLog(this.getClass()); try {//from ww w .j a v a 2 s .c om 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:com.ethercamp.harmony.desktop.HarmonyDesktop.java
private void start() throws Exception { log.info("Starting..."); final TrayIcon trayIcon = new TrayIcon(new ImageIcon(imageDisabledUrl).getImage(), "Ethereum Harmony"); trayIcon.setImageAutoSize(true); // Auto-size icon base on space // doesn't work // Runtime.getRuntime().addShutdownHook(new Thread(() -> closeContext())); executor.submit(() -> {/*w w w. j a v a 2s. c om*/ try { context = new SpringApplicationBuilder(Application.class).headless(true).web(true).run(); serverPort = Integer.valueOf(context.getEnvironment().getProperty("local.server.port")); log.info("Spring context created at port " + serverPort); trayIcon.setImage(new ImageIcon(imageEnabledUrl).getImage()); setTrayMenu(trayIcon, browserMenu, logsMenu, quitMenu); openBrowser(); } catch (Exception e) { final Throwable cause = DesktopUtil.findCauseFromSpringException(e); showErrorWindow(cause.getMessage(), "Problem running Harmony:\n\n" + ExceptionUtils.getStackTrace(cause)); } }); if (!SystemTray.isSupported()) { log.error("System tray is not supported"); return; } browserMenu.addActionListener(e -> openBrowser()); quitMenu.addActionListener(event -> { log.info("Quit action was requested from tray menu"); trayIcon.setImage(new ImageIcon(imageDisabledUrl).getImage()); setTrayMenu(trayIcon, logsMenu, quitingMenu); closeContext(); System.exit(0); }); logsMenu.addActionListener(event -> { log.info("Logs action was requested from tray menu"); final File logsFile = new File(LOGS_PATH); try { Desktop.getDesktop().open(logsFile); } catch (IOException e) { log.error("Problem opening logs dir", e); } }); setTrayMenu(trayIcon, loadingMenu, logsMenu, quitMenu); }
From source file:iqq.app.ui.manager.MainManager.java
public void enableTray() { if (SystemTray.isSupported() && tray == null) { menu = new PopupMenu(); MenuItem restore = new MenuItem(" ? "); restore.addActionListener(new ActionListener() { @Override/*from w w w . j a va2 s . c o m*/ public void actionPerformed(ActionEvent e) { show(); } }); MenuItem exit = new MenuItem(" ? "); exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(restore); menu.addSeparator(); menu.add(exit); if (SystemUtils.isMac()) { defaultImage = skinService.getIconByKey("window/titleWIconBlack").getImage(); } else { defaultImage = mainFrame.getIconImage(); } blankImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); tray = SystemTray.getSystemTray(); icon = new TrayIcon(defaultImage, "IQQ"); icon.setImageAutoSize(true); if (!SystemUtils.isMac()) { icon.setPopupMenu(menu); } try { tray.add(icon); icon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { logger.debug("MouseEvent " + e.getButton() + " " + e.getClickCount()); //?? if (e.getButton() == MouseEvent.BUTTON1) { if (flashOwner != null) { Map<String, Object> data = (Map<String, Object>) flashOwner.getAttachment(); if (data != null && data.containsKey("action") && data.get("action").equals("ADD_BUDDY_REQUEST")) { IMContext.getBean(FrameManager.class).showGetFriendRequest((IMBuddy) flashOwner, data.get("buddy_request_id").toString()); eventService.broadcast(new UIEvent(UIEventType.FLASH_USER_STOP, flashOwner)); return; } else { // ? chatManager.addChat(flashOwner); } } else { show(); } } } }); } catch (AWTException e) { logger.error("SystemTray add icon.", e); } } }
From source file:de.mirkosertic.desktopsearch.DesktopSearch.java
@Override public void start(Stage aStage) throws Exception { // This is our base directory File theBaseDirectory = new File(SystemUtils.getUserHome(), "FreeSearchIndexDir"); theBaseDirectory.mkdirs();/* w w w. j a v a 2 s.c om*/ configurationManager = new ConfigurationManager(theBaseDirectory); Notifier theNotifier = new Notifier(); stage = aStage; // Create the known preview processors PreviewProcessor thePreviewProcessor = new PreviewProcessor(); try { // Boot the search backend and set it up for listening to configuration changes backend = new Backend(theNotifier, configurationManager.getConfiguration(), thePreviewProcessor); configurationManager.addChangeListener(backend); // Boot embedded JSP container embeddedWebServer = new FrontendEmbeddedWebServer(aStage, backend, thePreviewProcessor, configurationManager); embeddedWebServer.start(); } catch (BindException | LockReleaseFailedException | LockObtainFailedException e) { // In this case, there is already an instance of DesktopSearch running // Inform the instance to bring it to front end terminate the current process. URL theURL = new URL(FrontendEmbeddedWebServer.getBringToFrontUrl()); // Retrieve the content, but it can be safely ignored // There must only be the get request Object theContent = theURL.getContent(); // Terminate the JVM. The window of the running instance is visible now. System.exit(0); } aStage.setTitle("Free Desktop Search"); aStage.setWidth(800); aStage.setHeight(600); aStage.initStyle(StageStyle.TRANSPARENT); FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/mainscreen.fxml")); AnchorPane theMainScene = theLoader.load(); final DesktopSearchController theController = theLoader.getController(); theController.configure(this, backend, FrontendEmbeddedWebServer.getSearchUrl(), stage.getOwner()); Undecorator theUndecorator = new Undecorator(stage, theMainScene); theUndecorator.getStylesheets().add("/skin/undecorator.css"); Scene theScene = new Scene(theUndecorator); // Hacky, but works... theUndecorator.setStyle("-fx-background-color: rgba(0, 0, 0, 0);"); theScene.setFill(Color.TRANSPARENT); aStage.setScene(theScene); aStage.getIcons().add(new Image(getClass().getResourceAsStream("/fds.png"))); if (SystemTray.isSupported()) { Platform.setImplicitExit(false); SystemTray theTray = SystemTray.getSystemTray(); // We need to reformat the icon according to the current tray icon dimensions // this depends on the underlying OS java.awt.Image theTrayIconImage = Toolkit.getDefaultToolkit() .getImage(getClass().getResource("/fds_small.png")); int trayIconWidth = new TrayIcon(theTrayIconImage).getSize().width; TrayIcon theTrayIcon = new TrayIcon( theTrayIconImage.getScaledInstance(trayIconWidth, -1, java.awt.Image.SCALE_SMOOTH), "Free Desktop Search"); theTrayIcon.setImageAutoSize(true); theTrayIcon.setToolTip("FXDesktopSearch"); theTrayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { Platform.runLater(() -> { if (stage.isIconified()) { stage.setIconified(false); } stage.show(); stage.toFront(); }); } } }); theTray.add(theTrayIcon); aStage.setOnCloseRequest(aEvent -> stage.hide()); } else { aStage.setOnCloseRequest(aEvent -> shutdown()); } aStage.setMaximized(true); aStage.show(); }
From source file:org.exist.launcher.Launcher.java
public Launcher(final String[] args) { if (SystemTray.isSupported()) { tray = SystemTray.getSystemTray(); }/*ww w .jav a 2 s . c o m*/ captureConsole(); this.jettyConfig = getJettyConfig(); final Optional<Path> eXistHome = ConfigurationHelper.getExistHome(); final Path wrapperConfig; if (eXistHome.isPresent()) { wrapperConfig = eXistHome.get().resolve("tools/yajsw/conf/wrapper.conf"); } else { wrapperConfig = Paths.get("tools/yajsw/conf/wrapper.conf"); } wrapperProperties = new Properties(); wrapperProperties.setProperty("wrapper.working.dir", eXistHome.orElse(Paths.get(".")).toString()); wrapperProperties.setProperty("wrapper.config", wrapperConfig.toString()); System.setProperty("wrapper.config", wrapperConfig.toString()); installedAsService(); boolean initSystemTray = true; if (isSystemTraySupported()) { initSystemTray = initSystemTray(); } configDialog = new ConfigurationDialog(this::shutdown); splash = new SplashScreen(this); splash.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent windowEvent) { setServiceState(); if (runningAsService.isPresent()) { splash.setStatus("eXist-db is already installed as service! Attaching to it ..."); final Timer timer = new Timer(3000, (event) -> splash.setVisible(false)); timer.setRepeats(false); timer.start(); } else { if (ConfigurationUtility.isFirstStart()) { splash.setVisible(false); configDialog.open(true); configDialog.requestFocus(); } else { startJetty(); } } } }); final boolean systemTrayReady = tray != null && initSystemTray && tray.getTrayIcons().length > 0; SwingUtilities.invokeLater(() -> utilityPanel = new UtilityPanel(Launcher.this, systemTrayReady)); }
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 {//from www . j a v a 2 s .c o 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:org.duracloud.syncui.SyncUIDriver.java
private static void createSysTray(final String url, final Server srv) { final TrayIcon trayIcon; try {//ww w . ja v a2 s . c o m 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.devbury.desktoplib.systemtray.SystemTrayApplication.java
protected boolean isSystemTraySupported() { return SystemTray.isSupported(); }
From source file:org.shelloid.vpt.agent.App.java
public static void showTrayMessage(String msg, TrayIcon.MessageType type) { if (tray != null && tray.getTrayIcons().length > 0) { if (SystemTray.isSupported()) { tray.getTrayIcons()[0].displayMessage("Shelloid VPT Agent", msg, type); }//from w w w.j a v a2 s . c o m } }