Package sim.display
Class SimpleController
java.lang.Object
sim.display.SimpleController
- All Implemented Interfaces:
Controller
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe play thread is presently paused.static final intThe play thread is presently playing.static final intThe play thread is presently stopped. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleController(GUIState simulation) SimpleController(GUIState simulation, boolean displayInspectors) -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.voiddoClose()Closes the Controller and shuts down the simulation.booleandoNew()Calls forth the "New Simulation" window.Returns a list of all displays.Returns a list of all current inspectors.booleanDeprecated.renamed to getIncrementSeedOnStopbooleanintGets whether or not the current thread is PS_PLAYING, PS_STOPPED, or PS_PAUSED.voidCalled when the user presses the pause button.voidCalled when the user presses the play button.voidCalled when the user presses the stop button.voidrefresh()Lazily updates and redraws all the displays and inspectors.booleanregisterFrame(JFrame frame) Simulations can call this to add a frame to be listed in the "Display list" of the consolevoidregisterInspector(Inspector inspector, Stoppable stopper) Registers an inspector to be Stopped if necessary in the future.voidremoveAllInspectors(boolean killDraggedOutWindowsToo) Stops and removes all inspectors.voidsetIncrementSeedOnPlay(boolean val) Deprecated.renamed to setIncrementSeedOnStopvoidsetIncrementSeedOnStop(boolean val) voidsetInspectors(Bag inspectors, Bag names) Adds new inspectors to the Console's list, given the provided inspectors, their portrayals, and appropriate names for them.voidstopAllInspectors(boolean killDraggedOutWindowsToo) Stops all inspectors.booleanSimulations can call this to clear out the "Display list" of the consolebooleanunregisterFrame(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:
registerFramein interfaceController
-
unregisterFrame
Simulations can call this to remove a frame from the "Display list" of the console- Specified by:
unregisterFramein interfaceController
-
unregisterAllFrames
public boolean unregisterAllFrames()Simulations can call this to clear out the "Display list" of the console- Specified by:
unregisterAllFramesin interfaceController
-
doChangeCode
Deprecated.Description copied from interface:ControllerThis 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:
doChangeCodein interfaceController
-
refresh
public void refresh()Description copied from interface:ControllerLazily 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:
refreshin 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:
setInspectorsin interfaceController
-
registerInspector
Registers an inspector to be Stopped if necessary in the future. This automatically happens if you call setInspectors(...).- Specified by:
registerInspectorin 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:
getAllInspectorsin interfaceController
-
getAllFrames
Returns a list of all displays. You own the resulting list and can do what you like with it.- Specified by:
getAllFramesin interfaceController
-