de.matthiasmann.twl
Class ListBox<T>

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.ListBox<T>
Type Parameters:
T - the data type of the list entries

public class ListBox<T>
extends Widget

A list box. Supports single and multiple columns.


Nested Class Summary
static class ListBox.CallbackReason
           
protected static class ListBox.ListBoxLabel
           
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
static int DEFAULT_CELL_HEIGHT
           
static int NO_SELECTION
          The value returned by getSelected() to indicate that no entry is selected.
static int SINGLE_COLUMN
           
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
ListBox()
           
ListBox(ListModel<T> model)
           
ListBox(ListSelectionModel<T> model)
           
 
Method Summary
 void addCallback(CallbackWithReason<ListBox.CallbackReason> cb)
           
protected  void applyTheme(ThemeInfo themeInfo)
          Apply the given theme.
protected  ListBoxDisplay createDisplay()
           
 int findEntryByName(java.lang.String prefix)
           
 int getCellHeight()
           
 int getCellWidth()
           
 int getEntryAt(int x, int y)
          Returns the entry at the specific coordinates or -1 if there is no entry.
 int getFirstVisible()
           
 int getLastVisible()
           
 int getMinHeight()
          Returns the minimum height of the widget.
 int getMinWidth()
          Returns the minimum width of the widget.
 ListModel<T> getModel()
           
 int getNumColumns()
           
 int getNumEntries()
           
 int getNumRows()
           
 int getPreferredInnerHeight()
          Computes the preferred inner height (the size of the widget without the border) The default implementation uses the current position of the children.
 int getPreferredInnerWidth()
          Computes the preferred inner width (the size of the widget without the border) The default implementation uses the current position of the children.
 int getSelected()
           
 IntegerModel getSelectionModel()
           
 Widget getWidgetAt(int x, int y)
          The method always return this.
protected  void goKeyboard(int dir)
           
 boolean handleEvent(Event evt)
          Called when an event occurred that this widget could be interested in.
 void insertChild(Widget child, int index)
          Inserts a new child into this widget.
 boolean isFixedCellHeight()
           
 boolean isFixedCellWidth()
           
 boolean isRowMajor()
           
protected  boolean isSearchChar(char ch)
           
protected  void keyboardFocusGained()
          Called when this widget has gained the keyboard focus.
protected  void keyboardFocusLost()
          Called when this widget has lost the keyboard focus.
protected  void layout()
          Called when the layoutInvalid flag is set.
protected  void paint(GUI gui)
          Paints this widget and it's children.
 void removeAllChildren()
          Removes all children of this widget.
 void removeCallback(CallbackWithReason<ListBox.CallbackReason> cb)
           
 Widget removeChild(int index)
          Removes the specified child from this widget.
 void scrollToSelected()
           
 void setCellHeight(int cellHeight)
           
 void setCellWidth(int cellWidth)
           
 void setFirstVisible(int firstVisible)
           
 void setFixedCellHeight(boolean fixedCellHeight)
           
 void setFixedCellWidth(boolean fixedCellWidth)
           
 void setModel(ListModel<T> model)
           
 void setModel(ListSelectionModel<T> model)
           
 void setRowMajor(boolean rowMajor)
           
 void setSelected(int selected)
          Selects the specified entry and scrolls to make it visible
 void setSelected(int selected, boolean scroll)
          Selects the specified entry and optionally scrolls to that entry
 void setSelectionModel(IntegerModel selectionModel)
           
 
Methods inherited from class de.matthiasmann.twl.Widget
add, addActionMapping, addPropertyChangeListener, addPropertyChangeListener, adjustSize, afterAddToGUI, allChildrenRemoved, applyThemeBackground, applyThemeBorder, applyThemeInputMap, applyThemeMaxSize, applyThemeMinSize, applyThemeMouseCursor, applyThemeOffscreenExtra, applyThemeOverlay, applyThemeTooltip, beforeRemoveFromGUI, borderChanged, canAcceptKeyboardFocus, childAdded, childInvalidateLayout, childRemoved, childVisibilityChanged, computeSize, destroy, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, focusFirstChild, focusLastChild, focusNextChild, focusPrevChild, getActionMap, getAnimationState, getBackground, getBorderBottom, getBorderHorizontal, getBorderLeft, getBorderRight, getBorderTop, getBorderVertical, getBottom, getChild, getChildAt, getChildIndex, getGUI, getHeight, getInnerBottom, getInnerHeight, getInnerRight, getInnerWidth, getInnerX, getInnerY, getInputMap, getKeyboardFocusOrder, getMaxHeight, getMaxWidth, getMouseCursor, getMouseCursor, getNumChildren, getOffscreenExtraBottom, getOffscreenExtraLeft, getOffscreenExtraRight, getOffscreenExtraTop, getOrCreateActionMap, getOverlay, getParent, getPreferredHeight, getPreferredWidth, getRenderOffscreen, getRight, getRootWidget, getTheme, getThemePath, getThemeTooltipContent, getTintAnimator, getTooltipContent, getTooltipContentAt, getWidth, getX, getY, giveupKeyboardFocus, handleKeyStrokeAction, hasKeyboardFocus, hasOpenPopups, hasSharedAnimationState, invalidateLayout, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isMouseInside, isVisible, keyboardFocusChildChanged, keyboardFocusGained, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, paintWidget, positionChanged, reapplyTheme, removeChild, removePropertyChangeListener, removePropertyChangeListener, requestKeyboardFocus, requestKeyboardFocus, resetTooltip, setActionMap, setBackground, setBorderSize, setBorderSize, setBorderSize, setBorderSize, setCanAcceptKeyboardFocus, setClip, setDepthFocusTraversal, setEnabled, setFocusKeyEnabled, setInnerSize, setInputMap, setMaxSize, setMinSize, setMouseCursor, setOffscreenExtra, setOffscreenExtra, setOverlay, setPosition, setRenderOffscreen, setSize, setTheme, setTintAnimator, setTooltipContent, setVisible, sizeChanged, updateTintAnimation, updateTooltip, validateLayout, widgetDisabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_SELECTION

public static final int NO_SELECTION
The value returned by getSelected() to indicate that no entry is selected.

See Also:
setSelected(int), setSelected(int, boolean), Constant Field Values

DEFAULT_CELL_HEIGHT

public static final int DEFAULT_CELL_HEIGHT
See Also:
Constant Field Values

SINGLE_COLUMN

public static final int SINGLE_COLUMN
See Also:
Constant Field Values
Constructor Detail

ListBox

public ListBox()

ListBox

public ListBox(ListModel<T> model)

ListBox

public ListBox(ListSelectionModel<T> model)
Method Detail

getModel

public ListModel<T> getModel()

setModel

public void setModel(ListModel<T> model)

getSelectionModel

public IntegerModel getSelectionModel()

setSelectionModel

public void setSelectionModel(IntegerModel selectionModel)

setModel

public void setModel(ListSelectionModel<T> model)

addCallback

public void addCallback(CallbackWithReason<ListBox.CallbackReason> cb)

removeCallback

public void removeCallback(CallbackWithReason<ListBox.CallbackReason> cb)

getCellHeight

public int getCellHeight()

setCellHeight

public void setCellHeight(int cellHeight)

getCellWidth

public int getCellWidth()

setCellWidth

public void setCellWidth(int cellWidth)

isFixedCellHeight

public boolean isFixedCellHeight()

setFixedCellHeight

public void setFixedCellHeight(boolean fixedCellHeight)

isFixedCellWidth

public boolean isFixedCellWidth()

setFixedCellWidth

public void setFixedCellWidth(boolean fixedCellWidth)

isRowMajor

public boolean isRowMajor()

setRowMajor

public void setRowMajor(boolean rowMajor)

getFirstVisible

public int getFirstVisible()

getLastVisible

public int getLastVisible()

setFirstVisible

public void setFirstVisible(int firstVisible)

getSelected

public int getSelected()

setSelected

public void setSelected(int selected)
Selects the specified entry and scrolls to make it visible

Parameters:
selected - the index or NO_SELECTION
Throws:
java.lang.IllegalArgumentException - if index is invalid
See Also:
setSelected(int, boolean)

setSelected

public void setSelected(int selected,
                        boolean scroll)
Selects the specified entry and optionally scrolls to that entry

Parameters:
selected - the index or NO_SELECTION
scroll - true if it should scroll to make the entry visible
Throws:
java.lang.IllegalArgumentException - if index is invalid

scrollToSelected

public void scrollToSelected()

getNumEntries

public int getNumEntries()

getNumRows

public int getNumRows()

getNumColumns

public int getNumColumns()

findEntryByName

public int findEntryByName(java.lang.String prefix)

getWidgetAt

public Widget getWidgetAt(int x,
                          int y)
The method always return this. Use getEntryAt(x, y) to locate the listbox entry at the specific coordinates.

Overrides:
getWidgetAt in class Widget
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
this.

getEntryAt

public int getEntryAt(int x,
                      int y)
Returns the entry at the specific coordinates or -1 if there is no entry.

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the index of the entry or -1.

insertChild

public void insertChild(Widget child,
                        int index)
                 throws java.lang.IndexOutOfBoundsException
Description copied from class: Widget
Inserts a new child into this widget. The position of the child is treated as relative to this widget and adjusted. If a theme was applied to this widget then this theme is also applied to the new child.

Overrides:
insertChild in class Widget
Parameters:
child - the child that should be inserted
index - the index where it should be inserted
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid

removeAllChildren

public void removeAllChildren()
Description copied from class: Widget
Removes all children of this widget. The position of the all removed children is changed to the relative position to this widget. Calls allChildrenRemoved after removing all children.

Overrides:
removeAllChildren in class Widget
See Also:
Widget.allChildrenRemoved()

removeChild

public Widget removeChild(int index)
                   throws java.lang.IndexOutOfBoundsException
Description copied from class: Widget
Removes the specified child from this widget. The position of the removed child is changed to the relative position to this widget. Calls invalidateLayout after removing the child.

Overrides:
removeChild in class Widget
Parameters:
index - the index of the child
Returns:
the removed widget
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid
See Also:
Widget.invalidateLayout()

applyTheme

protected void applyTheme(ThemeInfo themeInfo)
Description copied from class: Widget
Apply the given theme. This method also calls invalidateLayout()

Overrides:
applyTheme in class Widget
Parameters:
themeInfo - The theme info for this widget

goKeyboard

protected void goKeyboard(int dir)

isSearchChar

protected boolean isSearchChar(char ch)

keyboardFocusGained

protected void keyboardFocusGained()
Description copied from class: Widget
Called when this widget has gained the keyboard focus. The default implementation does nothing.

Overrides:
keyboardFocusGained in class Widget
See Also:
Widget.keyboardFocusGained(de.matthiasmann.twl.FocusGainedCause, de.matthiasmann.twl.Widget)

keyboardFocusLost

protected void keyboardFocusLost()
Description copied from class: Widget
Called when this widget has lost the keyboard focus. The default implementation does nothing.

Overrides:
keyboardFocusLost in class Widget

handleEvent

public boolean handleEvent(Event evt)
Description copied from class: Widget
Called when an event occurred that this widget could be interested in.

The default implementation handles only keyboard events and delegates them to the child widget which has keyboard focus. If focusKey handling is enabled then this widget cycles the keyboard focus through it's children. If the key was not consumed by a child or focusKey and an inputMap is specified then the event is translated by the InputMap and handleKeyStrokeAction is called when a mapping was found.

If the widget wants to receive mouse events then it must return true for all mouse events except for MOUSE_WHEEL (which is optional) event. Otherwise the following mouse event are not send. Before mouse movement or button events are send a MOUSE_ENTERED event is send first.

Overrides:
handleEvent in class Widget
Parameters:
evt - The event - do not store this object - it may be reused
Returns:
true if the widget handled this event
See Also:
Widget.setFocusKeyEnabled(boolean), Widget.handleKeyStrokeAction(java.lang.String, de.matthiasmann.twl.Event), Widget.setInputMap(de.matthiasmann.twl.InputMap)

getMinWidth

public int getMinWidth()
Description copied from class: Widget
Returns the minimum width of the widget. Layout manager will allocate atleast the minimum width to a widget even when the container is not big enough. The default implementation will not return values smaller then the current border width.

Overrides:
getMinWidth in class Widget
Returns:
the minimum width of the widget

getMinHeight

public int getMinHeight()
Description copied from class: Widget
Returns the minimum height of the widget. Layout manager will allocate atleast the minimum height to a widget even when the container is not big enough. The default implementation will not return values smaller then the current border width.

Overrides:
getMinHeight in class Widget
Returns:
the minimum height of the widget

getPreferredInnerWidth

public int getPreferredInnerWidth()
Description copied from class: Widget
Computes the preferred inner width (the size of the widget without the border) The default implementation uses the current position of the children. It is highly recommended to override this method as the default implementation lead to unstable layouts. The default behavior might change in the future to provide a better default behavior.

Overrides:
getPreferredInnerWidth in class Widget
Returns:
the preferred inner width

getPreferredInnerHeight

public int getPreferredInnerHeight()
Description copied from class: Widget
Computes the preferred inner height (the size of the widget without the border) The default implementation uses the current position of the children. It is highly recommended to override this method as the default implementation lead to unstable layouts. The default behavior might change in the future to provide a better default behavior.

Overrides:
getPreferredInnerHeight in class Widget
Returns:
the preferred inner height

paint

protected void paint(GUI gui)
Description copied from class: Widget
Paints this widget and it's children.

A subclass should overwrite paintWidget() instead of this function.

The default implementation calls the following method in order:

  1. Widget.paintBackground(de.matthiasmann.twl.GUI)
  2. Widget.paintWidget(de.matthiasmann.twl.GUI)
  3. Widget.paintChildren(de.matthiasmann.twl.GUI)
  4. Widget.paintOverlay(de.matthiasmann.twl.GUI)

Overrides:
paint in class Widget
Parameters:
gui - the GUI object

layout

protected void layout()
Description copied from class: Widget
Called when the layoutInvalid flag is set. The default implementation does nothing.

Overrides:
layout in class Widget

createDisplay

protected ListBoxDisplay createDisplay()