RePast
v. 2.0

uchicago.src.sim.engine
Class Controller

java.lang.Object
  |
  +--uchicago.src.sim.engine.BaseController
        |
        +--uchicago.src.sim.engine.AbstractGUIController
              |
              +--uchicago.src.sim.engine.Controller
All Implemented Interfaces:
IController, SimEventListener

public class Controller
extends AbstractGUIController

Default GUI control of the simulation. Allows start stop, step, exit, as well as setup to re-run the simulation after a stop. A user will interact with a Controller through the GUI, but, under normal circumstances, should not create one. See SimInit for more on how to run a simulation.

A list of the buttons displayed by the controller and what they do follows:


Field Summary
protected  JButton btnBegin
           
protected  JButton btnExit
           
protected  JButton btnLoad
           
protected  JButton btnPause
           
protected  JButton btnSettings
           
protected  JButton btnSetup
           
protected  JButton btnStart
           
protected  JButton btnStep
           
protected  JButton btnStop
           
protected  ArrayList keyListeners
           
protected  ArrayList listeners
           
protected  IntrospectPanel modelPanel
           
protected  RepastActionPanel repastPanel
           
protected  JFrame settingsFrame
           
protected  IntrospectPanel simPanel
           
protected  JTabbedPane tabPane
           
protected  JFrame tbFrame
           
protected  JLabel tickCount
           
protected  JToolBar toolBar
           
protected  ArrayList userButtons
           
 
Fields inherited from class uchicago.src.sim.engine.AbstractGUIController
ALPHA_ORDER, chartModels, customCharts, DEFAULTS_INCLUDE_RNGSEED, exitOnExit, mediaSchedulers, myParams, SHOW_CHARTS, UPDATE_PROBES
 
Fields inherited from class uchicago.src.sim.engine.BaseController
done, doStep, executeBegin, go, isGui, listenerList, model, monitor, params, pauseActionsExecuted, pauseAt, pauseAtAction, pauseSim, persistentObj, runFinished, runThread, schedule, simRun, sleepValue, time
 
Constructor Summary
Controller()
          Constructs a Controller with no associated model, or parameters.
Controller(Vector parameters)
          Constructs a controller whose model has the specified parameters.
 
Method Summary
 JButton addButton(JButton b)
          Adds a user defined button to the toolbar.
 JButton addButton(String label, ActionListener listener)
          Adds a user defined button to the toolbar.
 void addExitListener(ActionListener listener)
          Adds an ActionListener listening for exit button presses.
 JButton addIconButton(String path, ActionListener l)
          Adds a user defined button to the toolbar.
 void addKeyListener(KeyListener listener)
          Adds a KeyListener listening for any keyboard action when the control toolbar has focus.
 void addPauseListener(ActionListener listener)
          Adds an ActionListener listening for pause button presses.
 void addStartListener(ActionListener listener)
          Adds an ActionListener listening for start button presses.
 void addStepListener(ActionListener listener)
          Adds an ActionListener listening for step button presses.
 void addStopListener(ActionListener listener)
          Adds an ActionListener listening for stop button presses.
 void beginModel()
          Executes begin() on the SimModel associated with this AbstractGUIController.
 void display()
          Displays the controller
 JFrame getFrame()
          Returns the JFrame for controller tool bar.
 JTabbedPane getTabPane()
          Returns the JTabbedPane that contains the parameter panel etc.
 JToolBar getToolBar()
          Returns the tool bar containing the stop, start etc.
protected  void onTickCountUpdate()
          Updates the tick clock whenever the tick count is incremented
 void pauseSim()
          Pauses the simulation
 void setModel(SimModel model)
          Sets the model that is controlled by this Controller.
 void setup()
          Sets up this controller and is associated SimModel prior to a model run.
 void showSettings()
           
 void shutdown()
          Exits the simulation but does not exit the jvm.
 void simEventPerformed(SimEvent evt)
          Invoked by a source on which this is a listener when a SimEvent is fired.
 void startSim()
          Starts the simulation.
 void stepSim()
          Steps the simulation through one iteration of execution.
 void stopSim()
          Stops the simulation.
 
Methods inherited from class uchicago.src.sim.engine.AbstractGUIController
enableManipulation, exitSim, exitSimulation, getModelParameterPanel, getRepastParameterPanel, isBatch, isGUI, loadAndStart, makeCurrentParamsDefault, pauseSimulation, setExitOnExit, setParameters, showChartDialog, showLoadModelDialog, showMakeMovieDialog, showSnapshotDialog, showVersion, showWriteParamsDialog, stopSimulation
 
Methods inherited from class uchicago.src.sim.engine.BaseController
addSimEventListener, fireSimEvent, getCellDepth, getCellHeight, getCellWidth, getCurrentTime, getCurrentTimeDouble, getDefaultModelParameters, getModel, getModelParameters, getPauseAt, getPersistentObj, getRandomSeed, getSchedule, notifyMonitor, putPersistentObj, removeSimEventListener, setCellDepth, setCellHeight, setCellWidth, setPauseAt, setRandomSeed, setSchedule, setupSchedule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toolBar

protected JToolBar toolBar

tbFrame

protected JFrame tbFrame

btnSetup

protected JButton btnSetup

btnStart

protected JButton btnStart

btnStep

protected JButton btnStep

btnStop

protected JButton btnStop

btnPause

protected JButton btnPause

btnExit

protected JButton btnExit

btnLoad

protected JButton btnLoad

btnSettings

protected JButton btnSettings

btnBegin

protected JButton btnBegin

tickCount

protected JLabel tickCount

settingsFrame

protected JFrame settingsFrame

tabPane

protected JTabbedPane tabPane

modelPanel

protected IntrospectPanel modelPanel

simPanel

protected IntrospectPanel simPanel

repastPanel

protected RepastActionPanel repastPanel

userButtons

protected ArrayList userButtons

listeners

protected ArrayList listeners

keyListeners

protected ArrayList keyListeners
Constructor Detail

Controller

public Controller()
Constructs a Controller with no associated model, or parameters.


Controller

public Controller(Vector parameters)
Constructs a controller whose model has the specified parameters. The model itself is set via setModel().

Parameters:
parameters - default values for the model's parameters
Method Detail

setModel

public void setModel(SimModel model)
Sets the model that is controlled by this Controller.

Specified by:
setModel in interface IController
Overrides:
setModel in class AbstractGUIController
Parameters:
model - the model associated with this BaseController

addButton

public JButton addButton(String label,
                         ActionListener listener)
Adds a user defined button to the toolbar. This must be called in the model's setup method or the button will not be added.

Parameters:
label - the label for the new JButton
listener - the ActionListener fired when the button is clicked

addButton

public JButton addButton(JButton b)
Adds a user defined button to the toolbar. This must be called in the model's setup method or the button will not be added.

Parameters:
b - the JButton to add

addIconButton

public JButton addIconButton(String path,
                             ActionListener l)
Adds a user defined button to the toolbar. This must be called in the model's setup method or the button will not be added. The location of the image to create the icon from is given the specified path.

Parameters:
path - the path to image to use as an ImageIcon for the created JButton
l - ActionListener fired when the button is clicked

startSim

public void startSim()
Description copied from class: BaseController
Starts the simulation. Fires a START_EVENT before the simulation thread is actually started.

Specified by:
startSim in interface IController
Overrides:
startSim in class BaseController

stopSim

public void stopSim()
Description copied from class: BaseController
Stops the simulation.

Specified by:
stopSim in interface IController
Overrides:
stopSim in class BaseController

shutdown

public void shutdown()
Description copied from class: AbstractGUIController
Exits the simulation but does not exit the jvm. This is useful if you run a simulation in from some other application within the same jvm instance.

Overrides:
shutdown in class AbstractGUIController

showSettings

public void showSettings()

stepSim

public void stepSim()
Description copied from class: AbstractGUIController
Steps the simulation through one iteration of execution.

Overrides:
stepSim in class AbstractGUIController

beginModel

public void beginModel()
Description copied from class: AbstractGUIController
Executes begin() on the SimModel associated with this AbstractGUIController. This is useful for displaying and recording the state of the model before any scheduled actions are executed. In addition this will displays any custom charts associated with this model if that option is selected.

Overrides:
beginModel in class AbstractGUIController

pauseSim

public void pauseSim()
Description copied from class: BaseController
Pauses the simulation

Specified by:
pauseSim in interface IController
Overrides:
pauseSim in class BaseController

setup

public void setup()
Description copied from class: AbstractGUIController
Sets up this controller and is associated SimModel prior to a model run.

Overrides:
setup in class AbstractGUIController

onTickCountUpdate

protected void onTickCountUpdate()
Updates the tick clock whenever the tick count is incremented

Overrides:
onTickCountUpdate in class AbstractGUIController

display

public void display()
Displays the controller


getFrame

public JFrame getFrame()
Returns the JFrame for controller tool bar.


getToolBar

public JToolBar getToolBar()
Returns the tool bar containing the stop, start etc. buttons.


getTabPane

public JTabbedPane getTabPane()
Returns the JTabbedPane that contains the parameter panel etc.


addStartListener

public void addStartListener(ActionListener listener)
Adds an ActionListener listening for start button presses. The source for the event fired here will be the start button with an actionCommand of "start".

Parameters:
listener - the listener to listen for button clicks.

addStopListener

public void addStopListener(ActionListener listener)
Adds an ActionListener listening for stop button presses. The source for the event fired here will be the stop button with an actionCommand of "stop".

Parameters:
listener - the listener to listen for button clicks.

addPauseListener

public void addPauseListener(ActionListener listener)
Adds an ActionListener listening for pause button presses. The source for the event fired here will be the pause button with an actionCommand of "pause".

Parameters:
listener - the listener to listen for button clicks.

addExitListener

public void addExitListener(ActionListener listener)
Adds an ActionListener listening for exit button presses. The source for the event fired here will be the exit button with an actionCommand of "exit".

Parameters:
listener - the listener to listen for button clicks.

addStepListener

public void addStepListener(ActionListener listener)
Adds an ActionListener listening for step button presses. The source for the event fired here will be the step button with an actionCommand of "step".

Parameters:
listener - the listener to listen for button clicks.

addKeyListener

public void addKeyListener(KeyListener listener)
Adds a KeyListener listening for any keyboard action when the control toolbar has focus.

Parameters:
listener - the listener to listen for keyboard events

simEventPerformed

public void simEventPerformed(SimEvent evt)
Invoked by a source on which this is a listener when a SimEvent is fired. Controller listens for stop, end, and rng_seed events. Stop will stop the simulation, end will end the simluation and an rng_seed event will update the model panel with the new rng seed value.

Specified by:
simEventPerformed in interface SimEventListener
Overrides:
simEventPerformed in class AbstractGUIController

RePast
v. 2.0

Bug reports and feature requests to RePast