de.matthiasmann.twl
Class WheelWidget<T>

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.WheelWidget<T>
Type Parameters:
T - The data type for the wheel items

public class WheelWidget<T>
extends Widget

A wheel widget.


Nested Class Summary
static interface WheelWidget.ItemRenderer
           
static class WheelWidget.StringItemRenderer
           
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
protected  boolean cyclic
           
protected  boolean dragActive
           
protected  int dragStartY
           
protected  boolean hasDragStart
           
protected  int itemHeight
           
protected  long lastDragDelta
           
protected  int lastDragDist
           
protected  long lastDragTime
           
protected  ListModel<T> model
           
protected  int numVisibleItems
           
protected  int scrollAmount
           
protected  int scrollOffset
           
protected  int selected
           
protected  IntegerModel selectedModel
           
protected  Image selectedOverlay
           
protected  Timer timer
           
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
WheelWidget()
           
WheelWidget(ListModel<T> model)
           
 
Method Summary
protected  void afterAddToGUI(GUI gui)
          Called after this widget has been added to a GUI tree.
protected  void applyTheme(ThemeInfo themeInfo)
          Apply the given theme.
protected  void applyThemeWheel(ThemeInfo themeInfo)
           
 void autoScroll(int dir)
           
protected  void beforeRemoveFromGUI(GUI gui)
          Called when this widget is removed from the GUI tree.
 int getItemHeight()
           
protected  Widget getItemRenderer(int i)
           
 ListModel<T> getModel()
           
protected  int getNumEntries()
           
 int getNumVisibleItems()
           
 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 getSelectedModel()
           
protected  long getTime()
           
protected  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 isCyclic()
           
protected  void layout()
          Called when the layoutInvalid flag is set.
protected  void onTimer()
           
protected  void paintOverlay(GUI gui)
          Paints the overlay image of this widget.
 void registerItemRenderer(java.lang.Class<? extends T> clazz, WheelWidget.ItemRenderer value)
           
 void removeAllChildren()
          Removes all children of this widget.
 Widget removeChild(int index)
          Removes the specified child from this widget.
 boolean removeItemRenderer(java.lang.Class<? extends T> clazz)
           
 void scroll(int amount)
           
protected  void scrollInt(int amount)
           
 void setCyclic(boolean cyclic)
           
 void setModel(ListModel<T> model)
           
 void setSelected(int selected)
           
 void setSelectedModel(IntegerModel selectedModel)
           
protected  void startTimer()
           
protected  void stopTimer()
           
 
Methods inherited from class de.matthiasmann.twl.Widget
add, addActionMapping, addPropertyChangeListener, addPropertyChangeListener, adjustSize, allChildrenRemoved, applyThemeBackground, applyThemeBorder, applyThemeInputMap, applyThemeMaxSize, applyThemeMinSize, applyThemeMouseCursor, applyThemeOffscreenExtra, applyThemeOverlay, applyThemeTooltip, 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, getMinHeight, getMinWidth, getMouseCursor, getMouseCursor, getNumChildren, getOffscreenExtraBottom, getOffscreenExtraLeft, getOffscreenExtraRight, getOffscreenExtraTop, getOrCreateActionMap, getOverlay, getParent, getPreferredHeight, getPreferredWidth, getRenderOffscreen, getRight, getRootWidget, getTheme, getThemePath, getThemeTooltipContent, getTintAnimator, getTooltipContent, getTooltipContentAt, getWidgetAt, getWidth, getX, getY, giveupKeyboardFocus, handleKeyStrokeAction, hasKeyboardFocus, hasOpenPopups, hasSharedAnimationState, invalidateLayout, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isMouseInside, isVisible, keyboardFocusChildChanged, keyboardFocusGained, keyboardFocusGained, keyboardFocusLost, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, 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

itemHeight

protected int itemHeight

numVisibleItems

protected int numVisibleItems

selectedOverlay

protected Image selectedOverlay

timer

protected Timer timer

dragStartY

protected int dragStartY

lastDragTime

protected long lastDragTime

lastDragDelta

protected long lastDragDelta

lastDragDist

protected int lastDragDist

hasDragStart

protected boolean hasDragStart

dragActive

protected boolean dragActive

scrollOffset

protected int scrollOffset

scrollAmount

protected int scrollAmount

model

protected ListModel<T> model

selectedModel

protected IntegerModel selectedModel

selected

protected int selected

cyclic

protected boolean cyclic
Constructor Detail

WheelWidget

public WheelWidget()

WheelWidget

public WheelWidget(ListModel<T> model)
Method Detail

getModel

public ListModel<T> getModel()

setModel

public void setModel(ListModel<T> model)

getSelectedModel

public IntegerModel getSelectedModel()

setSelectedModel

public void setSelectedModel(IntegerModel selectedModel)

getSelected

public int getSelected()

setSelected

public void setSelected(int selected)

isCyclic

public boolean isCyclic()

setCyclic

public void setCyclic(boolean cyclic)

getItemHeight

public int getItemHeight()

getNumVisibleItems

public int getNumVisibleItems()

removeItemRenderer

public boolean removeItemRenderer(java.lang.Class<? extends T> clazz)

registerItemRenderer

public void registerItemRenderer(java.lang.Class<? extends T> clazz,
                                 WheelWidget.ItemRenderer value)

scroll

public void scroll(int amount)

scrollInt

protected void scrollInt(int amount)

autoScroll

public void autoScroll(int dir)

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

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

paintOverlay

protected void paintOverlay(GUI gui)
Description copied from class: Widget
Paints the overlay image of this widget.

Overrides:
paintOverlay in class Widget
Parameters:
gui - the GUI object
See Also:
Widget.paint(de.matthiasmann.twl.GUI)

handleEvent

protected 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)

getTime

protected long getTime()

getNumEntries

protected int getNumEntries()

getItemRenderer

protected Widget getItemRenderer(int i)

startTimer

protected void startTimer()

stopTimer

protected void stopTimer()

onTimer

protected void onTimer()

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

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

applyThemeWheel

protected void applyThemeWheel(ThemeInfo themeInfo)

afterAddToGUI

protected void afterAddToGUI(GUI gui)
Description copied from class: Widget
Called after this widget has been added to a GUI tree.

Overrides:
afterAddToGUI in class Widget
Parameters:
gui - the GUI object - same as getGUI()
See Also:
Widget.getGUI()

beforeRemoveFromGUI

protected void beforeRemoveFromGUI(GUI gui)
Description copied from class: Widget
Called when this widget is removed from the GUI tree. After this call getGUI() will return null.

Overrides:
beforeRemoveFromGUI in class Widget
Parameters:
gui - the GUI object - same as getGUI()
See Also:
Widget.getGUI()

insertChild

public void insertChild(Widget child,
                        int index)
                 throws java.lang.UnsupportedOperationException
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.UnsupportedOperationException

removeAllChildren

public void removeAllChildren()
                       throws java.lang.UnsupportedOperationException
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
Throws:
java.lang.UnsupportedOperationException
See Also:
Widget.allChildrenRemoved()

removeChild

public Widget removeChild(int index)
                   throws java.lang.UnsupportedOperationException
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.UnsupportedOperationException
See Also:
Widget.invalidateLayout()