Changeset 15633 in josm for trunk/src/org/openstreetmap/josm/gui/MainMenu.java
- Timestamp:
- 2020-01-05T16:36:31+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r15445 r15633 448 448 final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu(); 449 449 for (int i = 0; i < m.getComponentCount()-1; i++) { 450 if (!(m.getComponent(i) instanceof JSeparator)) { 451 continue; 450 // hide separator if the next menu item is one as well 451 if (m.getComponent(i) instanceof JSeparator && m.getComponent(i+1) instanceof JSeparator) { 452 ((JSeparator) m.getComponent(i)).setVisible(false); 452 453 } 453 // hide separator if the next menu item is one as well454 ((JSeparator) m.getComponent(i)).setVisible(!(m.getComponent(i+1) instanceof JSeparator));455 454 } 456 455 // hide separator at the end of the menu … … 566 565 if (action.getShortcut().isAutomatic()) 567 566 return null; 568 int i = getInsertionIndexForGroup(menu, group.ordinal() );567 int i = getInsertionIndexForGroup(menu, group.ordinal(), false); 569 568 JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i); 570 569 KeyStroke ks = action.getShortcut().getKeyStroke(); … … 587 586 */ 588 587 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) { 589 int i = getInsertionIndexForGroup(menu, group.ordinal()); 588 return addWithCheckbox(menu, action, group, false, false); 589 } 590 591 /** 592 * Add a JosmAction to a menu and automatically prints accelerator if available. 593 * Also adds a checkbox that may be toggled. 594 * @param <E> group enum item type 595 * @param menu to add the action to 596 * @param action the action that should get a menu item 597 * @param group the item should be added to. Groups are split by a separator. Use 598 * one of the enums that are defined for some of the menus to tell in which 599 * group the item should go. 600 * @param isEntryExpert whether the entry should only be visible if the expert mode is activated 601 * @param isGroupSeparatorExpert whether the group separator should only be visible if the expert mode is activated 602 * @return The created menu item 603 * @since 15633 604 */ 605 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group, 606 boolean isEntryExpert, boolean isGroupSeparatorExpert) { 607 int i = getInsertionIndexForGroup(menu, group.ordinal(), isGroupSeparatorExpert); 590 608 final JCheckBoxMenuItem mi = (JCheckBoxMenuItem) menu.add(new JCheckBoxMenuItem(action), i); 591 609 final KeyStroke ks = action.getShortcut().getKeyStroke(); … … 593 611 mi.setAccelerator(ks); 594 612 } 613 if (isEntryExpert) { 614 ExpertToggleAction.addVisibilitySwitcher(mi); 615 } 595 616 return mi; 596 617 } … … 600 621 * @param menu menu 601 622 * @param group group number 623 * @param isGroupSeparatorExpert whether the added separators should only be visible if the expert mode is activated 602 624 * @return correct insertion index 603 625 */ 604 private static int getInsertionIndexForGroup(JMenu menu, int group ) {626 private static int getInsertionIndexForGroup(JMenu menu, int group, boolean isGroupSeparatorExpert) { 605 627 if (group < 0) 606 628 return -1; … … 619 641 while (group > 0) { 620 642 menu.addSeparator(); 643 if (isGroupSeparatorExpert) { 644 ExpertToggleAction.addVisibilitySwitcher(menu.getMenuComponent(menu.getMenuComponentCount() - 1)); 645 } 621 646 group--; 622 647 i++; … … 832 857 // -- changeset manager toggle action 833 858 final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManager, 834 MainMenu.WINDOW_MENU_GROUP.ALWAYS );859 MainMenu.WINDOW_MENU_GROUP.ALWAYS, true, false); 835 860 changesetManager.addButtonModel(mi.getModel()); 836 861
Note:
See TracChangeset
for help on using the changeset viewer.