- 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 aMenuwith an optional action attached to it
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMenuItem.DefaultMenuItemRendererDefault renderer for menu items (both sub-menus and regular items)static classMenuItem.MenuItemRendererHelper 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 aMenuItemwith a label that does nothing when activatedMenuItem(java.lang.String label, java.lang.Runnable action)Creates a newMenuItemwith 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.StringgetLabel()Returns the label of this menu itemprotected Interactable.ResulthandleKeyStroke(KeyStroke keyStroke)This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.protected booleanonActivated()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 aMenuItemwith 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 newMenuItemwith a label and an action that will run on the GUI thread when activated. When the action has finished, theMenucontaining this item will close.- Parameters:
label- Label of the newMenuItemaction- 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:AbstractComponentWhen 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:
createDefaultRendererin 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
trueif 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:AbstractInteractableComponentThis 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 inAbstractInteractableComponentto ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.- Overrides:
handleKeyStrokein classAbstractInteractableComponent<MenuItem>- Parameters:
keyStroke- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
-