org.xith3d.ui.hud.base
Class ListModel

java.lang.Object
  extended by org.xith3d.ui.hud.base.ListModel
Direct Known Subclasses:
DefaultAbstractListModel

public abstract class ListModel
extends java.lang.Object

A ListModel holds data for a List Widget.


Constructor Summary
ListModel()
           
 
Method Summary
 void addItem(int index, java.lang.Object item)
          Adds a new Item at the given position.
 int addItem(java.lang.Object item)
          Adds a new Item at the end of the list.
protected abstract  void addItemImpl(int index, java.lang.Object item)
          Adds a new Item at the given position.
 void addItems(java.util.List<?> items)
          Adds all items from the given List to this ListModel.
 void addItems(java.lang.Object[] items)
          Adds all items from the given array to this ListModel.
 boolean checkOnMouseButtonPressed(int itemIndex, float itemLeft, float listContentWidth, float itemTop, float itemBottom, float mouseX, float mouseY)
          Checks, if the item should be selected after it was clicked at the specified location.
protected  boolean checkOnMouseButtonPressedImpl(int itemIndex, float itemTop, float itemBottom, float mouseX, float mouseY)
          Checks, if the item should be selected after it was clicked at the specified location.
abstract  void clear()
          Clears the list.
 java.lang.Object getItem(int index)
          Gets the item at index index.
 float getItemHeight(int itemIndex)
          Gets the item's height in HUD space.
protected abstract  float getItemHeightImpl(int itemIndex)
          Gets the item's height in HUD space.
protected abstract  java.lang.Object getItemImpl(int index)
          Gets the item at index index.
abstract  int getItemsCount()
          Gets the number of items in the list.
protected  AbstractList getList()
          Gets the List Widget, that this model is used for (can be null).
 float getMinItemWidth(int itemIndex)
          Gets the item's minimum width in HUD space.
protected abstract  float getMinItemWidthImpl(int itemIndex)
          Gets the item's minimum width in HUD space.
 int getSelectedIndex()
          Gets the selected index.
 java.lang.Object getSelectedItem()
          Gets the selected item.
protected abstract  Widget[] getUsedWidgets()
          Gets an array of all Widgets, that are used by this model.
 boolean getUsesFixedHeight()
          Returns, whether all items have the same height.
protected  Widget getWidget(int itemIndex)
          Gets the Widget to render the specified item.
protected abstract  Widget getWidgetImpl(int itemIndex)
          Gets the Widget, that is used to render the specified item.
 boolean hoverNeedsRedraw()
          Checks, whether hovering the items needs the List to be redrawn.
 boolean isSelected(int index)
          Queries, whether the specified index is selected.
 void markListDirty()
          Notifies the List be be redrawn.
protected  void prepareWidget(float listContentWidth, Widget widget, java.lang.Object item, int itemIndex)
          This method is called right before the Widget is used to render a specific item.
protected abstract  void prepareWidgetImpl(float listContentWidth, Widget widget, java.lang.Object item, int itemIndex)
          This method is called right before the Widget is used to render a specific item.
 java.lang.Object removeItem(int index)
          Removes an Item at the given position.
protected abstract  java.lang.Object removeItemImpl(int index)
          Removes an Item at the given position.
 void setItem(int index, java.lang.Object item)
          Sets the item at the given position.
protected abstract  void setItemImpl(int index, java.lang.Object item)
          Sets the item at the given position.
 void setSelectedIndex(int index)
          Sets the selected index.
 void setUsesFixedHeight(boolean usesFixedHeight)
          Sets, whether all items have the same height.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListModel

public ListModel()
Method Detail

getList

protected final AbstractList getList()
Gets the List Widget, that this model is used for (can be null).

Returns:
the List Widget, that this model is used for.

getUsedWidgets

protected abstract Widget[] getUsedWidgets()
Gets an array of all Widgets, that are used by this model.

Returns:
an array of all Widgets, that are used by this model.

addItemImpl

protected abstract void addItemImpl(int index,
                                    java.lang.Object item)
Adds a new Item at the given position.

Parameters:
index -
item -

addItem

public final void addItem(int index,
                          java.lang.Object item)
Adds a new Item at the given position.

Parameters:
index -
item -

addItem

public final int addItem(java.lang.Object item)
Adds a new Item at the end of the list.

Parameters:
item -
Returns:
the index, at which the item has been added.

addItems

public void addItems(java.util.List<?> items)
Adds all items from the given List to this ListModel.

Parameters:
items -

addItems

public void addItems(java.lang.Object[] items)
Adds all items from the given array to this ListModel.

Parameters:
items -

setItemImpl

protected abstract void setItemImpl(int index,
                                    java.lang.Object item)
Sets the item at the given position.

Parameters:
index -
item -

setItem

public final void setItem(int index,
                          java.lang.Object item)
Sets the item at the given position.

Parameters:
index -
item -

removeItemImpl

protected abstract java.lang.Object removeItemImpl(int index)
Removes an Item at the given position.

Parameters:
index -
Returns:
the removed Item or null, if there was no item at the given index.

removeItem

public final java.lang.Object removeItem(int index)
Removes an Item at the given position.

Parameters:
index -
Returns:
the removed Item or null, if there was no item at the given index.

clear

public abstract void clear()
Clears the list.


getItemsCount

public abstract int getItemsCount()
Gets the number of items in the list.

Returns:
the number of items in the list.

getItemImpl

protected abstract java.lang.Object getItemImpl(int index)
Gets the item at index index. This item must be handleable by the used Widget.

Parameters:
index -
Returns:
the index'th item.

getItem

public java.lang.Object getItem(int index)
Gets the item at index index. This item must be handleable by the used Widget.

Parameters:
index -
Returns:
the index'th item.

getWidgetImpl

protected abstract Widget getWidgetImpl(int itemIndex)
Gets the Widget, that is used to render the specified item. This method should not do anything to the returned Widget. All setup stuff is done in the #prepareWidget(Widget, Object) method.

Parameters:
itemIndex -
Returns:
the raw Widget.

prepareWidgetImpl

protected abstract void prepareWidgetImpl(float listContentWidth,
                                          Widget widget,
                                          java.lang.Object item,
                                          int itemIndex)
This method is called right before the Widget is used to render a specific item.
It must only return the Widget.

Parameters:
listContentWidth -
widget -
item -
itemIndex -

prepareWidget

protected void prepareWidget(float listContentWidth,
                             Widget widget,
                             java.lang.Object item,
                             int itemIndex)
This method is called right before the Widget is used to render a specific item.

Parameters:
listContentWidth -
widget -
item -
itemIndex -

getWidget

protected final Widget getWidget(int itemIndex)
Gets the Widget to render the specified item. The Widget will be fully setup to be rendered to the list.

Parameters:
itemIndex -
Returns:
the fully setup Widget.

hoverNeedsRedraw

public boolean hoverNeedsRedraw()
Checks, whether hovering the items needs the List to be redrawn.

Returns:
if hovering the items needs a redraw.

checkOnMouseButtonPressedImpl

protected boolean checkOnMouseButtonPressedImpl(int itemIndex,
                                                float itemTop,
                                                float itemBottom,
                                                float mouseX,
                                                float mouseY)
Checks, if the item should be selected after it was clicked at the specified location.

Parameters:
itemIndex -
itemTop -
itemBottom -
mouseX -
mouseY -
Returns:
should the item get selected?

checkOnMouseButtonPressed

public final boolean checkOnMouseButtonPressed(int itemIndex,
                                               float itemLeft,
                                               float listContentWidth,
                                               float itemTop,
                                               float itemBottom,
                                               float mouseX,
                                               float mouseY)
Checks, if the item should be selected after it was clicked at the specified location.

Parameters:
itemIndex -
itemLeft -
itemTop -
itemBottom -
mouseX -
mouseY -
Returns:
should the item get selected?

setUsesFixedHeight

public void setUsesFixedHeight(boolean usesFixedHeight)
Sets, whether all items have the same height. If true, getItemHeight(0) is used for all items. Default: true.

Parameters:
usesFixedHeight -

getUsesFixedHeight

public final boolean getUsesFixedHeight()
Returns, whether all items have the same height. If true, getItemHeight(0) is used for all items. Default: true.

Returns:
whether all items have the same height.

getItemHeightImpl

protected abstract float getItemHeightImpl(int itemIndex)
Gets the item's height in HUD space. If getUsesFixedHeight() is true, only the value of the first item is used for all.

Parameters:
itemIndex -
Returns:
the item's height.

getItemHeight

public final float getItemHeight(int itemIndex)
Gets the item's height in HUD space. If getUsesFixedHeight() is true, only the value of the first item is used for all.

Parameters:
itemIndex -
Returns:
the item's height.

getMinItemWidthImpl

protected abstract float getMinItemWidthImpl(int itemIndex)
Gets the item's minimum width in HUD space.

Parameters:
itemIndex -
Returns:
the item's minimum height.

getMinItemWidth

public final float getMinItemWidth(int itemIndex)
Gets the item's minimum width in HUD space.

Parameters:
itemIndex -
Returns:
the item's minimum height.

setSelectedIndex

public void setSelectedIndex(int index)
Sets the selected index.

Parameters:
index -

getSelectedIndex

public int getSelectedIndex()
Gets the selected index. This method is not used by the (default) list implementation. isSelected(int) is used instead, which is more flexible.

Returns:
the selected index.

getSelectedItem

public java.lang.Object getSelectedItem()
Gets the selected item.

Returns:
the selected item.

isSelected

public boolean isSelected(int index)
Queries, whether the specified index is selected.

Parameters:
index -
Returns:
index selected?

markListDirty

public void markListDirty()
Notifies the List be be redrawn.