List of usage examples for java.awt MenuItem MenuItem
public MenuItem(String label) throws HeadlessException
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/*from ww w.j a v a 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) { } } }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * Creates the Pop-up menu for System Tray Icon * //w ww. j a v a2 s .c o m * @return PopupMenu */ private PopupMenu createTrayPopup() { PopupMenu trayPopup = new PopupMenu(); // About MenuItem aboutItem = new MenuItem("About"); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showAbout(); } }); trayPopup.add(aboutItem); trayPopup.addSeparator(); // Shutdown MenuItem shutdownItem = new MenuItem("Shutdown"); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doShutdownCluster(); } }); trayPopup.add(shutdownItem); return trayPopup; }
From source file:org.exist.launcher.Launcher.java
private PopupMenu createMenu() { final PopupMenu popup = new PopupMenu(); startItem = new MenuItem("Start server"); popup.add(startItem);/*w w w . j a v a 2s . c om*/ startItem.addActionListener(actionEvent -> { if (jetty.isPresent()) { jetty.ifPresent(server -> { if (server.isStarted()) { showTrayMessage("Server already started", TrayIcon.MessageType.WARNING); } else { server.run(new String[] { jettyConfig.toAbsolutePath().toString() }, null); if (server.isStarted()) { showTrayMessage("eXist-db server running on port " + server.getPrimaryPort(), TrayIcon.MessageType.INFO); } } setServiceState(); }); } else if (runningAsService.isPresent()) { showTrayMessage("Starting the eXistdb service. Please wait...", TrayIcon.MessageType.INFO); if (runningAsService.get().start()) { showTrayMessage("eXistdb service started", TrayIcon.MessageType.INFO); } else { showTrayMessage("Starting eXistdb service failed", TrayIcon.MessageType.ERROR); } setServiceState(); } }); stopItem = new MenuItem("Stop server"); popup.add(stopItem); stopItem.addActionListener(actionEvent -> { if (jetty.isPresent()) { jetty.get().shutdown(); setServiceState(); showTrayMessage("eXist-db stopped", TrayIcon.MessageType.INFO); } else if (runningAsService.isPresent()) { if (runningAsService.get().stop()) { showTrayMessage("eXistdb service stopped", TrayIcon.MessageType.INFO); } else { showTrayMessage("Stopping eXistdb service failed", TrayIcon.MessageType.ERROR); } setServiceState(); } }); popup.addSeparator(); final MenuItem configItem = new MenuItem("System Configuration"); popup.add(configItem); configItem.addActionListener(e -> EventQueue.invokeLater(() -> { configDialog.open(false); configDialog.toFront(); configDialog.repaint(); configDialog.requestFocus(); })); if (SystemUtils.IS_OS_WINDOWS) { canUseServices = true; } else { isRoot((root) -> canUseServices = root); } final String requiresRootMsg; if (canUseServices) { requiresRootMsg = ""; } else { requiresRootMsg = " (requires root)"; } installServiceItem = new MenuItem("Install as service" + requiresRootMsg); popup.add(installServiceItem); installServiceItem.setEnabled(canUseServices); installServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::installAsService)); uninstallServiceItem = new MenuItem("Uninstall service" + requiresRootMsg); popup.add(uninstallServiceItem); uninstallServiceItem.setEnabled(canUseServices); uninstallServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::uninstallService)); if (SystemUtils.IS_OS_WINDOWS) { showServices = new MenuItem("Show services console"); popup.add(showServices); showServices.addActionListener(e -> SwingUtilities.invokeLater(this::showServicesConsole)); } popup.addSeparator(); final MenuItem toolbar = new MenuItem("Show tool window"); popup.add(toolbar); toolbar.addActionListener(actionEvent -> EventQueue.invokeLater(() -> { utilityPanel.toFront(); utilityPanel.setVisible(true); })); MenuItem item; if (Desktop.isDesktopSupported()) { popup.addSeparator(); final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { dashboardItem = new MenuItem("Open Dashboard"); popup.add(dashboardItem); dashboardItem.addActionListener(actionEvent -> dashboard(desktop)); eXideItem = new MenuItem("Open eXide"); popup.add(eXideItem); eXideItem.addActionListener(actionEvent -> eXide(desktop)); item = new MenuItem("Open Java Admin Client"); popup.add(item); item.addActionListener(actionEvent -> client()); monexItem = new MenuItem("Open Monitoring and Profiling"); popup.add(monexItem); monexItem.addActionListener(actionEvent -> monex(desktop)); } if (desktop.isSupported(Desktop.Action.OPEN)) { popup.addSeparator(); item = new MenuItem("Open exist.log"); popup.add(item); item.addActionListener(new LogActionListener()); } popup.addSeparator(); quitItem = new MenuItem("Quit (and stop server)"); popup.add(quitItem); quitItem.addActionListener(actionEvent -> shutdown(false)); setServiceState(); } return popup; }
From source file:Unicode.java
/** Convenience routine to make a MenuItem */ public MenuItem mkMenuItem(ResourceBundle b, String menu, String name) { String miLabel;//from w w w. ja va 2 s . c om try { miLabel = b.getString(menu + "." + name + ".label"); } catch (MissingResourceException e) { miLabel = name; } String key = null; try { key = b.getString(menu + "." + name + ".key"); } catch (MissingResourceException e) { key = null; } if (key == null) return new MenuItem(miLabel); else return new MenuItem(miLabel, new MenuShortcut(key.charAt(0))); }
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;/*from w w w . j a v a 2 s . com*/ } 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:de.codesourcery.gittimelapse.MyFrame.java
private MenuBar createMenuBar() { final MenuBar menuBar = new MenuBar(); final Menu menu = new Menu("File"); final MenuItem item1 = new MenuItem("About..."); item1.addActionListener(new ActionListener() { @Override// w w w. jav a2 s . c o m public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "GIT timelapse V0.1\n\n(C) 2014 tobias.gierke@code-sourcery.de", "About", JOptionPane.PLAIN_MESSAGE); } }); menu.add(item1); final MenuItem item2 = new MenuItem("Quit"); item2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(item2); menuBar.add(menu); return menuBar; }
From source file:net.sf.jhylafax.JHylaFAX.java
private void initializeSystemTray() { tray = new FaxTray(); if (tray.isSupported()) { tray.getPopupMenu().add(new MenuItem((String) exitAction.getValue(Action.NAME))); }//from w w w . jav a 2 s . c o m }
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;/*w w w .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 {//www.jav a 2 s . com 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 PopupMenu getTrayIconPopup() { PopupMenu pop = new PopupMenu("EntrainerFX"); MenuItem start = new MenuItem("Start EntrainerFX"); start.addActionListener(new ActionListener() { @Override//from w w w . j a va 2 s . c o m public void actionPerformed(ActionEvent arg0) { fireReceiverChangeEvent(true, START_ENTRAINMENT); playPressed(); } }); pop.add(start); MenuItem stop = new MenuItem("Stop EntrainerFX"); stop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { fireReceiverChangeEvent(false, START_ENTRAINMENT); stopPressed(); } }); pop.add(stop); MenuItem exit = new MenuItem("Exit"); exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { exitPressed(); } }); pop.add(exit); return pop; }