org.deken.game.component
Class GComponent

java.lang.Object
  extended by org.deken.game.sprites.Sprite
      extended by org.deken.game.component.GComponent
All Implemented Interfaces:
InputMouseListener, Updateable
Direct Known Subclasses:
GContainer, GParagraph, GScrollingLabel, GScrollingParagraph, GTextContainer

public abstract class GComponent
extends Sprite
implements InputMouseListener

Title: GComponent

Description: This abstract object is an element that is used for user interaction. GComponents can be any type of element that the user will directly interact with, such as a button, or window.

The GComponent has a location that is relative to its parent. if there is no parent, the location is relative to the top of the viewing screen. The GComponent has a height and width. It can be seen or not seen. It can be enabled or disabled. A GComponent can tell if it has been clicked by the mouse. It can tell if it has focus or not. Even though a GComponents is a sprite, it is intended to be added to a map through the addComponent() method. The map will render all components on top of every other element.

Copyright: Copyright (c) 2006

Version:
1.0
Author:
Gary Deken

Nested Class Summary
static class GComponent.Alignment
           
static class GComponent.MouseActions
           
 
Field Summary
protected  GComponent.Alignment horizontalAlignment
           
protected static int id
           
protected  boolean invalid
           
protected  keyPolling keyPolling
           
protected  java.util.List<InputMonitor.Mouse> mouseActions
           
protected  GContainer parent
           
protected  boolean requestKeyPolling
           
protected  int screenHeight
           
protected  int screenWidth
           
protected  GComponent.Alignment verticalAlignment
           
protected  int xOffSet
           
protected  int yOffSet
           
 
Fields inherited from class org.deken.game.sprites.Sprite
boundingBox, collisionMap, location, size
 
Constructor Summary
GComponent()
           
GComponent(InputMonitor.Mouse mouseAction)
           
 
Method Summary
 void addMouseAction(InputMonitor.Mouse mouseAction)
           
abstract  GComponent copy()
           
protected  GComponent copyBase(GComponent component)
           
abstract  void draw(java.awt.Graphics2D graphics, int xOffset, int yOffset)
          Draws the sprite with the current offset.
 GComponent.Alignment getHorizontalAlignment()
           
 java.util.List<InputMonitor.Mouse> getMouseActions()
          Returns a list of MouseActions that this component will listen for.
 GContainer getParent()
           
 GComponent.Alignment getVerticalAlignment()
           
 double getXLocation()
          getXLocation
 double getYLocation()
          getYLocation
 boolean isEnabled()
           
protected  void positionHorizontalAlignment()
          Calculates the horizontal position based on the parent or screen width, and the Alignment set.
protected  void positionVerticalAlignment()
          Calculates the vertical position based on the parent or screen height, and the Alignment set.
 boolean requestKeyPolling()
           
 void setEnabled(boolean enabled)
           
 void setHorizontalAlignment(GComponent.Alignment horizontalAlignment, int screenWidth)
           
 void setInvalid()
          Makes this GComponent invalid, so that it will be re-validated.
 void setKeyPolling(keyPolling polling)
           
abstract  void setMonitored(boolean active)
           
 void setParent(GContainer parent)
           
 void setVerticalAlignment(GComponent.Alignment verticalAlignment, int screenHeight)
           
abstract  void update(long elapseTime)
          update
abstract  void validate(java.awt.Graphics2D graphics)
           
 
Methods inherited from class org.deken.game.sprites.Sprite
getBounds, getDepth, getHeight, getLocation, getName, getSize, getWidth, removeFromMap, setBoundingBox, setBoundingBox, setCollisionMap, setLocation, setName, setSize, spriteCollison, toString, updateLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.deken.game.input.InputMouseListener
notifyListener
 

Field Detail

id

protected static int id

mouseActions

protected java.util.List<InputMonitor.Mouse> mouseActions

requestKeyPolling

protected boolean requestKeyPolling

keyPolling

protected keyPolling keyPolling

parent

protected GContainer parent

xOffSet

protected int xOffSet

yOffSet

protected int yOffSet

invalid

protected boolean invalid

horizontalAlignment

protected GComponent.Alignment horizontalAlignment

verticalAlignment

protected GComponent.Alignment verticalAlignment

screenWidth

protected int screenWidth

screenHeight

protected int screenHeight
Constructor Detail

GComponent

public GComponent()

GComponent

public GComponent(InputMonitor.Mouse mouseAction)
Method Detail

addMouseAction

public void addMouseAction(InputMonitor.Mouse mouseAction)
Parameters:
mouseAction -

copy

public abstract GComponent copy()
Specified by:
copy in class Sprite
Returns:
GComponent

draw

public abstract void draw(java.awt.Graphics2D graphics,
                          int xOffset,
                          int yOffset)
Draws the sprite with the current offset.

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

getHorizontalAlignment

public GComponent.Alignment getHorizontalAlignment()
Returns:
Alignment

getMouseActions

public java.util.List<InputMonitor.Mouse> getMouseActions()
Returns a list of MouseActions that this component will listen for.

Returns:
List

getParent

public GContainer getParent()
Returns:
GContainer

getVerticalAlignment

public GComponent.Alignment getVerticalAlignment()
Returns:
Alignment

getXLocation

public double getXLocation()
getXLocation

Overrides:
getXLocation in class Sprite
Returns:
double

getYLocation

public double getYLocation()
getYLocation

Overrides:
getYLocation in class Sprite
Returns:
double

isEnabled

public boolean isEnabled()
Returns:
boolean

requestKeyPolling

public boolean requestKeyPolling()

setEnabled

public void setEnabled(boolean enabled)
Parameters:
enabled -

setHorizontalAlignment

public void setHorizontalAlignment(GComponent.Alignment horizontalAlignment,
                                   int screenWidth)
Parameters:
horizontalAlignment -
screenWidth -

setInvalid

public void setInvalid()
Makes this GComponent invalid, so that it will be re-validated.


setKeyPolling

public void setKeyPolling(keyPolling polling)

setMonitored

public abstract void setMonitored(boolean active)

setParent

public void setParent(GContainer parent)
Parameters:
parent -

setVerticalAlignment

public void setVerticalAlignment(GComponent.Alignment verticalAlignment,
                                 int screenHeight)
Parameters:
verticalAlignment -
screenHeight -

update

public abstract void update(long elapseTime)
update

This method takes the elapse time, and calculates the new current frame of the animation.

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

validate

public abstract void validate(java.awt.Graphics2D graphics)
Parameters:
graphics -

copyBase

protected GComponent copyBase(GComponent component)

positionVerticalAlignment

protected void positionVerticalAlignment()
Calculates the vertical position based on the parent or screen height, and the Alignment set.


positionHorizontalAlignment

protected void positionHorizontalAlignment()
Calculates the horizontal position based on the parent or screen width, and the Alignment set.