elge.engine
Class Engine

java.lang.Object
  |
  +--elge.engine.Engine
All Implemented Interfaces:
ExceptionListener

public class Engine
extends Object
implements ExceptionListener

Engine is a class which is responsible for running the environment. It starts the GUI mode (batch mode is not yet done), and handles all important things, like projects, helps, main configuration.

This is also the class, which should be run as main class when starting up the environment:

cmdline>java elge.engine.Engine

Author:
Pavol Žibrita

Field Summary
 String configPath
          The standart config path for the engine.
protected  EngineConfiguration econf
          The engine configuration
protected static ResourceBundle elgeBundle
           
protected static Locale elgeLocale
           
static String ENGINE_CONFIG_FILE
          a file name of the angine configuration (elge.xml)
protected  ElgeGUI gui
          The gui interface.
protected static javax.help.HelpSet mainHS
          The main help set.
static String PROJECT_CONFIG
          standart file name of the project configuration (config.xml)
static String PROJECT_EXT
          The standart file extension of the project files (.elp)
static String PROP_RECENTS
          Identification of the property RecentProjects.
protected static Engine singleton
          The singleton of the engine.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Adds a property change listener
 void addRecentProject(Project pt)
          Adds a recent project to the vector.
 void closeProject(Project pt)
          Close the porject and remove from list..
 Project createProject(String name, World w)
          Creates a project in the project dir under the name "name" with a world - w.
 void exceptionThrown(Exception e)
          This method is called when a recoverable exception has been caught.
 EngineConfiguration getConf()
          returns the EngineConfiguration for this instance
 String getConfigPath()
          returns the config path of the engine.
static Engine getEngine()
          Gets the singleton that is the engine using.
 ElgeGUI getGUI()
          get the running gui, if available.
 javax.help.HelpSet getHelpSet()
          Returns the main helpset for the engine.
 Vector getOpenedProjects()
           
 String getProjectPath()
          The project dir is a directory, where the projects are saved.
static Object getRandomElement(List list)
          Choose a random element from the list and return it.
static int getRandomNumber(int from, int to)
          Returns a random number in range of from to to included.
static Engine getSingleton()
          like getEngine()
static String getString(String key)
          Gets a string from the bundle resource.
 boolean checkProjectName(String name)
          Checks the project name, if it can be used for new project.
 boolean isGUI()
          True if the guis is running false otherwise.
 void loadConfiguration()
          Loads the engine configuration.
protected  void loadEngine()
          Loads the engine xonfiguration (elge.xml)
 Project loadProject(File file)
          Tries to load project.
static void main(String[] args)
          Runs the engine.
 void removePropertyChangeListener(PropertyChangeListener l)
          Removes a property change listener
 void removeRecentProject(String path)
          Removes a recent project from the vecot
 void run(String[] args)
          this run is like main method.
 void saveConfiguration()
          Save configuration for the engine.
protected  void saveEngine()
          saves only the egnine configuration (elge.xml)
 boolean saveProject(Project pt)
          Saves the state of the project.
 boolean saveProjectAs(Project pt, String pname)
          Saves project under other name.
 boolean saveProjects()
          Saves all opened projects
 void setConfiPath(String configPath)
          Sets the config path for the engine.
 void setProjectPath(String configPath)
          Sets the directory where the projects should be saved.
 void stop()
          Stops and closes the engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_RECENTS

public static final String PROP_RECENTS
Identification of the property RecentProjects.

See Also:
Constant Field Values

PROJECT_EXT

public static final String PROJECT_EXT
The standart file extension of the project files (.elp)

See Also:
Constant Field Values

PROJECT_CONFIG

public static final String PROJECT_CONFIG
standart file name of the project configuration (config.xml)

See Also:
Constant Field Values

ENGINE_CONFIG_FILE

public static final String ENGINE_CONFIG_FILE
a file name of the angine configuration (elge.xml)

See Also:
Constant Field Values

configPath

public String configPath
The standart config path for the engine.


gui

protected ElgeGUI gui
The gui interface.


econf

protected EngineConfiguration econf
The engine configuration


mainHS

protected static javax.help.HelpSet mainHS
The main help set.


singleton

protected static Engine singleton
The singleton of the engine.


elgeLocale

protected static Locale elgeLocale

elgeBundle

protected static ResourceBundle elgeBundle
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Adds a property change listener

Parameters:
l - the listener

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Removes a property change listener

Parameters:
l - the listener

createProject

public Project createProject(String name,
                             World w)
Creates a project in the project dir under the name "name" with a world - w. It also saves the config.xml of the project.

Parameters:
name - project name
w - project world. Main AgentContainer.
Returns:
Returns the project instance or null if the project could not be created

loadProject

public Project loadProject(File file)
Tries to load project. The file should be a dir, containg a project config.xml file.

Parameters:
file - the directory of the project
Returns:
Returns the project instance or null, if the project could not be loaded.

saveProject

public boolean saveProject(Project pt)
Saves the state of the project.

Parameters:
pt - proejct to save
Returns:
true if the save was successfull

saveProjectAs

public boolean saveProjectAs(Project pt,
                             String pname)
Saves project under other name.

Parameters:
pt - project to save
pname - alternative project name
Returns:
true if the save was successfull

saveProjects

public boolean saveProjects()
Saves all opened projects

Returns:
true if the save was successfull

closeProject

public void closeProject(Project pt)
Close the porject and remove from list..

Parameters:
pt - project to close

getConfigPath

public String getConfigPath()
returns the config path of the engine.

Returns:
path to config dir for the engine.

setConfiPath

public void setConfiPath(String configPath)
Sets the config path for the engine.

Parameters:
configPath - path to config dir for the engine

getProjectPath

public String getProjectPath()
The project dir is a directory, where the projects are saved.

Returns:
project dir

setProjectPath

public void setProjectPath(String configPath)
Sets the directory where the projects should be saved.

Parameters:
configPath - path to dir for saving the projects.

loadConfiguration

public void loadConfiguration()
Loads the engine configuration. It searches the elge.xml in the directory from where the engine was run.


saveConfiguration

public void saveConfiguration()
Save configuration for the engine. Well, try to save all...


saveEngine

protected void saveEngine()
saves only the egnine configuration (elge.xml)


loadEngine

protected void loadEngine()
Loads the engine xonfiguration (elge.xml)


run

public void run(String[] args)
this run is like main method. Whit this method is the engine started. It also accpets the arguments like main (but not for now).

Parameters:
args - cmd line arguments.

stop

public void stop()
Stops and closes the engine. It closes the projects first, then the saves the engine if needed and then closes the jvm.


getConf

public EngineConfiguration getConf()
returns the EngineConfiguration for this instance

Returns:
the actual config object.

addRecentProject

public void addRecentProject(Project pt)
Adds a recent project to the vector.

Parameters:
pt - project to be added.

removeRecentProject

public void removeRecentProject(String path)
Removes a recent project from the vecot

Parameters:
path - project path to be removed.

getGUI

public ElgeGUI getGUI()
get the running gui, if available.

Returns:
return the gui object or null, if the gui is not running.

isGUI

public boolean isGUI()
True if the guis is running false otherwise.

Returns:
true if the gui is running

checkProjectName

public boolean checkProjectName(String name)
Checks the project name, if it can be used for new project.

Parameters:
name - name of future project
Returns:
true if the name can be used.

getOpenedProjects

public Vector getOpenedProjects()

exceptionThrown

public void exceptionThrown(Exception e)
This method is called when a recoverable exception has been caught.

Specified by:
exceptionThrown in interface ExceptionListener
Parameters:
e - The exception that was caught.

main

public static void main(String[] args)
Runs the engine.

Parameters:
args - cmd line arguments.

getEngine

public static Engine getEngine()
Gets the singleton that is the engine using. Only one engine can be run in one jvm.

Returns:
the Engine singleton.

getSingleton

public static Engine getSingleton()
like getEngine()

Returns:
the Engine singleton.

getString

public static String getString(String key)
Gets a string from the bundle resource. If the string is not found, the string is returned.

Parameters:
key - the key in the bundle resource
Returns:
the string under the key or the key itself if it is not in the bundle.

getHelpSet

public javax.help.HelpSet getHelpSet()
Returns the main helpset for the engine.

Returns:
HelpSet object for main help.

getRandomNumber

public static int getRandomNumber(int from,
                                  int to)
Returns a random number in range of from to to included.

Parameters:
from - begin of interval
to - end of interval
Returns:
random int.

getRandomElement

public static Object getRandomElement(List list)
Choose a random element from the list and return it.

Parameters:
list - list to choose from
Returns:
random element choosed from the list