Class IzMenuItem
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionIzMenuItem
(IzMenu menu, int style) Constructor.IzMenuItem
(IzMenu menu, int style, String text) Constructor for menu item.IzMenuItem
(IzMenu menu, int style, String text, Image image) Constructor for menu item.IzMenuItem
(IzMenu menu, int style, String text, Image image, Listener selectionListener) Constructor for menu item.IzMenuItem
(IzMenu menu, int style, String text, Listener selectionListener) Constructor for menu item.IzMenuItem
(IzMenu menu, IzSubMenu subMenu) Creates a submenu.IzMenuItem
(IzMenu menu, String text) Constructor for push button menu item.IzMenuItem
(IzMenu menu, String text, Image image) Constructor for push button menu item.IzMenuItem
(IzMenu menu, String text, Image image, Listener selectionListener) Constructor for push button menu item.IzMenuItem
(IzMenu menu, String text, Listener selectionListener) Constructor for push button menu item.IzMenuItem
(IzMenu menu, IAction action) Creates a menu item from a action.Method Summary
Modifier and TypeMethodDescriptionaddListener
(int eventType, Listener listener) Adds the listener to the collection of listeners who will be notified when an event of the given type occurs.void
dispose()
Disposes of the menu item.void
fireSelectionEvent
(Event event) Fires a selection event to all listeners.static final IzMenuItem
Gets the IzMenuItem from a menu event, typically a selection event.boolean
Returnstrue
if the receiver is enabled, andfalse
otherwise.getImage()
Returns the receiver's image if it has one, or null if it does not.boolean
Returnstrue
if the receiver is selected, and false otherwise.Returns the SWT menu item for this menu item.getText()
Returns the receiver's text, which will be an empty string if it has never been set.Gets the tooltip text for the menu item.boolean
Verifies if there are selection listeners for the menu item.boolean
Returns if the menu item is disposed.boolean
The enabled state is reflected from this menu item state and all parent states.boolean
Returns if this is a separator.setAccelerator
(int accelerator) Sets the accelerator for plain menu items (not cascaded or contribution items).setEnabled
(boolean enabled) Enables the receiver if the argument istrue
, and disables it otherwise.Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.Sets the menu for the cascaded menu item.setSelection
(boolean selected) Sets the selection state of the receiver.Sets the receiver's text.setToolTipText
(String toolTip) Sets the tooltip text for the menu item.
Constructor Details
IzMenuItem
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
Constructor for push button menu item.- Parameters:
menu
- The parent menu.text
- The text, null for none.- Throws:
IllegalArgumentException
- For invalid styles.
IzMenuItem
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
Constructor for push button menu item.- Parameters:
menu
- The parent menu.text
- The text, null for none.- Throws:
IllegalArgumentException
- For invalid styles.
IzMenuItem
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
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
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
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
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
Creates a menu item from a action.- Parameters:
menu
- The parent menu.action
- The action.- Throws:
NullPointerException
- If action is null.
IzMenuItem
Creates a submenu.- Parameters:
menu
- The parent menu.subMenu
- The submenu.- Throws:
NullPointerException
- If action is null.
Method Details
fromEvent
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
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
Enables the receiver if the argument istrue
, 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()Returnstrue
if the receiver is enabled, andfalse
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
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
Sets the selection state of the receiver.When the receiver is of type
CHECK
orRADIO
, 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()Returnstrue
if the receiver is selected, and false otherwise.When the receiver is of type
CHECK
orRADIO
, 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
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
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
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
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
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
Gets the tooltip text for the menu item.- Returns:
- The tooltip, or null for none.
setAccelerator
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
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 thehandleEvent()
message. The event type is one of the event constants defined in classSWT
.NOTE: Only SWT.Selection is supported.
- Parameters:
eventType
- the type of event to listen forlistener
- 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
- iflistener == null
oreventType != SWT.Selection
.
hasSelectionListeners
public boolean hasSelectionListeners()Verifies if there are selection listeners for the menu item.- Returns:
- true if listeners are present.
fireSelectionEvent
Fires a selection event to all listeners.- Parameters:
event
- The SWT event.
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.