List of usage examples for javax.swing JMenu getPopupMenu
@BeanProperty(bound = false)
public JPopupMenu getPopupMenu()
From source file:net.cantab.hayward.george.OCS.Statics.java
/** * Display the command menu//from w ww. j a v a 2 s . co m */ public void launchCommandMenu() { if (curCommander == null) { return; } int i; JMenu theMenu = new JMenu(); JMenuItem mi; for (i = 0; i < 2; i++) { int j; int k = 0; for (j = 0; j < theCommanders.length; j++) { if (theCommanders[j].sidesCommanded[i]) { k++; } } if (k != 0) { JMenu com = new JMenu("Commanders of the " + theSides[i].name + " side"); for (j = 0; j < theCommanders.length; j++) { if (theCommanders[j].sidesCommanded[i]) { mi = new JMenuItem(theCommanders[j].name); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); mi.setEnabled(true); com.add(mi); } } theMenu.add(com); } if (curCommander.sidesCommanded[i]) { final int m = i; mi = new JMenuItem("Resign from " + theSides[i].name + " side"); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resignSide(m); } }); mi.setEnabled(true); theMenu.add(mi); int n = 0; for (j = 0; j < theCommanders.length; j++) { if (theCommanders[j].sidesRequested[i]) { n++; } } if (n != 0) { JMenu app = new JMenu("Approve to join " + theSides[i].name + " side"); JMenu rej = new JMenu("Reject to join " + theSides[i].name + " side"); for (j = 0; j < theCommanders.length; j++) { if (theCommanders[j].sidesRequested[i]) { mi = new JMenuItem(theCommanders[j].name); final int p = j; mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { acceptSide(m, p); } }); mi.setEnabled(true); app.add(mi); mi = new JMenuItem(theCommanders[j].name); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rejectSide(m, p); } }); mi.setEnabled(true); rej.add(mi); } } theMenu.add(app); theMenu.add(rej); } } else { final int m = i; if (k != 0) { mi = new JMenuItem("Join " + theSides[i].name + " side"); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { joinSide(m); } }); mi.setEnabled(true); theMenu.add(mi); } else { mi = new JMenuItem("Command " + theSides[i].name + " side"); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { commandSide(m); } }); mi.setEnabled(true); theMenu.add(mi); } } } for (i = 0; i < 2; i++) { final int m = i; mi = new JMenuItem((showPZs[i] ? "Hide " : "Show ") + theSides[i].name + " PZs"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayPZs(m); } }); mi.setEnabled(true); theMenu.add(mi); mi = new JMenuItem((showZOCs[i] ? "Hide " : "Show ") + theSides[i].name + " ZOCs"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayZOCs(m); } }); mi.setEnabled(true); theMenu.add(mi); if (curCommander.sidesCommanded[i]) { mi = new JMenuItem((showHQs[i] ? "Hide " : "Show ") + theSides[i].name + " HQs"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayHQs(m); } }); mi.setEnabled(true); theMenu.add(mi); } } theMenu.getPopupMenu().show(commandLaunch, 0, commandLaunch.getHeight()); }
From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java
/** * Copies the items from the specified menu and creates a new menu. * * @param original The menu to handle./* w ww . j ava2 s .c o m*/ * @return See above. */ private JMenu copyItemsFromMenu(JMenu original) { Component[] comps = original.getPopupMenu().getComponents(); JMenu menu = new JMenu(); menu.setText(original.getText()); menu.setToolTipText(original.getToolTipText()); ActionListener[] al = original.getActionListeners(); for (int j = 0; j < al.length; j++) menu.addActionListener(al[j]); MenuKeyListener[] mkl = original.getMenuKeyListeners(); for (int j = 0; j < mkl.length; j++) menu.addMenuKeyListener(mkl[j]); MenuListener[] ml = original.getMenuListeners(); for (int j = 0; j < ml.length; j++) menu.addMenuListener(ml[j]); for (int i = 0; i < comps.length; i++) { if (comps[i] instanceof JMenu) { menu.add(copyItemsFromMenu((JMenu) comps[i])); } else if (comps[i] instanceof JMenuItem) { menu.add(copyItem((JMenuItem) comps[i])); } else if (comps[i] instanceof JSeparator) { menu.add(new JSeparator(JSeparator.HORIZONTAL)); } } return menu; }
From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java
/** * Implemented as specified by {@link TaskBar}. * @see TaskBar#removeFromMenu(int, JMenuItem) *///w ww . java 2 s .co m public void removeFromMenu(int menuID, JMenuItem entry) { if (menuID < 0 || menus.length <= menuID) throw new IllegalArgumentException("Invalid menu id: " + menuID + "."); Iterator<JMenu> i; JMenu menu; Component[] comps; Component c; if (menuID == WINDOW_MENU && entry instanceof JMenu) { i = windowMenus.iterator(); //tmp solution to remove item from the copy of the windows menu. while (i.hasNext()) { menu = i.next(); comps = menu.getPopupMenu().getComponents(); for (int j = 0; j < comps.length; j++) { c = comps[j]; if (c instanceof JMenu) { if (((JMenu) c).getText().equals(entry.getText())) menu.remove(c); } } } } else if (menuID == HELP_MENU && entry instanceof JMenu) { i = helpMenus.iterator(); //tmp solution to remove item from the copy of the windows menu. while (i.hasNext()) { menu = i.next(); comps = menu.getPopupMenu().getComponents(); for (int j = 0; j < comps.length; j++) { c = comps[j]; if (c instanceof JMenu) { if (((JMenu) c).getText() == entry.getText()) { menu.remove(c); } } } } } menus[menuID].remove(entry); }