de.matthiasmann.twl
Class ValueAdjuster

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.ValueAdjuster
Direct Known Subclasses:
ValueAdjusterFloat, ValueAdjusterInt

public abstract class ValueAdjuster
extends Widget

Base class for value adjuster widgets. It has a value display/edit widget and 2 buttons. You can adjust the value via drag&drop on the display or by clicking on the display which will open an edit field or using the +/- buttons or using the left/right keys


Nested Class Summary
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
static AnimationState.StateKey STATE_EDIT_ACTIVE
           
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
ValueAdjuster()
           
 
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 applyThemeValueAdjuster(ThemeInfo themeInfo)
           
protected  void beforeRemoveFromGUI(GUI gui)
          Called when this widget is removed from the GUI tree.
 void cancelEdit()
           
 void cancelOrAcceptEdit()
           
protected abstract  void doDecrement()
           
protected abstract  void doIncrement()
           
protected abstract  java.lang.String formatText()
           
 java.lang.String getDisplayPrefix()
           
 int getMinHeight()
          Returns the minimum height of the widget.
 int getMinWidth()
          Returns the minimum width of the widget.
 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.
protected  boolean handleEvent(Event evt)
          Called when an event occurred that this widget could be interested in.
 boolean isAcceptValueOnFocusLoss()
           
 boolean isUseMouseWheel()
           
protected  void keyboardFocusGained()
          Called when this widget has gained the keyboard focus.
protected  void keyboardFocusGained(FocusGainedCause cause, Widget previousWidget)
          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 abstract  void onDragCancelled()
           
protected  void onDragEnd()
           
protected abstract  void onDragStart()
           
protected abstract  void onDragUpdate(int dragDelta)
           
protected abstract  void onEditCanceled()
           
protected abstract  boolean onEditEnd(java.lang.String text)
           
protected abstract  java.lang.String onEditStart()
           
 void setAcceptValueOnFocusLoss(boolean acceptValueOnFocusLoss)
          Controls the behavior on focus loss when editing the value.
 void setDisplayPrefix(java.lang.String displayPrefix)
          Sets the display prefix which is displayed before the value.
protected  void setDisplayText()
           
 void setTooltipContent(java.lang.Object tooltipContent)
          Changes the tooltip context.
 void setUseMouseWheel(boolean useMouseWheel)
          Controls if the ValueAdjuster should respond to the mouse wheel or not
 void setVisible(boolean visible)
          Changes the visibility flag of this widget.
protected abstract  boolean shouldStartEdit(char ch)
           
 void startEdit()
           
protected abstract  void syncWithModel()
           
protected abstract  java.lang.String validateEdit(java.lang.String text)
           
protected  void widgetDisabled()
          This method is called when this widget has been disabled, either directly or one of it's parents.
 
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, 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, insertChild, invalidateLayout, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isMouseInside, isVisible, keyboardFocusChildChanged, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, paintWidget, positionChanged, reapplyTheme, removeAllChildren, removeChild, 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, sizeChanged, updateTintAnimation, updateTooltip, validateLayout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_EDIT_ACTIVE

public static final AnimationState.StateKey STATE_EDIT_ACTIVE
Constructor Detail

ValueAdjuster

public ValueAdjuster()
Method Detail

getDisplayPrefix

public java.lang.String getDisplayPrefix()

setDisplayPrefix

public void setDisplayPrefix(java.lang.String displayPrefix)
Sets the display prefix which is displayed before the value. If this is property is null then the value from the theme is used, otherwise this one.

Parameters:
displayPrefix - the prefix or null

isUseMouseWheel

public boolean isUseMouseWheel()

setAcceptValueOnFocusLoss

public void setAcceptValueOnFocusLoss(boolean acceptValueOnFocusLoss)
Controls the behavior on focus loss when editing the value. If true then the value is accepted (like pressing RETURN). If false then it is discard (like pressing ESCAPE). Default is true.

Parameters:
acceptValueOnFocusLoss - true if focus loss should accept the edited value.

isAcceptValueOnFocusLoss

public boolean isAcceptValueOnFocusLoss()

setUseMouseWheel

public void setUseMouseWheel(boolean useMouseWheel)
Controls if the ValueAdjuster should respond to the mouse wheel or not

Parameters:
useMouseWheel - true if the mouse wheel is used

setTooltipContent

public void setTooltipContent(java.lang.Object tooltipContent)
Description copied from class: Widget
Changes the tooltip context. If the tooltip is currently active then it's refreshed with the new content.

Overrides:
setTooltipContent in class Widget
Parameters:
tooltipContent - the new tooltip content.
See Also:
Widget.updateTooltip(), Widget.getTooltipContent()

startEdit

public void startEdit()

cancelEdit

public void cancelEdit()

cancelOrAcceptEdit

public void cancelOrAcceptEdit()

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

applyThemeValueAdjuster

protected void applyThemeValueAdjuster(ThemeInfo themeInfo)

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

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

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)

keyboardFocusGained

protected void keyboardFocusGained(FocusGainedCause cause,
                                   Widget previousWidget)
Description copied from class: Widget
Called when this widget has gained the keyboard focus. The default implementation calls Widget.keyboardFocusGained()

Overrides:
keyboardFocusGained in class Widget
Parameters:
cause - the cause for the this focus transfer
previousWidget - the widget which previously had the keyboard focus - can be null.

setVisible

public void setVisible(boolean visible)
Description copied from class: Widget
Changes the visibility flag of this widget. Widgets are by default visible. Invisible widgets don't receive paint() or handleEvent() calls

Overrides:
setVisible in class Widget
Parameters:
visible - the new visibility flag

widgetDisabled

protected void widgetDisabled()
Description copied from class: Widget
This method is called when this widget has been disabled, either directly or one of it's parents.

The default implementation does nothing.

Overrides:
widgetDisabled in class Widget

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

setDisplayText

protected void setDisplayText()

formatText

protected abstract java.lang.String formatText()

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

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)

onEditStart

protected abstract java.lang.String onEditStart()

onEditEnd

protected abstract boolean onEditEnd(java.lang.String text)

validateEdit

protected abstract java.lang.String validateEdit(java.lang.String text)

onEditCanceled

protected abstract void onEditCanceled()

shouldStartEdit

protected abstract boolean shouldStartEdit(char ch)

onDragStart

protected abstract void onDragStart()

onDragUpdate

protected abstract void onDragUpdate(int dragDelta)

onDragCancelled

protected abstract void onDragCancelled()

onDragEnd

protected void onDragEnd()

doDecrement

protected abstract void doDecrement()

doIncrement

protected abstract void doIncrement()

syncWithModel

protected abstract void syncWithModel()