ch.aplu.jgamegrid
Class GGToggleButton

java.lang.Object
  extended by ch.aplu.jgamegrid.Actor
      extended by ch.aplu.jgamegrid.GGButtonBase
          extended by ch.aplu.jgamegrid.GGToggleButton
All Implemented Interfaces:
GGActorCollisionListener, GGBorderListener, GGTileCollisionListener, java.util.EventListener

public class GGToggleButton
extends GGButtonBase

Class that implements a toggle button (2-state button) actor with standard behavior. Events are generated when the button changes its state due to a mouse click. The button is centered in the middle of a cell. Use Actor.setLocationOffset() to fine tune the button location.


Field Summary
 
Fields inherited from class ch.aplu.jgamegrid.Actor
gameGrid, nbCycles
 
Constructor Summary
GGToggleButton(java.lang.String buttonImage)
          Same as GGToggleButton(String buttonImage, false, false) (no rollover, untoggled).
GGToggleButton(java.lang.String buttonImage, boolean isRollover)
          Same as GGToggleButton(String buttonImage, boolean isRollover, false) (untoggled).
GGToggleButton(java.lang.String buttonImage, boolean isRollover, boolean isToggled)
          Creates a button from the given sprite images.
 
Method Summary
 void addButtonOverListener(GGButtonOverListener listener)
          Registers a GGOverButtonListener to get notifications when the mouse cursor enters the active mouse area.
 void addToggleButtonListener(GGToggleButtonListener listener)
          Registers a GGToggleButtonListener to get notifications when the button is manipulated.
 boolean isToggled()
          Returns the current state of the button.
 void reset()
          Overrides the actor's reset() called when the button is added to the game grid.
 void setToggled(boolean b)
          Sets the button in the toggled/untoggled state.
 
Methods inherited from class ch.aplu.jgamegrid.GGButtonBase
isEnabled, setEnabled, setHotspotArea, setRefreshEnabled
 
Methods inherited from class ch.aplu.jgamegrid.Actor
act, addActorCollisionListener, addBorderListener, addCollisionActor, addCollisionActors, addCollisionActors, addCollisionTile, addCollisionTiles, addCollisionTiles, addMouseTouchListener, addMouseTouchListener, addTileCollisionListener, collide, collide, delay, displace, getBackground, getCollisionActors, getCollisionActorsInRange, getCollisionTiles, getCurrentImage, getDirection, getDirectionStart, getDisplacePosition, getHeight, getIdVisible, getImage, getImage, getIntDirection, getLocation, getLocationOffset, getLocationStart, getNbCycles, getNbHorzCells, getNbSprites, getNbVertCells, getNeighbours, getNeighbours, getNextMoveLocation, getPixelColor, getPixelLocation, getRotatedPosition, getRotationIndex, getScaledImage, getScaledImage, getScaledImage, getSlowDown, getWidth, getX, getXStart, getY, getYStart, hide, isActEnabled, isActorCollisionEnabled, isHorzMirror, isInGrid, isMoveValid, isNearBorder, isRemoved, isRotatable, isTileCollisionEnabled, isVertMirror, isVisible, move, move, nearBorder, removeSelf, rotate, rotate, setActEnabled, setActorCollisionEnabled, setCollisionCircle, setCollisionCircle, setCollisionImage, setCollisionImage, setCollisionLine, setCollisionLine, setCollisionRectangle, setCollisionRectangle, setCollisionSpot, setCollisionSpot, setDirection, setDirection, setDisplacePosition, setHorzMirror, setLocation, setLocationOffset, setLocationOffset, setMouseTouchCircle, setMouseTouchCircle, setMouseTouchEnabled, setMouseTouchImage, setMouseTouchImage, setMouseTouchRectangle, setMouseTouchRectangle, setOnBottom, setOnTop, setPixelLocation, setSlowDown, setTileCollisionEnabled, setVertMirror, setX, setY, show, show, showNextSprite, showPreviousSprite, turn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GGToggleButton

public GGToggleButton(java.lang.String buttonImage,
                      boolean isRollover,
                      boolean isToggled)
Creates a button from the given sprite images. Multiple sprites are assumed, using the implicite underline convention. If isRollover is true, image_0.gif corresponds to the released state, image_1.gif to the pressed state, image_2.gif to the rollover released state and image_3.gif to the rollover pressed state. If isRollover is false, only image_0.gif and image_1.gif are needed.

Parameters:
buttonImage - the filename or URL of the 2 or 4 button sprites
isRollover - if true, rollover imaged are used
isToggled - if true, the button is initially toggled; otherwise it is untoggled

GGToggleButton

public GGToggleButton(java.lang.String buttonImage,
                      boolean isRollover)
Same as GGToggleButton(String buttonImage, boolean isRollover, false) (untoggled).

Parameters:
buttonImage - the filename or URL of the 2 or 4 button sprites

GGToggleButton

public GGToggleButton(java.lang.String buttonImage)
Same as GGToggleButton(String buttonImage, false, false) (no rollover, untoggled). Only image_0.gif and image_1.gif are needed.

Parameters:
buttonImage - the filename or URL of the 2 button sprites
Method Detail

reset

public void reset()
Overrides the actor's reset() called when the button is added to the game grid.

Overrides:
reset in class Actor

isToggled

public boolean isToggled()
Returns the current state of the button.

Returns:
true, if the button is toggled

setToggled

public void setToggled(boolean b)
Sets the button in the toggled/untoggled state. Does not generate a notification event. If automatic refresh is enabled, refreshs the game grid.

Parameters:
b - if true, the button is toggled; otherwise it is untoggled

addToggleButtonListener

public void addToggleButtonListener(GGToggleButtonListener listener)
Registers a GGToggleButtonListener to get notifications when the button is manipulated.

Parameters:
listener - the GGToggleButtonListener to register

addButtonOverListener

public void addButtonOverListener(GGButtonOverListener listener)
Registers a GGOverButtonListener to get notifications when the mouse cursor enters the active mouse area. The button must be created with type "Rollover".

Parameters:
listener - the GGButtonOverListener to register