List of usage examples for java.awt MenuItem addActionListener
public synchronized void addActionListener(ActionListener l)
From source file:jatoo.app.App.java
private PopupMenu getTrayIconPopup() { MenuItem openItem = new MenuItem(getText("popup.open") + " " + getTitle()); openItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { show();// ww w.j a v a2 s . c o m } }); MenuItem hideItem = new MenuItem(getText("popup.hide") + " " + getTitle()); hideItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { hide(); } }); CheckboxMenuItem hideWhenMinimizedItem = new CheckboxMenuItem(getText("popup.hide_when_minimized"), isHideWhenMinimized()); hideWhenMinimizedItem.addItemListener(new ItemListener() { public void itemStateChanged(final ItemEvent e) { setHideWhenMinimized(e.getStateChange() == ItemEvent.SELECTED); } }); MenuItem sendToBackItem = new MenuItem(getText("popup.send_to_back")); sendToBackItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { sendToBack(); } }); MenuItem closeItem = new MenuItem(getText("popup.close")); closeItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { System.exit(0); } }); // // Font font = new JMenuItem().getFont(); if (font != null) { openItem.setFont(font.deriveFont(Font.BOLD)); hideItem.setFont(font); hideWhenMinimizedItem.setFont(font); sendToBackItem.setFont(font); closeItem.setFont(font); } // // the popup PopupMenu popup = new PopupMenu(getTitle()); popup.add(openItem); popup.add(hideItem); popup.addSeparator(); popup.add(hideWhenMinimizedItem); popup.addSeparator(); popup.add(sendToBackItem); popup.addSeparator(); popup.add(closeItem); return popup; }
From source file:org.sleeksnap.ScreenSnapper.java
/** * Initialize the tray menu/*from w w w .java2 s.c o m*/ */ private void initializeTray() { // Add uploaders from the list we loaded earlier final PopupMenu tray = new PopupMenu(); // Add the action menu tray.add(new ActionMenuItem(Language.getString("cropupload"), ScreenshotAction.CROP)); tray.add(new ActionMenuItem(Language.getString("fullupload"), ScreenshotAction.FULL)); if (Platform.isWindows() || Platform.isLinux()) { tray.add(new ActionMenuItem(Language.getString("activeupload"), ScreenshotAction.ACTIVE)); } tray.addSeparator(); tray.add(new ActionMenuItem(Language.getString("clipboardupload"), ScreenshotAction.CLIPBOARD)); tray.add(new ActionMenuItem(Language.getString("fileupload"), ScreenshotAction.FILE)); tray.addSeparator(); final MenuItem settings = new MenuItem(Language.getString("options")); settings.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (!openSettings()) { icon.displayMessage(Language.getString("error"), Language.getString("optionsOpenError"), TrayIcon.MessageType.ERROR); } } }); tray.add(settings); final MenuItem exit = new MenuItem(Language.getString("exit")); exit.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { shutdown(); } }); tray.add(exit); icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(Resources.ICON), Application.NAME + " v" + Version.getVersionString()); icon.setPopupMenu(tray); icon.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (lastUrl != null) { try { Util.openURL(new URL(lastUrl)); } catch (final Exception e1) { showException(e1, "Unable to open URL"); } } } }); try { SystemTray.getSystemTray().add(icon); } catch (final AWTException e1) { this.showException(e1); } }
From source file:Unicode.java
/** Construct the object including its GUI */ public Unicode() { super("Unicode"); Container cp = getContentPane(); // Used both for Buttons and Menus ResourceBundle b = ResourceBundle.getBundle("UnicodeWidgets"); JButton quitButton, nextButton, prevButton; Panel p = new Panel(); // Make a grid, add one for labels. p.setLayout(new GridLayout(ROWS + 1, COLUMNS + 1)); DecimalFormat df2d = new DecimalFormat("00"); // Add first row, just column labels. p.add(new JLabel("")); for (int i = 0; i < COLUMNS; i++) p.add(new JLabel(Integer.toString(i, 16), JLabel.CENTER)); // Add subsequent rows, each with an offset label for (int i = 0; i < ROWS; i++) { JLabel l = new JLabel("0000"); // room for max, i.e. \uFFFF p.add(l);//from w w w . j a va 2 s .c o m rowLabs[i] = l; for (int j = 0; j < COLUMNS; j++) { JLabel pb = new JLabel(" "); buttons[j][i] = pb; p.add(pb); } } // ActionListeners for jumping around; used by buttons and menus ActionListener firster = new ActionListener() { public void actionPerformed(ActionEvent e) { gotoPage(startNum = 0); } }; ActionListener previouser = new ActionListener() { public void actionPerformed(ActionEvent e) { if (startNum > 0) gotoPage(startNum -= QUADSIZE); } }; ActionListener nexter = new ActionListener() { public void actionPerformed(ActionEvent e) { if (startNum < 65535) gotoPage(startNum += QUADSIZE); } }; ActionListener laster = new ActionListener() { public void actionPerformed(ActionEvent e) { gotoPage(65536 - QUADSIZE); } }; cp.add(BorderLayout.NORTH, p); fontName = new JLabel("Default font", JLabel.CENTER); cp.add(BorderLayout.CENTER, fontName); Panel q = new Panel(); cp.add(BorderLayout.SOUTH, q); q.add(prevButton = mkButton(b, "page.prev")); prevButton.addActionListener(previouser); q.add(nextButton = mkButton(b, "page.next")); nextButton.addActionListener(nexter); q.add(quitButton = mkButton(b, "exit")); quitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); dispose(); System.exit(0); } }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); dispose(); System.exit(0); } }); MenuItem mi; // used in various spots MenuBar mb = new MenuBar(); setMenuBar(mb); String titlebar; try { titlebar = b.getString("program" + ".title"); } catch (MissingResourceException e) { titlebar = "Unicode Demo"; } setTitle(titlebar); ActionListener fontSelector = new ActionListener() { public void actionPerformed(ActionEvent e) { String font = e.getActionCommand(); mySetFont(font, FONTSIZE); } }; Menu fontMenu = mkMenu(b, "font"); // String[] fontList = Toolkit.getDefaultToolkit().getFontList(); String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); for (int i = 0; i < fontList.length; i++) { fontMenu.add(mi = new MenuItem(fontList[i])); mi.addActionListener(fontSelector); } mb.add(fontMenu); gotoPageUI = new GoToPage("Unicode Page"); centre(gotoPageUI); Menu vm = mkMenu(b, "page"); vm.add(mi = mkMenuItem(b, "page", "first")); mi.addActionListener(firster); vm.add(mi = mkMenuItem(b, "page", "prev")); mi.addActionListener(previouser); vm.add(mi = mkMenuItem(b, "page", "next")); mi.addActionListener(nexter); vm.add(mi = mkMenuItem(b, "page", "last")); mi.addActionListener(laster); vm.add(mi = mkMenuItem(b, "page", "goto")); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Unicode.this.gotoPageUI.setVisible(true); } }); mb.add(vm); Menu hm = mkMenu(b, "help"); hm.add(mi = mkMenuItem(b, "help", "about")); mb.setHelpMenu(hm); // needed for portability (Motif, etc.). pack(); // After packing the Frame, centre it on the screen. centre(this); // start at a known place mySetFont(fontList[0], FONTSIZE); gotoPage(startNum); }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * Creates the Pop-up menu for System Tray Icon * //from w w w .j a va 2s . co 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.nebulaframework.ui.swing.node.NodeMainUI.java
/** * System Tray Icon Pop Up Menu//from ww w . ja v a 2 s . co 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 Node MenuItem shutdownItem = new MenuItem("Shutdown"); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doShutdownNode(); } }); trayPopup.add(shutdownItem); return trayPopup; }
From source file:de.jakop.ngcalsync.application.TrayStarter.java
private void moveToTray(final Settings settings, final Application application) { final PopupMenu popup = new PopupMenu(); // Create a pop-up menu components final MenuItem syncItem = new MenuItem(UserMessage.get().MENU_ITEM_SYNCHRONIZE()); final CheckboxMenuItem schedulerItem = new CheckboxMenuItem(UserMessage.get().MENU_ITEM_SCHEDULER_ACTIVE()); final MenuItem logItem = new MenuItem(UserMessage.get().MENU_ITEM_SHOW_LOG()); final MenuItem aboutItem = new MenuItem(UserMessage.get().MENU_ITEM_ABOUT()); final MenuItem exitItem = new MenuItem(UserMessage.get().MENU_ITEM_EXIT()); // let the tray icon listen to sync events for state change application.addObserver(getTrayIcon()); //Add components to pop-up menu popup.add(syncItem);// ww w . ja v a 2 s . c o m popup.add(schedulerItem); popup.add(logItem); popup.add(aboutItem); popup.addSeparator(); popup.add(exitItem); getTrayIcon().setPopupMenu(popup); application.reloadSettings(); final JFrame logWindow = createLogWindow(Level.toLevel(settings.getPopupThresholdLevel(), Level.INFO)); final JFrame aboutWindow = createAboutWindow(); final ActionListener syncActionListener = createSyncActionListener(application.getScheduler()); syncItem.addActionListener(syncActionListener); // sync also on double click getTrayIcon().addActionListener(syncActionListener); getTrayIcon().addMouseListener(createLogMouseListener(logWindow)); schedulerItem.addItemListener(createSchedulerItemListener(settings, application)); logItem.addActionListener(createLogActionListener(logWindow)); aboutItem.addActionListener(createAboutActionListener(aboutWindow)); exitItem.addActionListener(createExitActionListener(logWindow, aboutWindow)); schedulerItem.setState(settings.isSchedulerStarted()); toggleScheduler(settings.isSchedulerStarted(), settings, application); }
From source file:net.mybox.mybox.ClientGUI.java
private void placeTrayIconAWT() { //Check the SystemTray support if (!SystemTray.isSupported()) { System.out.println("SystemTray is not supported"); return;//w w w .j a v a 2 s. c o m } final PopupMenu popup = new PopupMenu(); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components MenuItem aboutItem = new MenuItem("About Mybox"); MenuItem opendirItem = new MenuItem("Open Directory"); MenuItem prefsItem = new MenuItem("Preferences"); MenuItem exitItem = new MenuItem("Quit Mybox"); //Add components to popup menu popup.add(opendirItem); popup.add(pauseItem); popup.add(syncnowItem); popup.addSeparator(); popup.add(prefsItem); popup.add(aboutItem); popup.add(connectionItem); popup.add(exitItem); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Mybox"); 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) { launchFileBrowser(); } }); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //JOptionPane.showMessageDialog(null, "Mybox!"); Dialog dialog = new Dialog((ClientGUI) client.clientGui, "Mybox..."); dialog.setVisible(true); //MessageDialog dialog = new InfoMessageDialog(null, "Mybox", "... is awesome!");//ErrorMessageDialog(null, "Error", message); //dialog.setTitle("About Mybox"); //dialog.run(); //dialog.hide(); } }); prefsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //window.showAll(); ((ClientGUI) client.clientGui).setVisible(true); } }); syncnowItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { client.FullSync(); } }); opendirItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { launchFileBrowser(); } }); pauseItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (pauseItem.getLabel().equals("Pause Syncing")) { client.pause(); pauseItem.setLabel("Unpause Syncing"); } else if (pauseItem.getLabel().equals("Unpause Syncing")) { client.unpause(); pauseItem.setLabel("Pause Syncing"); } } }); connectionItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (connectionItem.getLabel().equals("Connect")) { client.start(); } else if (connectionItem.getLabel().equals("Disconnect")) { client.stop(); } } }); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); }
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 ww .j a v a 2 s . co m 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.puzzle.gui.MainFrame.java
public void tray() {//-----ljs tray = SystemTray.getSystemTray(); // ? PopupMenu pop = new PopupMenu(); // ???? final MenuItem show = new MenuItem("?"); final MenuItem exit = new MenuItem("?"); pop.add(show);//from w w w . j a va 2 s . co m pop.add(exit); show.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showMouseClick(e); } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { exitMouseClick(e); } }); trayIcon = new TrayIcon( Toolkit.getDefaultToolkit().getImage(MainFrame.class.getResource("/images/flag.png")), "??V1.0", pop);// trayIcon.setImageAutoSize(true); //? trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { trayIconMouseClick(e); } }); try { tray.add(trayIcon); // } catch (AWTException ex) { log.error(ex.getMessage(), ex); ex.printStackTrace(); } }
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 v a2s . co 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; }