elge.engine
Class Project

java.lang.Object
  |
  +--elge.engine.Project
All Implemented Interfaces:
Runnable

public class Project
extends Object
implements Runnable

Project is the second most important class. It holds all this graphs, monitors, storage and world in one and it also performs the simulation.

The project is also as bean an xml persistant class, so the state of it can be stored at any time and then resumed.

To load, save and create a project use methods in Engine class.

As bean project also support the propertyChange interface for listener. Projects fires events for properties: world, simulations, graphs, monitors etc. View the PROP_'NAME' constants for the fire events the Project can fire.

Author:
Pavol Žibrita

Field Summary
protected  long countDown
          the countDown till the count..
protected  Vector graphs
          graphs
protected  int grRefresh
          graph refresh step
protected  boolean inSimulation
          the simulation state variable
protected  long iterationCount
          the count to iterate in simulation
protected  Vector monitors
          Monitors
protected  String name
          Project name
protected  ProjectEditor peditor
          The project editor instance.
protected  File projectDir
          The project directory.
static String PROP_GRAPHS
          Property name for graphs
static String PROP_ISSIMULATION
          Property project in simulation
static String PROP_MONITORS
          Property name for monitors
static String PROP_SIMULATIONS
          name of simulation propery
static String PROP_WORLD
          Name of world propery
protected  int rSleep
          a simulation run sleep count
protected  Thread simulation
          the simulation thread
protected  Vector simulations
          Simulations (runs).
protected  DataStorage store
          The data storage.
protected  World world
          The world the project is using.
protected  int wrRefresh
          world refresh step
protected  WorldView wv
          The world view if available.
 
Constructor Summary
Project()
          Creates a new instance of WorkSpace
Project(String name, World w)
          Creates project with a name and world.
 
Method Summary
 void addGraph(Graph g)
          Adds a Graph to the project
 void addMonitor(Monitor mon)
          Adds a monitor to the project
 void addPropertyChangeListener(PropertyChangeListener l)
          Adds a listener for the propertye changes
 void endGUI()
          Close all project windows.
 long getCountDown()
          Gets how many simulations step have to be made. -1 means infinity.
 int getGraphRefresh()
          setGraphRefresh(int)
 Vector getGraphs()
          Gets the graphs of this project
 long getIterationCount()
          see setIterationCount(long)
 Vector getMonitors()
          Return actual monitors that are in project.
 String getName()
          Gets the project name
 File getProjectDir()
          Returns the project dir path, as it should be.
 ProjectEditor getProjectEditor()
           
 int getRunSleep()
          see setRunSleep(int)
 DataStorage getStorage()
          Gets the actual DataStorage if available
 World getWorld()
          Get the World the Project is using.
 int getWorldRefresh()
          setWorldRefresh(int)
 WorldView getWorldView()
          returns the WorldView if available.
 void hideWorldView()
          Hides the world view, if it is available.
 void init()
           
 boolean inSimulation()
          Shows the state of the simulation.
 void iterate(long num)
          Sets the iteration count and starts the simulation.
 void removeGraph(Graph g)
          Removes a Graph from the project
 void removeGraphs(int[] idx)
          Removes Graphs from the project
 void removeMonitor(int i)
          Removes a monitor from the project
 void removeMonitor(int[] idxs)
          Removes a monitor from the project
 void removeMonitor(Monitor mon)
          Removes a monitor from the project
 void removePropertyChangeListener(PropertyChangeListener l)
          Removes a listener for the propertye changes
 void restart()
          Restarts the simulation in these steps:
- calls the stop method
- calls the refreshStore method
- calls the world's restart method
- calls the restart method for each graph
- calls the restart mehtod for each monitor
- udpates the display
 void run()
          When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
 void runGUI()
          Runs the project gui.
 void setGraphRefresh(int gr)
          In what tick should the graphs be refreshed.
 void setGraphs(Vector graphs)
          Sets the graphs for this project
 void setIterationCount(long it)
          Sets how many simulation steps to do.
 void setMonitors(Vector mons)
          Sets monitors for this project
 void setNameFromDir(File dir)
          Sest the name of the project from the directory where it it stored.
 void setRunSleep(int rs)
          How long should the simulation sleep between steps.
 void setWorld(World world)
          Sets the world for the Project
 void setWorldRefresh(int wr)
          In what tick should the world be repained.
 void showWorldView()
          Shows the world view, if it is available.
 void start()
          Starts simulation for exact count - getIterationCount()
Event property changed for PROP_ISSIMULATION if fired.
 void stop()
          Stops the simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_WORLD

public static final String PROP_WORLD
Name of world propery

See Also:
Constant Field Values

PROP_SIMULATIONS

public static final String PROP_SIMULATIONS
name of simulation propery

See Also:
Constant Field Values

PROP_ISSIMULATION

public static final String PROP_ISSIMULATION
Property project in simulation

See Also:
Constant Field Values

PROP_MONITORS

public static final String PROP_MONITORS
Property name for monitors

See Also:
Constant Field Values

PROP_GRAPHS

public static final String PROP_GRAPHS
Property name for graphs

See Also:
Constant Field Values

wv

protected WorldView wv
The world view if available.


peditor

protected ProjectEditor peditor
The project editor instance.


world

protected World world
The world the project is using.


projectDir

protected File projectDir
The project directory.


name

protected String name
Project name


simulations

protected Vector simulations
Simulations (runs).


monitors

protected Vector monitors
Monitors


graphs

protected Vector graphs
graphs


store

protected DataStorage store
The data storage. (Currently only DataRecorder is used as file DataStorage)


inSimulation

protected boolean inSimulation
the simulation state variable


simulation

protected Thread simulation
the simulation thread


iterationCount

protected long iterationCount
the count to iterate in simulation


countDown

protected long countDown
the countDown till the count..


grRefresh

protected int grRefresh
graph refresh step


wrRefresh

protected int wrRefresh
world refresh step


rSleep

protected int rSleep
a simulation run sleep count

Constructor Detail

Project

public Project()
Creates a new instance of WorkSpace


Project

public Project(String name,
               World w)
Creates project with a name and world. The name is restricted so that it should be also a valid name for a file.

Parameters:
name - name of the project
w - World the use
See Also:
World
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Adds a listener for the propertye changes

Parameters:
l - the listener

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Removes a listener for the propertye changes

Parameters:
l - the lsitener

getProjectDir

public File getProjectDir()
Returns the project dir path, as it should be.

Returns:
The path to the project dir.

setWorld

public void setWorld(World world)
Sets the world for the Project

Parameters:
world - the World
See Also:
World

getWorld

public World getWorld()
Get the World the Project is using.

Returns:
the World
See Also:
World

runGUI

public void runGUI()
Runs the project gui.


endGUI

public void endGUI()
Close all project windows. Does not save the project.


getProjectEditor

public ProjectEditor getProjectEditor()

getName

public String getName()
Gets the project name

Returns:
Name of the project.

setNameFromDir

public void setNameFromDir(File dir)
Sest the name of the project from the directory where it it stored.

Parameters:
dir - this should be the project directory.

getWorldView

public WorldView getWorldView()
returns the WorldView if available.

Returns:
the WorldView or null
See Also:
WorldView

showWorldView

public void showWorldView()
Shows the world view, if it is available.


hideWorldView

public void hideWorldView()
Hides the world view, if it is available.


getMonitors

public Vector getMonitors()
Return actual monitors that are in project.

Returns:
vector of monitors
See Also:
Monitor

setMonitors

public void setMonitors(Vector mons)
Sets monitors for this project

Parameters:
mons - Vector of monitors
See Also:
Monitor

addMonitor

public void addMonitor(Monitor mon)
Adds a monitor to the project

Parameters:
mon - Monitor to be added
See Also:
Monitor

removeMonitor

public void removeMonitor(Monitor mon)
Removes a monitor from the project

Parameters:
mon - Monitor to be removed
See Also:
Monitor

removeMonitor

public void removeMonitor(int i)
Removes a monitor from the project

Parameters:
i - index of the monitor that should be removed
See Also:
Monitor

removeMonitor

public void removeMonitor(int[] idxs)
Removes a monitor from the project

Parameters:
idxs - indexes of the Monitors that should be removed
See Also:
Monitor

addGraph

public void addGraph(Graph g)
Adds a Graph to the project

Parameters:
g - Graph to add
See Also:
Graph

removeGraph

public void removeGraph(Graph g)
Removes a Graph from the project

Parameters:
g - Graph to remove
See Also:
Graph

removeGraphs

public void removeGraphs(int[] idx)
Removes Graphs from the project

Parameters:
idx - indexs of Graph to remove
See Also:
Graph

setGraphs

public void setGraphs(Vector graphs)
Sets the graphs for this project

Parameters:
graphs - Vector of Graph instances
See Also:
Graph

getGraphs

public Vector getGraphs()
Gets the graphs of this project

Returns:
Vector of Graph instances
See Also:
Graph

init

public void init()

restart

public void restart()
Restarts the simulation in these steps:
- calls the stop method
- calls the refreshStore method
- calls the world's restart method
- calls the restart method for each graph
- calls the restart mehtod for each monitor
- udpates the display

See Also:
stop(), World.restart(), Graph.restart(), Monitor.restart(), ProjectEditor.updateAfterStep()

getStorage

public DataStorage getStorage()
Gets the actual DataStorage if available

Returns:
actual DataStorage
See Also:
DataStorage

start

public void start()
Starts simulation for exact count - getIterationCount()
Event property changed for PROP_ISSIMULATION if fired.


stop

public void stop()
Stops the simulation.
Event property changed for PROP_ISSIMULATION if fired.


iterate

public void iterate(long num)
Sets the iteration count and starts the simulation.
Event property changed for PROP_ISSIMULATION if fired.
This method also tries to call the refreshStore if the store has not yet been initialized.

if the num is -1 then the simulation runs until the pause from the user

Parameters:
num - count to iterate the simulation

inSimulation

public boolean inSimulation()
Shows the state of the simulation.

Returns:
true, if simulation is in process. False if there is no simulation running. This should be false after restart!

run

public void run()
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

The general contract of the method run is that it may take any action whatsoever.

This method is called to run the simulation. The simulation process is follows:
- the private step method is called
- the the Thread's yield method is called
- if rSleep is > 0, the Thread's sleep is called
- or if the agentCount of the World is zero a sleep(1) method is called

After the user pause or the iteration count has passed to 0, the simulation quits and calls the stop() method

Specified by:
run in interface Runnable
See Also:
Thread.run(), Thread.yield(), Thread.sleep(long), stop()

setGraphRefresh

public void setGraphRefresh(int gr)
In what tick should the graphs be refreshed. The ProjectEditor's udpateAfterStep method uses this variable.

Parameters:
gr - the tick step
See Also:
ProjectEditor.updateAfterStep()

getGraphRefresh

public int getGraphRefresh()
setGraphRefresh(int)

Returns:
get the value

setWorldRefresh

public void setWorldRefresh(int wr)
In what tick should the world be repained. The ProjectEditor's udpateAfterStep method uses this variable.

See Also:
ProjectEditor.updateAfterStep()

getWorldRefresh

public int getWorldRefresh()
setWorldRefresh(int)

Returns:
get the value

setRunSleep

public void setRunSleep(int rs)
How long should the simulation sleep between steps.

Parameters:
rs - sleep count in miliseconds.

getRunSleep

public int getRunSleep()
see setRunSleep(int)

Returns:
get the sleep count in miliseconds.

setIterationCount

public void setIterationCount(long it)
Sets how many simulation steps to do.

Parameters:
it - the simulation step count

getIterationCount

public long getIterationCount()
see setIterationCount(long)

Returns:
the simulation step count

getCountDown

public long getCountDown()
Gets how many simulations step have to be made. -1 means infinity.

Returns:
returns the simulation step count to be made.