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

The following examples show how to use javax.swing.JMenu#getItemCount() . 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: ViewHelper.java    From FastCopy with Apache License 2.0 6 votes vote down vote up
/**
 * Resgier allthe components in the jFrame.
 *
 * @param c
 * @return
 */
public static List<Component> getAllComponents(final Container c) {
	Component[] comps = c.getComponents();
	List<Component> compList = new ArrayList<Component>();
	for (Component comp : comps) {
		compList.add(comp);

		if (comp instanceof JMenu) {
			JMenu menu = (JMenu) comp;
			for (int i = 0; i < menu.getItemCount(); i++) {
				if (menu.getItem(i)!=null)
					compList.add(menu.getItem(i));
			}
		}
		else if (comp instanceof Container)
			compList.addAll(getAllComponents((Container) comp));

	}
	return compList;
}
 
Example 2
Source File: MainMenu.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
@Override
public void currentIntervalChanged(Interval interval) {
    JMenu intervals = getMenu(2);

    for (int i = 0; i < intervals.getItemCount(); i++) {
        JMenuItem item = intervals.getItem(i);

        if ((item != null) && (item.getClass() == IntervalMenuItem.class)) {
            IntervalMenuItem intervalItem = (IntervalMenuItem) item;

            if (intervalItem.getInterval().equals(interval)) {
                intervalItem.setSelected(true);
                break;
            }
        }
    }
}
 
Example 3
Source File: ComboMenuBar.java    From ChatGameFontificator with The Unlicense 6 votes vote down vote up
private void setListener(JMenuItem item, ActionListener listener)
{
    if (item instanceof JMenu)
    {
        JMenu menu = (JMenu) item;
        int n = menu.getItemCount();
        for (int i = 0; i < n; i++)
        {
            setListener(menu.getItem(i), listener);
        }
    }
    else if (item != null)
    {
        item.addActionListener(listener);
    }
}
 
Example 4
Source File: AbstractMenuCreator.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
/**
 * Add submenus to a menu.
 * 
 * @param menu Menu.
 * @param items Submenus.
 */
public void addSubmenus(JPopupMenu menu, List<JMenuItem> items) {
  Configuration config = Configuration.getConfiguration();
  final int maxElements = Math.max(config.getInt(null, ConfigurationValueInteger.MENU_SIZE), 10);
  if (items.size() <= maxElements) {
    for (JMenuItem item : items) {
      menu.add(item);
    }
    return;
  }
  int i = 0;
  while (i < items.size()) {
    JMenu currentMenu = new JMenu(items.get(i).getText());
    menu.add(currentMenu);
    while ((i < items.size()) && (currentMenu.getItemCount() < maxElements)) {
      currentMenu.add(items.get(i));
      i++;
    }
  }
}
 
Example 5
Source File: LuckArrowIcon.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public Image getPreImg(Component c, ButtonModel model)
{
    JMenu menu = (JMenu) c;

    if (menu.getItemCount() > 0)
    {
        if (model.isSelected())
        {
            return getRollverImg();
        }
        else
        {
            return getNormalImg();
        }
    }

    return null;
}
 
Example 6
Source File: OSPFrame.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Removes a menu item with the given name from the menu bar and returns the removed item.
 * Returns null if menu item does not exist.
 *
 * @param menuName String
 * @return JMenu
 */
public JMenuItem removeMenuItem(String menuName, String itemName) {
  JMenu menu = getMenu(menuName);
  if(menu==null) {
    return null;
  }
  itemName = itemName.trim();
  JMenuItem item = null;
  for(int i = 0; i<menu.getItemCount(); i++) {
    JMenuItem next = menu.getItem(i);
    if(next.getText().trim().equals(itemName)) {
      item = next;
      menu.remove(i);
      break;
    }
  }
  return item;
}
 
Example 7
Source File: AbstractMenuFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateMenu (JMenu menu) {
        ActionProvider provider = getEngine().getActionProvider();
        Map context = getEngine().getContextProvider().getContext();
        String containerCtx = (String) menu.getClientProperty(KEY_CONTAINERCONTEXT);
        boolean isDynamic = getEngine().getContainerProvider().isDynamicContext(
            ContainerProvider.TYPE_MENU, containerCtx);
        
        String[] actions = provider.getActionNames(containerCtx);
//        System.err.println("Updating menu " + containerCtx + "actions: " + Arrays.asList(actions));
        
        int count = menu.getItemCount();
//        System.err.println("Item count = " + count);
        //XXX for dynamic menus, we'll need to compare the contents of the
        //menu with the list of strings, and add/prune
        
        for (int i=0; i < count; i++) {
            JMenuItem item = menu.getItem(i);
            if (item != null) {
                String action = (String) item.getClientProperty (KEY_ACTION);
                configureMenuItem (item, containerCtx, action, provider, context);
            }
        }
    }
 
Example 8
Source File: DynamicMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 9
Source File: ShelveChangesMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 10
Source File: DynamicMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 11
Source File: Debug.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Construct cascading pull-aside menus using the values of the debug flags
 * in the Preferences object.
 * 
 * @param topMenu attach the menus as children of this one.
 */
public static void constructMenu(JMenu topMenu) {
  if (debug)
    System.out.println("Debug.constructMenu ");

  if (topMenu.getItemCount() > 0)
    topMenu.removeAll();

  try {
    addToMenu(topMenu, store); // recursive
  } catch (BackingStoreException e) {
  }

  topMenu.revalidate();
}
 
Example 12
Source File: ProfilerPlugins.java    From netbeans with Apache License 2.0 5 votes vote down vote up
List<JMenuItem> menuItems() {
    List<JMenuItem> menus = new ArrayList();
    
    if (plugins != null) for (ProfilerPlugin plugin : plugins) {
        try {
            JMenu menu = new JMenu(plugin.getName());
            plugin.createMenu(menu);
            if (menu.getItemCount() > 0) menus.add(menu);
        } catch (Throwable t) {
            handleThrowable(plugin, t);
        }
    }
    
    return menus;
}
 
Example 13
Source File: MenuComboBox.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the listener.
 *
 * @param item the item
 * @param listener the listener
 */
private void setListener(JMenuItem item, ActionListener listener) {
    if (item instanceof JMenu) {
        JMenu localMenu = (JMenu) item;
        int n = localMenu.getItemCount();
        for (int i = 0; i < n; i++) {
            setListener(localMenu.getItem(i), listener);
        }
    } else if (item != null) { // null means separator
        item.addActionListener(listener);
    }
}
 
Example 14
Source File: ActionSubMenuStructure.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
public final void addSubMenus(JPopupMenu menu) {
	List<T> actionKeys = getActionKeys(existingSubMenus.keySet());
	for(T actionKey : actionKeys) {
		JMenu actionMenu = existingSubMenus.get(actionKey);
		if (actionMenu.getItemCount() > 0) {
			menu.add(actionMenu);
		}
	}
}
 
Example 15
Source File: LogParserView.java    From yGuard with MIT License 5 votes vote down vote up
private void updateRecent( final UiContext context, final File path ) {
  final JMenu menu = context.recentMenu;
  final JMenuItem ami = getItem();
  if (ami != null) {
    for (int i = 0, n = menu.getItemCount(); i < n; ++i) {
      final JMenuItem mi = menu.getItem(i);
      if (mi == ami) {
        menu.remove(i);
        menu.add(ami, 0);
        break;
      }
    }
  }
}
 
Example 16
Source File: ComboMenuBar.java    From ChatGameFontificator with The Unlicense 5 votes vote down vote up
private void applyFilter(String filterText)
{
    resetMenu();

    for (JMenu menuFolder : allMenuFolders.keySet())
    {
        boolean atLeastOneHit = false;
        boolean matchesMenu = menuFolder.getText().toLowerCase().contains(filterText.toLowerCase().trim());

        for (int i = 0; i < menuFolder.getItemCount(); i++)
        {
            GameFontMenuItem gfmi = (GameFontMenuItem) menuFolder.getItem(i);
            final boolean matchesGame = gfmi.isMatchingFilterGame(filterText);
            final boolean matchesGenre = gfmi.isMatchingFilterGenre(filterText);
            final boolean matchesSystem = gfmi.isMatchingFilterSystem(filterText);

            boolean hit = matchesMenu || matchesGame || matchesGenre || matchesSystem;

            gfmi.setVisible(hit);
            if (hit)
            {
                atLeastOneHit = true;
            }
        }
        allMenuItems.get(menuFolder).setFiltered(!atLeastOneHit);
    }

    setMenuItemFilterVisibility();
}
 
Example 17
Source File: Utils.java    From j-j-jvm with Apache License 2.0 5 votes vote down vote up
public static final void changeMenuItemsState(final JMenu menu, final boolean enableState) {
  final int size = menu.getItemCount();
  for (int i = 0; i < size; i++) {
    final JMenuItem item = menu.getItem(i);
    item.setEnabled(enableState);
  }
}
 
Example 18
Source File: LogParserView.java    From yGuard with MIT License 5 votes vote down vote up
static void addRecent( final UiContext context, final File path ) {
  final JMenu menu = context.recentMenu;
  final int n = menu.getItemCount();
  if (n > 9) {
    menu.remove(n - 1);
  }

  final RecentAction ra = new RecentAction(context, path);
  final JMenuItem jc = menu.add(ra);
  ra.setItem(jc);
  if (n > 0) {
    menu.remove(menu.getItemCount() - 1);
    menu.add(jc, 0);
  }
}
 
Example 19
Source File: ActionManager.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Register all actions as listed in the descriptor files, and organize them
 * according to the various domains defined.
 * There is one pull-down menu generated for each domain found.
 */
public void registerAllActions ()
{
    // Insert an initial separator, to let user easily grab the toolBar
    toolBar.addSeparator();

    DomainLoop:
    for (String domain : Actions.getDomainNames()) {
        // Create dedicated menu for this range, if not already existing
        JMenu menu = menuMap.get(domain);

        if (menu == null) {
            logger.debug("Creating menu:{}", domain);
            menu = new SeparableMenu(domain);
            menuMap.put(domain, menu);
        } else {
            logger.debug("Augmenting menu:{}", domain);
        }

        // Proper menu decoration
        ResourceMap resource = OmrGui.getApplication().getContext().getResourceMap(
                Actions.class);
        menu.setText(domain); // As default
        menu.setName(domain);

        // Register all actions in the given domain
        registerDomainActions(domain, menu);
        resource.injectComponents(menu); // Localized

        SeparableMenu.trimSeparator(menu); // No separator at end of menu

        // Smart insertion of the menu into the menu bar, and separators into the toolBar
        if (menu.getItemCount() > 0) {
            final int toolCount = toolBar.getComponentCount();

            if (toolCount > 0) {
                Component comp = toolBar.getComponent(toolCount - 1);

                if (!(comp instanceof JToolBar.Separator)) {
                    toolBar.addSeparator();
                }
            }

            menuBar.add(menu);
        }
    }
}
 
Example 20
Source File: CInstructionMenu.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * Adds the instruction menu for the clicked instruction.
 *
 * @param model The graph model that provides information about the graph.
 * @param node The node whose menu is created.
 * @param instruction The instruction that was clicked on.
 * @param extensions The list of code node extensions that extend the menu.
 */
public CInstructionMenu(final CGraphModel model, final NaviNode node,
    final INaviInstruction instruction, final List<ICodeNodeExtension> extensions) {
  super("Instruction" + " " + ZyInstructionBuilder.buildInstructionLine(instruction,
      model.getGraph().getSettings(),
      new CDefaultModifier(model.getGraph().getSettings(), model.getDebuggerProvider())).first());

  final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();

  final IDebugger debugger = CGraphDebugger.getDebugger(model.getDebuggerProvider(), instruction);

  if (debugger != null) {
    final INaviModule module = instruction.getModule();

    final UnrelocatedAddress instructionAddress =
        new UnrelocatedAddress(instruction.getAddress());

    add(CActionProxy.proxy(new CActionToggleBreakpoint(
        debugger.getBreakpointManager(), module, instructionAddress)));

    final BreakpointAddress relocatedAddress =
        new BreakpointAddress(module, instructionAddress);

    if (debugger.getBreakpointManager().hasBreakpoint(BreakpointType.REGULAR, relocatedAddress)) {
      add(CActionProxy.proxy(new CActionToggleBreakpointStatus(
          debugger.getBreakpointManager(), module, instructionAddress)));
    }

    addSeparator();
  }

  for (final ICodeNodeExtension extension : extensions) {
    extension.extendInstruction(this, codeNode, instruction);
  }

  try {
    try {
      final JMenu operandsMenu = new COperandsMenu(codeNode, instruction, extensions);

      if (operandsMenu.getItemCount() != 0) {
        add(operandsMenu);
      }
    } catch (final MaybeNullException exception) {
      // No operands menu to add
    }
  } catch (final InternalTranslationException e) {
    CUtilityFunctions.logException(e);
  }

  addSeparator();

  final JMenu advancedMenu = new JMenu("Advanced");

  advancedMenu.add(CActionProxy.proxy(
      new CActionDeleteInstruction(model.getParent(), model.getGraph(), node, instruction)));
  advancedMenu.add(CActionProxy.proxy(
      new CActionSplitAfter(model.getGraph().getRawView(), codeNode, instruction)));
  advancedMenu.add(CActionProxy.proxy(new CActionShowReilCode(model.getParent(), instruction)));

  add(advancedMenu);
}