if (awt != null) { MenuItem item = awt.getItem(0); String oldStatus = item.getLabel(); if (!status.equals(oldStatus)) item.setLabel(status);
/** Provide a string representation of the given component (Component or * MenuComponent. */ public static String toString(Object obj) { if (obj instanceof Component) return toString((Component)obj); else if (obj instanceof MenuBar) return "MenuBar"; else if (obj instanceof MenuItem) return ((MenuItem)obj).getLabel(); return obj.toString(); }
/** Called once when ImageJ quits. */ public static void savePreferences(Properties prefs) { int index = 0; for (Enumeration en=pluginsPrefs.elements(); en.hasMoreElements();) { String key = "plugin" + (index/10)%10 + index%10; String value = (String)en.nextElement(); prefs.put(key, value); index++; } int n = openRecentMenu.getItemCount(); for (int i=0; i<n; i++) { String key = ""+i; if (key.length()==1) key = "0"+key; key = "recent"+key; prefs.put(key, openRecentMenu.getItem(i).getLabel()); } prefs.put(Prefs.MENU_SIZE, Integer.toString(fontSize)); }
/** Called once when ImageJ quits. */ public static void savePreferences(Properties prefs) { int index = 0; for (Enumeration en=pluginsPrefs.elements(); en.hasMoreElements();) { String key = "plugin" + (index/10)%10 + index%10; String value = (String)en.nextElement(); prefs.put(key, value); index++; } int n = openRecentMenu.getItemCount(); for (int i=0; i<n; i++) { String key = ""+i; if (key.length()==1) key = "0"+key; key = "recent"+key; prefs.put(key, openRecentMenu.getItem(i).getLabel()); } prefs.put(Prefs.MENU_SIZE, Integer.toString(fontSize)); }
/** Inserts 'item' into 'menu' in alphanumeric order. */ static void addOrdered(Menu menu, MenuItem item) { String label = item.getLabel(); int start = addPluginSeparatorIfNeeded(menu); for (int i=start; i<menu.getItemCount(); i++) { if (label.compareTo(menu.getItem(i).getLabel())<0) { menu.insert(item, i); return; } } menu.add(item); }
/** Inserts 'item' into 'menu' in alphanumeric order. */ static void addOrdered(Menu menu, MenuItem item) { String label = item.getLabel(); int start = addPluginSeparatorIfNeeded(menu); for (int i=start; i<menu.getItemCount(); i++) { if (label.compareTo(menu.getItem(i).getLabel())<0) { menu.insert(item, i); return; } } menu.add(item); }
static void addItemSorted(Menu menu, MenuItem item, int startingIndex) { String itemLabel = item.getLabel(); int count = menu.getItemCount(); boolean inserted = false; for (int i=startingIndex; i<count; i++) { MenuItem mi = menu.getItem(i); String label = mi.getLabel(); //IJ.log(i+ " "+itemLabel+" "+label + " "+(itemLabel.compareTo(label))); if (itemLabel.compareTo(label)<0) { menu.insert(item, i); inserted = true; break; } } if (!inserted) menu.add(item); }
static void addItemSorted(Menu menu, MenuItem item, int startingIndex) { String itemLabel = item.getLabel(); int count = menu.getItemCount(); boolean inserted = false; for (int i=startingIndex; i<count; i++) { MenuItem mi = menu.getItem(i); String label = mi.getLabel(); //IJ.log(i+ " "+itemLabel+" "+label + " "+(itemLabel.compareTo(label))); if (itemLabel.compareTo(label)<0) { menu.insert(item, i); inserted = true; break; } } if (!inserted) menu.add(item); }
public static void loadRecentFiles() { recentFiles.removeAll(); for (String recent : userPreferences.getLastOpenedFiles()) { if (recent != null && !recent.isEmpty() && new File(recent).exists()) { MenuItem fileButton = new MenuItem(recent); fileButton.addActionListener(a -> { log.log(Level.INFO, "load " + fileButton.getLabel()); EditorScreen.instance().load(new File(fileButton.getLabel())); }); recentFiles.add(fileButton); } } }
/** Returns, as an array of strings, a list of the LUTs in the Image/Lookup Tables menu. */ public static String[] getLuts() { ArrayList list = new ArrayList(); Hashtable commands = Menus.getCommands(); Menu lutsMenu = Menus.getImageJMenu("Image>Lookup Tables"); if (commands==null || lutsMenu==null) return new String[0]; for (int i=0; i<lutsMenu.getItemCount(); i++) { MenuItem menuItem = lutsMenu.getItem(i); if (menuItem.getActionListeners().length == 0) // separator? continue; String label = menuItem.getLabel(); if (label.equals("Invert LUT") || label.equals("Apply LUT")) continue; String command = (String)commands.get(label); if (command==null || command.startsWith("ij.plugin.LutLoader")) list.add(label); } return (String[])list.toArray(new String[list.size()]); }
public static String[] getSampleImageNames() { ArrayList list = new ArrayList(); Hashtable commands = Menus.getCommands(); Menu samplesMenu = Menus.getImageJMenu("File>Open Samples"); if (samplesMenu==null) return new String[0]; for (int i=0; i<samplesMenu.getItemCount(); i++) { MenuItem menuItem = samplesMenu.getItem(i); if (menuItem.getActionListeners().length == 0) continue; // separator? String label = menuItem.getLabel(); if (label.contains("Cache Sample Images")) continue; String command = (String)commands.get(label); if (command==null) continue; String[] items = command.split("\""); if (items.length!=3) continue; String name = items[1]; list.add(name); } return (String[])list.toArray(new String[list.size()]); }
/** * Helper method to look up special cases for menu weighting */ private int getIndex(final Menu menu, final String label) { // Place export sub-menu after import sub-menu if (menu.getLabel().equals("File") && label.equals("Export")) { for (int i = 0; i < menu.getItemCount(); i++) { final MenuItem menuItem = menu.getItem(i); if (menuItem.getLabel().equals("Import")) return i + 1; } } // TODO pass and use actual command weight from IJ2.. maybe? // No special case: append to end of menu return menu.getItemCount(); }
/** Opens a file from the File/Open Recent menu and returns 'true' if successful. */ boolean openRecent(String cmd) { Menu menu = Menus.getOpenRecentMenu(); if (menu==null) return false; for (int i=0; i<menu.getItemCount(); i++) { if (menu.getItem(i).getLabel().equals(cmd)) { IJ.open(cmd); return true; } } return false; }
/** Opens a file from the File/Open Recent menu and returns 'true' if successful. */ boolean openRecent(String cmd) { Menu menu = Menus.getOpenRecentMenu(); if (menu==null) return false; for (int i=0; i<menu.getItemCount(); i++) { if (menu.getItem(i).getLabel().equals(cmd)) { IJ.open(cmd); return true; } } return false; }
/** * Loads the {@link LyrebirdTrayIcon} in the current OS's system tray. */ private void loadTrayIcon() { LOG.debug("Registering tray icon for Lyrebird..."); LOG.debug("Creating a tray icon..."); final SystemTray tray = SystemTray.get(); tray.setImage(lyrebirdTrayIcon.getIcon()); tray.setTooltip("Lyrebird"); LOG.debug("Adding items to tray icon's menu..."); final Menu menu = tray.getMenu(); lyrebirdTrayIcon.getMenuItems().forEach((item, action) -> { LOG.debug("Adding menu item : {} (callback : {})", item, action); final MenuItem menuItem = new MenuItem(item.getLabel()); menuItem.setCallback(action); menu.add(menuItem); }); LOG.debug("Finished creating tray icon!"); }
@Override void postInitSwingComponent() { setLabel(getAWTMenu().getLabel()); setEnabled(getAWTMenu().isEnabled()); if (needActionProxy()) { getSwingMenu().addActionListener(new ProxyListener()); } }
/** Adds a file path to the beginning of the File/Open Recent submenu. */ public static synchronized void addOpenRecentItem(String path) { if (ij==null) return; int count = openRecentMenu.getItemCount(); for (int i=0; i<count; ) { if (openRecentMenu.getItem(i).getLabel().equals(path)) { openRecentMenu.remove(i); count--; } else i++; } if (count==MAX_OPEN_RECENT_ITEMS) openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1); MenuItem item = new MenuItem(path); openRecentMenu.insert(item, 0); item.addActionListener(ij); }
/** Adds a file path to the beginning of the File/Open Recent submenu. */ public static synchronized void addOpenRecentItem(String path) { if (ij==null) return; int count = openRecentMenu.getItemCount(); for (int i=0; i<count; ) { if (openRecentMenu.getItem(i).getLabel().equals(path)) { openRecentMenu.remove(i); count--; } else i++; } if (count==MAX_OPEN_RECENT_ITEMS) openRecentMenu.remove(MAX_OPEN_RECENT_ITEMS-1); MenuItem item = new MenuItem(path); openRecentMenu.insert(item, 0); item.addActionListener(ij); }
/** Open the file and move the path to top of the submenu. */ public void run() { Opener o = new Opener(); o.open(path); Menu menu = Menus.getOpenRecentMenu(); int n = menu.getItemCount(); int index = 0; for (int i=0; i<n; i++) { if (menu.getItem(i).getLabel().equals(path)) { index = i; break; } } if (index>0) { MenuItem item = menu.getItem(index); menu.remove(index); menu.insert(item, 0); } }
/** Open the file and move the path to top of the submenu. */ public void run() { Opener o = new Opener(); o.open(path); Menu menu = Menus.getOpenRecentMenu(); int n = menu.getItemCount(); int index = 0; for (int i=0; i<n; i++) { if (menu.getItem(i).getLabel().equals(path)) { index = i; break; } } if (index>0) { MenuItem item = menu.getItem(index); menu.remove(index); menu.insert(item, 0); } }