ch.aplu.jgamegrid
Class GGButtonBase

java.lang.Object
  extended by ch.aplu.jgamegrid.Actor
      extended by ch.aplu.jgamegrid.GGButtonBase
All Implemented Interfaces:
GGActorCollisionListener, GGBorderListener, GGTileCollisionListener, java.util.EventListener
Direct Known Subclasses:
GGButton, GGCheckButton, GGRadioButton, GGToggleButton

public abstract class GGButtonBase
extends Actor

Abstract superclass of all button types. Buttons of all types are GameGrid actors with special behaviour. They implement a GGMouseListener that reports press, release and click events when the mouse curser is over the button image. The button images for the non-pressed, the pressed or the rollover state should have the same size. hide() may be called before the button is added to the game grid to make the button invisible (and inactive) when added. The parameterless show() will make it visible (in non-pressed state). Like any other actor, the buttons will be painted over or under other actors depending on the paint order.

The button events will be reported by callback methods declared in the GGButtonListener interface.


Field Summary
 
Fields inherited from class ch.aplu.jgamegrid.Actor
gameGrid, nbCycles
 
Method Summary
 boolean isEnabled()
          Returns true if button is enabled.
 void setEnabled(boolean enable)
          Enable/Disable button actions.
 void setHotspotArea(java.awt.Point center, int width, int height)
          Selects the rectangle (in pixel units) relative to the button image as active mouse area.
 void setRefreshEnabled(boolean enable)
          Enables/disables automatic refresh of game grid on button actions.
 
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, reset, 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
 

Method Detail

setEnabled

public void setEnabled(boolean enable)
Enable/Disable button actions. The button image is not changed.

Parameters:
enable - if true, the button actions are enabled; otherwise disabled

isEnabled

public boolean isEnabled()
Returns true if button is enabled.

Returns:
true if button is enabled; otherwise false

setRefreshEnabled

public void setRefreshEnabled(boolean enable)
Enables/disables automatic refresh of game grid on button actions. If the game grid is refreshed by the simulation cycling, it is advisable to disabled the automatic refresh on button actions to avoid flickering.

Parameters:
enable - if true, the automatic refresh on button action is enable; otherwise disabled

setHotspotArea

public void setHotspotArea(java.awt.Point center,
                           int width,
                           int height)
Selects the rectangle (in pixel units) relative to the button image as active mouse area. The following coordinate system is used:

x-axis to the left, y-axis downward, zero at image center

(For even image pixel width or height, the center is half pixel width to the left or resp. to the top).

The default hotspot area is the button image bounding rectangle.

Parameters:
center - the rectangle center (zero at image center)
width - the width in pixel units of the rectangle (in x-direction)
height - the height in pixel units of the rectangle (in y-direction)