Package com.iizix.swt

Class IzMenuItem


  • public class IzMenuItem
    extends java.lang.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 Summary

      Constructors 
      ConstructorDescription
      IzMenuItem​(IzMenu menu, int style)
      Constructor.
      IzMenuItem​(IzMenu menu, int style, java.lang.String text)
      Constructor for menu item.
      IzMenuItem​(IzMenu menu, int style, java.lang.String text, org.eclipse.swt.graphics.Image image)
      Constructor for menu item.
      IzMenuItem​(IzMenu menu, int style, java.lang.String text, org.eclipse.swt.graphics.Image image, org.eclipse.swt.widgets.Listener selectionListener)
      Constructor for menu item.
      IzMenuItem​(IzMenu menu, int style, java.lang.String text, org.eclipse.swt.widgets.Listener selectionListener)
      Constructor for menu item.
      IzMenuItem​(IzMenu menu, IzSubMenu subMenu)
      Creates a submenu.
      IzMenuItem​(IzMenu menu, java.lang.String text)
      Constructor for push button menu item.
      IzMenuItem​(IzMenu menu, java.lang.String text, org.eclipse.swt.graphics.Image image)
      Constructor for push button menu item.
      IzMenuItem​(IzMenu menu, java.lang.String text, org.eclipse.swt.graphics.Image image, org.eclipse.swt.widgets.Listener selectionListener)
      Constructor for push button menu item.
      IzMenuItem​(IzMenu menu, java.lang.String text, org.eclipse.swt.widgets.Listener selectionListener)
      Constructor for push button menu item.
      IzMenuItem​(IzMenu menu, org.eclipse.jface.action.IAction action)
      Creates a menu item from a action.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      IzMenuItemaddListener​(int eventType, org.eclipse.swt.widgets.Listener listener)
      Adds the listener to the collection of listeners who will be notified when an event of the given type occurs.
      voiddispose()
      Disposes of the menu item.
      voidfireSelectionEvent​(org.eclipse.swt.widgets.Event event)
      Fires a selection event to all listeners.
      static IzMenuItemfromEvent​(org.eclipse.swt.widgets.Event event)
      Gets the IzMenuItem from a menu event, typically a selection event.
      booleangetEnabled()
      Returns true if the receiver is enabled, and false otherwise.
      org.eclipse.swt.graphics.ImagegetImage()
      Returns the receiver's image if it has one, or null if it does not.
      booleangetSelection()
      Returns true if the receiver is selected, and false otherwise.
      org.eclipse.swt.widgets.MenuItemgetSWTMenuItem()
      Returns the SWT menu item for this menu item.
      java.lang.StringgetText()
      Returns the receiver's text, which will be an empty string if it has never been set.
      java.lang.StringgetToolTipText()
      Gets the tooltip text for the menu item.
      booleanhasSelectionListeners()
      Verifies if there are selection listeners for the menu item.
      booleanisDisposed()
      Returns if the menu item is disposed.
      booleanisEnabled()
      The enabled state is reflected from this menu item state and all parent states.
      booleanisSeparator()
      Returns if this is a separator.
      IzMenuItemsetAccelerator​(int accelerator)
      Sets the accelerator for plain menu items (not cascaded or contribution items).
      IzMenuItemsetEnabled​(boolean enabled)
      Enables the receiver if the argument is true, and disables it otherwise.
      IzMenuItemsetImage​(org.eclipse.swt.graphics.Image image)
      Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.
      IzMenuItemsetMenu​(IzMenu menu)
      Sets the menu for the cascaded menu item.
      IzMenuItemsetSelection​(boolean selected)
      Sets the selection state of the receiver.
      IzMenuItemsetText​(java.lang.String string)
      Sets the receiver's text.
      IzMenuItemsetToolTipText​(java.lang.String toolTip)
      Sets the tooltip text for the menu item.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

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

        public IzMenuItem​(IzMenu menu,
                          java.lang.String text,
                          org.eclipse.swt.widgets.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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

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

        public IzMenuItem​(IzMenu menu,
                          java.lang.String text,
                          org.eclipse.swt.graphics.Image image,
                          org.eclipse.swt.widgets.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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

        public IzMenuItem​(IzMenu menu,
                          int style,
                          java.lang.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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

        public IzMenuItem​(IzMenu menu,
                          int style,
                          java.lang.String text,
                          org.eclipse.swt.widgets.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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

        public IzMenuItem​(IzMenu menu,
                          int style,
                          java.lang.String text,
                          org.eclipse.swt.graphics.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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

        public IzMenuItem​(IzMenu menu,
                          int style,
                          java.lang.String text,
                          org.eclipse.swt.graphics.Image image,
                          org.eclipse.swt.widgets.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:
        java.lang.IllegalArgumentException - For invalid styles.
      • IzMenuItem

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

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

      • fromEvent

        public static final IzMenuItem fromEvent​(org.eclipse.swt.widgets.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:
        java.lang.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:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        java.lang.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:
        org.eclipse.swt.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:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        java.lang.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:
        org.eclipse.swt.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​(org.eclipse.swt.graphics.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:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the image has been disposed
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        java.lang.IllegalArgumentException - If action or submenu is used.
      • getImage

        public org.eclipse.swt.graphics.Image getImage()
        Returns the receiver's image if it has one, or null if it does not.
        Returns:
        the receiver's image
        Throws:
        org.eclipse.swt.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​(java.lang.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:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the text is null
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        java.lang.IllegalArgumentException - If action or submenu is used.
      • getText

        public java.lang.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:
        org.eclipse.swt.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​(java.lang.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 java.lang.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,
                                      org.eclipse.swt.widgets.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:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        java.lang.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​(org.eclipse.swt.widgets.Event event)
        Fires a selection event to all listeners.
        Parameters:
        event - The SWT event.
      • getSWTMenuItem

        public org.eclipse.swt.widgets.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.