List of usage examples for java.awt TrayIcon setImageAutoSize
public void setImageAutoSize(boolean autosize)
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 ww. j a v a2 s . co m 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:com.darkenedsky.reddit.traders.RedditTraders.java
/** * Construct a new RedditTraders instance. * //from w w w.j ava 2s.com * */ 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:misc.TrayIconDemo.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;// w w w .ja v a 2 s . c om } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("images/bulb.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip"); Menu displayMenu = new Menu("Display"); MenuItem errorItem = new MenuItem("Error"); MenuItem warningItem = new MenuItem("Warning"); MenuItem infoItem = new MenuItem("Info"); MenuItem noneItem = new MenuItem("None"); MenuItem exitItem = new MenuItem("Exit"); //Add components to popup menu popup.add(aboutItem); popup.addSeparator(); popup.add(cb1); popup.add(cb2); popup.addSeparator(); popup.add(displayMenu); displayMenu.add(errorItem); displayMenu.add(warningItem); displayMenu.add(infoItem); displayMenu.add(noneItem); popup.add(exitItem); trayIcon.setPopupMenu(popup); try { tray.add(trayIcon); } catch (AWTException e) { System.out.println("TrayIcon could not be added."); return; } trayIcon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray"); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "This dialog box is run from the About menu item"); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(false); } } }); cb2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb2Id = e.getStateChange(); if (cb2Id == ItemEvent.SELECTED) { trayIcon.setToolTip("Sun TrayIcon"); } else { trayIcon.setToolTip(null); } } }); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuItem item = (MenuItem) e.getSource(); //TrayIcon.MessageType type = null; System.out.println(item.getLabel()); if ("Error".equals(item.getLabel())) { //type = TrayIcon.MessageType.ERROR; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR); } else if ("Warning".equals(item.getLabel())) { //type = TrayIcon.MessageType.WARNING; trayIcon.displayMessage("Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING); } else if ("Info".equals(item.getLabel())) { //type = TrayIcon.MessageType.INFO; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO); } else if ("None".equals(item.getLabel())) { //type = TrayIcon.MessageType.NONE; trayIcon.displayMessage("Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE); } } }; errorItem.addActionListener(listener); warningItem.addActionListener(listener); infoItem.addActionListener(listener); noneItem.addActionListener(listener); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:org.duracloud.syncui.SyncUIDriver.java
private static void createSysTray(final String url, final Server srv) { final TrayIcon trayIcon; try {// www. j av a 2 s. c om 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:ui.main.MainViewController.java
private void showNotifications(String chat, String message) { // a general method for view notifications -> windows notification if (!isnotifiable.isSelected()) { return;//w w w.ja va 2 s. com } URL url = System.class.getResource("/resources/LogoTransparent.png"); java.awt.Image image = Toolkit.getDefaultToolkit().getImage(url); TrayIcon trayIcon = new TrayIcon(image, "Instant Messenger Plus"); if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); trayIcon.setImageAutoSize(true); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); } trayIcon.displayMessage("IMP: " + chat, message, TrayIcon.MessageType.INFO); } }
From source file:com.jsystem.j2autoit.AutoItAgent.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { Log.error("SystemTray is not supported\n"); return;//from www. j a v a2 s . c om } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("images/jsystem_ico.gif", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components final MenuItem aboutItem = new MenuItem("About"); final MenuItem startAgentItem = new MenuItem("Start J2AutoIt Agent"); final MenuItem stopAgentItem = new MenuItem("Stop J2AutoIt Agent"); final MenuItem exitItem = new MenuItem("Exit"); final MenuItem changePortItem = new MenuItem("Setting J2AutoIt Port"); final MenuItem deleteTemporaryFilesItem = new MenuItem("Delete J2AutoIt Script"); final MenuItem temporaryHistoryFilesItem = new MenuItem("History Size"); final MenuItem displayLogFile = new MenuItem("Log"); final MenuItem forceShutDownTimeOutItem = new MenuItem("Force ShutDown TimeOut"); final MenuItem writeConfigurationToFile = new MenuItem("Save Configuration To File"); final CheckboxMenuItem debugModeItem = new CheckboxMenuItem("Debug Mode", isDebug); final CheckboxMenuItem forceAutoItShutDownItem = new CheckboxMenuItem("Force AutoIt Script ShutDown", isForceAutoItShutDown); final CheckboxMenuItem autoDeleteHistoryItem = new CheckboxMenuItem("Auto Delete History", isAutoDeleteFiles); final CheckboxMenuItem useAutoScreenShot = new CheckboxMenuItem("Auto Screenshot", isUseScreenShot); //Add components to popup menu popup.add(aboutItem); popup.add(writeConfigurationToFile); popup.addSeparator(); popup.add(forceAutoItShutDownItem); popup.add(forceShutDownTimeOutItem); popup.addSeparator(); popup.add(debugModeItem); popup.add(displayLogFile); popup.add(useAutoScreenShot); popup.addSeparator(); popup.add(autoDeleteHistoryItem); popup.add(deleteTemporaryFilesItem); popup.add(temporaryHistoryFilesItem); popup.addSeparator(); popup.add(changePortItem); popup.addSeparator(); popup.add(startAgentItem); popup.add(stopAgentItem); popup.addSeparator(); popup.add(exitItem); trayIcon.setToolTip("J2AutoIt Agent"); trayIcon.setImageAutoSize(true); trayIcon.setPopupMenu(popup); final DisplayLogFile displayLog = new DisplayLogFile(); try { tray.add(trayIcon); } catch (AWTException e) { Log.error("TrayIcon could not be added.\n"); return; } trayIcon.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { startAgentItem.setEnabled(!serverState); stopAgentItem.setEnabled(serverState); deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries()); autoDeleteHistoryItem.setEnabled(isDebug); temporaryHistoryFilesItem.setEnabled(isDebug && isAutoDeleteFiles); displayLogFile.setEnabled(isDebug); forceShutDownTimeOutItem.setEnabled(isForceAutoItShutDown); } @Override public void mouseReleased(MouseEvent e) { } }); writeConfigurationToFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { AutoItProperties.DEBUG_MODE_KEY.setValue(isDebug.toString()); AutoItProperties.AUTO_DELETE_TEMPORARY_SCRIPT_FILE_KEY.setValue(isAutoDeleteFiles.toString()); AutoItProperties.AUTO_IT_SCRIPT_HISTORY_SIZE_KEY.setValue(DEFAULT_HistorySize.toString()); AutoItProperties.FORCE_AUTO_IT_PROCESS_SHUTDOWN_KEY.setValue(isForceAutoItShutDown.toString()); AutoItProperties.AGENT_PORT_KEY.setValue(webServicePort.toString()); AutoItProperties.SERVER_UP_ON_INIT_KEY.setValue(serverState.toString()); if (!AutoItProperties.savePropertiesFileSafely()) { Log.error("Fail to save properties file"); } } }); debugModeItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isDebug = (e.getStateChange() == ItemEvent.SELECTED); deleteTemporaryFilesItem.setEnabled(isDebug && HistoryFile.containEntries()); Log.infoLog("Keeping the temp file is " + (isDebug ? "en" : "dis") + "able\n"); trayIcon.displayMessage((isDebug ? "Debug" : "Normal") + " Mode", "The system will " + (isDebug ? "not " : "") + "delete \nthe temporary autoIt scripts." + (isDebug ? "\nSee log file for more info." : ""), MessageType.INFO); } }); useAutoScreenShot.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isUseScreenShot = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog("Auto screenshot is " + (isUseScreenShot ? "" : "in") + "active\n"); } }); forceAutoItShutDownItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isForceAutoItShutDown = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog((isForceAutoItShutDown ? "Force" : "Soft") + " AutoIt Script ShutDown\n"); trayIcon.displayMessage("AutoIt Script Termination", (isForceAutoItShutDown ? "Hard shutdown" : "Soft shutdown"), MessageType.INFO); } }); autoDeleteHistoryItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { isAutoDeleteFiles = (e.getStateChange() == ItemEvent.SELECTED); Log.infoLog((isAutoDeleteFiles ? "Auto" : "Manual") + " AutoIt Script Deletion\n"); trayIcon.displayMessage("AutoIt Script Deletion", (isAutoDeleteFiles ? "Auto" : "Manual") + " Mode", MessageType.INFO); if (isAutoDeleteFiles) { HistoryFile.init(); } else { HistoryFile.close(); } } }); forceShutDownTimeOutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String timeOutAsString = JOptionPane.showInputDialog( "Please Insert Force ShutDown TimeOut (in seconds)", String.valueOf(shutDownTimeOut / 1000)); try { shutDownTimeOut = 1000 * Long.parseLong(timeOutAsString); } catch (Exception e2) { } Log.infoLog("Setting the force shutdown time out to : " + (shutDownTimeOut / 1000) + " seconds.\n"); } }); displayLogFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { try { displayLog.reBuild(Log.getCurrentLogs()); displayLog.actionPerformed(actionEvent); } catch (Exception e2) { } } }); temporaryHistoryFilesItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String historySize = JOptionPane.showInputDialog("Please Insert History AutoIt Script Files", String.valueOf(HistoryFile.getHistory_Size())); try { int temp = Integer.parseInt(historySize); if (temp > 0) { if (HistoryFile.getHistory_Size() != temp) { HistoryFile.setHistory_Size(temp); Log.infoLog("The history files size is " + historySize + NEW_LINE); } } else { Log.warning("Illegal History Size: " + historySize + NEW_LINE); } } catch (Exception exception) { Log.throwableLog(exception.getMessage(), exception); } } }); deleteTemporaryFilesItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { HistoryFile.forceDeleteAll(); } }); startAgentItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { runWebServer(); } }); stopAgentItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { shutDownWebServer(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "J2AutoIt Agent By JSystem And Aqua Software"); } }); changePortItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { String portAsString = JOptionPane.showInputDialog("Please Insert new Port", String.valueOf(webServicePort)); if (portAsString != null) { try { int temp = Integer.parseInt(portAsString); if (temp > 1000) { if (temp != webServicePort) { webServicePort = temp; shutDownWebServer(); startAutoItWebServer(webServicePort); runWebServer(); } } else { Log.warning("Port number should be greater then 1000\n"); } } catch (Exception exception) { Log.error("Illegal port number\n"); return; } } } }); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { tray.remove(trayIcon); shutDownWebServer(); Log.info("Exiting from J2AutoIt Agent\n"); System.exit(0); } }); }