de.matthiasmann.twl
Class Button

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.TextWidget
          extended by de.matthiasmann.twl.Button
Direct Known Subclasses:
DraggableButton, RadialPopupMenu.RoundButton, TableBase.ColumnHeader, ToggleButton

public class Button
extends TextWidget

A generic button. Behavior is defined by a ButtonModel.

To implement toggle or radio buttons use ToggleButton


Nested Class Summary
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
static AnimationState.StateKey STATE_ARMED
           
static AnimationState.StateKey STATE_PRESSED
           
static AnimationState.StateKey STATE_SELECTED
           
 
Fields inherited from class de.matthiasmann.twl.TextWidget
STATE_HOVER, STATE_TEXT_CHANGED, STATE_TEXT_SELECTION
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
Button()
           
Button(AnimationState animState)
          Creates a Button with a shared animation state
Button(AnimationState animState, boolean inherit)
          Creates a Button with a shared or inherited animation state
Button(AnimationState animState, boolean inherit, ButtonModel model)
          Creates a Button with a shared or inherited animation state
Button(AnimationState animState, ButtonModel model)
          Creates a Button with a shared animation state
Button(ButtonModel model)
           
Button(java.lang.String text)
           
 
Method Summary
 void addCallback(java.lang.Runnable callback)
           
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 applyThemeButton(ThemeInfo themeInfo)
           
protected  void beforeRemoveFromGUI(GUI gui)
          Called when this widget is removed from the GUI tree.
protected  void disarm()
           
protected  void doCallback()
           
 int getMinHeight()
          Returns the minimum height of the widget.
 int getMinWidth()
          Returns the minimum width of the widget.
 ButtonModel getModel()
           
 int getMouseButton()
           
 java.lang.String getText()
           
protected  boolean handleEvent(Event evt)
          Called when an event occurred that this widget could be interested in.
 boolean hasCallbacks()
           
 void removeCallback(java.lang.Runnable callback)
           
 void setEnabled(boolean enabled)
          Sets the local enabled state of that widget.
 void setModel(ButtonModel model)
           
 void setMouseButton(int mouseButton)
          Sets the mouse button to which this button should react.
 void setText(java.lang.String text)
           
 void setVisible(boolean visible)
          Changes the visibility flag of this widget.
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.TextWidget
applyThemeTextWidget, computeRelativeCursorPositionX, computeRelativeCursorPositionX, computeTextHeight, computeTextWidth, computeTextX, computeTextY, destroy, getAlignment, getCharSequence, getFont, getNumTextLines, getPreferredInnerHeight, getPreferredInnerWidth, handleMouseHover, hasText, isCache, isMultilineText, paintLabelText, paintTextAt, paintWidget, paintWithSelection, paintWithSelection, setAlignment, setCache, setCharSequence, setFont
 
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, 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, keyboardFocusGained, keyboardFocusGained, keyboardFocusLost, layout, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, positionChanged, reapplyTheme, removeAllChildren, removeChild, removeChild, removePropertyChangeListener, removePropertyChangeListener, requestKeyboardFocus, requestKeyboardFocus, resetTooltip, setActionMap, setBackground, setBorderSize, setBorderSize, setBorderSize, setBorderSize, setCanAcceptKeyboardFocus, setClip, setDepthFocusTraversal, setFocusKeyEnabled, setInnerSize, setInputMap, setMaxSize, setMinSize, setMouseCursor, setOffscreenExtra, setOffscreenExtra, setOverlay, setPosition, setRenderOffscreen, setSize, setTheme, setTintAnimator, setTooltipContent, 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_ARMED

public static final AnimationState.StateKey STATE_ARMED

STATE_PRESSED

public static final AnimationState.StateKey STATE_PRESSED

STATE_SELECTED

public static final AnimationState.StateKey STATE_SELECTED
Constructor Detail

Button

public Button()

Button

public Button(ButtonModel model)

Button

public Button(AnimationState animState)
Creates a Button with a shared animation state

Parameters:
animState - the animation state to share, can be null

Button

public Button(AnimationState animState,
              boolean inherit)
Creates a Button with a shared or inherited animation state

Parameters:
animState - the animation state to share or inherit, can be null
inherit - true if the animation state should be inherited false for sharing

Button

public Button(java.lang.String text)

Button

public Button(AnimationState animState,
              ButtonModel model)
Creates a Button with a shared animation state

Parameters:
animState - the animation state to share, can be null
model - the button behavior model, if null a SimpleButtonModel is created

Button

public Button(AnimationState animState,
              boolean inherit,
              ButtonModel model)
Creates a Button with a shared or inherited animation state

Parameters:
animState - the animation state to share or inherit, can be null
inherit - true if the animation state should be inherited false for sharing
model - the button behavior model, if null a SimpleButtonModel is created
Method Detail

getModel

public ButtonModel getModel()

setModel

public void setModel(ButtonModel model)

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

setEnabled

public void setEnabled(boolean enabled)
Description copied from class: Widget
Sets the local enabled state of that widget. The effective enabled state of the widget is the effective enabled state of it's parent and it's local enabled state. The effective enabled state is exposed as animation state but with inverse polarity as STATE_DISABLED. On disabling the keyboard focus will be removed. If a widget is disabled it will not receive keyboard or mouse events except MOUSE_ENTERED and MOUSE_EXITED

Overrides:
setEnabled in class Widget
Parameters:
enabled - true if the widget should be locally enabled
See Also:
Widget.isEnabled(), Widget.isLocallyEnabled()

addCallback

public void addCallback(java.lang.Runnable callback)

removeCallback

public void removeCallback(java.lang.Runnable callback)

hasCallbacks

public boolean hasCallbacks()

getText

public java.lang.String getText()

setText

public void setText(java.lang.String text)

getMouseButton

public int getMouseButton()

setMouseButton

public void setMouseButton(int mouseButton)
Sets the mouse button to which this button should react. The default is Event.MOUSE_LBUTTON

Parameters:
mouseButton - the mouse button

applyTheme

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

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

applyThemeButton

protected void applyThemeButton(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()

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

doCallback

protected final void doCallback()

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

disarm

protected void disarm()

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)