private static Menu initProjectMenu() { Menu mnProject = new Menu(Resources.get("menu_project")); CheckboxMenuItem compress = new CheckboxMenuItem(Resources.get("menu_compressProjectFile")); compress.setState(userPreferences.isCompressFile()); compress.addItemListener(e -> userPreferences.setCompressFile(compress.getState())); CheckboxMenuItem sync = new CheckboxMenuItem(Resources.get("menu_syncMaps")); sync.setState(userPreferences.isSyncMaps()); sync.addItemListener(e -> userPreferences.setSyncMaps(sync.getState())); MenuItem importSpriteFile = new MenuItem(Resources.get("menu_assets_importSpriteFile")); importSpriteFile.addActionListener(a -> EditorScreen.instance().importSpriteFile()); MenuItem importSprite = new MenuItem(Resources.get("menu_assets_importSprite")); importSprite.addActionListener(a -> EditorScreen.instance().importSprites()); mnProject.add(importSprite); mnProject.add(importSpriteFile); mnProject.addSeparator(); mnProject.add(compress); mnProject.add(sync); return mnProject; }
private static void initSystemTray() { // add system tray icon with popup menu if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); PopupMenu menu = new PopupMenu(); MenuItem exitItem = new MenuItem(Resources.get("menu_exit")); exitItem.addActionListener(a -> Game.terminate()); menu.add(exitItem); trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu); trayIcon.setImageAutoSize(true); try { tray.add(trayIcon); } catch (AWTException e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); } } }
@Test public void register_system_tray_icon() throws ExecutionException, InterruptedException { final SystemTraySupport systemTraySupport = this.applicationContext.getBean(SystemTraySupport.class); final MenuItem testItem = new MenuItem("DISABLED_ON_CLICK"); final ActionListener disableOnClick = e -> testItem.setEnabled(false); final Map<MenuItem, ActionListener> menuItems = new HashMap<MenuItem, ActionListener>() {{ this.put(testItem, disableOnClick); }}; final SystemTrayIcon trayIcon = this.systemTrayIconWith(menuItems); systemTraySupport.registerTrayIcon(trayIcon) .whenCompleteAsync((res, err) -> assertThat(res.isSuccess()).isTrue()) .thenApply(Try::get) .whenCompleteAsync((res, err) -> assertThat(systemTraySupport.getTrayIcons()).containsExactly(res)) .whenCompleteAsync((res, err) -> systemTraySupport.removeTrayIcon(res)) .thenAccept(icon -> assertThat(systemTraySupport.getTrayIcons()).doesNotContain(icon)) .toCompletableFuture().get(); }
private SystemTrayIcon systemTrayIconWith(final Map<MenuItem, ActionListener> menuItems) { return new SystemTrayIcon() { @Override public String getLabel() { return TRAY_LABEL; } @Override public URL getIcon() { return TRAY_ICON_URL; } @Override public Map<MenuItem, ActionListener> getMenuItems() { return menuItems; } }; }
private void addToRecent(String s) { for (int i = 0; i < iMaxRecent; i++) { if (s.equals(sRecent[i])) { return; } } if (sRecent[iRecent] != null) { mRecent.remove(iRecent); } sRecent[iRecent] = s; if (s.length() > 43) { s = s.substring(0, 40) + "..."; } MenuItem item = new MenuItem(s); item.setActionCommand("#" + iRecent); item.addActionListener(this); mRecent.insert(item, iRecent); iRecent = (iRecent + 1) % iMaxRecent; }
void addMenuItems(Menu f, String[] m) { for (int i = 0; i < m.length; i++) { MenuItem item = new MenuItem(m[i].substring(1)); char c = m[i].charAt(0); if (c != '-') { item.setShortcut(new MenuShortcut(c)); } item.addActionListener(this); f.add(item); } }
private PopupMenu createPopupMenu(final TrayIcon trayIcon, final int menuCount) { final PopupMenu trayIconPopupMenu = new PopupMenu(); for (int i = 1; i <= menuCount; ++i) { final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i); popupMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { trayIcon.setPopupMenu(createPopupMenu(trayIcon, menuCount + 1)); } }); trayIconPopupMenu.add(popupMenuItem); } return trayIconPopupMenu; }
/** * creates a PopUp menu for the TrayIcon * * @return PopUp menu for the TrayIcon */ private PopupMenu createMenu() { PopupMenu menu = new PopupMenu("TimeTray " + this.VERSION); // about item MenuItem menuSettings = new MenuItem("Settings"); menuSettings.setActionCommand("settings"); menu.add(menuSettings); // exit item MenuItem menuExit = new MenuItem("Quit"); menuExit.setActionCommand("quit"); menu.add(menuExit); menu.addActionListener(this); return menu; }
private static MenuItem generateMenuItem(TreeElement element) { if(element.isLeaf()) { MenuItem item = new MenuItem(element.getCaption()); item.addActionListener(new MasterFrameMenu(element.getFullID())); if(element.isHidden()) { item.setEnabled(false); } else if(!element.getEnabled()) { item.setEnabled(false); } items.put(element.getFullID(), item); return(item); } else { Menu menu = new Menu(element.getCaption()); Iterator<TreeElement> i = element.getChilds(); while(i.hasNext()) { menu.add(generateMenuItem(i.next())); } if(element.isHidden()) { menu.setEnabled(false); } items.put(element.getFullID(), menu); return(menu); } }
/** * Method declaration * * * @param f * @param m */ private void addMenuItems(Menu f, String[] m) { for (int i = 0; i < m.length; i++) { if (m[i].equals("-")) { f.addSeparator(); } else { MenuItem item = new MenuItem(m[i]); item.addActionListener(this); f.add(item); } } }
private PopupMenu createPopupMenu() { final PopupMenu popup = new PopupMenu(); if (allowScreenSwitch) { MenuItem switchItem = new MenuItem(Main.getString("text.switchscreen")); switchItem.setActionCommand("switch"); switchItem.addActionListener(this); // add to popup popup.add(switchItem); } MenuItem exitItem = new MenuItem(Main.getString("text.exit")); exitItem.setActionCommand("exit"); exitItem.addActionListener(this); // add to pop-up menu popup.add(exitItem); return popup; }
private void addExitItem( PopupMenu popup ) { MenuItem exit = new MenuItem( "Exit" ); exit.addActionListener( new ActionListener() { @Override public void actionPerformed( ActionEvent e ) { // Exits the program // plugin.resetLeds(); // TODO: Decide whether or not LEDS should turn off when // program exits. // Pros: You can set a color and then quit the program // Cons: For LEDS to turn off, user has to unload plugins System.exit(0); } }); popup.add( exit ); }
@Override public void actionPerformed(ActionEvent e) { String label = ((MenuItem) e.getSource()).getLabel(); if (CREATE_NOTE_TEXT.equals(label)) { createNote(); } else if (SHOW_ALL_NOTES_TEXT.equals(label)) { showNotes(ALL); } else if (HIDE_ALL_NOTES_TEXT.equals(label)) { showNotes(NONE); } else if (PREFERENCES_TEXT.equals(label)) { new PreferencesDialog(frame, preferencesManager.getPreferences()).setVisible(true); } else if (ABOUT_TEXT.equals(label)) { JLabel about = new JLabel(ABOUT_DIALOG_TEXT); about.setIcon(Icon.getJStickyNotesImageIcon(48)); JOptionPane.showMessageDialog(frame, about, ABOUT_DIALOG_TITLE_TEXT, JOptionPane.PLAIN_MESSAGE); } else if (EXIT_TEXT.equals(label)) { System.exit(0); } }
/** * Initializes the context menu for adding Comments. */ private static void initAddCommentMenu() { ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock"); addCommentItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.add_comment")); addCommentItem.setActionCommand(ADD_COMMENT_BLOCK); addCommentItem.addActionListener(rndBlockMenu); addCommentMenu.add(addCommentItem); cloneItem1 = new MenuItem(uiMessageBundle.getString("ardublock.ui.clone")); cloneItem1.setActionCommand(CLONE_BLOCK); cloneItem1.addActionListener(rndBlockMenu); addCommentMenu.add(cloneItem1); addCommentMenuInit = true; }
/** * Initializes the context menu for deleting Comments. */ private static void initRemoveCommentMenu() { ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock"); removeCommentItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.delete_comment")); removeCommentItem.setActionCommand(REMOVE_COMMENT_BLOCK); removeCommentItem.addActionListener(rndBlockMenu); removeCommentMenu.add(removeCommentItem); //rndBlockMenu.add(runBlockItem); cloneItem2 = new MenuItem(uiMessageBundle.getString("ardublock.ui.clone")); cloneItem2.setActionCommand(CLONE_BLOCK); cloneItem2.addActionListener(rndBlockMenu); removeCommentMenu.add(cloneItem2); removeCommentMenuInit = true; }
private PopupMenu makePopupMenu() { final PopupMenu popup = new PopupMenu(); final ActionListener rmbListener = new TrayActionRMBListener(); // Check clipboard text: final MenuItem checkClipboardItem = new MenuItem( StringTools.getLabel(messages .getString("guiMenuCheckClipboard"))); checkClipboardItem.addActionListener(rmbListener); popup.add(checkClipboardItem); // Open main window: final MenuItem restoreItem = new MenuItem(StringTools.getLabel(messages .getString("guiMenuShowMainWindow"))); restoreItem.addActionListener(rmbListener); popup.add(restoreItem); // Exit: final MenuItem exitItem = new MenuItem(StringTools.getLabel(messages .getString("guiMenuQuit"))); exitItem.addActionListener(rmbListener); popup.add(exitItem); return popup; }
public static void main(String[] args) { Container container = new Container(); Panel panel = new Panel(); Menu menu = new Menu(); //!!! its not component TextField textField = new TextField(); container.add(textField); Window win = new Window(null); win.pack(); menu.setShortcut(new MenuShortcut(12)); new MenuItem("label", new MenuShortcut(33, true)); Menu file = new Menu("File"); MenuItem print; file.add(print = new MenuItem("Print", new MenuShortcut('p'))); }
private PopupMenu generateMenu() { // 创建弹出菜单 PopupMenu popup = new PopupMenu(); // 以下将各个菜单项加入到弹出菜单中 MenuItem full = new MenuItem("全屏截图"); full.addActionListener(listener); popup.add(full); MenuItem select = new MenuItem("选择截图"); select.addActionListener(listener); popup.add(select); MenuItem settings = new MenuItem("设置"); settings.addActionListener(listener); popup.add(settings); MenuItem quit = new MenuItem("退出"); quit.addActionListener(listener); popup.add(quit); return popup; }
private IconeTaches() { super(Images.get("divers/icone.png", true), TITRE); setImageAutoSize(true); setPopupMenu(menu = new PopupMenu("Menu")); menu.add(quitter = new MenuItem("Quitter")); menu.add(infos = new MenuItem("A propos...")); menu.add(admin = new MenuItem("Administrer")); menu.addSeparator(); menu.add(d3d = new MenuItem("Dessin 3D")); menu.add(d2d = new MenuItem("Dessin 2D")); quitter.addActionListener(this); infos.addActionListener(this); admin.addActionListener(this); d3d.addActionListener(this); d2d.addActionListener(this); if(SystemTray.isSupported()) try { SystemTray.getSystemTray().add(this); } catch(AWTException e) { e.printStackTrace(); } }
private void show(Component origin, InputMethodContext imc) { imContext = imc; for (int i = 0; i < getItemCount(); i++) { MenuItem item = getItem(i); if (!(item instanceof IMSubmenu)) { // skip all non-menu elements, such as separators continue; } IMSubmenu subMenu = (IMSubmenu) item; InputMethodDescriptor desc = subMenu.getDesc(); if (desc == null) { continue; } if (desc.hasDynamicLocaleList()) { subMenu.removeAll(); subMenu.addLocales(); } subMenu.checkItems(); i++; } show(origin, 50, 50); }
protected static PopupMenu createPopupMenu() { final PopupMenu popup = new PopupMenu(); 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 pop-up 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); return popup; }
StaveActionHandler(Stave stave) { theApp = stave; noteContextMenu = new PopupMenu(); editNote = new MenuItem("Edit Note"); editNote.addActionListener(this); noteContextMenu.add(editNote ); repeatNote = new MenuItem("Repeat Note"); repeatNote.addActionListener(this); noteContextMenu.add(repeatNote ); makeRest = new MenuItem("Change to Rest"); makeRest.addActionListener(this); noteContextMenu.add(makeRest); deleteNote = new MenuItem("Delete Note"); deleteNote.addActionListener(this); noteContextMenu.add(deleteNote ); theApp.add(noteContextMenu); }
public TrayIcon buildTrayIcon() throws IOException { PopupMenu popup = new PopupMenu(); for (MenuItemDefinition mid : menuItems) { if (mid instanceof SeperatorMenuItem) { popup.addSeparator(); } else { MenuItem item = new MenuItem(); item.setLabel(mid.getText()); item.addActionListener(mid); popup.add(item); } } TrayIcon ti = new TrayIcon(getImage(imageName), tooltip, popup); ti.setImageAutoSize(true); return ti; }
private void createItems() { ih = new ItemHandler(); MenuItem info = new MenuItem("(c) UploadR v"+Constants.VERSION +" | shortcuts "+(Constants.KEYS_ENABLED ? "enabled" : "disabled")); info.setEnabled(false); this.add(info); for(byte i=0;i<ItemHandler.items.length;++i) { if(ItemHandler.items[i][0].equals("s")) { this.addSeparator(); continue; } MenuItem item = new MenuItem(ItemHandler.items[i][0]); item.setActionCommand(ItemHandler.items[i][1]); item.addActionListener(ih); this.add(item); } }