List of usage examples for java.awt SystemTray isSupported
public static boolean isSupported()
From source file:MonitorSaurausRex.MainMenu.java
private static void createAndShowGUI() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//ww w .j a va 2 s . c o m } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("Logo.png", "tray icon")); final SystemTray tray = SystemTray.getSystemTray(); trayIcon.setImageAutoSize(true); // Create a popup menu components MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem cb1 = new CheckboxMenuItem("Menu"); CheckboxMenuItem cb2 = new CheckboxMenuItem("Quarantine!"); Menu displayMenu = new Menu("Actions"); MenuItem errorItem = new MenuItem("Cut Connections"); MenuItem warningItem = new MenuItem("Send Reports"); MenuItem infoItem = new MenuItem("Kill Processes"); 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); 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, "MonitorSaurausRex, Designed for sec203 group project. The program was designed to be piece of software to combat Ransomware" + " in a corparate enviroment. The Project was created by Luke Barlow, Dayan Patel, Rob Shire and Sian Skiggs."); } }); cb1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { int cb1Id = e.getStateChange(); trayIcon.setImageAutoSize(true); if (cb1Id == ItemEvent.SELECTED) { trayIcon.setImageAutoSize(true); } else { trayIcon.setImageAutoSize(true); } } }); 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); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * Removes System Tray icon.//from w ww .j a v a 2 s . c o m */ private void removeIcon() { if (SystemTray.isSupported()) { SystemTray.getSystemTray().remove(trayIcon); } }
From source file: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. {/* w w w. j ava 2 s. co m*/ 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); } }); } }
From source file:jatoo.app.App.java
public App(final String title) { this.title = title; ////from ww w . ja va2s. c om // load properties properties = new AppProperties(new File(getWorkingDirectory(), "app.properties")); properties.loadSilently(); // // resources texts = new ResourcesTexts(getClass(), new ResourcesTexts(App.class)); images = new ResourcesImages(getClass(), new ResourcesImages(App.class)); // // create & initialize the window if (isDialog()) { window = new JDialog((Frame) null, getTitle()); if (isUndecorated()) { ((JDialog) window).setUndecorated(true); ((JDialog) window).setBackground(new Color(0, 0, 0, 0)); } ((JDialog) window).setResizable(isResizable()); } else { window = new JFrame(getTitle()); if (isUndecorated()) { ((JFrame) window).setUndecorated(true); ((JFrame) window).setBackground(new Color(0, 0, 0, 0)); } ((JFrame) window).setResizable(isResizable()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { System.exit(0); } @Override public void windowIconified(final WindowEvent e) { if (isHideWhenMinimized()) { hide(); } } }); // // set icon images // is either all icons from initializer package // or all icons from app package List<Image> windowIconImages = new ArrayList<>(); String[] windowIconImagesNames = new String[] { "016", "020", "022", "024", "032", "048", "064", "128", "256", "512" }; for (String size : windowIconImagesNames) { try { windowIconImages.add(new ImageIcon(getClass().getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } if (windowIconImages.size() == 0) { for (String size : windowIconImagesNames) { try { windowIconImages .add(new ImageIcon(App.class.getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } } window.setIconImages(windowIconImages); // // this is the place for to call init method // after all local components are created // from now (after init) is only configuration init(); // // set content pane ( and ansure transparency ) JComponent contentPane = getContentPane(); contentPane.setOpaque(false); ((RootPaneContainer) window).setContentPane(contentPane); // // pack the window right after the set of the content pane window.pack(); // // center window (as default in case restore fails) // and try to restore the last location window.setLocationRelativeTo(null); window.setLocation(properties.getLocation(window.getLocation())); if (!isUndecorated()) { if (properties.getLastUndecorated(isUndecorated()) == isUndecorated()) { if (isResizable() && isSizePersistent()) { final String currentLookAndFeel = String.valueOf(UIManager.getLookAndFeel()); if (properties.getLastLookAndFeel(currentLookAndFeel).equals(currentLookAndFeel)) { window.setSize(properties.getSize(window.getSize())); } } } } // // fix location if out of screen Rectangle intersection = window.getGraphicsConfiguration().getBounds().intersection(window.getBounds()); if ((intersection.width < window.getWidth() * 1 / 2) || (intersection.height < window.getHeight() * 1 / 2)) { UIUtils.setWindowLocationRelativeToScreen(window); } // // restore some properties setAlwaysOnTop(properties.isAlwaysOnTop()); setHideWhenMinimized(properties.isHideWhenMinimized()); setTransparency(properties.getTransparency(transparency)); // // null is also a good value for margins glue gaps (is [0,0,0,0]) Insets marginsGlueGaps = getMarginsGlueGaps(); if (marginsGlueGaps == null) { marginsGlueGaps = new Insets(0, 0, 0, 0); } // // glue to margins on Ctrl + ARROWS if (isGlueToMarginsOnCtrlArrows()) { UIUtils.setActionForCtrlDownKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginBottom(window, marginsGlueGaps.bottom)); UIUtils.setActionForCtrlLeftKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginLeft(window, marginsGlueGaps.left)); UIUtils.setActionForCtrlRightKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginRight(window, marginsGlueGaps.right)); UIUtils.setActionForCtrlUpKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginTop(window, marginsGlueGaps.top)); } // // drag to move ( when provided component is not null ) JComponent dragToMoveComponent = getDragToMoveComponent(); if (dragToMoveComponent != null) { // // move the window by dragging the UI component int marginsGlueRange = Math.min(window.getGraphicsConfiguration().getBounds().width, window.getGraphicsConfiguration().getBounds().height); marginsGlueRange /= 60; marginsGlueRange = Math.max(marginsGlueRange, 15); UIUtils.forwardDragAsMove(dragToMoveComponent, window, marginsGlueRange, marginsGlueGaps); // // window popup dragToMoveComponent.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { windowPopup = getWindowPopup(e.getLocationOnScreen()); windowPopup.setVisible(true); } } }); // // always dispose the popup when window lose the focus window.addFocusListener(new FocusAdapter() { public void focusLost(final FocusEvent e) { if (windowPopup != null) { windowPopup.setVisible(false); windowPopup = null; } } }); } // // tray icon if (hasTrayIcon()) { if (SystemTray.isSupported()) { Image trayIconImage = windowIconImages.get(0); Dimension trayIconSize = SystemTray.getSystemTray().getTrayIconSize(); for (Image windowIconImage : windowIconImages) { if (Math.abs(trayIconSize.width - windowIconImage.getWidth(null)) < Math .abs(trayIconImage.getWidth(null) - windowIconImage.getWidth(null))) { trayIconImage = windowIconImage; } } final TrayIcon trayIcon = new TrayIcon(trayIconImage); trayIcon.setPopupMenu(getTrayIconPopup()); trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() >= 2) { if (window.isVisible()) { hide(); } else { show(); } } } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { logger.error( "unexpected exception trying to add the tray icon ( the desktop system tray is missing? )", e); } } else { logger.error("the system tray is not supported on the current platform"); } } // // hidden or not if (properties.isVisible()) { window.setVisible(true); } // // close the splash screen // if there is one try { SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { splash.close(); } } catch (UnsupportedOperationException e) { getLogger().info("splash screen not supported", e); } // // add shutdown hook for #destroy() Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { App.this.destroy(); } }); // // after init afterInit(); }
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;/* www. ja v a2 s .c o m*/ } 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); } }); }
From source file:org.shelloid.vpt.agent.App.java
private void setupSystemTray() { if (SystemTray.isSupported()) { try {//w w w .j av a 2s. c o m final ConfigForm configForm = new ConfigForm(false); final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = new TrayIcon(createImage("/images/logo.jpg"), "Shelloid VPT Agent"); tray = SystemTray.getSystemTray(); MenuItem authenticateItem = new MenuItem("Configure Authentication"); MenuItem aboutItem = new MenuItem("About Shelloid VPT Agent"); MenuItem exitItem = new MenuItem("Exit"); trayIcon.setPopupMenu(popup); tray.add(trayIcon); authenticateItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { configForm.setVisible(true); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "Shelloid VPT Agent.\nVersion : " + getVersion() + "\n\n(c) 2014 Shelloid LLC. \nhttps://www.shelloid.com", "Shelloid VPT Client", JOptionPane.INFORMATION_MESSAGE); } }); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(null, "Are you sure to exit Shelloid VPT Agent?", "Shelloid VPT Agent", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { shuttingDown = true; closeAllConnections(); System.exit(0); } } }); popup.add(authenticateItem); popup.add(aboutItem); popup.addSeparator(); popup.add(exitItem); } catch (Exception ex) { Platform.shelloidLogger.warn("System Tray Error: ", ex); } } else { System.out.println("System tray is not supported"); } }
From source file:net.sourceforge.entrainer.gui.EntrainerFX.java
private void addSystemTrayIcon() { if (!SystemTray.isSupported()) return;//from w w w . j av a 2 s .c o m TrayIcon icon = new TrayIcon(this.icon.getImage()); icon.setPopupMenu(getTrayIconPopup()); icon.setToolTip("EntrainerFX"); try { SystemTray.getSystemTray().add(icon); } catch (AWTException e) { GuiUtil.handleProblem(e); } }
From source file:org.jajuk.ui.views.ParameterViewGUIHelper.java
/** * Update GUI tab.//from w ww . j av a 2 s . c om */ private void updateGUIFromConfGUI() { String notificatorType = Messages .getString(ParameterView.NOTIFICATOR_PREFIX + Conf.getString(Const.CONF_UI_NOTIFICATOR_TYPE)); pv.jcbNotificationType.setSelectedItem(notificatorType); pv.jcbShowSystray.setSelected(Conf.getBoolean(Const.CONF_SHOW_SYSTRAY)); pv.jcbMinimizeToTray.setEnabled(SystemTray.isSupported() && pv.jcbShowSystray.isSelected()); pv.jcbMinimizeToTray.setSelected(Conf.getBoolean(Const.CONF_MINIMIZE_TO_TRAY)); pv.jcbClickTrayAlwaysDisplayWindow.setSelected(Conf.getBoolean(Const.CONF_TRAY_CLICK_DISPLAY_WINDOW)); pv.jcbClickTrayAlwaysDisplayWindow.setEnabled(SystemTray.isSupported()); pv.jcbSplashscreen.setSelected(Conf.getBoolean(Const.CONF_SPLASH_SCREEN)); pv.scbLAF.removeActionListener(this); pv.scbLAF.setSelectedItem(Conf.getString(Const.CONF_OPTIONS_LNF)); pv.scbLAF.addActionListener(this); pv.jsPerspectiveSize.setValue(Conf.getInt(Const.CONF_PERSPECTIVE_ICONS_SIZE)); pv.jcbTitleAnimation.setSelected(Conf.getBoolean(Const.CONF_TITLE_ANIMATION)); }
From source file:vn.topmedia.monitor.form.MDIMain.java
public void goToTray() { if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); normal = Toolkit.getDefaultToolkit().getImage("normal.gif"); MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { // System.out.println("Tray Icon - Mouse clicked!"); }/*from w ww .j a v a 2 s.c om*/ public void mouseEntered(MouseEvent e) { // System.out.println("Tray Icon - Mouse entered!"); } public void mouseExited(MouseEvent e) { // System.out.println("Tray Icon - Mouse exited!"); } public void mousePressed(MouseEvent e) { // System.out.println("Tray Icon - Mouse pressed!"); showMonitor(0); } public void mouseReleased(MouseEvent e) { // System.out.println("Tray Icon - Mouse released!"); } }; ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exiting..."); mnuItmExit.doClick(); } }; ActionListener showMonitorListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; popup = new PopupMenu(); //--------------------------- MenuItem showItem; showItem = new MenuItem("Show"); showItem.addActionListener(showMonitorListener); popup.add(showItem); //----------------- popup.addSeparator(); //------------------------ MenuItem defaultItem = new MenuItem("Exit"); defaultItem.addActionListener(exitListener); popup.add(defaultItem); //------------------------ trayIcon = new TrayIcon(normal, "ExMonitor 1.3", popup); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { showMonitor(2); } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println("TrayIcon could not be added."); } } else { // System Tray is not supported } }
From source file:org.gtdfree.GTDFree.java
/** * @param args/* w w w . jav a2s. c o m*/ */ @SuppressWarnings("static-access") public static void main(final String[] args) { //ApplicationHelper.changeDefaultFontSize(6, "TextField"); //ApplicationHelper.changeDefaultFontSize(6, "TextArea"); //ApplicationHelper.changeDefaultFontSize(6, "Table"); //ApplicationHelper.changeDefaultFontSize(6, "Tree"); //ApplicationHelper.changeDefaultFontStyle(Font.BOLD, "Tree"); final Logger logger = Logger.getLogger(GTDFree.class); logger.setLevel(Level.ALL); BasicConfigurator.configure(); Options op = new Options(); op.addOption("data", true, Messages.getString("GTDFree.Options.data")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("eodb", true, Messages.getString("GTDFree.Options.eodb")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("exml", true, Messages.getString("GTDFree.Options.exml")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("h", "help", false, Messages.getString("GTDFree.Options.help")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ op.addOption("log", true, Messages.getString("GTDFree.Options.log")); //$NON-NLS-1$ //$NON-NLS-2$ Options op2 = new Options(); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.lang")) //$NON-NLS-1$ .format(new Object[] { "'en'", "'de', 'en'" })) //$NON-NLS-1$ //$NON-NLS-2$ .withArgName("de|en") //$NON-NLS-1$ .withLongOpt("Duser.language") //$NON-NLS-1$ .withValueSeparator('=').create()); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.laf")).format(new Object[] { //$NON-NLS-1$ "'com.jgoodies.looks.plastic.Plastic3DLookAndFeel', 'com.jgoodies.looks.plastic.PlasticLookAndFeel', 'com.jgoodies.looks.plastic.PlasticXPLookAndFeel', 'com.jgoodies.looks.windows.WindowsLookAndFeel' (only on MS Windows), 'com.sun.java.swing.plaf.gtk.GTKLookAndFeel' (only on Linux with GTK), 'com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel', 'javax.swing.plaf.metal.MetalLookAndFeel'" })) //$NON-NLS-1$ .withLongOpt("Dswing.crossplatformlaf") //$NON-NLS-1$ .withValueSeparator('=').create()); CommandLineParser clp = new GnuParser(); CommandLine cl = null; try { cl = clp.parse(op, args); } catch (ParseException e1) { logger.error("Parse error.", e1); //$NON-NLS-1$ } System.out.print("GTD-Free"); //$NON-NLS-1$ String ver = ""; //$NON-NLS-1$ try { System.out.println(" version " + (ver = ApplicationHelper.getVersion())); //$NON-NLS-1$ } catch (Exception e) { System.out.println(); // ignore } if (true) { // || cl.hasOption("help") || cl.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java [Java options] -jar gtd-free.jar [gtd-free options]" //$NON-NLS-1$ , "[gtd-free options] - " + Messages.getString("GTDFree.Options.appop") //$NON-NLS-1$ //$NON-NLS-2$ , op, "[Java options] - " + new MessageFormat(Messages.getString("GTDFree.Options.javaop")) //$NON-NLS-1$//$NON-NLS-2$ .format(new Object[] { "'-jar'" }) //$NON-NLS-1$ , false); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); hf.setLongOptPrefix("-"); //$NON-NLS-1$ hf.setWidth(88); hf.printOptions(pw, hf.getWidth(), op2, hf.getLeftPadding(), hf.getDescPadding()); String s = sw.getBuffer().toString(); s = s.replaceAll("\\A {3}", ""); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll("\n {3}", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll(" <", "=<"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.print(s); } String val = cl.getOptionValue("data"); //$NON-NLS-1$ if (val != null) { System.setProperty(ApplicationHelper.DATA_PROPERTY, val); System.setProperty(ApplicationHelper.TITLE_PROPERTY, "1"); //$NON-NLS-1$ } else { System.setProperty(ApplicationHelper.TITLE_PROPERTY, "0"); //$NON-NLS-1$ } val = cl.getOptionValue("log"); //$NON-NLS-1$ if (val != null) { Level l = Level.toLevel(val, Level.ALL); logger.setLevel(l); } if (!ApplicationHelper.tryLock(null)) { System.out.println("Instance of GTD-Free already running, pushing it to be visible..."); //$NON-NLS-1$ remotePushVisible(); System.out.println("Instance of GTD-Free already running, exiting."); //$NON-NLS-1$ System.exit(0); } if (!"OFF".equalsIgnoreCase(val)) { //$NON-NLS-1$ RollingFileAppender f = null; try { f = new RollingFileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), ApplicationHelper.getLogFileName(), true); f.setMaxBackupIndex(3); BasicConfigurator.configure(f); f.rollOver(); } catch (IOException e2) { logger.error("Logging error.", e2); //$NON-NLS-1$ } } logger.info("GTD-Free " + ver + " started."); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Args: " + Arrays.toString(args)); //$NON-NLS-1$ logger.info("Using data in: " + ApplicationHelper.getDataFolder()); //$NON-NLS-1$ if (cl.getOptionValue("exml") != null || cl.getOptionValue("eodb") != null) { //$NON-NLS-1$ //$NON-NLS-2$ GTDFreeEngine engine = null; try { engine = new GTDFreeEngine(); } catch (Exception e1) { logger.fatal("Fatal error, exiting.", e1); //$NON-NLS-1$ } val = cl.getOptionValue("exml"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { engine.getGTDModel().exportXML(f1); logger.info("Data successfully exported as XML to " + f1.toString()); //$NON-NLS-1$ } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } val = cl.getOptionValue("eodb"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".odb-xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { GTDData data = engine.getGTDModel().getDataRepository(); if (data instanceof GTDDataODB) { try { ((GTDDataODB) data).exportODB(f1); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } logger.info("Data successfully exported as ODB to " + f1.toString()); //$NON-NLS-1$ } else { logger.info("Data is not stored in ODB database, nothing is exported."); //$NON-NLS-1$ } } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } try { engine.close(true, false); } catch (Exception e) { logger.error("Internal error.", e); //$NON-NLS-1$ } return; } logger.debug("Using OS '" + System.getProperty("os.name") + "', '" + System.getProperty("os.version") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + "', '" + System.getProperty("os.arch") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ logger.debug("Using Java '" + System.getProperty("java.runtime.name") + "' version '" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + System.getProperty("java.runtime.version") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ Locale[] supported = { Locale.ENGLISH, Locale.GERMAN }; String def = Locale.getDefault().getLanguage(); boolean toSet = true; for (Locale locale : supported) { toSet &= !locale.getLanguage().equals(def); } if (toSet) { logger.debug("System locale '" + def + "' not supported, setting to '" + Locale.ENGLISH.getLanguage() //$NON-NLS-1$//$NON-NLS-2$ + "'."); //$NON-NLS-1$ try { Locale.setDefault(Locale.ENGLISH); } catch (Exception e) { logger.warn("Setting default locale failed.", e); //$NON-NLS-1$ } } else { logger.debug("Using locale '" + Locale.getDefault().toString() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } try { //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.metal.MetalLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); if (System.getProperty("swing.crossplatformlaf") == null) { //$NON-NLS-1$ String osName = System.getProperty("os.name"); //$NON-NLS-1$ if (osName != null && osName.toLowerCase().indexOf("windows") != -1) { //$NON-NLS-1$ UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel"); //$NON-NLS-1$ } else { try { // we prefer to use native L&F, many systems support GTK, even if Java thinks it is not supported UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //$NON-NLS-1$ } catch (Throwable e) { logger.debug("GTK L&F not supported.", e); //$NON-NLS-1$ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } } } catch (Throwable e) { logger.warn("Setting L&F failed.", e); //$NON-NLS-1$ } logger.debug("Using L&F '" + UIManager.getLookAndFeel().getName() + "' by " //$NON-NLS-1$//$NON-NLS-2$ + UIManager.getLookAndFeel().getClass().getName()); try { final GTDFree application = new GTDFree(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { application.getJFrame(); application.restore(); //application.getJFrame().setVisible(true); application.pushVisible(); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { if (SystemTray.isSupported() && application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.SHOW_TRAY_ICON, false)) { try { SystemTray.getSystemTray().add(application.getTrayIcon()); } catch (AWTException e) { logger.error("Failed to activate system tray icon.", e); //$NON-NLS-1$ } } } }); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.exportRemote(); } }); if (application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.CHECK_FOR_UPDATE_AT_START, true)) { ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.checkForUpdates(false); } }); } } catch (Throwable t) { t.printStackTrace(); logger.fatal("Failed to start application, exiting.", t); //$NON-NLS-1$ if (application != null) { application.close(true); } System.exit(0); } } }); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { application.close(true); } catch (Exception e) { logger.warn("Failed to stop application.", e); //$NON-NLS-1$ } logger.info("Closed."); //$NON-NLS-1$ ApplicationHelper.releaseLock(); LogManager.shutdown(); } }); } catch (Throwable t) { logger.fatal("Initialization failed, exiting.", t); //$NON-NLS-1$ t.printStackTrace(); System.exit(0); } }