- Timestamp:
- 2020-01-05T16:36:31+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/HideableButton.java
r8510 r15633 23 23 boolean isButtonVisible(); 24 24 25 boolean isExpert(); 26 25 27 void setShowHideButtonListener(ShowHideButtonListener l); 26 28 } -
trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java
r12846 r15633 162 162 163 163 @Override 164 public boolean isExpert() { 165 return isExpert; 166 } 167 168 @Override 164 169 public void setShowHideButtonListener(ShowHideButtonListener l) { 165 170 listener = l; -
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 -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r15445 r15633 44 44 import javax.swing.plaf.basic.BasicSplitPaneUI; 45 45 46 import org.openstreetmap.josm.actions.ExpertToggleAction; 46 47 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 47 48 import org.openstreetmap.josm.actions.mapmode.DrawAction; … … 671 672 JPopupMenu menu = new JPopupMenu(); 672 673 for (HideableButton b : buttons) { 673 final HideableButton t = b; 674 menu.add(new JCheckBoxMenuItem(new AbstractAction() { 675 { 676 putValue(NAME, t.getActionName()); 677 putValue(SMALL_ICON, t.getIcon()); 678 putValue(SELECTED_KEY, t.isButtonVisible()); 679 putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button")); 680 } 681 682 @Override 683 public void actionPerformed(ActionEvent e) { 684 if ((Boolean) getValue(SELECTED_KEY)) { 685 t.showButton(); 686 } else { 687 t.hideButton(); 674 if (!b.isExpert() || ExpertToggleAction.isExpert()) { 675 final HideableButton t = b; 676 menu.add(new JCheckBoxMenuItem(new AbstractAction() { 677 { 678 putValue(NAME, t.getActionName()); 679 putValue(SMALL_ICON, t.getIcon()); 680 putValue(SELECTED_KEY, t.isButtonVisible()); 681 putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button")); 688 682 } 689 validateToolBarsVisibility(); 690 } 691 })); 683 684 @Override 685 public void actionPerformed(ActionEvent e) { 686 if ((Boolean) getValue(SELECTED_KEY)) { 687 t.showButton(); 688 } else { 689 t.hideButton(); 690 } 691 validateToolBarsVisibility(); 692 } 693 })); 694 } 692 695 } 693 696 if (button != null && button.isShowing()) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r14903 r15633 266 266 windowMenuItem = MainMenu.addWithCheckbox(MainApplication.getMenu().windowMenu, 267 267 (JosmAction) getToggleAction(), 268 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG );268 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG, false, true); 269 269 } 270 270
Note:
See TracChangeset
for help on using the changeset viewer.