Package com.iizix.swt

Class IzMenuItem

java.lang.Object
com.iizix.swt.IzMenuItem

public class IzMenuItem extends Object
The Menu drop-in replacement in iiziGo that does not consume handles, i.e. creates the SWT menu only when required.
Author:
Christopher Mindus
  • Constructor Details

    • IzMenuItem

      public IzMenuItem(IzMenu menu, int style)
      Constructor.

      NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!

      Parameters:
      menu - The parent menu.
      style - The menu item style.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, String text)
      Constructor for push button menu item.
      Parameters:
      menu - The parent menu.
      text - The text, null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, String text, Listener selectionListener)
      Constructor for push button menu item.
      Parameters:
      menu - The parent menu.
      text - The text, null for none.
      selectionListener - The selection listener, or null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, String text, Image image)
      Constructor for push button menu item.
      Parameters:
      menu - The parent menu.
      text - The text, null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, String text, Image image, Listener selectionListener)
      Constructor for push button menu item.
      Parameters:
      menu - The parent menu.
      text - The text, null for none.
      image - The image, null for none.
      selectionListener - The selection listener, or null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, int style, String text)
      Constructor for menu item.

      NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!

      Parameters:
      menu - The parent menu.
      style - The menu item style.
      text - The text, null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, int style, String text, Listener selectionListener)
      Constructor for menu item.

      NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!

      Parameters:
      menu - The parent menu.
      style - The menu item style.
      text - The text, null for none.
      selectionListener - The selection listener, or null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, int style, String text, Image image)
      Constructor for menu item.

      NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!

      Parameters:
      menu - The parent menu.
      style - The menu item style.
      text - The text, null for none.
      image - The image, null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, int style, String text, Image image, Listener selectionListener)
      Constructor for menu item.

      NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!

      Parameters:
      menu - The parent menu.
      style - The menu item style.
      text - The text, null for none.
      image - The image, null for none.
      selectionListener - The selection listener, or null for none.
      Throws:
      IllegalArgumentException - For invalid styles.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, IAction action)
      Creates a menu item from a action.
      Parameters:
      menu - The parent menu.
      action - The action.
      Throws:
      NullPointerException - If action is null.
    • IzMenuItem

      public IzMenuItem(IzMenu menu, IzSubMenu subMenu)
      Creates a submenu.
      Parameters:
      menu - The parent menu.
      subMenu - The submenu.
      Throws:
      NullPointerException - If action is null.
  • Method Details

    • fromEvent

      public static final IzMenuItem fromEvent(Event event)
      Gets the IzMenuItem from a menu event, typically a selection event.
      Parameters:
      event - The event.
      Returns:
      The menu item that corresponds to the event, null if not found.
    • isSeparator

      public boolean isSeparator()
      Returns if this is a separator.
    • setMenu

      public IzMenuItem setMenu(IzMenu menu)
      Sets the menu for the cascaded menu item.
      Returns:
      this menu item to enable concatenation.
      Throws:
      IllegalArgumentException - If action or submenu is used, or if a second call to setMenu(menu) is done.
    • dispose

      public void dispose()
      Disposes of the menu item.
    • isDisposed

      public boolean isDisposed()
      Returns if the menu item is disposed.
      Returns:
      true if disposed, false otherwise.
    • setEnabled

      public IzMenuItem setEnabled(boolean enabled)
      Enables the receiver if the argument is true, and disables it otherwise. A disabled menu item is typically not selectable from the user interface and draws with an inactive or "grayed" look.
      Parameters:
      enabled - the new enabled state
      Returns:
      this menu item to enable concatenation.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      IllegalArgumentException - If action or submenu is used.
    • getEnabled

      public boolean getEnabled()
      Returns true if the receiver is enabled, and false otherwise. A disabled menu item is typically not selectable from the user interface and draws with an inactive or "grayed" look.
      Returns:
      the receiver's enabled state.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      See Also:
      • isEnabled
    • isEnabled

      public boolean isEnabled()
      The enabled state is reflected from this menu item state and all parent states.
      Returns:
      The enabled state of this menu item within the menu, i.e. if a parent is disabled, then false is returned.
    • setSelection

      public IzMenuItem setSelection(boolean selected)
      Sets the selection state of the receiver.

      When the receiver is of type CHECK or RADIO, it is selected when it is checked.

      Parameters:
      selected - the new selection state
      Returns:
      this menu item to enable concatenation.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      IllegalArgumentException - If action or submenu is used.
    • getSelection

      public boolean getSelection()
      Returns true if the receiver is selected, and false otherwise.

      When the receiver is of type CHECK or RADIO, it is selected when it is checked.

      Returns:
      the selection state
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setImage

      public IzMenuItem setImage(Image image)
      Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.
      Parameters:
      image - the image to display on the receiver (may be null)
      Returns:
      this menu item to enable concatenation.
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the image has been disposed
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      IllegalArgumentException - If action or submenu is used.
    • getImage

      public Image getImage()
      Returns the receiver's image if it has one, or null if it does not.
      Returns:
      the receiver's image
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setText

      public IzMenuItem setText(String string)
      Sets the receiver's text.

      Note: If control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.

      Parameters:
      string - the new text
      Returns:
      this menu item to enable concatenation.
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the text is null
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      IllegalArgumentException - If action or submenu is used.
    • getText

      public String getText()
      Returns the receiver's text, which will be an empty string if it has never been set.
      Returns:
      the receiver's text
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
    • setToolTipText

      public IzMenuItem setToolTipText(String toolTip)
      Sets the tooltip text for the menu item.
      Parameters:
      toolTip - The tooltip, or null to clear it.
      Returns:
      this menu item to enable concatenation.
    • getToolTipText

      public String getToolTipText()
      Gets the tooltip text for the menu item.
      Returns:
      The tooltip, or null for none.
    • setAccelerator

      public IzMenuItem setAccelerator(int accelerator)
      Sets the accelerator for plain menu items (not cascaded or contribution items). This method will not affect any keyboard processing, merely the display of the accelerator text. It will not change the text if the menu item is visible.
      Parameters:
      accelerator - The SWT accelerator or SWT.NONE to clear.
      Returns:
      this menu item to enable concatenation.
    • addListener

      public IzMenuItem addListener(int eventType, Listener listener)
      Adds the listener to the collection of listeners who will be notified when an event of the given type occurs. When the event does occur in the widget, the listener is notified by sending it the handleEvent() message. The event type is one of the event constants defined in class SWT.

      NOTE: Only SWT.Selection is supported.

      Parameters:
      eventType - the type of event to listen for
      listener - the listener which should be notified when the event occurs
      Returns:
      this menu item to enable concatenation.
      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      IllegalArgumentException - if listener == null or eventType != SWT.Selection.
    • hasSelectionListeners

      public boolean hasSelectionListeners()
      Verifies if there are selection listeners for the menu item.
      Returns:
      true if listeners are present.
    • fireSelectionEvent

      public void fireSelectionEvent(Event event)
      Fires a selection event to all listeners.
      Parameters:
      event - The SWT event.
    • getSWTMenuItem

      public MenuItem getSWTMenuItem()
      Returns the SWT menu item for this menu item.
      Returns:
      The SWT menu item, only set when processing the menu (it is displayed), otherwise this value is null.