org.deken.game.component
Class GButton

java.lang.Object
  extended by org.deken.game.sprites.Sprite
      extended by org.deken.game.component.GComponent
          extended by org.deken.game.component.GTextContainer
              extended by org.deken.game.component.GButton
All Implemented Interfaces:
InputListener, InputMouseListener, Updateable
Direct Known Subclasses:
GToggleButton, GWindow.CloseButton

public class GButton
extends GTextContainer
implements InputListener

Title: GButton

Description: The GButton component is a lightweight sprite that display a GText or Animation. It is wired into the MouseListener to determine when to display a roll over text or image.

Copyright: Copyright (c) 2005

Version:
1.0
Author:
Gary Deken

Nested Class Summary
 
Nested classes/interfaces inherited from class org.deken.game.component.GComponent
GComponent.Alignment, GComponent.MouseActions
 
Field Summary
static int ANIMATION_DEFAULT
          Button Effects.
static int ANIMATION_DIABLED
           
static int ANIMATION_PRESSED
           
static int ANIMATION_ROLLOVER
           
protected  int animationIndex
           
protected  java.util.List<ButtonListener> buttonListeners
           
protected  ButtonNotify buttonNotify
           
 
Fields inherited from class org.deken.game.component.GTextContainer
baseAnimation, gText
 
Fields inherited from class org.deken.game.component.GComponent
horizontalAlignment, id, invalid, keyPolling, mouseActions, parent, requestKeyPolling, screenHeight, screenWidth, verticalAlignment, xOffSet, yOffSet
 
Fields inherited from class org.deken.game.sprites.Sprite
boundingBox, collisionMap, location, size
 
Constructor Summary
GButton()
          GButton is created with the Mouse action of button 1 pressed.
GButton(Animation animation)
          GButton is created with the Mouse action of button 1 pressed.
GButton(GText gText)
          GButton is created with the Mouse action of button 1 pressed.
GButton(GText gText, java.awt.Color fontHighlightColor)
          GButton is created with the Mouse action of button 1 pressed.
GButton(java.lang.String text)
          GButton is created with the Mouse action of button 1 pressed.
GButton(java.lang.String text, java.awt.Font font, java.awt.Color fontColor, java.awt.Color fontHighlightColor)
          GButton is created with the Mouse action of button 1 pressed.
 
Method Summary
 void addAnimation(int id, Animation animation)
           
 void addFontColor(int id, java.awt.Color color)
           
 void addGText(GText gText)
           
 void addInputAction(InputAction inputAction)
          add an InputAction for monitoring.
 void addKeyAction(InputAction keyAction)
          Add a key input action, that will trigger this button.
 boolean addListener(ButtonListener listener)
          Listeners for when this button is pressed.
 GButton copy()
           
protected  void copyGButtonBase(GButton that)
          Copies the animations and fontColors
 void draw(java.awt.Graphics2D graphics, int xOffset, int yOffset)
          Draws the sprite with the current offset.
 GComponent.Alignment getAlignment()
          getAlignment
 Animation getAnimation()
           
 Animation getAnimation(int buttonEffect)
           
 java.awt.Color getFontHighlightColor()
           
 java.awt.Image getImage()
          getImage
 int[] getInputActionIds()
          Gets the Key IDs.
 java.lang.String getKeyAssociated()
           
 boolean hasListeners()
          Convenience method for determining if child has InputListeners.
 void notifyListener(InputAction inputAction)
          Receive Key actions.
 void notifyListener(InputMouseAction inputMouseAction)
          Receive Mouse actions.
 void setAlignment(GComponent.Alignment alignment)
          setAlignment
 void setAnimation(Animation animation, int buttonEffect)
          Sets the animation to one of the four button effects: The default, rollover, pressed and disabled.
 void setEnabled(boolean b)
          setEnabled
 void setFontHighlightColor(java.awt.Color fontHighlightColor)
           
 void setGText(GText gText)
           
 void setKeyAssociated(java.lang.String keyAssociated)
           
 void setMonitored(boolean active)
           
protected  void spriteCollison(Sprite collideSprite)
          Handle the collision with another sprite.
 void update(long elapseTime)
          update()
 void validate(java.awt.Graphics2D graphics)
           
 
Methods inherited from class org.deken.game.component.GTextContainer
getBaseAnimation, getGText, setInvalid
 
Methods inherited from class org.deken.game.component.GComponent
addMouseAction, copyBase, getHorizontalAlignment, getMouseActions, getParent, getVerticalAlignment, getXLocation, getYLocation, isEnabled, positionHorizontalAlignment, positionVerticalAlignment, requestKeyPolling, setHorizontalAlignment, setKeyPolling, setParent, setVerticalAlignment
 
Methods inherited from class org.deken.game.sprites.Sprite
getBounds, getDepth, getHeight, getLocation, getName, getSize, getWidth, removeFromMap, setBoundingBox, setBoundingBox, setCollisionMap, setLocation, setName, setSize, toString, updateLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANIMATION_DEFAULT

public static final int ANIMATION_DEFAULT
Button Effects.

See Also:
Constant Field Values

ANIMATION_ROLLOVER

public static final int ANIMATION_ROLLOVER
See Also:
Constant Field Values

ANIMATION_PRESSED

public static final int ANIMATION_PRESSED
See Also:
Constant Field Values

ANIMATION_DIABLED

public static final int ANIMATION_DIABLED
See Also:
Constant Field Values

animationIndex

protected int animationIndex

buttonListeners

protected java.util.List<ButtonListener> buttonListeners

buttonNotify

protected ButtonNotify buttonNotify
Constructor Detail

GButton

public GButton()
GButton is created with the Mouse action of button 1 pressed.


GButton

public GButton(java.lang.String text)
GButton is created with the Mouse action of button 1 pressed.

Parameters:
text - String

GButton

public GButton(Animation animation)
GButton is created with the Mouse action of button 1 pressed.

Parameters:
animation - Animation

GButton

public GButton(java.lang.String text,
               java.awt.Font font,
               java.awt.Color fontColor,
               java.awt.Color fontHighlightColor)
GButton is created with the Mouse action of button 1 pressed.

Parameters:
text -
font -
fontColor -
fontHighlightColor -

GButton

public GButton(GText gText)
GButton is created with the Mouse action of button 1 pressed.

Parameters:
gText -

GButton

public GButton(GText gText,
               java.awt.Color fontHighlightColor)
GButton is created with the Mouse action of button 1 pressed.

Parameters:
gText -
fontHighlightColor -
Method Detail

addAnimation

public void addAnimation(int id,
                         Animation animation)
Specified by:
addAnimation in class GTextContainer

addFontColor

public void addFontColor(int id,
                         java.awt.Color color)
Specified by:
addFontColor in class GTextContainer

addGText

public void addGText(GText gText)
Specified by:
addGText in class GTextContainer

addInputAction

public void addInputAction(InputAction inputAction)
Description copied from interface: InputListener
add an InputAction for monitoring.

Specified by:
addInputAction in interface InputListener

addKeyAction

public void addKeyAction(InputAction keyAction)
Add a key input action, that will trigger this button.

Parameters:
keyAction -

addListener

public boolean addListener(ButtonListener listener)
Listeners for when this button is pressed.

Parameters:
listener -
Returns:
if added.

copy

public GButton copy()
Specified by:
copy in class GComponent
Returns:
GameButton

draw

public void draw(java.awt.Graphics2D graphics,
                 int xOffset,
                 int yOffset)
Description copied from class: GComponent
Draws the sprite with the current offset.

Specified by:
draw in class GComponent
Parameters:
graphics -
xOffset -
yOffset -

hasListeners

public boolean hasListeners()
Convenience method for determining if child has InputListeners.

Overrides:
hasListeners in class GTextContainer
Returns:

notifyListener

public void notifyListener(InputAction inputAction)
Receive Key actions.

Specified by:
notifyListener in interface InputListener
Parameters:
inputAction -

notifyListener

public void notifyListener(InputMouseAction inputMouseAction)
Receive Mouse actions. The mouse hover action does not set the selected boolean. The selected boolean is when this button is selected by another means.

Specified by:
notifyListener in interface InputMouseListener
Parameters:
inputMouseAction -

getAlignment

public GComponent.Alignment getAlignment()
getAlignment

Returns:
Alignment

getAnimation

public Animation getAnimation()

getAnimation

public Animation getAnimation(int buttonEffect)

getImage

public java.awt.Image getImage()
getImage

Returns the current image for the button.

Returns:
Image

getInputActionIds

public int[] getInputActionIds()
Description copied from interface: InputListener
Gets the Key IDs. This is mainly used for wiring the object into the current GameMap Actions.

Specified by:
getInputActionIds in interface InputListener
Returns:
Array of InputActionIDs

getKeyAssociated

public java.lang.String getKeyAssociated()

getFontHighlightColor

public java.awt.Color getFontHighlightColor()

setAlignment

public void setAlignment(GComponent.Alignment alignment)
setAlignment

Parameters:
alignment - Alignment

setAnimation

public void setAnimation(Animation animation,
                         int buttonEffect)
Sets the animation to one of the four button effects: The default, rollover, pressed and disabled.

Parameters:
animation -
buttonEffect -

setEnabled

public void setEnabled(boolean b)
setEnabled

Calls the super method, and set the current animation to the enabled or disabled.

Overrides:
setEnabled in class GComponent
Parameters:
b - boolean

setFontHighlightColor

public void setFontHighlightColor(java.awt.Color fontHighlightColor)

setGText

public void setGText(GText gText)

setKeyAssociated

public void setKeyAssociated(java.lang.String keyAssociated)

setMonitored

public void setMonitored(boolean active)
Specified by:
setMonitored in class GComponent

update

public void update(long elapseTime)
update()

Update the button animation.

Specified by:
update in interface Updateable
Specified by:
update in class GComponent
Parameters:
elapseTime - long

validate

public void validate(java.awt.Graphics2D graphics)
Specified by:
validate in class GComponent
Parameters:
graphics -

copyGButtonBase

protected void copyGButtonBase(GButton that)
Copies the animations and fontColors

Parameters:
that -

spriteCollison

protected void spriteCollison(Sprite collideSprite)
Description copied from class: Sprite
Handle the collision with another sprite.

Specified by:
spriteCollison in class Sprite