org.haphazard.gui.engine
Class GraphicalObject

java.lang.Object
  extended byorg.haphazard.gui.engine.GraphicalObject
Direct Known Subclasses:
GeneralItem, MoveableGraphicalObject

public class GraphicalObject
extends java.lang.Object

Superclass for anything that can exist on a map


Field Summary
 long id
          A unique id for the object
protected  Sprite mDefaultSprite
          The default look
protected  java.lang.String mDescription
          the description of the object
protected  java.awt.Color mDescriptionColor
          The color of the description text
protected  long mDescriptionDisplayTime
          The duration for displaying the description
protected  long mDescriptionStartTime
          The time the description started displaying
protected  Dimension3D mDimension
          The volume of the object in cm x cm x cm
 java.lang.String mLink
          Where the object was loaded from originally
protected  java.lang.String mName
          The name of the object
protected  Sprite mSpriteDisplayed
           
protected  java.util.Hashtable mSprites
           
protected  int mWeight
          The weight of the object in grams
 
Constructor Summary
GraphicalObject()
          Creates a new graphical object
GraphicalObject(Sprite defaultSprite)
          The constructor updates the map
 
Method Summary
 void addSprite(Sprite sprite)
          Adds a sprite to this object
 boolean combineSprites(java.lang.String baseSprite, java.lang.String frontSprite, java.lang.String newSpriteName)
          Combines two Sprites to one new.
 void displayDescription(long displayTime, java.awt.Color color)
          Sets the time to display the description
 void displaySprite(java.lang.String spriteKey)
          Sets the sprite to be displayed according to the spriteKey and flippedVertically.
 java.util.Enumeration getAvailableSprites()
          Gets the available sprites
 java.awt.Rectangle getBoundingBox(java.awt.Point middleTileCoordinate)
          Return the bounding box on the screen of this Frame of the Sprite that is displayed.
 java.lang.String getDescription()
          returns the description for this graphical object
 Dimension3D getDimension()
          Gets this objects dimension
 java.lang.String getName()
          Gets the name of the graphical object
 Sprite getNotResettedSprite(java.lang.String spriteKey)
          Gets a specific sprite that is reseted.
 Sprite getResettedSprite(java.lang.String spriteKey)
          Gets a specific sprite that is resetted.
 int getWeight()
          Gets the weight of the item
 boolean isDefaultSpriteDisplayed()
          checks if the defaultSprite is displayed.
 void load(java.io.InputStream stream)
          Loads an object from a file
static GraphicalObject loadInstance(java.io.InputStream input)
          Loads an instance of GraphicalObject
 void optimize()
          Optimizes the clipping rectangle of all sprites
 boolean paintComponent(java.awt.Graphics2D g, Map map, java.awt.Point middleTileScreenCoord)
          Paints the component
 void resetDisplayedSprite()
          Resets this DynamicGraphicalObject to displayed its defaultSprite
 void save(java.io.OutputStream stream)
          Saves the object in an XML-file
 void setDefaultSprite(Sprite sprite)
          Sets the default sprite.
 void setDefaultSprite(java.lang.String spriteKey)
          Sets what sprite should be displayed as default.
 void setDescription(java.lang.String description)
          sets the description for this graphical object FIXME: format the string to a nice format .
 void setDimension(Dimension3D dimension)
          Sets this objects dimension
 void setName(java.lang.String name)
          Sets the name of the graphical object
 void setWeight(int weight)
          Sets the weight of the item
 java.lang.String toString()
          Returns this GraphicalObject as a string.
 java.lang.String toXML(int indent)
          Transforms this object into XML-notation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mName

protected java.lang.String mName
The name of the object


mDescription

protected java.lang.String mDescription
the description of the object


mDimension

protected Dimension3D mDimension
The volume of the object in cm x cm x cm


mWeight

protected int mWeight
The weight of the object in grams


mLink

public java.lang.String mLink
Where the object was loaded from originally


id

public long id
A unique id for the object


mDescriptionDisplayTime

protected long mDescriptionDisplayTime
The duration for displaying the description


mDescriptionStartTime

protected long mDescriptionStartTime
The time the description started displaying


mDescriptionColor

protected java.awt.Color mDescriptionColor
The color of the description text


mDefaultSprite

protected Sprite mDefaultSprite
The default look


mSpriteDisplayed

protected Sprite mSpriteDisplayed

mSprites

protected java.util.Hashtable mSprites
Constructor Detail

GraphicalObject

public GraphicalObject()
Creates a new graphical object


GraphicalObject

public GraphicalObject(Sprite defaultSprite)
The constructor updates the map

Parameters:
defaultSprite - which sprite should be default
Method Detail

setName

public void setName(java.lang.String name)
Sets the name of the graphical object

Parameters:
name - The name to set

getName

public java.lang.String getName()
Gets the name of the graphical object

Returns:
The name of the object

setDescription

public void setDescription(java.lang.String description)
sets the description for this graphical object FIXME: format the string to a nice format .

Parameters:
description - the description for the object

getDescription

public java.lang.String getDescription()
returns the description for this graphical object

Returns:
string with the description

getWeight

public int getWeight()
Gets the weight of the item

Returns:
The weight in grams

setWeight

public void setWeight(int weight)
Sets the weight of the item

Parameters:
weight - The weight in grams

setDimension

public void setDimension(Dimension3D dimension)
Sets this objects dimension

Parameters:
dimension - The dimension to be set

getDimension

public Dimension3D getDimension()
Gets this objects dimension

Returns:
The objects dimension

getBoundingBox

public java.awt.Rectangle getBoundingBox(java.awt.Point middleTileCoordinate)
Return the bounding box on the screen of this Frame of the Sprite that is displayed. If this is called after the paintComponent then the rectangle can be from the frame after! .

Parameters:
middleTileCoordinate - The middle coordinate of the tile the object is residing on
Returns:
the Rectangle with the bounding box

addSprite

public void addSprite(Sprite sprite)
Adds a sprite to this object

Parameters:
sprite - The sprite to add

setDefaultSprite

public void setDefaultSprite(Sprite sprite)
Sets the default sprite.

Parameters:
sprite - The sprite to set as the default sprite

setDefaultSprite

public void setDefaultSprite(java.lang.String spriteKey)
Sets what sprite should be displayed as default. If there is already a sprite set with setSpriteToBeDisplayed(..) then this function will only update the default sprite not the displayed sprite

Parameters:
spriteKey - the "name" of the sprite to be set as default

getAvailableSprites

public java.util.Enumeration getAvailableSprites()
Gets the available sprites

Returns:
The names of the available sprites

displayDescription

public void displayDescription(long displayTime,
                               java.awt.Color color)
Sets the time to display the description

Parameters:
displayTime - the time to display the description in milliseconds if displayTime == -1 then it is always displayed
color - the color for the description

displaySprite

public void displaySprite(java.lang.String spriteKey)
Sets the sprite to be displayed according to the spriteKey and flippedVertically. If there is no sprite with that key the the default sprite will be displayed.

Parameters:
spriteKey - the "name" of the sprite

getResettedSprite

public Sprite getResettedSprite(java.lang.String spriteKey)
Gets a specific sprite that is resetted.

Parameters:
spriteKey - the name of the sprite to be returned
Returns:
sprite or null

getNotResettedSprite

public Sprite getNotResettedSprite(java.lang.String spriteKey)
Gets a specific sprite that is reseted.

Parameters:
spriteKey - the name of the sprite to be returned
Returns:
sprite or null

resetDisplayedSprite

public void resetDisplayedSprite()
Resets this DynamicGraphicalObject to displayed its defaultSprite


isDefaultSpriteDisplayed

public boolean isDefaultSpriteDisplayed()
checks if the defaultSprite is displayed.

Returns:
true if it is displayed false if not

paintComponent

public boolean paintComponent(java.awt.Graphics2D g,
                              Map map,
                              java.awt.Point middleTileScreenCoord)
Paints the component

Parameters:
middleTileScreenCoord - The middle coordinate of the tile the object is residing on
g - The graphics control to use to paint this object
map - this is user by the DynamicGraphicalObject for calculating moves on a tile
Returns:
true if the image is changed during painting

optimize

public void optimize()
Optimizes the clipping rectangle of all sprites


combineSprites

public boolean combineSprites(java.lang.String baseSprite,
                              java.lang.String frontSprite,
                              java.lang.String newSpriteName)
Combines two Sprites to one new.

Parameters:
baseSprite - the name of the sprite that serves as a base
frontSprite - the name of the sprite that should be in front
newSpriteName - the name of the new sprite
Returns:
true if succeded false if not (i.e. if baseSprite or frontSprite does not exists in this GraphicalObject)

save

public void save(java.io.OutputStream stream)
Saves the object in an XML-file

Parameters:
stream - The stream to save to

loadInstance

public static GraphicalObject loadInstance(java.io.InputStream input)
Loads an instance of GraphicalObject

Parameters:
input - The input for the stream
Returns:
The loaded graphical object

load

public void load(java.io.InputStream stream)
Loads an object from a file

Parameters:
stream - The stream to load

toXML

public java.lang.String toXML(int indent)
Transforms this object into XML-notation

Parameters:
indent - The level of indentation to use
Returns:
The object in a String notation

toString

public java.lang.String toString()
Returns this GraphicalObject as a string.

Returns:
The object denoted as a String