com.threerings.opengl.gui
Class Button

java.lang.Object
  extended by com.threerings.opengl.gui.Component
      extended by com.threerings.opengl.gui.TextComponent
          extended by com.threerings.opengl.gui.Label
              extended by com.threerings.opengl.gui.Button
All Implemented Interfaces:
ConfigUpdateListener<ManagedConfig>, UIConstants
Direct Known Subclasses:
CommandButton, ToggleButton

public class Button
extends Label
implements UIConstants

Displays a simple button that can be depressed and which generates an action event when pressed and released.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.opengl.gui.Label
Label.Fit
 
Field Summary
protected  String _action
           
protected  Object _argument
           
protected  String[] _feedbackSounds
           
protected  boolean _pressed
           
protected  long _releasedWhen
           
static int DOWN
          Indicates that this button is in the down state.
protected static int STATE_COUNT
           
protected static String[] STATE_PCLASSES
           
 
Fields inherited from class com.threerings.opengl.gui.Label
_label
 
Fields inherited from class com.threerings.opengl.gui.TextComponent
_effcols, _effsizes, _haligns, _lineSpacings, _teffects, _textfacts, _valigns
 
Fields inherited from class com.threerings.opengl.gui.Component
_alpha, _backgrounds, _borders, _colors, _ctx, _cursor, _enabled, _height, _hover, _hoverable, _insets, _listeners, _parent, _preferredSize, _properties, _rect, _styleConfigs, _tipmouse, _tiptext, _tooltipStyle, _transferHandler, _valid, _visible, _width, _x, _y, DEFAULT, DISABLED, HOVER
 
Fields inherited from interface com.threerings.opengl.gui.UIConstants
BOTTOM, CENTER, DEFAULT_SIZE, DEFAULT_SPACING, GLOW, HORIZONTAL, LEFT, NORMAL, OUTLINE, OVERLAPPING, PLAIN, RIGHT, SHADOW, TOP, VERTICAL
 
Constructor Summary
Button(GlContext ctx, Icon icon, ActionListener listener, String action)
          Creates a button with the specified icon and action.
Button(GlContext ctx, Icon icon, ActionListener listener, String action, Object argument)
          Creates a button with the specified icon, action, and argument.
Button(GlContext ctx, Icon icon, String action)
          Creates a button with the specified icon and action.
Button(GlContext ctx, Icon icon, String action, Object argument)
          Creates a button with the specified icon, action, and argument.
Button(GlContext ctx, String text)
          Creates a button with the specified textual label.
Button(GlContext ctx, String text, ActionListener listener, String action)
          Creates a button with the specified label and action.
Button(GlContext ctx, String text, ActionListener listener, String action, Object argument)
          Creates a button with the specified label, action, and argument.
Button(GlContext ctx, String text, String action)
          Creates a button with the specified label and action.
Button(GlContext ctx, String text, String action, Object argument)
          Creates a button with the specified label, action, and argument.
 
Method Summary
 boolean dispatchEvent(Event event)
          Instructs this component to process the supplied event.
 void doClick()
          Programmatically activates the button.
protected  void fireAction(long when, int modifiers)
          Called when the button is "clicked" which may due to the mouse being pressed and released while over the button or due to keyboard manipulation while the button has focus.
 String getAction()
          Returns the action generated when this button is clicked.
 Object getArgument()
          Get the argument dispatched by this button.
protected  String getDefaultStyleConfig()
          Returns the name of the default config to be used for all instances of this component.
 String getFeedbackSound()
          Returns a reference to the feedback sound used by this component.
 int getState()
          Returns the state of this component, either Component.DEFAULT or Component.DISABLED.
protected  int getStateCount()
          Returns the number of different states that this component can take.
protected  String getStatePseudoClass(int state)
          Returns the pseudoclass identifier for the specified component state.
protected  void playFeedbackSound()
          Plays the feedback sound, if any.
 void setAction(String action)
          Configures the action to be generated when this button is clicked.
 void setArgument(Object argument)
          Set the argument dispatched by this button.
protected  void updateFromStyleConfig(int state, StyleConfig.Original config)
          Updates from the resolved style config.
 
Methods inherited from class com.threerings.opengl.gui.Label
computePreferredSize, getFit, getIcon, getIconTextGap, getLabelRenderer, getText, layout, renderComponent, setFit, setIcon, setIconTextGap, setOrientation, setPreferredWidth, setText, setTextRotation
 
Methods inherited from class com.threerings.opengl.gui.TextComponent
getEffectColor, getEffectSize, getHorizontalAlignment, getLabelRendererConfig, getLineSpacing, getTextEffect, getTextFactory, getTextFactory, getVerticalAlignment
 
Methods inherited from class com.threerings.opengl.gui.Component
acceptsFocus, addListener, boundsToString, changeCursor, configUpdated, contains, createDefaultTooltipComponent, createDefaultTooltipComponent, createTooltipComponent, emitEvent, getAbsoluteX, getAbsoluteY, getAlpha, getBackground, getBorder, getBounds, getColor, getContext, getCursor, getFallbackState, getFirstDescendantFocus, getFocusTarget, getHeight, getHitComponent, getInsets, getLastDescendantFocus, getNextFocus, getParent, getPreferredSize, getPreviousFocus, getProperty, getStyleConfigs, getTooltipText, getTooltipTimeout, getTooltipWindowStyle, getTransferHandler, getWidth, getWindow, getX, getY, hasFocus, intersectScissor, invalidate, isAdded, isEnabled, isHoverable, isShowing, isTooltipRelativeToMouse, isValid, isVisible, removeAllListeners, removeAllListeners, removeListener, render, renderBackground, renderBorder, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlpha, setBackground, setBounds, setCursor, setEnabled, setHoverable, setLocation, setParent, setPreferredSize, setPreferredSize, setProperty, setSize, setStyleConfig, setStyleConfig, setStyleConfig, setStyleConfigs, setTooltipRelativeToMouse, setTooltipText, setTransferHandler, setVisible, stateDidChange, updateCursor, updateFromStyleConfig, validate, wasAdded, wasRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOWN

public static final int DOWN
Indicates that this button is in the down state.

See Also:
Constant Field Values

_pressed

protected boolean _pressed

_releasedWhen

protected long _releasedWhen

_action

protected String _action

_argument

protected Object _argument

_feedbackSounds

protected String[] _feedbackSounds

STATE_COUNT

protected static final int STATE_COUNT
See Also:
Constant Field Values

STATE_PCLASSES

protected static final String[] STATE_PCLASSES
Constructor Detail

Button

public Button(GlContext ctx,
              String text)
Creates a button with the specified textual label.


Button

public Button(GlContext ctx,
              String text,
              String action)
Creates a button with the specified label and action. The action will be dispatched via an ActionEvent when the button is clicked.


Button

public Button(GlContext ctx,
              String text,
              String action,
              Object argument)
Creates a button with the specified label, action, and argument.


Button

public Button(GlContext ctx,
              String text,
              ActionListener listener,
              String action)
Creates a button with the specified label and action. The action will be dispatched via an ActionEvent to the specified ActionListener when the button is clicked.


Button

public Button(GlContext ctx,
              String text,
              ActionListener listener,
              String action,
              Object argument)
Creates a button with the specified label, action, and argument.


Button

public Button(GlContext ctx,
              Icon icon,
              String action)
Creates a button with the specified icon and action. The action will be dispatched via an ActionEvent when the button is clicked.


Button

public Button(GlContext ctx,
              Icon icon,
              String action,
              Object argument)
Creates a button with the specified icon, action, and argument.


Button

public Button(GlContext ctx,
              Icon icon,
              ActionListener listener,
              String action)
Creates a button with the specified icon and action. The action will be dispatched via an ActionEvent to the specified ActionListener when the button is clicked.


Button

public Button(GlContext ctx,
              Icon icon,
              ActionListener listener,
              String action,
              Object argument)
Creates a button with the specified icon, action, and argument.

Method Detail

setAction

public void setAction(String action)
Configures the action to be generated when this button is clicked.


getAction

public String getAction()
Returns the action generated when this button is clicked.


setArgument

public void setArgument(Object argument)
Set the argument dispatched by this button.


getArgument

public Object getArgument()
Get the argument dispatched by this button.


getFeedbackSound

public String getFeedbackSound()
Returns a reference to the feedback sound used by this component.


doClick

public void doClick()
Programmatically activates the button.


getState

public int getState()
Description copied from class: Component
Returns the state of this component, either Component.DEFAULT or Component.DISABLED.

Overrides:
getState in class Component

dispatchEvent

public boolean dispatchEvent(Event event)
Description copied from class: Component
Instructs this component to process the supplied event. If the event is not processed, it will be passed up to its parent component for processing. Derived classes should thus only call super.dispatchEvent for events that they did not "consume".

Overrides:
dispatchEvent in class Component
Returns:
true if this event was consumed, false if not.

getDefaultStyleConfig

protected String getDefaultStyleConfig()
Description copied from class: Component
Returns the name of the default config to be used for all instances of this component. Derived classes will likely want to override this method and set up a default config for their type of component.

Overrides:
getDefaultStyleConfig in class Label

getStateCount

protected int getStateCount()
Description copied from class: Component
Returns the number of different states that this component can take. These states correspond to stylesheet pseudoclasses that allow components to customize their configuration based on whether they are enabled or disabled, or pressed if they are a button, etc.

Overrides:
getStateCount in class Component

getStatePseudoClass

protected String getStatePseudoClass(int state)
Description copied from class: Component
Returns the pseudoclass identifier for the specified component state. This string will be the way that the state is identified in the associated stylesheet. For example, the Component.DISABLED state maps to disabled and is configured like so:
 component:disabled {
    color: #CCCCCC; // etc.
 }
 

Overrides:
getStatePseudoClass in class Component

updateFromStyleConfig

protected void updateFromStyleConfig(int state,
                                     StyleConfig.Original config)
Description copied from class: Component
Updates from the resolved style config.

Overrides:
updateFromStyleConfig in class TextComponent

fireAction

protected void fireAction(long when,
                          int modifiers)
Called when the button is "clicked" which may due to the mouse being pressed and released while over the button or due to keyboard manipulation while the button has focus.


playFeedbackSound

protected void playFeedbackSound()
Plays the feedback sound, if any.