- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<MenuBar>
-
- com.googlecode.lanterna.gui2.menu.MenuBar
-
- All Implemented Interfaces:
Component,Container,TextGUIElement
- Direct Known Subclasses:
AbstractBasePane.EmptyMenuBar
public class MenuBar extends AbstractComponent<MenuBar> implements Container
A menu bar offering drop-down menus. You can attach a menu bar to aWindowby using theWindow.setMenuBar(MenuBar)method, then useadd(Menu)to add sub-menus to the menu bar.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMenuBar.DefaultMenuBarRendererThe default implementation for rendering aMenuBar
-
Field Summary
Fields Modifier and Type Field Description private static intEXTRA_PADDINGprivate java.util.List<Menu>menus
-
Constructor Summary
Constructors Constructor Description MenuBar()Creates a new menu bar
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MenuBaradd(Menu menu)Adds a new drop-down menu to the menu bar, at the endbooleancontainsComponent(Component component)Returnstrueif this container contains the supplied component either directly or indirectly through intermediate containers.protected ComponentRenderer<MenuBar>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).intgetChildCount()Returns the number of children this container currently hasjava.util.Collection<Component>getChildren()Returns collection that is to be considered a copy of the list of children contained inside of this object.java.util.List<Component>getChildrenList()Returns list that is to be considered a copy of the list of children inside of this container.MenugetMenu(int index)Returns the drop-down menu at the specified index.intgetMenuCount()Returns the number of menus this menu bar currently hasbooleanhandleInput(KeyStroke key)If an interactable component inside this container received a keyboard event that wasn't handled, the GUI system will recursively send the event to each parent container to give each of them a chance to consume the event.booleanisEmptyMenuBar()InteractablenextFocus(Interactable fromThis)Given an interactable, find the next one in line to receive focus.InteractablepreviousFocus(Interactable fromThis)Given an interactable, find the previous one in line to receive focus.booleanremoveComponent(Component component)Removes the component from the container.TerminalPositiontoBasePane(TerminalPosition position)Translates a position local to the container to the base pane's coordinate space.voidupdateLookupMap(InteractableLookupMap interactableLookupMap)Takes a lookup map and updates it with information about where all the interactables inside of this container are located.-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, 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, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isVisible, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, setVisible, toGlobal, withBorder
-
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUIElement
draw, isInvalid
-
-
-
-
Field Detail
-
EXTRA_PADDING
private static final int EXTRA_PADDING
- See Also:
- Constant Field Values
-
menus
private final java.util.List<Menu> menus
-
-
Method Detail
-
add
public MenuBar add(Menu menu)
Adds a new drop-down menu to the menu bar, at the end- Parameters:
menu- Menu to add to the menu bar- Returns:
- Itself
-
getChildCount
public int getChildCount()
Description copied from interface:ContainerReturns the number of children this container currently has- Specified by:
getChildCountin interfaceContainer- Returns:
- Number of children currently in this container
-
getChildrenList
public java.util.List<Component> getChildrenList()
Description copied from interface:ContainerReturns list that is to be considered a copy of the list of children inside of this container. Modifying this list will not affect any internal state. This method is essentially the same as getChildren but the returned collection is a list.- Specified by:
getChildrenListin interfaceContainer- Returns:
- Child-components inside of this Container
- See Also:
Container.getChildren()
-
getChildren
public java.util.Collection<Component> getChildren()
Description copied from interface:ContainerReturns collection that is to be considered a copy of the list of children contained inside of this object. Modifying this collection will not affect any internal state.This method isn't deprecated but it should have originally been defined as returning a List instead of a Collection. See
getChildrenListfor a method with this signature.- Specified by:
getChildrenin interfaceContainer- Returns:
- Child-components inside of this Container
- See Also:
Container.getChildrenList()
-
containsComponent
public boolean containsComponent(Component component)
Description copied from interface:ContainerReturnstrueif this container contains the supplied component either directly or indirectly through intermediate containers.- Specified by:
containsComponentin interfaceContainer- Parameters:
component- Component to check if it's part of this container- Returns:
trueif the component is inside this Container, otherwisefalse
-
removeComponent
public boolean removeComponent(Component component)
Description copied from interface:ContainerRemoves the component from the container. This should remove the component from the Container's internal data structure as well as call the onRemoved(..) method on the component itself if it was found inside the container.- Specified by:
removeComponentin interfaceContainer- Parameters:
component- Component to remove from the Container- Returns:
trueif the component existed inside the container and was removed,falseotherwise
-
nextFocus
public Interactable nextFocus(Interactable fromThis)
Description copied from interface:ContainerGiven an interactable, find the next one in line to receive focus. If the interactable isn't inside this container, this method should returnnull.
-
previousFocus
public Interactable previousFocus(Interactable fromThis)
Description copied from interface:ContainerGiven an interactable, find the previous one in line to receive focus. If the interactable isn't inside this container, this method should returnnull.- Specified by:
previousFocusin interfaceContainer- Parameters:
fromThis- Component from which to get the previous interactable, or if null, pick the last interactable in the list- Returns:
- The previous interactable component, or null if there are no more interactables in the list
-
handleInput
public boolean handleInput(KeyStroke key)
Description copied from interface:ContainerIf an interactable component inside this container received a keyboard event that wasn't handled, the GUI system will recursively send the event to each parent container to give each of them a chance to consume the event. Returnfalseif the implementer doesn't care about this particular keystroke and it will be automatically sent up the hierarchy the to next container. If you returntrue, the event will stop here and won't be reported as unhandled.- Specified by:
handleInputin interfaceContainer- Parameters:
key- Keystroke that was ignored by the interactable inside this container- Returns:
trueif this event was handled by this container and shouldn't be processed anymore,falseif the container didn't take any action on the event and want to pass it on
-
getMenu
public Menu getMenu(int index)
Returns the drop-down menu at the specified index. This method will throw an Array- Parameters:
index- Index of the menu to return- Returns:
- The drop-down menu at the specified index
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range
-
getMenuCount
public int getMenuCount()
Returns the number of menus this menu bar currently has- Returns:
- The number of menus this menu bar currently has
-
createDefaultRenderer
protected ComponentRenderer<MenuBar> 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 classAbstractComponent<MenuBar>- Returns:
- Renderer to use when sizing and drawing this component
-
updateLookupMap
public void updateLookupMap(InteractableLookupMap interactableLookupMap)
Description copied from interface:ContainerTakes a lookup map and updates it with information about where all the interactables inside of this container are located.- Specified by:
updateLookupMapin interfaceContainer- Parameters:
interactableLookupMap- Interactable map to update
-
toBasePane
public TerminalPosition toBasePane(TerminalPosition position)
Description copied from interface:ComponentTranslates a position local to the container to the base pane's coordinate space. For a window-based GUI, this be a coordinate in the window's coordinate space. If the component belongs to no base pane, it will returnnull.- Specified by:
toBasePanein interfaceComponent- Overrides:
toBasePanein classAbstractComponent<MenuBar>- Parameters:
position- Position to translate (relative to the container's top-left corner)- Returns:
- Position in base pane space, or
nullif the component is an orphan
-
isEmptyMenuBar
public boolean isEmptyMenuBar()
-
-