/** * Support the subscript operator for JMenu. * * @param self a JMenu * @param index the index of the menu component to get * @return the menu component at the given index * @since 1.6.4 */ public static Component getAt(JMenu self, int index) { return self.getMenuComponent(index); }
@Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { Component componentSource = (Component) e.getSource(); JPopupMenu menu = new JPopupMenu(); for (int position = 0 ; position < MediatorGui.menubar().getMenuView().getMenuComponentCount() ; position++) { // Fix #35348: SerializationException on clone() try { JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorGui.menubar().getMenuView().getMenuComponent(position)); menu.add(itemMenu); final int positionFinal = position; itemMenu.addActionListener(actionEvent -> MediatorGui.tabManagers().setSelectedIndex(positionFinal)); } catch (SerializationException ex) { LOGGER.error(ex, ex); } } menu.show(componentSource, e.getX(), e.getY()); menu.setLocation( ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? e.getXOnScreen() - menu.getWidth() : e.getXOnScreen(), e.getYOnScreen() ); } }
/** * Figures out what index (from 0 to WINDOW_MENU_MAX_SIZE-1) this item is in * the window menu. * <p> * @return -1 if this item isn't showing. */ protected int getIndex() { for (int i = 0; i < WINDOW_MENU_MAX_SIZE && i < parentMenu.getMenuComponentCount() - PRECEDING_WINDOW_MENU_ITEMS - SUBSEQUENT_WINDOW_MENU_ITEMS; i++) { if (this == parentMenu.getMenuComponent(i + PRECEDING_WINDOW_MENU_ITEMS)) { return i; } } return -1; }
/** * Support the subscript operator for JMenu. * * @param self a JMenu * @param index the index of the menu component to get * @return the menu component at the given index * @since 1.6.4 */ public static Component getAt(JMenu self, int index) { return self.getMenuComponent(index); }
@Override public void addSeparator() { int count = target.getMenuComponentCount(); boolean canAddSeparator = count != 0 && target.getMenuComponent(count-1).getClass() != JPopupMenu.Separator.class; if ( canAddSeparator ) target.addSeparator(); }
/** * Support the subscript operator for JMenu. * * @param self a JMenu * @param index the index of the menu component to get * @return the menu component at the given index * @since 1.6.4 */ public static Component getAt(JMenu self, int index) { return self.getMenuComponent(index); }
@Override public void addSeparator() { int count = target.getMenuComponentCount(); boolean canAddSeparator = count != 0 && target.getMenuComponent(count-1).getClass() != JPopupMenu.Separator.class; if ( canAddSeparator ) target.addSeparator(); }
/** * Support the subscript operator for JMenu. * * @param self a JMenu * @param index the index of the menu component to get * @return the menu component at the given index * @since 1.6.4 */ public static Component getAt(JMenu self, int index) { return self.getMenuComponent(index); }
private static <T extends Component> T findMenuComponent(JMenu menu, String menuComponentName, Class<T> componentClass) { for (int i = 0; i < menu.getMenuComponentCount(); i++) { Component component = menu.getMenuComponent(i); if (menuComponentName.equals(component.getName()) && componentClass.isInstance(component)) return componentClass.cast(component); } return null; }
@Override public void execute() { if (MediatorGui.managerDatabase() == null) { LOGGER.error("Unexpected unregistered MediatorGui.managerDatabase() in "+ this.getClass()); } MediatorGui.managerDatabase().getMenuStrategy().setText(StrategyInjection.ERROR.toString()); JMenu menuError = (JMenu) MediatorGui.managerDatabase().getMenuStrategy().getMenuComponent(2); int indexError = StrategyInjection.ERROR.instance().getIndexMethod(); String nameError = MediatorModel.model().getVendor().instance().getXmlModel().getStrategy().getError().getMethod().get(indexError).getName(); for (int i = 0 ; i < MediatorGui.managerDatabase().getMenuStrategy().getItemCount() ; i++) { // Fix #44635: ArrayIndexOutOfBoundsException on getItem() try { if (menuError.getItem(i).getText().equals(nameError)) { menuError.getItem(i).setSelected(true); MediatorGui.managerDatabase().getMenuStrategy().setText(nameError); break; } } catch (ArrayIndexOutOfBoundsException e) { LOGGER.error(e, e); } } }
/** * Remove any potential orphan separator at the end of the menu. * * @param menu the menu to purge */ public static void trimSeparator (JMenu menu) { int count = menu.getMenuComponentCount(); if ((count > 0) && menu.getMenuComponent(count - 1) instanceof JSeparator) { menu.remove(count - 1); } } }
@ScriptFunction(jsDoc = CHILD_JSDOC, params = {"index"}) @Override public JComponent child(int aIndex) { return (JComponent) super.getMenuComponent(aIndex); }
private static void updateMenu(final JMenu _m,final String actionCommand){ for (int i = _m.getMenuComponentCount() - 1; i >= 0; i--) { if (_m.getMenuComponent(i) instanceof JMenuItem) { final JMenuItem it = (JMenuItem) _m.getMenuComponent(i); it.setSelected(it.getActionCommand().equals(actionCommand)); } } }
/** * Make menu scrollable * @param menu {@link JMenu} */ public static void makeScrollableMenu(JMenu menu) { if (menu.getItemCount() > 0 && !GraphicsEnvironment.isHeadless()) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // We use 80% of height int maxItems = (int)Math.round( screenSize.getHeight()*0.8/menu.getMenuComponent(0).getPreferredSize().getHeight()); MenuScroller.setScrollerFor(menu, maxItems, 200); } }
JMenuBar menubar1 = getJMenuBar(); for (int i = 0; i < menubar1.getMenuCount(); i++) { JMenu menu1 = menubar1.getMenu(i); System.out.println("Menu:" + menu1.getText()); for (int j = 0; j < menu1.getMenuComponentCount(); j++) { java.awt.Component comp = menu1.getMenuComponent(j); if (comp instanceof JMenuItem) { JMenuItem menuItem1 = (JMenuItem) comp; System.out.println("MenuItem:" + menuItem1.getText()); } } }
@Override public void addMenuSeparator(final double gravity) { final int index = getInsertLocation("-", gravity); menu.insertSeparator(index); final Component separator = menu.getMenuComponent(index); componentGravity.put(separator, gravity); logger.debug("Inserted menu separator with gravity: " + gravity); }
JMenuBar menubar1 = getJMenuBar(); for (int i = 0; i < menubar1.getMenuCount(); i++) { JMenu menu1 = menubar1.getMenu(i); System.out.println("Menu:" + menu1.getText()); for (int j = 0; j < menu1.getMenuComponentCount(); j++) { java.awt.Component comp = menu1.getMenuComponent(j); if (comp instanceof JMenuItem) { JMenuItem menuItem1 = (JMenuItem) comp; System.out.println("MenuItem:" + menuItem1.getText()); } } }
public void contentsChanged(ListDataEvent e) { for (int i = e.getIndex0(); i <= e.getIndex1(); i++) { if (i >= 0 && i < menu.getMenuComponentCount()) { BaseRoute route = formatAndRoutesModel.getRoute(i); JMenuItem menuItem = (JMenuItem) menu.getMenuComponent(i); menuItem.setText(shortenRouteName(route)); } } } });
@Override public void addNotify() { super.addNotify(); float size = Driver.getFontSize(); JMenuBar menubar = getJMenuBar(); if (menubar != null) { menubar.setFont(menubar.getFont().deriveFont(size)); for (int i = 0; i < menubar.getMenuCount(); i++) { for (int j = 0; j < menubar.getMenu(i).getMenuComponentCount(); j++) { Component temp = menubar.getMenu(i).getMenuComponent(j); temp.setFont(temp.getFont().deriveFont(size)); } } mainFrameTree.updateFonts(size); } }
public void intervalRemoved(ListDataEvent e) { for (int i = e.getIndex1(); i >= e.getIndex0(); i--) { JMenuItem menuItem = i < menu.getMenuComponentCount() ? (JMenuItem) menu.getMenuComponent(i) : null; if (menuItem != null) { MergePositionListAction action = (MergePositionListAction) menuItem.getAction(); action.dispose(); menuItem.setAction(null); } if (menu.getItemCount() > i) menu.remove(i); } menu.setEnabled(formatAndRoutesModel.getSize() > 1); }