javax.swing.JMenu#getItemCount ( )源码实例Demo

下面列出了javax.swing.JMenu#getItemCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: AbstractMenuFactory.java
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);
            }
        }
    }
 
源代码2 项目: osp   文件: OSPFrame.java
/**
 * 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;
}
 
源代码3 项目: FastCopy   文件: ViewHelper.java
/**
 * 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;
}
 
源代码4 项目: littleluck   文件: LuckArrowIcon.java
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;
}
 
源代码5 项目: wpcleaner   文件: AbstractMenuCreator.java
/**
 * 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++;
    }
  }
}
 
源代码6 项目: ChatGameFontificator   文件: ComboMenuBar.java
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);
    }
}
 
源代码7 项目: nmonvisualizer   文件: MainMenu.java
@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;
            }
        }
    }
}
 
源代码8 项目: netcdf-java   文件: Debug.java
/**
 * 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();
}
 
源代码9 项目: yGuard   文件: LogParserView.java
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);
  }
}
 
源代码10 项目: yGuard   文件: LogParserView.java
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;
      }
    }
  }
}
 
源代码11 项目: netbeans   文件: ProfilerPlugins.java
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;
}
 
源代码12 项目: netbeans   文件: DynamicMenu.java
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);
}
 
源代码13 项目: netbeans   文件: DynamicMenu.java
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);
}
 
源代码14 项目: netbeans   文件: ShelveChangesMenu.java
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);
}
 
源代码15 项目: sldeditor   文件: MenuComboBox.java
/**
 * 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);
    }
}
 
源代码16 项目: WorldGrower   文件: ActionSubMenuStructure.java
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);
		}
	}
}
 
源代码17 项目: ChatGameFontificator   文件: ComboMenuBar.java
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();
}
 
源代码18 项目: j-j-jvm   文件: Utils.java
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);
  }
}
 
源代码19 项目: audiveris   文件: ActionManager.java
/**
 * 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);
        }
    }
}
 
源代码20 项目: binnavi   文件: CInstructionMenu.java
/**
 * 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);
}