org.vishia.gral.base

## Class GralMenu

- java.lang.Object
- - org.vishia.gral.base.GralMenu

-     public class GralMenu
      extends java.lang.Object

  Super class of Menu root wrappers of the graphic implementation layer independent of the implementation graphic. This class is the super class either for the menu bar of a window or for the context menu for any widget.
  It refers the window or the widget. The graphical implementation layer associates an event listener to any menu item created with `addMenuItem(String, String, GralUserAction)`. That event listener invokes the `GralUserAction` given as parameter.
  - To add a menu bar to a window call `GralWindow.addMenuBarItemGThread(String, String, GralUserAction)`.
  - To get or create a context menu to a widget call `GralWidget.getContextMenu()`
  - To add a menu item to the context menu or any menu item call `addMenuItem(String, String, GralUserAction)`.
  One should call this methods only in the graphic thread in the initalizing phase.
  The basic idea for menus is: A path is used instead a tree of menus. To add any new menu item to a window's pull-down menu bar, use `GralWindow.addMenuBarItemGThread(String, String, GralUserAction)`. You needn't have knowledge about the tree structure of the menu. The String sMenuPath should consist of the parts of the menu tree, for example "&File/&Check/rest&Ore". For this example a menu bar entry "File" is created or the yet existing is used. Then the sub menu entry "Check" is created or the existing is used. There the entry "restOre" is created with 'O' as hot-key.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `GralMenu._GraphicImpl`
    `static class` | `GralMenu.MenuEntry` This class wraps a menu entry of the implementation.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) GralMenu._GraphicImpl` | `_impl`
    `protected java.util.Map<java.lang.String,GralMenu.MenuEntry>` | `menus`
    `static int` | `version` Version, history and license.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GralMenu()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMenuItem(GralWidget widggP, java.lang.String nameWidgg, java.lang.String sMenuPath, GralUserAction action)` Adds with a given widget.
    `void` | `addMenuItem(java.lang.String sMenuPath, GralUserAction gralAction)` Adds any menu item.
    `void` | `addMenuItem(java.lang.String name, java.lang.String sMenuPath, GralUserAction action)` Adds any menu item
    `java.lang.Object` | `getMenuImpl()` Returns the implementation instance for the menu.
    `boolean` | `hasImplementation()`
    `void` | `setVisible()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### version

          public static final int version

      Version, history and license.
      - 2016-11-04 Hartmut new `GralMenu.MenuEntry.widgg` to transport the widget to the implementation widget.
      - 2016-09 Hartmut redesign: Now the GralMenu is an implementation-independent class. It contains references to the implementation menu instances and supports creation of them if the graphic implementation is present. `GralMenu._GraphicImpl` is now the base class for the `SwtMenu`.
      - 2014-06-23 Hartmut new: Now the `#widgg` is stored here. It is used for all sub menus to refer it for calling `GralUserAction.exec(int, org.vishia.gral.ifc.GralWidget_ifc, Object...)`. The `addMenuItem(String, String, GralUserAction)` is now deprecated, the String is not used. But only that method creates an instance of `gral.swt.SwtWidgetMenu` which is deprecated too and only used to held a reference to the GralWidget. The `addMenuItem(String, GralUserAction)` is the new one to use.
      - 2012-03-17 Hartmut new: `addMenuItem(String, String, GralUserAction)` returns now a `GralWidget`. It is necessary to add some information to the menu-widget, which can be used if the `GralUserAction.userActionGui(int, GralWidget, Object...)` for this menu is called. The second param of this method is that menu-GralWidget.
      - 2011-11-00 Hartmut created, menus are present not only in the main window. Context menu etc.
        Copyright/Copyleft: For this source the LGPL Lesser General Public License, published by the Free Software Foundation is valid. It means:
        1. You can use this source without any restriction for any desired purpose.
        2. You can redistribute copies of this source to everybody.
        3. Every user of this source, also the user of redistribute copies with or without payment, must accept this license for further using.
        4. But the LPGL ist not appropriate for a whole software product, if this source is only a part of them. It means, the user must publish this part of source, but don't need to publish the whole source of the own product.
        5. You can study and modify (improve) this source for own using or for redistribution, but you have to license the modified sources likewise under this LGPL Lesser General Public License. You mustn't delete this Copyright/Copyleft inscription in this source file.
        If you are indent to use this sources without publishing its usage, you can get a second license subscribing a special contract with the author.
      See Also:
        Constant Field Values

    - #### menus

          protected java.util.Map<java.lang.String,GralMenu.MenuEntry> menus

    - #### _impl

          GralMenu._GraphicImpl _impl

  - ### Constructor Detail

    - #### GralMenu

          public GralMenu()

  - ### Method Detail

    - #### addMenuItem

          public final void addMenuItem(java.lang.String name,
                                        java.lang.String sMenuPath,
                                        GralUserAction action)

      Adds any menu item
      Parameters:
        `name` - name of the menu, it is used as widget name.
        `sMenuPath` - Menu position. Use slash as separator, use & for hot key. For example "&edit/&search/co&ntinue" creates a menu 'edit' or uses the existing one in the top level (menu bar), then creates the search menu item as pull down in menu bar, and then 'continue' with 'n' as hot key as sub-menu. It is stored in `GralWidget.sDataPath`
        `action` - called on menu activation.

    - #### addMenuItem

          public final void addMenuItem(GralWidget widggP,
                                        java.lang.String nameWidgg,
                                        java.lang.String sMenuPath,
                                        GralUserAction action)

      Adds with a given widget. Note the widget is in difference with the `#widgg` of the constructor. Check what is happen. Therefore:
      Parameters:
        `widggMenu` - the widget can be used to add any `GralWidget.setContentInfo(Object)` etc. It is provided in the action method.
        `name` -
        `sMenuPath` -
        `action` -

    - #### addMenuItem

          public final void addMenuItem(java.lang.String sMenuPath,
                                        GralUserAction gralAction)

      Adds any menu item.
      Parameters:
        `sMenuPath` - Menu position. Use slash as separator, use & for hot key. For example "&edit/&search/co&ntinue" creates a menu 'edit' or uses the existing one in the top level (menu bar), then creates the search menu item as pull down in menu bar, and then 'continue' with 'n' as hot key as sub-menu. It is stored in `GralWidget.sDataPath`
        `action` - called on menu activation.

    - #### setVisible

          public final void setVisible()

    - #### hasImplementation

          public boolean hasImplementation()

    - #### getMenuImpl

          public final java.lang.Object getMenuImpl()

      Returns the implementation instance for the menu.