Component
, Interactable
, TextGUIElement
Menu
public class MenuItem extends AbstractInteractableComponent<MenuItem>
Menu
with an optional action attached to itModifier and Type | Class | Description |
---|---|---|
static class |
MenuItem.DefaultMenuItemRenderer |
Default renderer for menu items (both sub-menus and regular items)
|
static class |
MenuItem.MenuItemRenderer |
Helper interface that doesn't add any new methods but makes coding new menu renderers a little bit more clear
|
Interactable.FocusChangeDirection, Interactable.Result
Constructor | Description |
---|---|
MenuItem(String label) |
Creates a
MenuItem with a label that does nothing when activated |
MenuItem(String label,
Runnable action) |
Creates a new
MenuItem with a label and an action that will run on the GUI thread when activated. |
Modifier and Type | Method | Description |
---|---|---|
protected InteractableRenderer<MenuItem> |
createDefaultRenderer() |
When you create a custom component, you need to implement this method and return a Renderer which is responsible
for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).
|
String |
getLabel() |
Returns the label of this menu item
|
protected Interactable.Result |
handleKeyStroke(KeyStroke keyStroke) |
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in
focus.
|
protected boolean |
onActivated() |
Method to invoke when a menu item is "activated" by pressing the Enter key.
|
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
afterEnterFocus, afterLeaveFocus, getCursorLocation, getInputFilter, getRenderer, handleInput, isActivationStroke, isEnabled, isFocusable, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
addTo, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isVisible, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
draw, isInvalid
public MenuItem(String label)
MenuItem
with a label that does nothing when activatedlabel
- Label of the new MenuItem
public MenuItem(String label, Runnable action)
MenuItem
with a label and an action that will run on the GUI thread when activated. When
the action has finished, the Menu
containing this item will close.label
- Label of the new MenuItem
action
- Action to invoke on the GUI thread when the menu item is activatedpublic String getLabel()
protected InteractableRenderer<MenuItem> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractInteractableComponent<MenuItem>
protected boolean onActivated()
true
if the action was performed successfully, otherwise false
, which will not
automatically close the popup window itself.protected Interactable.Result handleKeyStroke(KeyStroke keyStroke)
AbstractInteractableComponent
handleInput(..)
is final in
AbstractInteractableComponent
to ensure the input filter is properly handled. If the filter decides that
this event should be processed, it will call this method.handleKeyStroke
in class AbstractInteractableComponent<MenuItem>
keyStroke
- What input was entered by the userCopyright © 2020. All rights reserved.