public class IlvSimplePopupMenu extends JPopupMenu
JPopupMenu
component.IlvPopupMenuManager
,
Serialized FormJPopupMenu.AccessibleJPopupMenu, JPopupMenu.Separator
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_CHECK_KEY
Key for the action property that indicates whether the menu item
is checked or unchecked.
|
static String |
ACTION_GROUP_KEY
Key for the action property that indicates whether the menu item
is in a action group.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
IlvSimplePopupMenu()
Constructs a
IlvSimplePopupMenu . |
IlvSimplePopupMenu(String title,
Action[] actions)
Constructs a
IlvSimplePopupMenu from an array of actions. |
IlvSimplePopupMenu(String title,
String[] actions,
ResourceBundle bundle,
ActionListener actionListener)
Constructs a
IlvSimplePopupMenu from an array of actions. |
IlvSimplePopupMenu(String title,
String actionspec,
ResourceBundle bundle,
ActionListener actionListener)
Constructs a
IlvSimplePopupMenu from a string specification. |
Modifier and Type | Method and Description |
---|---|
void |
addActions(Action[] actions)
Adds the input actions as menu items to this pop-up menu.
|
void |
addActions(String[] actions,
ResourceBundle bundle,
ActionListener actionListener)
Adds actions to this pop-up menu.
|
void |
addActions(String actionspec,
char itemDelimiter,
char groupStartDelimiter,
char groupEndDelimiter,
ResourceBundle bundle,
ActionListener actionListener)
Adds actions to this pop-up menu.
|
protected void |
afterDisplay(IlvPopupMenuContext context)
This method is called after the pop-up menu is made invisible.
|
protected void |
beforeDisplay(IlvPopupMenuContext context)
This method is called before the pop-up menu is displayed.
|
int |
getBaseTextDirection()
Returns the base text direction.
|
JMenuItem |
getItemForActionCommand(String actionCommand)
Returns the menu item for a given action command.
|
JMenuItem |
getItemForText(String label)
Returns the menu item for a given menu item text label.
|
static String |
getMenuItemText(JMenuItem mi)
Returns the original menu item text of a simple pop-up menu.
|
boolean |
isComponentOrientationFromGraphic()
Returns whether the pop-up menu inherits the component orientation from
the graphic object that the pop-up menu is displayed for.
|
void |
setBaseTextDirection(int baseTextDirection)
Changes the base direction of menu items and tooltips.
|
void |
setComponentOrientationFromGraphic(boolean enable)
Sets whether the pop-up menu inherits the component orientation from
the graphic object that the pop-up menu is displayed for.
|
void |
setVisible(boolean visible)
Sets the visibility of the pop-up menu.
|
add, add, add, addMenuKeyListener, addPopupMenuListener, addSeparator, createActionChangeListener, createActionComponent, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getDefaultLightWeightPopupEnabled, getInvoker, getLabel, getMargin, getMenuKeyListeners, getPopupMenuListeners, getSelectionModel, getSubElements, getUI, getUIClassID, insert, insert, isBorderPainted, isLightWeightPopupEnabled, isPopupTrigger, isVisible, menuSelectionChanged, pack, paintBorder, paramString, processFocusEvent, processKeyEvent, processKeyEvent, processMouseEvent, remove, removeMenuKeyListener, removePopupMenuListener, setBorderPainted, setDefaultLightWeightPopupEnabled, setInvoker, setLabel, setLightWeightPopupEnabled, setLocation, setPopupSize, setPopupSize, setSelected, setSelectionModel, setUI, show, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final String ACTION_CHECK_KEY
Boolean
.public static final String ACTION_GROUP_KEY
String
.public IlvSimplePopupMenu()
IlvSimplePopupMenu
.public IlvSimplePopupMenu(String title, String actionspec, ResourceBundle bundle, ActionListener actionListener)
IlvSimplePopupMenu
from a string specification.
Here is an example specification:
"Save | Load | - | { Mode1 | Mode2 | Mode3 }"
The menu items are separated by the bar (|) character. Groups of radio menu items (i.e., menu items with a check mark so that only one of them is checked) are enclosed in the opening bracket ({) and the closing bracket (}). The dash character (-) adds a separator line between the menu items.
If a resource bundle is passed as argument, the menu items are translated by the resource bundle. For each menu entry, additional options can be specified using the '@' option separator. Here is an example which specifies tooltips for the menu items:
"Save @T=Save to file | Load @T=Load from file"
See the method
addActions(String, char, char, char, ResourceBundle, ActionListener)
for the explanation about the specification format.
title
- The title of the pop-up menu. This can be null
.actionspec
- The string specification of the actions.bundle
- The resource bundle for i18nactionListener
- The action listener that receives all action events
from all menu items of this menu.Action
public IlvSimplePopupMenu(String title, String[] actions, ResourceBundle bundle, ActionListener actionListener)
IlvSimplePopupMenu
from an array of actions.
Each action is specified by a string entry in the input array.
Here is an example string:
"Hello @M=H @I=hello.gif @T=Hello Tooltip"See
addActions(String[], ResourceBundle, ActionListener)
for the explanation about the specification format.title
- The title of the pop-up menu. This can be null
.actions
- The string specification of the actions.bundle
- The resource bundle for i18nactionListener
- The action listener that receives all action events
from all menu items of this menu.Action
public IlvSimplePopupMenu(String title, Action[] actions)
IlvSimplePopupMenu
from an array of actions.
Each action must have the Action.NAME
property, which is used as
label of the corresponding menu item. Furthermore, the following optional
action properties are recognized:
Action.MNEMONIC_KEY
Action.SHORT_DESCRIPTION
Action.SMALL_ICON
Action.ACTION_COMMAND_KEY
ACTION_CHECK_KEY
ACTION_GROUP_KEY
null
entry in the actions
array generates
a separator line in the menu.title
- The title of the pop-up menu. This can be null
.actions
- The actions of the pop-up menu.Action
public void addActions(String actionspec, char itemDelimiter, char groupStartDelimiter, char groupEndDelimiter, ResourceBundle bundle, ActionListener actionListener)
"Save | Load | - | { Mode1 | Mode2 | Mode3 }"The menu items are separated by the
itemDelimiter
character.
In the example, the bar (|) is used as item delimiter.
Groups of radio menu items (i.e., menu items with a check mark so that
only one of them is checked) must be enclosed in the
groupStartDelimiter
and groupEndDelimiter
.
In the example, the opening bracket ({) starts a group, and the closing
bracket (}) end the group.
The dash character (-) adds a separator line between the menu items.
If a resource bundle is passed as argument, the menu items are translated by the resource bundle. For each menu entry, additional options can be specified using the '@' option separator. Here is an example which specifies tooltips for the menu items:
"Save @T=Save to file | Load @T=Load from file"See the method
addActions(String[], ResourceBundle, ActionListener)
for details about the specification with '@'.
Note that blanks are significant in the specification, so they should
not be used as white space. The only exception is the single blank before
and after the delimiters, and before the '@' character. These blanks are
optional, and they are ignored if there are there.actionspec
- The string specification of the actions.itemDelimiter
- The character that separates the menu items.groupStartDelimiter
- The character that starts a radio group.groupEndDelimiter
- The character that finishes a radio group.bundle
- The resource bundle for i18nactionListener
- The action listener that receives all action events
from all menu items of this menu.Action
public void addActions(String[] actions, ResourceBundle bundle, ActionListener actionListener)
"Hello @M=H @I=hello.gif @T=Hello Tooltip"The separator character is '@'. The first entry is the mandatory title of the corresponding menu item. Possible optional parts of the specification are:
@M=
The mnemonic, as parsed by javax.swing.KeyStroke.
If the resource bundle is not null, the mnemonic is first translated
by the resource bundle, and then parsed by javax.swing.KeyStroke.
@I=
The icon file. It makes several attempts to load
the icon file. It first tries to load the icon
image as resource (relative to the path of the action listener),
then as file name, and finally as fully specified URL.
URL.
@T=
The tooltip.
If the resource bundle is not null, the tooltip is translated
by the resource bundle.
@A=
The action command.
@C=
Whether the action is checked or unchecked.
The possible values are true
and false
.
If this option is specified, the action is checkable; if the option
is missing, the action is not checkable.
@G=
The group.
If the group is specified, the action behaves like a radio checkbox.
If no group is specified, the action behaves like a normal action.
@
which is optional.
A null
entry in the actions
array generates
a separator line in the menu.actions
- The string specification of the actions.bundle
- The resource bundle for i18nactionListener
- The action listener that receives all action events
from all menu items of this menu.Action
public void addActions(Action[] actions)
Action.NAME
property, which is used as
label of the corresponding menu item. Furthermore, the following optional
action properties are recognized:
Action.MNEMONIC_KEY
Action.SHORT_DESCRIPTION
Action.SMALL_ICON
Action.ACTION_COMMAND_KEY
ACTION_CHECK_KEY
ACTION_GROUP_KEY
null
entry in the actions
array generates
a separator line in the menu.
Ratio menu item groups are only recognized if they are added in one step.
This means, if addActions
is called multiple times, then
each time, different groups are created for each call even if the same
group name is used in the multiple calls.actions
- The actions of the pop-up menu.Action
public JMenuItem getItemForText(String label)
null
if no menu item is found for the text label.label
- The text label.public JMenuItem getItemForActionCommand(String actionCommand)
null
if no menu item is found for the action
command.actionCommand
- The action command.public void setComponentOrientationFromGraphic(boolean enable)
IlvGraphic
objects, this
option has no effect.
This option is enabled by default.public boolean isComponentOrientationFromGraphic()
IlvGraphic
objects, this
option has no effect.public void setBaseTextDirection(int baseTextDirection)
IlvBidiUtil.UNDEFINED_DIRECTION
:
the base text direction is not taken into account in any
way. This is the default.
IlvBidiUtil.INHERITED_DIRECTION
:
the base text direction is inherited from the
IlvGraphic
object that displays this pop-up menu.
If the pop-up menu is not used of graphic objects,
the base text direction is calculated from the
component orientation.
IlvBidiUtil.COMPONENT_DIRECTION
:
the base text direction is calculated from the
component orientation.
IlvBidiUtil.LEFT_TO_RIGHT
:
the base text direction is left-to-right.
IlvBidiUtil.RIGHT_TO_LEFT
:
the base text direction is right-to-left.
IlvBidiUtil.CONTEXTUAL_DIRECTION
:
the base test direction is determined from the text
that is displayed according to the standard Bidi
algorithm, if the text contains at least one character
with a strong left-to-right or right-to-left direction.
If the text doesn't contain any character with a strong
direction, the real text direction is determined from
the current component orientation of the object.
IlvBidiUtil.UNDEFINED_DIRECTION
also influences the component
orientation of each pop-up menu item, independent from the component
oientation of the entire pop-up menu.
Also, it changes the text of menu items by adding Bidi control characters.
To retrieve the original text of menu items, use
getMenuItemText(javax.swing.JMenuItem)
.baseTextDirection
- The base text directionpublic int getBaseTextDirection()
public void setVisible(boolean visible)
setVisible
in class JPopupMenu
visible
- true to make the pop-up visible, or false to hide it.protected void beforeDisplay(IlvPopupMenuContext context)
super.beforeDisplay(context)
.
It allows to configure the pop-up menu according to the pop-up context,
for instance to enable or disable menu items, or to update the checked
status of the menu items.
The default implementation updates the menu items according to the
state of the corresponding actions.context
- The pop-up menu contextprotected void afterDisplay(IlvPopupMenuContext context)
super.afterDisplay(context)
.
It allows to cleanup the pop-up menu according to the pop-up context.context
- The pop-up menu contextpublic static String getMenuItemText(JMenuItem mi)
IlvBidiUtil.UNDEFINED_DIRECTION
,
a modified text is stored in the menu items to implement the base text
direction. This modified text may contain additional Unicode control
characters. If you need the original text of the menu item excluding the
added Unicode control characters, call this method.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.