Class IzMenu
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionIzMenu
(IzMenuItem parent) Constructor for cascaded menu.IzMenu
(org.eclipse.swt.widgets.Control parent) Constructor for menu on a Control.Method Summary
Modifier and TypeMethodDescriptionadd
(int style, String text, org.eclipse.swt.graphics.Image image, org.eclipse.swt.widgets.Listener selectionListener) Adds a menu item.Adds a menu item.Adds a submenu as a "contribution".add
(String text, org.eclipse.swt.graphics.Image image, org.eclipse.swt.widgets.Listener selectionListener) Adds a menu item as a "push button".Adds a menu item as a "push button".add
(org.eclipse.jface.action.IAction action) Adds an action as a menu item to this menu.Adds all items that must be either instance of IAction of IzSubMenu, or null entries for separators.addMenuListener
(Runnable menuListener) Sets the listener when the menu is about to be shown.Adds a separator to the menu.clear()
Removes all menu items so as to clear the menu.void
dispose()
Disposes of the menu.static IzMenu
fromControl
(org.eclipse.swt.widgets.Control control) Gets the pop-up menu associated with a component.org.eclipse.swt.widgets.Control
Gets the control for which the menu was created for.getItem
(int index) Gets a menu item at index.int
Returns the number of items contained in the receiver.getItems()
Returns a (possibly empty) array ofMenuItem
s which are the items in the receiver.boolean
Returns if there are any enabled menu items to show.boolean
Returns if the menu is disposed.boolean
Returnstrue
if the receiver is enabled and all of the receiver's ancestors are enabled, andfalse
otherwise.boolean
Returns if the menu is currently displaying.Set the disabled menu item omitting when displaying the menu.void
setEnabled
(boolean enabled) Enables the receiver if the argument istrue
, and disables it otherwise.void
setLocation
(int x, int y) Sets the location of the receiver, which must be a popup, to the point specified by the arguments which are relative to the display.void
setLocation
(org.eclipse.swt.graphics.Point location) Sets the location of the receiver, which must be a popup, to the point specified by the argument which is relative to the display.setMenu
(org.eclipse.swt.widgets.Control parent, boolean alignBottomLeft) Assigns the menu to the control.void
setVisible
(boolean visible) Marks the receiver as visible if the argument istrue
, and marks it invisible otherwise.
Constructor Details
IzMenu
public IzMenu(org.eclipse.swt.widgets.Control parent) Constructor for menu on a Control.- Parameters:
parent
- The control parent.
IzMenu
Constructor for cascaded menu.- Parameters:
parent
- The menu item parent.
Method Details
fromControl
Gets the pop-up menu associated with a component. The parents are searched for the menu if not found.- Parameters:
control
- The control.- Returns:
- The IzMenu associated with the control (to display), null if not found.
clear
Removes all menu items so as to clear the menu. This call can be done during the call to the menu listener fired before the menu is shown.- Returns:
this
in order to be able to concatenate calls.
getControl
public org.eclipse.swt.widgets.Control getControl()Gets the control for which the menu was created for.- Returns:
- The control, or null for cascaded menus.
setMenu
Assigns the menu to the control. It must be the same control as the parent. When the right button (SWT.MenuDetect) is pressed, the menu is shown.- Parameters:
parent
- The control parent.alignBottomLeft
- Flag to align bottom left on control when mouse button 2 is pressed.- Returns:
this
in order to be able to concatenate calls.- Throws:
IllegalArgumentException
- If the menu is set to another control than it's parent.
dispose
public void dispose()Disposes of the menu.isDisposed
public boolean isDisposed()Returns if the menu is disposed.getItemCount
public int getItemCount()Returns the number of items contained in the receiver.- Returns:
- the number of items.
getItem
Gets a menu item at index.- Parameters:
index
- The index.- Returns:
- The menu item.
- Throws:
IndexOutOfBoundsException
- If range is wrong.
getItems
Returns a (possibly empty) array ofMenuItem
s which are the items in the receiver.Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array will not affect the receiver.
- Returns:
- the items in the receiver.
setLocation
public void setLocation(int x, int y) Sets the location of the receiver, which must be a popup, to the point specified by the arguments which are relative to the display.Note that this is different from most widgets where the location of the widget is relative to the parent.
Note that the platform window manager ultimately has control over the location of popup menus.
- Parameters:
x
- the new x coordinate for the receivery
- the new y coordinate for the receiver- 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
setLocation
public void setLocation(org.eclipse.swt.graphics.Point location) Sets the location of the receiver, which must be a popup, to the point specified by the argument which is relative to the display.Note that this is different from most widgets where the location of the widget is relative to the parent.
Note that the platform window manager ultimately has control over the location of popup menus.
- Parameters:
location
- the new location for the receiver- Throws:
NullPointerException
- If location is null.
setEnabled
public void setEnabled(boolean enabled) Enables the receiver if the argument istrue
, and disables it otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.- Parameters:
enabled
- the new 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
isEnabled
public boolean isEnabled()Returnstrue
if the receiver is enabled and all of the receiver's ancestors are enabled, andfalse
otherwise. A disabled menu is typically not selectable from the user interface and draws with an inactive or "grayed" look.- Returns:
- the receiver's enabled state
setVisible
public void setVisible(boolean visible) Marks the receiver as visible if the argument istrue
, and marks it invisible otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.
- Parameters:
visible
- the new visibility 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
isVisible
public boolean isVisible()Returns if the menu is currently displaying.- Returns:
- true when visible, false when not visible or a cascaded menu.
omitDisabled
Set the disabled menu item omitting when displaying the menu.- Returns:
this
in order to be able to concatenate calls.
hasEnabledItems
public boolean hasEnabledItems()Returns if there are any enabled menu items to show.- Returns:
- false for separator, disabled menu item. Cascaded menu are also checked.
addMenuListener
Sets the listener when the menu is about to be shown. Menu states can then be processed.- Parameters:
menuListener
- The runnable that will be called prior to displaying the menu.- Returns:
this
in order to be able to concatenate calls.
addSeparator
Adds a separator to the menu.- Returns:
this
in order to be able to concatenate calls.
add
Adds an action as a menu item to this menu.- Parameters:
action
- The action to add.- Returns:
this
in order to be able to concatenate calls.
add
Adds a menu item as a "push button".NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!
- Parameters:
text
- The text, null for none.selectionListener
- The selection listener or null for none.- Returns:
this
in order to be able to concatenate calls.- Throws:
IllegalArgumentException
- For invalid styles.
add
public IzMenu add(String text, org.eclipse.swt.graphics.Image image, org.eclipse.swt.widgets.Listener selectionListener) Adds a menu item as a "push button".NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!
- Parameters:
text
- The text, null for none.image
- The image, null for none.selectionListener
- The selection listener or null for none.- Returns:
this
in order to be able to concatenate calls.- Throws:
IllegalArgumentException
- For invalid styles.
add
Adds a menu item.NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!
- Parameters:
style
- The menu item style.text
- The text, null for none.- Throws:
IllegalArgumentException
- For invalid styles.
add
public IzMenu add(int style, String text, org.eclipse.swt.graphics.Image image, org.eclipse.swt.widgets.Listener selectionListener) Adds a menu item.NOTE: supported styles: SWT.SEPARATOR, SWT.PUSH, SWT.CHECK, SWT.RADIO and SWT.CASCADE: NO OTHER!
- Parameters:
style
- The menu item style.text
- The text, null for none.image
- The image, null for none.- Throws:
IllegalArgumentException
- For invalid styles.
add
Adds a submenu as a "contribution".- Parameters:
subMenu
- The submenu.- Returns:
- The
this
instance for concatenation.
addItems
Adds all items that must be either instance of IAction of IzSubMenu, or null entries for separators. An item can also be an Object [] in which case the addItems(objectArray) will be called.- Parameters:
items
- The items.- Returns:
- The
this
instance for concatenation.