com.threerings.media.sprite
Class ButtonSprite

java.lang.Object
  extended by com.threerings.media.AbstractMedia
      extended by com.threerings.media.sprite.Sprite
          extended by com.threerings.media.sprite.ButtonSprite
All Implemented Interfaces:
ActionSprite, ArmingSprite, CommandSprite, DisableableSprite, Pathable, DirectionCodes, Shape

public class ButtonSprite
extends Sprite
implements CommandSprite, ArmingSprite, DisableableSprite

A sprite that acts as a button.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.media.sprite.Sprite
Sprite.CancelledOp, Sprite.CompletedOp
 
Field Summary
protected  String _actionCommand
          The action command generated by this button.
protected  Color _alternateColor
          The alternate (outline) color of this sprite.
protected  int _arcHeight
          The height of the corner arcs for rounded rectangle buttons.
protected  int _arcWidth
          The width of the corner arcs for rounded rectangle buttons.
protected  Color _backgroundColor
          The background color of this sprite.
protected  Object _commandArgument
          The command argument generated by this button.
protected  boolean _enabled
          Whether or not the button is currently enabled.
protected  Label _label
          The label associated with this sprite.
protected  boolean _pressed
          Whether or not the button is currently pressed.
protected  int _style
          The button style.
static int NORMAL
          The normal, square button style.
protected static int PADDING
          The number of pixels to add between the text and the border.
static int ROUNDED
          The rounded button style.
 
Fields inherited from class com.threerings.media.sprite.Sprite
_orient, _ox, _oxoff, _oy, _oyoff, _path, _pathStamp
 
Fields inherited from class com.threerings.media.AbstractMedia
_bounds, _firstTick, _mgr, _observers, _renderOrder, HUD_LAYER
 
Fields inherited from interface com.threerings.util.DirectionCodes
CARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST
 
Constructor Summary
ButtonSprite(Label label, int style, Color backgroundColor, Color alternateColor, String actionCommand, Object commandArgument)
          Constructs a button sprite.
ButtonSprite(Label label, int style, int arcWidth, int arcHeight, Color backgroundColor, Color alternateColor, String actionCommand, Object commandArgument)
          Constructs a button sprite.
 
Method Summary
 String getActionCommand()
           
 int getArcHeight()
          Returns the arc height for rounded buttons.
 int getArcWidth()
          Returns the arc width for rounded buttons.
 Color getBackgroundColor()
          Returns the background color of this button.
 Object getCommandArgument()
           
 Label getLabel()
          Returns a reference to the label displayed by this sprite.
 int getStyle()
          Returns the style of this button.
protected  void init()
          Called when the media has had its manager set.
 boolean isArmed()
          Checks whether or not this button appears pressed.
 boolean isEnabled()
           
 void paint(Graphics2D gfx)
          Called by the appropriate manager to request that the media render itself with the given graphics context.
 void setActionCommand(String actionCommand)
          Sets the action command generated by this button.
 void setArcHeight(int arcHeight)
          Sets the arc height for rounded buttons.
 void setArcWidth(int arcWidth)
          Sets the arc width for rounded buttons.
 void setArmed(boolean pressed)
          Render this sprite such that is is drawn "armed".
 void setBackgroundColor(Color backgroundColor)
          Sets the background color of this button.
 void setCommandArgument(Object commandArgument)
          Sets the command argument generated by this button.
 void setEnabled(boolean enabled)
          Sets whether or not this button is enabled.
 void setStyle(int style)
          Sets the style of this button.
 void updateBounds()
          Updates this sprite's bounds after a change to the label.
 
Methods inherited from class com.threerings.media.sprite.Sprite
addSpriteObserver, cancelMove, contains, fastForward, getHeight, getOrientation, getPath, getWidth, getX, getXOffset, getY, getYOffset, hitTest, inside, intersects, isMoving, move, paintPath, pathBeginning, pathCompleted, removeSpriteObserver, setLocation, setOrientation, shutdown, tick, tickPath, toString, updateRenderOrigin, viewLocationDidChange
 
Methods inherited from class com.threerings.media.AbstractMedia
addObserver, contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, intersects, intersects, invalidate, invalidateAfterChange, naturalCompareTo, queueNotification, removeObserver, renderCompareTo, setRenderOrder, toString, willStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.threerings.media.util.Pathable
getBounds
 

Field Detail

NORMAL

public static final int NORMAL
The normal, square button style.

See Also:
Constant Field Values

ROUNDED

public static final int ROUNDED
The rounded button style.

See Also:
Constant Field Values

PADDING

protected static final int PADDING
The number of pixels to add between the text and the border.

See Also:
Constant Field Values

_label

protected Label _label
The label associated with this sprite.


_style

protected int _style
The button style.


_arcWidth

protected int _arcWidth
The width of the corner arcs for rounded rectangle buttons.


_arcHeight

protected int _arcHeight
The height of the corner arcs for rounded rectangle buttons.


_actionCommand

protected String _actionCommand
The action command generated by this button.


_commandArgument

protected Object _commandArgument
The command argument generated by this button.


_backgroundColor

protected Color _backgroundColor
The background color of this sprite.


_alternateColor

protected Color _alternateColor
The alternate (outline) color of this sprite.


_enabled

protected boolean _enabled
Whether or not the button is currently enabled.


_pressed

protected boolean _pressed
Whether or not the button is currently pressed.

Constructor Detail

ButtonSprite

public ButtonSprite(Label label,
                    int style,
                    Color backgroundColor,
                    Color alternateColor,
                    String actionCommand,
                    Object commandArgument)
Constructs a button sprite.

Parameters:
label - the label to render on the button
style - the style of button to render (NORMAL or ROUNDED)
backgroundColor - the background color of the button
alternateColor - the alternate (outline) color
actionCommand - the button's command
commandArgument - the button's command argument

ButtonSprite

public ButtonSprite(Label label,
                    int style,
                    int arcWidth,
                    int arcHeight,
                    Color backgroundColor,
                    Color alternateColor,
                    String actionCommand,
                    Object commandArgument)
Constructs a button sprite.

Parameters:
label - the label to render on the button
style - the style of button to render (NORMAL or ROUNDED)
arcWidth - the width of the corner arcs for rounded buttons
arcHeight - the height of the corner arcs for rounded buttons
backgroundColor - the background color of the button
alternateColor - the alternate (outline) color
actionCommand - the button's command
commandArgument - the button's command argument
Method Detail

getLabel

public Label getLabel()
Returns a reference to the label displayed by this sprite.


updateBounds

public void updateBounds()
Updates this sprite's bounds after a change to the label.


setStyle

public void setStyle(int style)
Sets the style of this button.


getStyle

public int getStyle()
Returns the style of this button.


setArcWidth

public void setArcWidth(int arcWidth)
Sets the arc width for rounded buttons.


getArcWidth

public int getArcWidth()
Returns the arc width for rounded buttons.


setArcHeight

public void setArcHeight(int arcHeight)
Sets the arc height for rounded buttons.


getArcHeight

public int getArcHeight()
Returns the arc height for rounded buttons.


setBackgroundColor

public void setBackgroundColor(Color backgroundColor)
Sets the background color of this button.


getBackgroundColor

public Color getBackgroundColor()
Returns the background color of this button.


setActionCommand

public void setActionCommand(String actionCommand)
Sets the action command generated by this button.


getActionCommand

public String getActionCommand()
Specified by:
getActionCommand in interface ActionSprite
Returns:
the action command to submit if this sprite is clicked.

setCommandArgument

public void setCommandArgument(Object commandArgument)
Sets the command argument generated by this button.


getCommandArgument

public Object getCommandArgument()
Specified by:
getCommandArgument in interface CommandSprite
Returns:
the argument to the action command.

setEnabled

public void setEnabled(boolean enabled)
Sets whether or not this button is enabled.


isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface DisableableSprite
Returns:
true if this sprite is currently enabled.

setArmed

public void setArmed(boolean pressed)
Description copied from interface: ArmingSprite
Render this sprite such that is is drawn "armed".

Specified by:
setArmed in interface ArmingSprite

isArmed

public boolean isArmed()
Checks whether or not this button appears pressed.


init

protected void init()
Description copied from class: AbstractMedia
Called when the media has had its manager set. Derived classes may override this method, but should be sure to call super.init().

Overrides:
init in class AbstractMedia

paint

public void paint(Graphics2D gfx)
Description copied from class: AbstractMedia
Called by the appropriate manager to request that the media render itself with the given graphics context. The media may wish to inspect the clipping region that has been set on the graphics context to render itself more efficiently. This method will only be called after it has been established that this media's bounds intersect the clipping region.

Overrides:
paint in class Sprite