List of usage examples for java.awt MenuItem MenuItem
public MenuItem(String label) throws HeadlessException
From source file:com.github.cmisbox.ui.UI.java
private UI() { this.log = LogFactory.getLog(this.getClass()); try {//from w ww .jav a 2 s . c o m this.available = !GraphicsEnvironment.isHeadless(); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); if (SystemTray.isSupported()) { this.tray = SystemTray.getSystemTray(); Image image = ImageIO.read(this.getClass().getResource("images/cmisbox.png")); ActionListener exitListener = new ActionListener() { public void actionPerformed(ActionEvent e) { Main.exit(0); } }; this.popup = new PopupMenu(); MenuItem defaultItem = new MenuItem(Messages.exit); defaultItem.addActionListener(exitListener); this.popup.add(defaultItem); MenuItem loginItem = new MenuItem(Messages.login); loginItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { new LoginDialog(); } }); this.popup.add(loginItem); MenuItem treeItem = new MenuItem(Messages.showTree); treeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { new TreeSelect(); } }); this.popup.add(treeItem); final TrayIcon trayIcon = new TrayIcon(image, UI.NOTIFY_TITLE, this.popup); trayIcon.setImageAutoSize(true); this.tray.add(trayIcon); this.notify(Messages.startupComplete); } } catch (Exception e) { this.log.error(e); } }
From source file:PopupDemo.java
void addPopup(Component c, String name) { PopupMenu pm = new PopupMenu(); MenuItem mi = new MenuItem(name + "-1"); mi.addActionListener(this); pm.add(mi);/*from w w w . j av a 2 s . c om*/ mi = new MenuItem(name + "-2"); pm.add(mi); setHash(c, pm); c.add(pm); c.addMouseListener(this); }
From source file:coolmap.module.impl.SideMapModule.java
public static void registerSideMapColumn(final Class<ColumnMap> columnMap) { columnMaps.add(columnMap);/*from w ww .ja v a2s . com*/ //Also add to menu // System.err.println(columnMap); try { MenuItem item = new MenuItem( ((ColumnMap) columnMap.getConstructor(CoolMapObject.class).newInstance(new CoolMapObject())) .getName()); CoolMapMaster.getCMainFrame().addMenuItem("View/Canvas config/Column side/", item, false, false); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { CoolMapObject object = CoolMapMaster.getActiveCoolMapObject(); object.getCoolMapView() .addColumnMap(columnMap.getConstructor(CoolMapObject.class).newInstance(object)); } catch (Exception ex) { // ex.printStackTrace(); //need an error logging system } } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.cryptomator.ui.ExitUtil.java
private TrayIcon createTrayIcon(Runnable exitCommand) { final PopupMenu popup = new PopupMenu(); final MenuItem showItem = new MenuItem(localization.getString("tray.menu.open")); showItem.addActionListener(this::restoreFromTray); popup.add(showItem);// ww w.j a va2 s.c o m final MenuItem exitItem = new MenuItem(localization.getString("tray.menu.quit")); exitItem.addActionListener(e -> exitCommand.run()); popup.add(exitItem); final Image image; if (SystemUtils.IS_OS_MAC_OSX && isMacMenuBarDarkMode()) { image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_white.png")); } else if (SystemUtils.IS_OS_MAC_OSX) { image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_black.png")); } else { image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon.png")); } return new TrayIcon(image, localization.getString("app.name"), popup); }
From source file:com.sec.ose.osi.ui.frm.tray.JTrayIconApp.java
private PopupMenu createPopupMenu(int state) { PopupMenu popupMenu = new PopupMenu("PopupMenu"); MenuItem miLogOut = new MenuItem("LogOut"); MenuItem miOpen = new MenuItem("Open"); MenuItem miExit = new MenuItem("Exit"); MenuItem miAbout = new MenuItem("About"); miLogOut.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { log.debug("actionPerformed() - LogOut"); mEventHandler.handle(EventHandler.LOGOUT_MENU); }//from w w w. j a v a2 s . c o m }); miOpen.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { log.debug("actionPerformed() - Open"); mEventHandler.handle(EventHandler.OPEN_MENU); } }); miAbout.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { log.debug("actionPerformed() - Help - SubSix"); mEventHandler.handle(EventHandler.HELP_ABOUT); } }); miExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { log.debug("actionPerformed() - Exit"); mEventHandler.handle(EventHandler.EXIT_MENU); } }); switch (state) { case BEFORE_LOGIN_STATE: popupMenu.add(miOpen); popupMenu.addSeparator(); popupMenu.add(miAbout); popupMenu.addSeparator(); popupMenu.add(miExit); break; case AFTER_LOGIN_STATE: popupMenu.add(miLogOut); popupMenu.addSeparator(); popupMenu.add(miOpen); popupMenu.addSeparator(); popupMenu.add(miAbout); popupMenu.addSeparator(); popupMenu.add(miExit); break; } return popupMenu; }
From source file:com.github.cmisbox.ui.UI.java
public void addWatch(String path) { final MenuItem mi = new MenuItem(path.replaceAll("/", "")); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { Desktop.getDesktop().open(new File(Config.getInstance().getWatchParent(), mi.getLabel())); } catch (IOException e) { UI.this.log.error(e); }/*from w w w. j a v a 2 s. c om*/ } }); this.popup.add(mi); }
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);/*from w ww . j a v a 2 s . c om*/ 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:iqq.app.ui.manager.MainManager.java
public void enableTray() { if (SystemTray.isSupported() && tray == null) { menu = new PopupMenu(); MenuItem restore = new MenuItem(" ? "); restore.addActionListener(new ActionListener() { @Override/*from w ww.ja v a 2 s.c o m*/ public void actionPerformed(ActionEvent e) { show(); } }); MenuItem exit = new MenuItem(" ? "); exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(restore); menu.addSeparator(); menu.add(exit); if (SystemUtils.isMac()) { defaultImage = skinService.getIconByKey("window/titleWIconBlack").getImage(); } else { defaultImage = mainFrame.getIconImage(); } blankImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); tray = SystemTray.getSystemTray(); icon = new TrayIcon(defaultImage, "IQQ"); icon.setImageAutoSize(true); if (!SystemUtils.isMac()) { icon.setPopupMenu(menu); } try { tray.add(icon); icon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { logger.debug("MouseEvent " + e.getButton() + " " + e.getClickCount()); //?? if (e.getButton() == MouseEvent.BUTTON1) { if (flashOwner != null) { Map<String, Object> data = (Map<String, Object>) flashOwner.getAttachment(); if (data != null && data.containsKey("action") && data.get("action").equals("ADD_BUDDY_REQUEST")) { IMContext.getBean(FrameManager.class).showGetFriendRequest((IMBuddy) flashOwner, data.get("buddy_request_id").toString()); eventService.broadcast(new UIEvent(UIEventType.FLASH_USER_STOP, flashOwner)); return; } else { // ? chatManager.addChat(flashOwner); } } else { show(); } } } }); } catch (AWTException e) { logger.error("SystemTray add icon.", e); } } }
From source file:MDIApp.java
private MenuBar createMenuBar() { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { String command = ae.getActionCommand(); if (command.equals("Open")) { if (fd == null) { fd = new FileDialog(MDIApp.this, "Open File", FileDialog.LOAD); fd.setDirectory("/movies"); }/*from ww w . ja v a 2 s .c o m*/ fd.show(); if (fd.getFile() != null) { String filename = fd.getDirectory() + fd.getFile(); openFile("file:" + filename); } } else if (command.equals("Exit")) { dispose(); System.exit(0); } } }; MenuItem item; MenuBar mb = new MenuBar(); // File Menu Menu mnFile = new Menu("File"); mnFile.add(item = new MenuItem("Open")); item.addActionListener(al); mnFile.add(item = new MenuItem("Exit")); item.addActionListener(al); // Options Menu Menu mnOptions = new Menu("Options"); cbAutoLoop = new CheckboxMenuItem("Auto replay"); cbAutoLoop.setState(true); mnOptions.add(cbAutoLoop); mb.add(mnFile); mb.add(mnOptions); return mb; }
From source file:zxmax.tools.timerreview.Main.java
private TrayIcon getTrayIcon() throws AWTException { final TrayIcon trayIcon = new TrayIcon( createImage("images/bulb.gif", I18N.getLabel(getClass(), "tray.icon.description"))); final SystemTray tray = SystemTray.getSystemTray(); tray.add(trayIcon);/*from ww w.j a va 2 s . c o m*/ final PopupMenu popup = new PopupMenu(); trayIcon.setPopupMenu(popup); /* * Serve per aprire il popup sulla tray icon con il tasto sx del mouse. * Il problema chiuderla/nasconderla ... */ // trayIcon.addMouseListener(new TrayIconMouseAdapter(popup)); final MenuItem exitItem = new MenuItem(I18N.getLabel(getClass(), "exit")); final MenuItem newTimerItem = new MenuItem(I18N.getLabel(getClass(), "new.timer")); newTimerItem.setEnabled(false); final MenuItem infoItem = new MenuItem(I18N.getLabel(getClass(), "info")); popup.add(exitItem); popup.add(newTimerItem); popup.add(infoItem); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); System.exit(0); } }); newTimerItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { StartTimerWindow timer = new StartTimerWindow(); timer.setVisible(true); } }); infoItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { InfoWindow infoWindow = new InfoWindow(); infoWindow.setVisible(true); infoWindow.createBufferStrategy(1); } }); return trayIcon; }