sema
Class Element

java.lang.Object
  extended bysema.Element
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
Agent, Pheromone

public class Element
extends java.lang.Object
implements java.lang.Comparable

An element is the basic world entity. They are every thing in the world (excepted the immaterial things, such as: the Nature, the Signal and the Element.ElementEvent).
The Element class is principaly meant to implement inanimate things of the world, in the meanwhile, the Agent extends the possibilities of an element.
The elements have the encapsulated basic event : Element.ElementEvent which provides basic functionalities.


Nested Class Summary
protected  class Element.ElementEvent
          Mother class for the event of an element.
 
Field Summary
 java.lang.Integer id
          ID (in a world, there is unicity of the ID).
 World world
          World in which is this element.
 
Constructor Summary
Element(World world, Area area, java.awt.Image image)
          Constructs an element of the specified world and register itself to this world.
 
Method Summary
 boolean canTake(Element e)
          Determinates whether the given element can take this one.
 int compareTo(java.lang.Object o)
          Used to compare two elements.
protected  void death()
          Death of the element.
 void draw()
          Draws the element.
 Area getArea()
          Returns the Area.
 float getDrawingPriority()
          Returns the drawing priority.
 float getHeight()
          Returns the height of the element.
 javax.swing.Icon getIcon()
          Returns the associated icon.
 java.awt.Image getImage()
          Returns the main image.
 java.lang.String getKind()
          Returns the kind of the element for example : "ant".
 java.lang.String getName()
          Returns the name.
 java.lang.String[][] getProperties()
          Returns the element's properties.
 void highlight()
           
 void highlight(java.awt.Color c)
          Highlights the element (used to draw that the element is selected in the interface).
 boolean isMarked()
          Returns whether the element is marked.
 boolean kill(Element killer)
          Tries to kill this element by the specified one.
protected  void setDrawingPriority(float priority)
          Sets the drawing priority The world elements are drawn by growing priority, so that the element with the greatest priority is finally on the top and entirely visible.
protected  void setHeight(float h)
          Sets the height of the element.
protected  void setKind(java.lang.String s)
          Sets the kind of the element for example : "ant".
 void setMarked(boolean b)
          Sets the marked property.
 void setProperties(java.lang.String property, java.lang.String value)
          Tries to set the value to the property of the element.
 java.lang.String toString()
          Returns the String representing the element.
static java.lang.String[][] union(java.lang.String[][] p1, java.lang.String[][] p2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

world

public final World world
World in which is this element.


id

public final java.lang.Integer id
ID (in a world, there is unicity of the ID).

Constructor Detail

Element

public Element(World world,
               Area area,
               java.awt.Image image)
Constructs an element of the specified world and register itself to this world.

Parameters:
world - the world which it have to register to.
area - the area of it's 'body'.
image - the main image of the element : used as an identity icon.
See Also:
Area
Method Detail

getDrawingPriority

public float getDrawingPriority()
Returns the drawing priority. The world elements are drawn by growing drawing priority, so that the element with the greatest priority is on the top and entirely visible. By default, it is 0.

Returns:
the drawing priority.
See Also:
Drawing

setDrawingPriority

protected void setDrawingPriority(float priority)
Sets the drawing priority The world elements are drawn by growing priority, so that the element with the greatest priority is finally on the top and entirely visible.

Parameters:
priority - the drawing priority.

getHeight

public float getHeight()
Returns the height of the element. By default it is 0.

Returns:
The height of the element.

setHeight

protected void setHeight(float h)
Sets the height of the element.

Parameters:
h - the height of the element.

getKind

public java.lang.String getKind()
Returns the kind of the element for example : "ant". By default : "object".

Returns:
the kind of the element

setKind

protected void setKind(java.lang.String s)
Sets the kind of the element for example : "ant".

Parameters:
s - the kind of the element.

getName

public java.lang.String getName()
Returns the name.

Returns:
the name.

getImage

public java.awt.Image getImage()
Returns the main image.

Returns:
the main image.
See Also:
Element(World world, Area area, Image image)

getArea

public Area getArea()
Returns the Area.

Returns:
the Area.
See Also:
Area

canTake

public boolean canTake(Element e)
Determinates whether the given element can take this one.

Parameters:
e - the element wanting to take this one.
Returns:
whether the given element can take this one.

death

protected void death()
Death of the element. Is called by itself only. Unregister it from its occupied boxes, from the world and prevent every event it has planned to arrive.


kill

public boolean kill(Element killer)
Tries to kill this element by the specified one. The killer can be null which correspond to a call by the interface to delete it.

Parameters:
killer - the element trying to kill this one.
Returns:
the success of the murder.

draw

public void draw()
Draws the element.

See Also:
Drawing

highlight

public void highlight(java.awt.Color c)
Highlights the element (used to draw that the element is selected in the interface).


highlight

public void highlight()

setMarked

public void setMarked(boolean b)
Sets the marked property. It indicates that the element should draw itself differently, it permit in the interface to visually follow a set of element.

Parameters:
b - the marked property.

isMarked

public boolean isMarked()
Returns whether the element is marked.

Returns:
whether the element is marked.

getIcon

public javax.swing.Icon getIcon()
Returns the associated icon. It has to be an icon of dimension smaller than 100x100. It is used as the identity icon in the graphical interface.
By default it is the main image resized and transformed into an icon.

Returns:
the associated icon.
See Also:
Icon

getProperties

public java.lang.String[][] getProperties()
Returns the element's properties.

Returns:
the element's properties.
See Also:
Engine.getProperties()

union

public static java.lang.String[][] union(java.lang.String[][] p1,
                                         java.lang.String[][] p2)

setProperties

public void setProperties(java.lang.String property,
                          java.lang.String value)
Tries to set the value to the property of the element. The new value is ignored if the property is read_only or if the value isn't valid.

Parameters:
property - the property to change.
value - the new value for the property.
See Also:
Engine.setProperties(java.lang.String, java.lang.String)

toString

public java.lang.String toString()
Returns the String representing the element. By default it is the name.

Returns:
the String representing the element.

compareTo

public int compareTo(java.lang.Object o)
Used to compare two elements. Sorted by growing drawing priority, and if equality, by growing ID.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the element to compare to this one.
Returns:
Comparable