org.deken.game.component
Class GMenu

java.lang.Object
  extended by org.deken.game.sprites.Sprite
      extended by org.deken.game.component.GComponent
          extended by org.deken.game.component.GContainer
              extended by org.deken.game.component.GMenu
All Implemented Interfaces:
ButtonListener, InputListener, InputMouseListener, Updateable

public class GMenu
extends GContainer
implements InputListener, ButtonListener

Title: GMenu

Description: This is a container object for storing a menu list.

Copyright: Copyright (c) Mar 6, 2011

Version:
1.0
Author:
Gary Deken

Nested Class Summary
static class GMenu.MenuOrientation
           
 
Nested classes/interfaces inherited from class org.deken.game.component.GComponent
GComponent.Alignment, GComponent.MouseActions
 
Field Summary
protected  java.util.List<java.lang.Integer> keyActions
           
protected  GComponent.Alignment menuAlignment
           
protected  int menuInset
           
protected  java.util.Collection<MenuListener> menuListeners
           
protected  GMenu.MenuOrientation menuOrientation
           
protected  int spacing
           
 
Fields inherited from class org.deken.game.component.GContainer
backgroundColor, grabbed
 
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
GMenu(int screenWidth, int screenHeight)
          Constructor
GMenu(int screenWidth, int screenHeight, GComponent.Alignment menuAlignment)
           
 
Method Summary
 void add(GComponent component)
          Adds the component to this GMenu if it extends GTextContainer.
 void add(GTextContainer gameTextContainer)
          Add a GameTextContainer at the end of the list.
 void add(GTextContainer gameTextContainer, int index)
          Add a GameTextContainer at the given index.
 void addInputAction(InputAction inputAction)
          add an InputAction for monitoring.
 void addMenuListener(MenuListener listener)
           
 GMenu copy()
           
 void draw(java.awt.Graphics2D graphics, int xOffset, int yOffset)
          Calls the draw for all menu times, each time adding the button heights spacing to the next button's Y location.
 java.util.List<? extends GComponent> getChildren()
           
 GTextContainer getComponentByName(java.lang.String name)
           
 int getHeight()
          Return the combined GameButton heights.
 int[] getInputActionIds()
          Gets the Key IDs.
 java.util.List<GTextContainer> getMenuList()
           
 int getWidth()
          Return the width of the menu, subtracting insets.
 void notifyButtonListener(java.lang.String name)
           
 void notifyListener(InputAction inputAction)
          Listen for the up and down arrow keys, to move the selection.
 void notifyListener(InputMouseAction inputMouseAction)
          notifyListener
 void remove(GComponent gComponent)
           
 void setEnabled(boolean enabled)
           
 void setMenuInset(int menuInset)
           
 void setMenuOrientation(GMenu.MenuOrientation menuOrientation)
           
 void setMonitored(boolean active)
           
 void setScreenHeightWidth(int screenWidth, int screenHeight)
           
 void setSpacing(int spacing)
          Set the spacing between menu elements.
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.GContainer
copyBase, isGrabbed, isSizeSet, setBackgroundColor, setGrabbed
 
Methods inherited from class org.deken.game.component.GComponent
addMouseAction, copyBase, getHorizontalAlignment, getMouseActions, getParent, getVerticalAlignment, getXLocation, getYLocation, isEnabled, positionHorizontalAlignment, positionVerticalAlignment, requestKeyPolling, setHorizontalAlignment, setInvalid, setKeyPolling, setParent, setVerticalAlignment
 
Methods inherited from class org.deken.game.sprites.Sprite
getBounds, getDepth, getLocation, getName, getSize, 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

spacing

protected int spacing

menuInset

protected int menuInset

keyActions

protected java.util.List<java.lang.Integer> keyActions

menuAlignment

protected GComponent.Alignment menuAlignment

menuListeners

protected java.util.Collection<MenuListener> menuListeners

menuOrientation

protected GMenu.MenuOrientation menuOrientation
Constructor Detail

GMenu

public GMenu(int screenWidth,
             int screenHeight)
Constructor

Parameters:
screenWidth -
screenHeight -

GMenu

public GMenu(int screenWidth,
             int screenHeight,
             GComponent.Alignment menuAlignment)
Parameters:
screenWidth -
screenHeight -
menuAlignment -
Method Detail

add

public void add(GComponent component)
Adds the component to this GMenu if it extends GTextContainer. Otherwise it will throw a FactoryException.

Specified by:
add in class GContainer
Parameters:
component -
Throws:
GameException

add

public void add(GTextContainer gameTextContainer)
Add a GameTextContainer at the end of the list.

Parameters:
gameTextContainer -

add

public void add(GTextContainer gameTextContainer,
                int index)
Add a GameTextContainer at the given index.

Parameters:
gameTextContainer -
index -

addInputAction

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

Specified by:
addInputAction in interface InputListener

addMenuListener

public void addMenuListener(MenuListener listener)

copy

public GMenu copy()
Specified by:
copy in class GComponent
Returns:
GComponent

draw

public void draw(java.awt.Graphics2D graphics,
                 int xOffset,
                 int yOffset)
Calls the draw for all menu times, each time adding the button heights spacing to the next button's Y location.

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

getChildren

public java.util.List<? extends GComponent> getChildren()
Specified by:
getChildren in class GContainer
Returns:
List of GComponents that this GContainer holds.

getComponentByName

public GTextContainer getComponentByName(java.lang.String name)
Specified by:
getComponentByName in class GContainer
Returns:
GComponent

getHeight

public int getHeight()
Return the combined GameButton heights.

Overrides:
getHeight in class Sprite
Returns:
int

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

getMenuList

public java.util.List<GTextContainer> getMenuList()

getWidth

public int getWidth()
Return the width of the menu, subtracting insets.

Overrides:
getWidth in class Sprite
Returns:
int

notifyButtonListener

public void notifyButtonListener(java.lang.String name)
Specified by:
notifyButtonListener in interface ButtonListener

notifyListener

public void notifyListener(InputAction inputAction)
Listen for the up and down arrow keys, to move the selection.

Specified by:
notifyListener in interface InputListener
Parameters:
inputAction -

notifyListener

public void notifyListener(InputMouseAction inputMouseAction)
Description copied from interface: InputMouseListener
notifyListener

This method is called when any Mouse Motion event occurs.

Specified by:
notifyListener in interface InputMouseListener
Parameters:
inputMouseAction - InputMouseAction

remove

public void remove(GComponent gComponent)
Specified by:
remove in class GContainer

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class GComponent

setMenuInset

public void setMenuInset(int menuInset)

setMenuOrientation

public void setMenuOrientation(GMenu.MenuOrientation menuOrientation)

setMonitored

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

setScreenHeightWidth

public void setScreenHeightWidth(int screenWidth,
                                 int screenHeight)
Overrides:
setScreenHeightWidth in class GContainer

setSpacing

public void setSpacing(int spacing)
Set the spacing between menu elements.

Parameters:
spacing -

update

public void update(long elapseTime)
Description copied from class: GComponent
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 GComponent
Parameters:
elapseTime - long

validate

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

spriteCollison

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

Specified by:
spriteCollison in class Sprite