本文整理了Java中java.awt.Menu.getItemCount()
方法的一些代码示例,展示了Menu.getItemCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu.getItemCount()
方法的具体详情如下:
包路径:java.awt.Menu
类名称:Menu
方法名:getItemCount
暂无
代码示例来源:origin: imagej/ImageJA
static int addPluginSeparatorIfNeeded(Menu menu) {
if (menuSeparators == null)
return 0;
Integer i = (Integer)menuSeparators.get(menu);
if (i == null) {
if (menu.getItemCount() > 0)
addSeparator(menu);
i = new Integer(menu.getItemCount());
menuSeparators.put(menu, i);
}
return i.intValue();
}
代码示例来源:origin: net.imagej/ij
static int addPluginSeparatorIfNeeded(Menu menu) {
if (menuSeparators == null)
return 0;
Integer i = (Integer)menuSeparators.get(menu);
if (i == null) {
if (menu.getItemCount() > 0)
addSeparator(menu);
i = new Integer(menu.getItemCount());
menuSeparators.put(menu, i);
}
return i.intValue();
}
代码示例来源:origin: net.imagej/imagej-legacy
/**
* 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();
}
代码示例来源:origin: net.imagej/ij
/** 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));
}
代码示例来源:origin: imagej/ImageJA
/** 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));
}
代码示例来源:origin: net.imagej/ij
/** 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()]);
}
代码示例来源:origin: net.imagej/ij
/** Removes the specified item from the Window menu. */
static synchronized void removeWindowMenuItem(int index) {
//IJ.log("removeWindowMenuItem: "+index+" "+windowMenuItems2+" "+window.getItemCount());
if (ij==null)
return;
try {
if (index>=0 && index<window.getItemCount()) {
window.remove(WINDOW_MENU_ITEMS+index);
if (index<windowMenuItems2) {
windowMenuItems2--;
if (windowMenuItems2==1) {
window.remove(WINDOW_MENU_ITEMS);
windowMenuItems2 = 0;
}
}
}
} catch (Exception e) {}
}
代码示例来源:origin: net.imagej/ij
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()]);
}
代码示例来源:origin: imagej/ImageJA
/** Removes the specified item from the Window menu. */
static synchronized void removeWindowMenuItem(int index) {
//IJ.log("removeWindowMenuItem: "+index+" "+windowMenuItems2+" "+window.getItemCount());
if (ij==null)
return;
try {
if (index>=0 && index<window.getItemCount()) {
window.remove(WINDOW_MENU_ITEMS+index);
if (index<windowMenuItems2) {
windowMenuItems2--;
if (windowMenuItems2==1) {
window.remove(WINDOW_MENU_ITEMS);
windowMenuItems2 = 0;
}
}
}
} catch (Exception e) {}
}
代码示例来源:origin: sc.fiji/TrakEM2_
static private void restoreMenu(final Menu menu) {
final int n_menuitems = menu.getItemCount();
for (int i=0; i<n_menuitems; i++) {
final MenuItem menu_item = menu.getItem(i);
if (menu_item instanceof Menu) {
restoreMenu((Menu)menu_item);
}
menu_item.setEnabled(true);
}
}
代码示例来源:origin: net.imagej/ij
/** 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;
}
代码示例来源:origin: imagej/ImageJA
/** 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;
}
代码示例来源:origin: net.java.openjdk.cacio/cacio-shared
@Override
void postInitSwingComponent() {
super.postInitSwingComponent();
Menu m = (Menu) getAWTMenu();
int itemCount = m.getItemCount();
for (int i = 0; i < itemCount; i++) {
addItem(m.getItem(i));
}
}
代码示例来源:origin: imagej/ImageJA
/** 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);
}
代码示例来源:origin: net.imagej/ij
/** 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);
}
代码示例来源:origin: net.imagej/ij
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);
}
代码示例来源:origin: imagej/ImageJA
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);
}
代码示例来源:origin: net.imagej/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);
}
代码示例来源:origin: imagej/ImageJA
/** 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);
}
代码示例来源:origin: net.imagej/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);
}
}
内容来源于网络,如有侵权,请联系作者删除!