Class MAction

java.lang.Object
javax.swing.AbstractAction
chemaxon.marvin.swing.DelegatingAction
chemaxon.marvin.swing.MAction
All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action

@PublicApi public class MAction extends chemaxon.marvin.swing.DelegatingAction
Comman base class for Marvin actions.
Since:
Marvin 3.1.3
See Also:
  • Field Details

    • AUTORM

      public static final int AUTORM
      Remove menu items automatically when the menu becomes invisible.
      See Also:
    • NO_MNEMONIC

      public static final int NO_MNEMONIC
      Do not set the mnemonic.
      See Also:
    • IN_POPUP

      public static final int IN_POPUP
      Popup menu item.
      See Also:
    • USE_DO_LABEL

      public static final int USE_DO_LABEL
      Use short `do' label instead of name for the created menu item.
      Since:
      Marvin 4.0, 07/08/2005
      See Also:
    • USE_WHAT_LABEL

      public static final int USE_WHAT_LABEL
      Use short `what' label instead of name for the created menu item.
      Since:
      Marvin 4.0, 07/08/2005
      See Also:
    • DISABLE_ACCELERATOR

      public static final int DISABLE_ACCELERATOR
      Disables the keyboard shortcut while still displaying its name in the menu.
      Since:
      Marvin 4.1, 01/31/2006
      See Also:
  • Constructor Details

    • MAction

      public MAction(String cmd, String label)
      Creates an action. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      cmd - the action command string
      label - label for the corresponding components
    • MAction

      public MAction(String cmd, String label, KeyStroke accel)
      Creates an action. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      cmd - the action command string
      label - label for the corresponding components
      accel - accelerator key or null
    • MAction

      public MAction(String cmd, String label, KeyStroke[] accel)
      Creates an action. If the label string is of the form "'x'label", then x will be the mnemonic character and the actual label will be label.
      Parameters:
      cmd - the action command string
      label - label for the corresponding components
      accel - accelerator key or null
  • Method Details

    • setActionCommand

      public void setActionCommand(String cmd)
      Sets the action command string.
      Parameters:
      cmd - the action command
    • getActionCommand

      public String getActionCommand()
      Gets the action command string.
      Returns:
      the action command
    • setNameAndMnemonic

      public void setNameAndMnemonic(String label)
      Sets the label and the mnemonic character. If the label string is of the form "'x'label[DO:]doLabel[WHAT:]whatLabel", then the mnemonic will be x, the menu item label will be label, the `do' label (for `what' menus) will be doLabel and the `what' label (for `do' menus) will be whatLabel. If "'x'" is missing, then the mnemonic is removed. If "[DO:]doLabel" and [WHAT:]whatLabel are optional.
      Parameters:
      label - the label (optionally containg the mnemonic)
      Since:
      Marvin 3.4, 05/01/2004
    • setMenuItem

      protected void setMenuItem(JMenuItem mi, int flags)
    • getMnemonic

      public int getMnemonic()
      Gets the mnemonic. The returned value is always an upper case character.
      Returns:
      the mnemonic or 0
    • getCurrentTarget

      public Object getCurrentTarget()
      Is the current action coming from a pop-up menu item?
      Since:
      Marvin 3.4, 05/11/2004
    • actionPerformed

      public void actionPerformed(ActionEvent ev)
      Sets the action state, performs a custom action, then propagates the event. The code of this method is the following:
       setActionState(ev);
       doAction(ev);
       fireActionPerformed(ev);
       
      Specified by:
      actionPerformed in interface ActionListener
      Overrides:
      actionPerformed in class chemaxon.marvin.swing.DelegatingAction
      Parameters:
      ev - action event from a component
    • setActionState

      protected void setActionState(ActionEvent ev)
      Sets the action state. The default implementation of this method is empty.
      Parameters:
      ev - action event from a component
      Since:
      Marvin 5.0, 11/12/2006
    • doAction

      protected void doAction(ActionEvent ev)
      Performs a custom action. The default implementation of this method is empty.
      Parameters:
      ev - action event from a component
      Since:
      Marvin 5.0, 11/12/2006
    • addTo

      public final Component addTo(Container menu)
      Add menu item to the specified menu.
      Parameters:
      menu - the menu
      Since:
      Marvin 5.0, 11/18/2006
    • addTo

      public final Component addTo(Container menu, int flags)
      Add menu item to the specified menu.
      Parameters:
      menu - the menu
      flags - options
      Since:
      Marvin 3.4, 04/18/2004
      See Also:
    • addTo

      public Component addTo(Container menu, int flags, Object t)
      Add menu item to the specified menu.
      Parameters:
      menu - the menu
      flags - options
      t - current action target
      Since:
      Marvin 4.0, 07/08/2005
      See Also:
    • insertTo

      public void insertTo(Container menu, int i, int flags)
      Insert menu item into the specified menu.
      Parameters:
      menu - the menu
      i - menu item index
      flags - options
      Since:
      Marvin 3.4, 04/18/2004
      See Also:
    • initAccelerators

      public void initAccelerators(JComponent c)
      Initializes this action's accelerator keys for the specified component.
      Parameters:
      c - the component
      Since:
      Marvin 5.0, 11/14/2006
    • toString

      public String toString()
      Overrides Object.toString() to ease debugging. Returns a string consisting of the classname (without the package name!), the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object, followed by the action command in square brackets.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object
    • initAccelerators

      protected void initAccelerators(KeyStroke[] strokes, JComponent c)