- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<T>
-
- com.googlecode.lanterna.gui2.AbstractInteractableComponent<MenuItem>
-
- com.googlecode.lanterna.gui2.menu.MenuItem
-
- All Implemented Interfaces:
Component
,Interactable
,TextGUIElement
- Direct Known Subclasses:
Menu
public class MenuItem extends AbstractInteractableComponent<MenuItem>
This class is a single item that appears in aMenu
with an optional action attached to it
-
-
Nested Class Summary
Nested Classes Modifier 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-
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.Interactable
Interactable.FocusChangeDirection, Interactable.Result
-
-
Constructor Summary
Constructors Constructor Description MenuItem(java.lang.String label)
Creates aMenuItem
with a label that does nothing when activatedMenuItem(java.lang.String label, java.lang.Runnable action)
Creates a newMenuItem
with a label and an action that will run on the GUI thread when activated.
-
Method Summary
All Methods Instance Methods Concrete Methods 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).java.lang.String
getLabel()
Returns the label of this menu itemprotected 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.-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractInteractableComponent
afterEnterFocus, afterLeaveFocus, getCursorLocation, getInputFilter, getRenderer, handleInput, isActivationStroke, isEnabled, isFocusable, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.googlecode.lanterna.gui2.Component
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
-
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUIElement
draw, isInvalid
-
-
-
-
Constructor Detail
-
MenuItem
public MenuItem(java.lang.String label)
Creates aMenuItem
with a label that does nothing when activated- Parameters:
label
- Label of the newMenuItem
-
MenuItem
public MenuItem(java.lang.String label, java.lang.Runnable action)
Creates a newMenuItem
with a label and an action that will run on the GUI thread when activated. When the action has finished, theMenu
containing this item will close.- Parameters:
label
- Label of the newMenuItem
action
- Action to invoke on the GUI thread when the menu item is activated
-
-
Method Detail
-
getLabel
public java.lang.String getLabel()
Returns the label of this menu item- Returns:
- Label of this menu item
-
createDefaultRenderer
protected InteractableRenderer<MenuItem> createDefaultRenderer()
Description copied from class:AbstractComponent
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). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRenderer
in classAbstractInteractableComponent<MenuItem>
- Returns:
- Renderer to use when sizing and drawing this component
-
onActivated
protected boolean onActivated()
Method to invoke when a menu item is "activated" by pressing the Enter key.- Returns:
- Returns
true
if the action was performed successfully, otherwisefalse
, which will not automatically close the popup window itself.
-
handleKeyStroke
protected Interactable.Result handleKeyStroke(KeyStroke keyStroke)
Description copied from class:AbstractInteractableComponent
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus. The input method from the interface,handleInput(..)
is final inAbstractInteractableComponent
to ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.- Overrides:
handleKeyStroke
in classAbstractInteractableComponent<MenuItem>
- Parameters:
keyStroke
- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
-