Changeset 15655 in josm


Ignore:
Timestamp:
2020-01-07T20:03:45+01:00 (4 years ago)
Author:
Don-vip
Message:

see #18514 - cleanup menu groups handling

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r15649 r15655  
    2828import javax.swing.AbstractAction;
    2929import javax.swing.JCheckBoxMenuItem;
    30 import javax.swing.JMenuItem;
    3130import javax.swing.JOptionPane;
    3231import javax.swing.SwingUtilities;
     
    6160import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
    6261import org.openstreetmap.josm.gui.NavigatableComponent;
    63 import org.openstreetmap.josm.gui.WindowMenu;
    6462import org.openstreetmap.josm.gui.draw.MapPath2D;
    6563import org.openstreetmap.josm.gui.layer.Layer;
     
    189187    private JCheckBoxMenuItem addMenuItem() {
    190188        int n = MainApplication.getMenu().editMenu.getItemCount();
    191         for (int i = n-1; i > 0; i--) {
    192             JMenuItem item = MainApplication.getMenu().editMenu.getItem(i);
    193             if (item != null && item.getAction() != null && item.getAction() instanceof SnapChangeAction) {
    194                 MainApplication.getMenu().editMenu.remove(i);
    195             }
    196         }
    197         return MainMenu.addWithCheckbox(MainApplication.getMenu().editMenu, snapChangeAction, WindowMenu.WINDOW_MENU_GROUP.VOLATILE);
     189        return MainMenu.addWithCheckbox(MainApplication.getMenu().editMenu, snapChangeAction, n-5, false);
    198190    }
    199191
     
    13761368        super.destroy();
    13771369        finishDrawing();
     1370        MainApplication.getMenu().editMenu.remove(snapCheckboxMenuItem);
    13781371        snapChangeAction.destroy();
    13791372    }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r15649 r15655  
    2727
    2828import javax.swing.JCheckBoxMenuItem;
    29 import javax.swing.JMenuItem;
    3029
    3130import org.openstreetmap.josm.actions.JosmAction;
     
    5150import org.openstreetmap.josm.gui.MapFrame;
    5251import org.openstreetmap.josm.gui.MapView;
    53 import org.openstreetmap.josm.gui.WindowMenu;
    5452import org.openstreetmap.josm.gui.draw.MapViewPath;
    5553import org.openstreetmap.josm.gui.draw.SymbolShape;
     
    241239    public void destroy() {
    242240        super.destroy();
     241        MainApplication.getMenu().editMenu.remove(dualAlignCheckboxMenuItem);
    243242        dualAlignChangeAction.destroy();
    244243    }
     
    246245    private JCheckBoxMenuItem addDualAlignMenuItem() {
    247246        int n = MainApplication.getMenu().editMenu.getItemCount();
    248         for (int i = n-1; i > 0; i--) {
    249             JMenuItem item = MainApplication.getMenu().editMenu.getItem(i);
    250             if (item != null && item.getAction() != null && item.getAction() instanceof DualAlignChangeAction) {
    251                 MainApplication.getMenu().editMenu.remove(i);
    252             }
    253         }
    254         return MainMenu.addWithCheckbox(MainApplication.getMenu().editMenu, dualAlignChangeAction, WindowMenu.WINDOW_MENU_GROUP.VOLATILE);
     247        return MainMenu.addWithCheckbox(MainApplication.getMenu().editMenu, dualAlignChangeAction, n-5, false);
    255248    }
    256249
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r15649 r15655  
    145145public class MainMenu extends JMenuBar {
    146146
     147    /**
     148     * The possible item groups of the Windows menu.
     149     * @see MainMenu#addWithCheckbox
     150     */
     151    public enum WINDOW_MENU_GROUP {
     152        /** Entries always displayed, at the top */
     153        ALWAYS,
     154        /** Entries displayed only for visible toggle dialogs */
     155        TOGGLE_DIALOG,
     156        /** Volatile entries displayed at the end */
     157        VOLATILE
     158    }
     159
    147160    /* File menu */
    148161    /** File / New Layer **/
     
    556569     * @param menu to add the action to
    557570     * @param action the action that should get a menu item
    558      * @param group the item should be added to. Groups are split by a separator.
    559      *        0 is the first group, -1 will add the item to the end.
     571     * @param group the item should be added to. Groups are split by a separator. null will add the item to the end.
    560572     * @return The created menu item
    561573     */
     
    563575        if (action.getShortcut().isAutomatic())
    564576            return null;
    565         int i = getInsertionIndexForGroup(menu, group.ordinal(), false);
     577        int i = group != null ? getInsertionIndexForGroup(menu, group.ordinal(), false) : -1;
    566578        JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i);
    567579        KeyStroke ks = action.getShortcut().getKeyStroke();
     
    595607     * @param group the item should be added to. Groups are split by a separator. Use
    596608     *        one of the enums that are defined for some of the menus to tell in which
    597      *        group the item should go.
     609     *        group the item should go. null will add the item to the end.
    598610     * @param isEntryExpert whether the entry should only be visible if the expert mode is activated
    599611     * @param isGroupSeparatorExpert whether the group separator should only be visible if the expert mode is activated
     
    603615    public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group,
    604616            boolean isEntryExpert, boolean isGroupSeparatorExpert) {
    605         int i = getInsertionIndexForGroup(menu, group.ordinal(), isGroupSeparatorExpert);
     617        int i = group != null ? getInsertionIndexForGroup(menu, group.ordinal(), isGroupSeparatorExpert) : -1;
     618        return addWithCheckbox(menu, action, i, isEntryExpert);
     619    }
     620
     621    /**
     622     * Add a JosmAction to a menu and automatically prints accelerator if available.
     623     * Also adds a checkbox that may be toggled.
     624     * @param <E> group enum item type
     625     * @param menu to add the action to
     626     * @param action the action that should get a menu item
     627     * @param i the item position in the menu. -1 will add the item to the end.
     628     * @param isEntryExpert whether the entry should only be visible if the expert mode is activated
     629     * @return The created menu item
     630     * @since 15655
     631     */
     632    public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, int i, boolean isEntryExpert) {
    606633        final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(action);
    607634        final KeyStroke ks = action.getShortcut().getKeyStroke();
     
    855882        // -- changeset manager toggle action
    856883        final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManager,
    857                 WindowMenu.WINDOW_MENU_GROUP.ALWAYS, true, false);
     884                WINDOW_MENU_GROUP.ALWAYS, true, false);
    858885        changesetManager.addButtonModel(mi.getModel());
    859886
  • trunk/src/org/openstreetmap/josm/gui/WindowMenu.java

    r15649 r15655  
    1818 */
    1919public class WindowMenu extends JMenu implements ContainerListener, ExpertModeChangeListener {
    20 
    21     /**
    22      * The possible item groups of the Windows menu.
    23      * @see MainMenu#addWithCheckbox
    24      */
    25     public enum WINDOW_MENU_GROUP {
    26         /** Entries always displayed, at the top */
    27         ALWAYS,
    28         /** Entries displayed only for visible toggle dialogs */
    29         TOGGLE_DIALOG,
    30         /** Volatile entries displayed at the end */
    31         VOLATILE
    32     }
    3320
    3421    /**
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r15650 r15655  
    5454import org.openstreetmap.josm.gui.ShowHideButtonListener;
    5555import org.openstreetmap.josm.gui.SideButton;
    56 import org.openstreetmap.josm.gui.WindowMenu;
    5756import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
    5857import org.openstreetmap.josm.gui.help.HelpUtil;
     
    286285        windowMenuItem = MainMenu.addWithCheckbox(MainApplication.getMenu().windowMenu,
    287286                (JosmAction) getToggleAction(),
    288                 WindowMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG, isExpert, true);
     287                MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG, isExpert, true);
    289288    }
    290289
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r15649 r15655  
    6060import org.openstreetmap.josm.gui.MainMenu;
    6161import org.openstreetmap.josm.gui.ScrollViewport;
    62 import org.openstreetmap.josm.gui.WindowMenu;
    6362import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    6463import org.openstreetmap.josm.gui.dialogs.relation.actions.AbstractRelationEditorAction;
     
    766765        };
    767766        focusAction.putValue("relationEditor", re);
    768         return MainMenu.add(MainApplication.getMenu().windowMenu, focusAction, WindowMenu.WINDOW_MENU_GROUP.VOLATILE);
     767        return MainMenu.add(MainApplication.getMenu().windowMenu, focusAction, MainMenu.WINDOW_MENU_GROUP.VOLATILE);
    769768    }
    770769
  • trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java

    r15649 r15655  
    3737import org.openstreetmap.josm.gui.MainApplication;
    3838import org.openstreetmap.josm.gui.MainMenu;
    39 import org.openstreetmap.josm.gui.WindowMenu;
    4039import org.openstreetmap.josm.gui.util.WindowGeometry;
    4140import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
     
    215214            }
    216215            if (windowMenuItem == null && visible) {
    217                 windowMenuItem = MainMenu.add(menu.windowMenu, FOCUS_ACTION, WindowMenu.WINDOW_MENU_GROUP.VOLATILE);
     216                windowMenuItem = MainMenu.add(menu.windowMenu, FOCUS_ACTION, MainMenu.WINDOW_MENU_GROUP.VOLATILE);
    218217            }
    219218        }
Note: See TracChangeset for help on using the changeset viewer.