Package sim.display
Class SimpleController
java.lang.Object
sim.display.SimpleController
- All Implemented Interfaces:
Controller
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The play thread is presently paused.static final int
The play thread is presently playing.static final int
The play thread is presently stopped. -
Constructor Summary
ConstructorDescriptionSimpleController
(GUIState simulation) SimpleController
(GUIState simulation, boolean displayInspectors) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.void
doClose()
Closes the Controller and shuts down the simulation.boolean
doNew()
Calls forth the "New Simulation" window.Returns a list of all displays.Returns a list of all current inspectors.boolean
Deprecated.renamed to getIncrementSeedOnStopboolean
int
Gets whether or not the current thread is PS_PLAYING, PS_STOPPED, or PS_PAUSED.void
Called when the user presses the pause button.void
Called when the user presses the play button.void
Called when the user presses the stop button.void
refresh()
Lazily updates and redraws all the displays and inspectors.boolean
registerFrame
(JFrame frame) Simulations can call this to add a frame to be listed in the "Display list" of the consolevoid
registerInspector
(Inspector inspector, Stoppable stopper) Registers an inspector to be Stopped if necessary in the future.void
removeAllInspectors
(boolean killDraggedOutWindowsToo) Stops and removes all inspectors.void
setIncrementSeedOnPlay
(boolean val) Deprecated.renamed to setIncrementSeedOnStopvoid
setIncrementSeedOnStop
(boolean val) void
setInspectors
(Bag inspectors, Bag names) Adds new inspectors to the Console's list, given the provided inspectors, their portrayals, and appropriate names for them.void
stopAllInspectors
(boolean killDraggedOutWindowsToo) Stops all inspectors.boolean
Simulations can call this to clear out the "Display list" of the consoleboolean
unregisterFrame
(JFrame frame) Simulations can call this to remove a frame from the "Display list" of the console
-
Field Details
-
PS_STOPPED
public static final int PS_STOPPEDThe play thread is presently stopped.- See Also:
-
PS_PLAYING
public static final int PS_PLAYINGThe play thread is presently playing.- See Also:
-
PS_PAUSED
public static final int PS_PAUSEDThe play thread is presently paused.- See Also:
-
-
Constructor Details
-
SimpleController
-
SimpleController
-
-
Method Details
-
getSimulation
-
getPlayState
public int getPlayState()Gets whether or not the current thread is PS_PLAYING, PS_STOPPED, or PS_PAUSED. -
doClose
public void doClose()Closes the Controller and shuts down the simulation. Quits the program only if other simulations are not running in the same program. Called when the user clicks on the close button of the Console, or during a program-wide doQuit() process. Can also be called programmatically. -
setIncrementSeedOnPlay
public void setIncrementSeedOnPlay(boolean val) Deprecated.renamed to setIncrementSeedOnStop -
getIncrementSeedOnPlay
public boolean getIncrementSeedOnPlay()Deprecated.renamed to getIncrementSeedOnStop -
setIncrementSeedOnStop
public void setIncrementSeedOnStop(boolean val) -
getIncrementSeedOnStop
public boolean getIncrementSeedOnStop() -
pressStop
public void pressStop()Called when the user presses the stop button. You can call this as well to simulate the same. -
pressPause
public void pressPause()Called when the user presses the pause button. You can call this as well to simulate the same. Keep in mind that pause is a toggle. -
pressPlay
public void pressPlay()Called when the user presses the play button. You can call this as well to simulate the same. Keep in mind that play will change to step if pause is down. -
registerFrame
Simulations can call this to add a frame to be listed in the "Display list" of the console- Specified by:
registerFrame
in interfaceController
-
unregisterFrame
Simulations can call this to remove a frame from the "Display list" of the console- Specified by:
unregisterFrame
in interfaceController
-
unregisterAllFrames
public boolean unregisterAllFrames()Simulations can call this to clear out the "Display list" of the console- Specified by:
unregisterAllFrames
in interfaceController
-
doChangeCode
Deprecated.Description copied from interface:Controller
This method will interrupt the simulation (pause it), call your runnable, then continue (uninterrupt) the simulation. This allows you to guarantee a way to change the model from a separate thread -- for example, the Swing event thread -- in a synchronous, blocking fashion.You have other options for updating the model from external threads. One option is to add a Steppable to GUIState's scheduleImmediate(...) queue. When the Steppable is stepped, it will be done so inside the model's thread. This is asynchronous (non-blocking), however.
Alternatively, you can synchronize on state.schedule and run your code. This is synchronous.
- Specified by:
doChangeCode
in interfaceController
-
refresh
public void refresh()Description copied from interface:Controller
Lazily updates and redraws all the displays and inspectors. Do not call this method from the model thread -- only from the Swing event thread. This is an expensive procedure and should not be done unless necessary. Typically it's done in response to some event (a button press etc.) rather than in the model itself.- Specified by:
refresh
in interfaceController
-
setInspectors
Adds new inspectors to the Console's list, given the provided inspectors, their portrayals, and appropriate names for them. These bags must match in size, else an exception will be thrown.- Specified by:
setInspectors
in interfaceController
-
registerInspector
Registers an inspector to be Stopped if necessary in the future. This automatically happens if you call setInspectors(...).- Specified by:
registerInspector
in interfaceController
-
stopAllInspectors
public void stopAllInspectors(boolean killDraggedOutWindowsToo) Stops all inspectors. If killDraggedOutWindowsToo is true, then the detatched inspectors are stopped as well. -
removeAllInspectors
public void removeAllInspectors(boolean killDraggedOutWindowsToo) Stops and removes all inspectors. If killDraggedOutWindowsToo is true, then all inspector windows will be closed; else only the inspectors presently embedded in the console will be stopped and removed. -
doNew
public boolean doNew()Calls forth the "New Simulation" window. -
getAllInspectors
Returns a list of all current inspectors. Some of these inspectors may be stored in the SimpleController itself, and others may have been dragged out into their own JFrames. You will need to distinguish between these two on your own. Note that some of these inspectors are stored as weak keys in the SimpleController, so holding onto this list will prevent them from getting garbage collected. As a result, you should only use this list for temporary scans.- Specified by:
getAllInspectors
in interfaceController
-
getAllFrames
Returns a list of all displays. You own the resulting list and can do what you like with it.- Specified by:
getAllFrames
in interfaceController
-