Class MainMenu

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.MenuElement

    public class MainMenu
    extends javax.swing.JMenuBar
    This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu entries as member variables (sort of collect them).

    It also provides possibilities to attach new menu entries (used by plugins).

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  MainMenu.EditLayerMenuEnabler  
      static class  MainMenu.WINDOW_MENU_GROUP
      The possible item groups of the Windows menu.
      • Nested classes/interfaces inherited from class javax.swing.JMenuBar

        javax.swing.JMenuBar.AccessibleJMenuBar
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      MainMenu()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.JMenuItem add​(javax.swing.JMenu menu, JosmAction action)
      Add a JosmAction at the end of a menu.
      static javax.swing.JMenuItem add​(javax.swing.JMenu menu, JosmAction action, boolean isExpert)
      Add a JosmAction at the end of a menu.
      static javax.swing.JMenuItem add​(javax.swing.JMenu menu, JosmAction action, boolean isExpert, java.lang.Integer index)
      Add a JosmAction at the end of a menu.
      static <E extends java.lang.Enum<E>>
      javax.swing.JMenuItem
      add​(javax.swing.JMenu menu, JosmAction action, java.lang.Enum<E> group)
      Add a JosmAction to a menu.
      static javax.swing.JMenuItem addAfter​(javax.swing.JMenu menu, JosmAction actionToBeInserted, boolean isExpert, JosmAction existingMenuEntryAction)
      Add the JosmAction actionToBeInserted directly below existingMenuEntryAction.
      javax.swing.JMenu addMenu​(java.lang.String name, java.lang.String translatedName, int mnemonicKey, int position, java.lang.String relativeHelpTopic)
      Creates a menu and adds it on the given position to the main menu.
      <T extends javax.swing.JMenu>
      T
      addMenu​(T menu, java.lang.String name, int mnemonicKey, int position, java.lang.String relativeHelpTopic)
      Adds the given menu on the given position to the main menu.
      static <E extends java.lang.Enum<E>>
      javax.swing.JCheckBoxMenuItem
      addWithCheckbox​(javax.swing.JMenu menu, JosmAction action, int i, boolean isEntryExpert)
      Add a JosmAction to a menu and automatically prints accelerator if available.
      static <E extends java.lang.Enum<E>>
      javax.swing.JCheckBoxMenuItem
      addWithCheckbox​(javax.swing.JMenu menu, JosmAction action, java.lang.Enum<E> group)
      Add a JosmAction to a menu and automatically prints accelerator if available.
      static <E extends java.lang.Enum<E>>
      javax.swing.JCheckBoxMenuItem
      addWithCheckbox​(javax.swing.JMenu menu, JosmAction action, java.lang.Enum<E> group, boolean isEntryExpert, boolean isGroupSeparatorExpert)
      Add a JosmAction to a menu and automatically prints accelerator if available.
      java.util.Optional<javax.swing.JCheckBoxMenuItem> findMapModeMenuItem​(MapMode mode)
      Returns the JCheckBoxMenuItem for the given MapMode.
      java.util.List<javax.swing.JMenuItem> findMenuItems​(java.lang.String textToFind, boolean skipPresets)
      Search main menu for items with textToFind in title.
      private static void findMenuItems​(javax.swing.JMenu menu, java.lang.String textToFind, java.util.List<javax.swing.JMenuItem> result)
      Recursive walker for menu items.
      int getDefaultMenuPos()
      Returns the default position of new top-level menus.
      private static int getInsertionIndexForGroup​(javax.swing.JMenu menu, int group, boolean isGroupSeparatorExpert)
      Finds the correct insertion index for a given group and adds separators if necessary
      void initialize()
      Initialize the main menu.
      protected void showAudioMenu​(boolean showMenu)  
      • Methods inherited from class javax.swing.JMenuBar

        add, addNotify, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getHelpMenu, getMargin, getMenu, getMenuCount, getSelectionModel, getSubElements, getUI, getUIClassID, isBorderPainted, isSelected, menuSelectionChanged, paintBorder, paramString, processKeyBinding, processKeyEvent, processMouseEvent, removeNotify, setBorderPainted, setHelpMenu, setMargin, setSelected, setSelectionModel, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getDefaultMenuPos

        public int getDefaultMenuPos()
        Returns the default position of new top-level menus.
        Returns:
        the default position of new top-level menus
        Since:
        6088
      • add

        public static javax.swing.JMenuItem add​(javax.swing.JMenu menu,
                                                JosmAction action)
        Add a JosmAction at the end of a menu.

        This method handles all the shortcut handling. It also makes sure that actions that are handled by the OS are not duplicated on the menu.

        Parameters:
        menu - the menu to add the action to
        action - the action that should get a menu item
        Returns:
        the created menu item
      • add

        public static javax.swing.JMenuItem add​(javax.swing.JMenu menu,
                                                JosmAction action,
                                                boolean isExpert)
        Add a JosmAction at the end of a menu.

        This method handles all the shortcut handling. It also makes sure that actions that are handled by the OS are not duplicated on the menu.

        Parameters:
        menu - the menu to add the action to
        action - the action that should get a menu item
        isExpert - whether the entry should only be visible if the expert mode is activated
        Returns:
        the created menu item
      • add

        public static javax.swing.JMenuItem add​(javax.swing.JMenu menu,
                                                JosmAction action,
                                                boolean isExpert,
                                                java.lang.Integer index)
        Add a JosmAction at the end of a menu.

        This method handles all the shortcut handling. It also makes sure that actions that are handled by the OS are not duplicated on the menu.

        Parameters:
        menu - the menu to add the action to
        action - the action that should get a menu item
        isExpert - whether the entry should only be visible if the expert mode is activated
        index - an integer specifying the position at which to add the action
        Returns:
        the created menu item
      • addAfter

        public static javax.swing.JMenuItem addAfter​(javax.swing.JMenu menu,
                                                     JosmAction actionToBeInserted,
                                                     boolean isExpert,
                                                     JosmAction existingMenuEntryAction)
        Add the JosmAction actionToBeInserted directly below existingMenuEntryAction.

        This method handles all the shortcut handling. It also makes sure that actions that are handled by the OS are not duplicated on the menu.

        Parameters:
        menu - the menu to add the action to
        actionToBeInserted - the action that should get a menu item directly below existingMenuEntryAction
        isExpert - whether the entry should only be visible if the expert mode is activated
        existingMenuEntryAction - an action already added to the menu menu, the action actionToBeInserted is added directly below
        Returns:
        the created menu item
      • add

        public static <E extends java.lang.Enum<E>> javax.swing.JMenuItem add​(javax.swing.JMenu menu,
                                                                              JosmAction action,
                                                                              java.lang.Enum<E> group)
        Add a JosmAction to a menu.

        This method handles all the shortcut handling. It also makes sure that actions that are handled by the OS are not duplicated on the menu.

        Type Parameters:
        E - group item enum type
        Parameters:
        menu - to add the action to
        action - the action that should get a menu item
        group - the item should be added to. Groups are split by a separator. null will add the item to the end.
        Returns:
        The created menu item
      • addWithCheckbox

        public static <E extends java.lang.Enum<E>> javax.swing.JCheckBoxMenuItem addWithCheckbox​(javax.swing.JMenu menu,
                                                                                                  JosmAction action,
                                                                                                  java.lang.Enum<E> group)
        Add a JosmAction to a menu and automatically prints accelerator if available. Also adds a checkbox that may be toggled.
        Type Parameters:
        E - group enum item type
        Parameters:
        menu - to add the action to
        action - the action that should get a menu item
        group - the item should be added to. Groups are split by a separator. Use one of the enums that are defined for some of the menus to tell in which group the item should go.
        Returns:
        The created menu item
      • addWithCheckbox

        public static <E extends java.lang.Enum<E>> javax.swing.JCheckBoxMenuItem addWithCheckbox​(javax.swing.JMenu menu,
                                                                                                  JosmAction action,
                                                                                                  java.lang.Enum<E> group,
                                                                                                  boolean isEntryExpert,
                                                                                                  boolean isGroupSeparatorExpert)
        Add a JosmAction to a menu and automatically prints accelerator if available. Also adds a checkbox that may be toggled.
        Type Parameters:
        E - group enum item type
        Parameters:
        menu - to add the action to
        action - the action that should get a menu item
        group - the item should be added to. Groups are split by a separator. Use one of the enums that are defined for some of the menus to tell in which group the item should go. null will add the item to the end.
        isEntryExpert - whether the entry should only be visible if the expert mode is activated
        isGroupSeparatorExpert - whether the group separator should only be visible if the expert mode is activated
        Returns:
        The created menu item
        Since:
        15633
      • addWithCheckbox

        public static <E extends java.lang.Enum<E>> javax.swing.JCheckBoxMenuItem addWithCheckbox​(javax.swing.JMenu menu,
                                                                                                  JosmAction action,
                                                                                                  int i,
                                                                                                  boolean isEntryExpert)
        Add a JosmAction to a menu and automatically prints accelerator if available. Also adds a checkbox that may be toggled.
        Type Parameters:
        E - group enum item type
        Parameters:
        menu - to add the action to
        action - the action that should get a menu item
        i - the item position in the menu. -1 will add the item to the end.
        isEntryExpert - whether the entry should only be visible if the expert mode is activated
        Returns:
        The created menu item
        Since:
        15655
      • getInsertionIndexForGroup

        private static int getInsertionIndexForGroup​(javax.swing.JMenu menu,
                                                     int group,
                                                     boolean isGroupSeparatorExpert)
        Finds the correct insertion index for a given group and adds separators if necessary
        Parameters:
        menu - menu
        group - group number
        isGroupSeparatorExpert - whether the added separators should only be visible if the expert mode is activated
        Returns:
        correct insertion index
      • addMenu

        public javax.swing.JMenu addMenu​(java.lang.String name,
                                         java.lang.String translatedName,
                                         int mnemonicKey,
                                         int position,
                                         java.lang.String relativeHelpTopic)
        Creates a menu and adds it on the given position to the main menu.
        Parameters:
        name - the untranslated name (used as identifier for shortcut registration)
        translatedName - the translated menu name (use I18n.trc("menu", name) to allow better internationalization
        mnemonicKey - the mnemonic key to register
        position - the position in the main menu
        relativeHelpTopic - the relative help topic
        Returns:
        the newly created menu
      • addMenu

        public <T extends javax.swing.JMenu> T addMenu​(T menu,
                                                       java.lang.String name,
                                                       int mnemonicKey,
                                                       int position,
                                                       java.lang.String relativeHelpTopic)
        Adds the given menu on the given position to the main menu.
        Type Parameters:
        T - menu type
        Parameters:
        menu - the menu to add
        name - the untranslated name (used as identifier for shortcut registration)
        mnemonicKey - the mnemonic key to register
        position - the position in the main menu
        relativeHelpTopic - the relative help topic
        Returns:
        the given menu}
      • initialize

        public void initialize()
        Initialize the main menu.
        Since:
        10340
      • findMenuItems

        public java.util.List<javax.swing.JMenuItem> findMenuItems​(java.lang.String textToFind,
                                                                   boolean skipPresets)
        Search main menu for items with textToFind in title.
        Parameters:
        textToFind - The text to find
        skipPresets - whether to skip the presetsMenu in the search
        Returns:
        not null list of found menu items.
      • findMapModeMenuItem

        public java.util.Optional<javax.swing.JCheckBoxMenuItem> findMapModeMenuItem​(MapMode mode)
        Returns the JCheckBoxMenuItem for the given MapMode.
        Parameters:
        mode - map mode
        Returns:
        the JCheckBoxMenuItem for the given MapMode
        Since:
        15438
      • findMenuItems

        private static void findMenuItems​(javax.swing.JMenu menu,
                                          java.lang.String textToFind,
                                          java.util.List<javax.swing.JMenuItem> result)
        Recursive walker for menu items. Only menu items with action are selected. If menu item contains textToFind it's appended to result.
        Parameters:
        menu - menu in which search will be performed
        textToFind - The text to find
        result - resulting list of menu items
      • showAudioMenu

        protected void showAudioMenu​(boolean showMenu)