Class AbstractListBox.ListItemRenderer<V,T extends AbstractListBox<V,T>>

java.lang.Object
com.googlecode.lanterna.gui2.AbstractListBox.ListItemRenderer<V,T>
Type Parameters:
V - Type of the items in the list box
T - Type of the list box class itself
Direct Known Subclasses:
CheckBoxList.CheckBoxListItemRenderer, RadioBoxList.RadioBoxListItemRenderer
Enclosing class:
AbstractListBox<V,T extends AbstractListBox<V,T>>

public static class AbstractListBox.ListItemRenderer<V,T extends AbstractListBox<V,T>> extends Object
The default list item renderer class, this can be extended and customized it needed. The instance which is assigned to the list box will be called once per item in the list when the list box is drawn.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    drawItem(TextGUIGraphics graphics, T listBox, int index, V item, boolean selected, boolean focused)
    This is the main drawing method for a single list box item, it applies the current theme to setup the colors and then calls getLabel(..) and draws the result using the supplied TextGUIGraphics.
    int
    getHotSpotPositionOnLine(int selectedIndex)
    Returns where on the line to place the text terminal cursor for a currently selected item.
    getLabel(T listBox, int index, V item)
    Given a list box, an index of an item within that list box and what the item is, this method should return what to draw for that item.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ListItemRenderer

      public ListItemRenderer()
  • Method Details

    • getHotSpotPositionOnLine

      public int getHotSpotPositionOnLine(int selectedIndex)
      Returns where on the line to place the text terminal cursor for a currently selected item. By default this will return 0, meaning the first character of the selected line. If you extend ListItemRenderer you can change this by returning a different number. Returning -1 will cause lanterna to hide the cursor.
      Parameters:
      selectedIndex - Which item is currently selected
      Returns:
      Index of the character in the string we want to place the terminal cursor on, or -1 to hide it
    • getLabel

      public String getLabel(T listBox, int index, V item)
      Given a list box, an index of an item within that list box and what the item is, this method should return what to draw for that item. The default implementation is to return whatever toString() returns when called on the item.
      Parameters:
      listBox - List box the item belongs to
      index - Index of the item
      item - The item itself
      Returns:
      String to draw for this item
    • drawItem

      public void drawItem(TextGUIGraphics graphics, T listBox, int index, V item, boolean selected, boolean focused)
      This is the main drawing method for a single list box item, it applies the current theme to setup the colors and then calls getLabel(..) and draws the result using the supplied TextGUIGraphics. The graphics object is created just for this item and is restricted so that it can only draw on the area this item is occupying. The top-left corner (0x0) should be the starting point when drawing the item.
      Parameters:
      graphics - Graphics object to draw with
      listBox - List box we are drawing an item from
      index - Index of the item we are drawing
      item - The item we are drawing
      selected - Will be set to true if the item is currently selected, otherwise false, but please notice what context 'selected' refers to here (see setSelectedIndex)
      focused - Will be set to true if the list box currently has input focus, otherwise false