Java Code Examples for javax.swing.JMenu#getMenuComponents()

The following examples show how to use javax.swing.JMenu#getMenuComponents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuBarFastFromAWTTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
final void doTestInAwt() {
    assertEquals("One menu", 1, mb.getMenuCount());
    JMenu m = mb.getMenu(0);
    assertEquals("named file", "File", m.getText());

    long before = System.currentTimeMillis();
    MenuBarTest.simulateExpansionOfMenu(m);
    Component[] arr = m.getMenuComponents();
    assertEquals("One menu item", 1, arr.length);
    long after = System.currentTimeMillis();
    
    long took = after - before;
    if (took > 5000) {
        fail("Too long time to compute menu items (" + took + " ms), probably time out somewhere!");
    }
}
 
Example 2
Source File: RefactoringContextAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public JComponent[] synchMenuPresenters(JComponent[] items) {
    JComponent[] comps = new JComponent[1];
    for (JComponent item : items) {
        if (item instanceof Actions.MenuItem) {
            comps[0] = item;
            // update menu items to reflect Action.isEnabled
            ((Actions.MenuItem) item).synchMenuPresenters(comps);
        } else if(item instanceof JMenu) {
            JMenu jMenu = (JMenu) item;
            for (Component subItem : jMenu.getMenuComponents()) {
                if (subItem instanceof Actions.MenuItem) {
                    comps[0] = (JComponent) subItem;
                    // update menu items to reflect Action.isEnabled
                    ((Actions.MenuItem) subItem).synchMenuPresenters(comps);
                }
            }
        }
    }
    // returns most up-to date items
    return createMenuItems();
}
 
Example 3
Source File: MenuManager.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
private void showTableHeaderPopupMenu(final MouseEvent e) {
	JPopupMenu jTableHeaderPopupMenu = new JPopupMenu();
	JMenu columnMenu = tableMenu.getColumnMenu();
	if (columnMenu != null) {
		for (Component component : columnMenu.getMenuComponents()) { //Clone!
			jTableHeaderPopupMenu.add(component);
		}
	}
	//SUM
	jTableHeaderPopupMenu.addSeparator();
	AutoMenu<Q> jSum = tablePopupMenu.get(MenuEnum.SUM);
	if (jSum instanceof JMenuSum) {
		((JMenuSum)jSum).updateMenuDataColumn(jTable.columnAtPoint(e.getPoint()));
		jTableHeaderPopupMenu.add(jSum.getComponent());
	}
	jTableHeaderPopupMenu.show(e.getComponent(), e.getX(), e.getY());
}
 
Example 4
Source File: RMenuItemTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private List<JMenuItem> getMenuComponents(JMenu AMenu) {
    Component[] components = AMenu.getMenuComponents();
    List<JMenuItem> items = new ArrayList<JMenuItem>();
    for (int j = 0; j < components.length; j++) {
        if (!(components[j] instanceof AbstractButton)) {
            continue;
        }
        items.add((JMenuItem) components[j]);
    }
    return items;
}
 
Example 5
Source File: MenuEditLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void configureMenu(final JComponent parent, final JMenu menu) {
    // make sure it will draw it's border so we can have rollovers and selection
    menu.setBorderPainted(true);
    //install the wrapper icon if not a toplevel JMenu
    if(!isTopLevelMenu(menu)) {
        if(!(menu.getIcon() instanceof WrapperIcon)) {
            menu.setIcon(new WrapperIcon(menu.getIcon()));
        }
    }
    
    // configure the maps and popups
    JPopupMenu popup = menu.getPopupMenu();
    menuPopupUIMap.put(menu, popup.getUI());
    popup.setUI(new VisualDesignerPopupMenuUI(this, popup.getUI()));
    
    // get all of the components in this menu
    Component[] subComps = menu.getMenuComponents();
    // if this isn't the first time this menu has been opened then the sub components
    // will have been moved to the popupPanel already, so we will find them there instead.
    JPanel popupPanel = getPopupFactory().containerMap.get(menu);
    if(popupPanel != null) {
        subComps = popupPanel.getComponents();
    }
    
    RADVisualContainer menuRAD = (RADVisualContainer) formDesigner.getMetaComponent(menu);
    registerForm(menuRAD,menu);
    
    // recurse for sub-menus
    for(Component c : subComps) {
        if(c instanceof JMenu) {
            configureMenu(menu, (JMenu)c);
            RADComponent rad = formDesigner.getMetaComponent(c);
            registerForm((RADVisualContainer)rad,(JMenu)c);
        } else {
            configureMenuItem(menu, (JComponent) c);
        }
    }
}
 
Example 6
Source File: DynamicMenuEnabler.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void menuSelected(MenuEvent event) {
    JMenu menu = (JMenu) event.getSource();
    for (Component component : menu.getMenuComponents()) {
        if (component instanceof JMenuItem) {
            JMenuItem item   = (JMenuItem) component;
            Action    action = item.getAction();
            if (action instanceof Command) {
                ((Command) action).adjust();
            }
        }
    }
}
 
Example 7
Source File: Command.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
public static void adjustMenuTree(JMenu menu) {
    for (Component component : menu.getMenuComponents()) {
        if (component instanceof JMenu) {
            adjustMenuTree((JMenu) component);
        } else if (component instanceof JMenuItem) {
            JMenuItem item   = (JMenuItem) component;
            Action    action = item.getAction();
            if (action instanceof Command) {
                ((Command) action).adjust();
            }
        }
    }
}
 
Example 8
Source File: MainFrame.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Removes duplicated separators from a JMenu
 *
 * @param menu the menu
 */
private static void removeDuplicatedSeparators(JMenu menu) {
	int separatorCount = 0;
	for (Component component : menu.getMenuComponents()) {
		if (component instanceof JPopupMenu.Separator) {
			separatorCount++;
		} else {
			separatorCount = 0;
		}
		if (separatorCount > 1) {
			menu.remove(component);
		}
	}
}
 
Example 9
Source File: MainFrame.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private void enableMenu(final JMenu menu) {
  menu.setEnabled(true);
  for (final Component c : menu.getMenuComponents()) {
    if (c instanceof JMenu) {
      enableMenu((JMenu) c);
    } else if (c instanceof JMenuItem) {
      ((JMenuItem) c).setEnabled(true);
    }
  }
}
 
Example 10
Source File: NbCodeFoldingAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override JPopupMenu getPopupMenu(){
    JPopupMenu pm = super.getPopupMenu();
    pm.removeAll();
    boolean enable = false;
    BaseKit bKit = getKit();
    if (bKit==null) bKit = BaseKit.getKit(NbEditorKit.class);
    if (bKit!=null){
        Action action = bKit.getActionByName(NbEditorKit.generateFoldPopupAction);
        if (action instanceof BaseAction) {
            JTextComponent component = NbCodeFoldingAction.getComponent();
            MimePath mimePath = component == null ? MimePath.EMPTY : MimePath.parse(DocumentUtilities.getMimeType(component));
            Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
            boolean foldingAvailable = prefs.getBoolean(SimpleValueNames.CODE_FOLDING_ENABLE, EditorPreferencesDefaults.defaultCodeFoldingEnable);
            
            if (foldingAvailable){
                ActionMap contextActionmap = org.openide.util.Utilities.actionsGlobalContext().lookup(ActionMap.class);
                if (contextActionmap!=null){
                    foldingAvailable = contextActionmap.get(BaseKit.collapseFoldAction) != null &&
                        component != null;

                    if (!foldingAvailable){
                        bKit = BaseKit.getKit(NbEditorKit.class);
                        if (bKit!=null){
                            Action defaultAction = bKit.getActionByName(NbEditorKit.generateFoldPopupAction);
                            if (defaultAction instanceof BaseAction) action = defaultAction;
                        }
                    }
                }
            }

            JMenu menu = (JMenu)((BaseAction)action).getPopupMenuItem(foldingAvailable ? component : null);
            if (menu!=null){
                Component comps[] = menu.getMenuComponents();
                for (int i=0; i<comps.length; i++){
                    pm.add(comps[i]);
                    if (comps[i].isEnabled() && !(comps[i] instanceof JSeparator)) {
                        enable = true;
                    }
                }
            }
        }
    }
    setEnabled(enable);
    pm.pack();
    return pm;
}