Class Console
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,RootPaneContainer,WindowConstants,Controller
- Playing, stopping, pausing, stepping, and various associated controls
- View of the current time and frame rate
- Control of the random number generator
- An HTML "page" of information about the model
- Loading and saving checkpointed simulations, and starting new simulation classes
- Hiding and showing simulation displays
- Storage for inspectors
Console maintains the underlying play thread of the model, and handles much of the complexities that come with doing threads.
When you create new simulations (by frobbing the "New Simulation..." menu), you're presented with a ComboBox. Here you can type in any simulation class you like, or you can pick from a collection of pre-defined classes. The pre-defined class names are stored in the text file "simulation.classes", located in the same directory as the Console.class file. Feel free to edit it.
While normally you'd start a MASON application by running a main() method created by the developer, you can also fire up the Console directly and pick a model from the aforementioned ComboBox. To do this, simply run java sim.display.Console
If you attach a Frame to the Console, it will appear in the Console's "Displays" tab, where the user has control over hiding and showing various frames. The best time to do such attaching is during your GUIState's init() method. Such Frames should be set to hide (not dispose) when closed. JFrames do this by default.
Console places itself on-screen using the following rule. First it moves itself to an unusual location (presently -10000 x -10000). Then it calls init() on your GUIState. If in init() you move the Console to a position, then that's where it will stay. If not, then the Console looks up all the Frames attached to it during init() and places itself to the right of the rightmost such Frame, if there is room on the main display. If not, then Console puts itself in its default position (typically the top left corner of the screeen).
Console generates a mammoth number of anonymous subclasses. Well, such is life with a complicated GUI I guess. Don't be daunted by them -- almost all of them are little tiny things like Runnables to pass into SwingUtilities.invokeLater() or various anonymous listeners and adapters for buttons and text fields etc.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic WeakHashMapA weak container for all current consoles and other controllers which wish to be there.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intWhen the Console is laid out to the right of some window, the space allocated between it and the windowstatic final intDefault height of the Console.static final Stringstatic final intDefault width of the Console.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intDefault maximum number of steps in the step sliderstatic final StringUsed in the 'simulation.classes' file to specify a special name for a simulation.static final Stringstatic final StringUsed in the 'simulation.classes' file to indicate that nonstandard classes may not be accessed.static final intThe play thread is presently paused.static final intThe play thread is presently playing.static final intThe play thread is presently stopped.static final Stringstatic final StringFields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoAbout()voidDeprecated.voiddoClose()Closes the Console and shuts down the simulation.voiddoNew()Pops up a window allowing the user to enter in a class name to start a new simulation.voiddoOpen()Reverts the current simulation to the simulation stored at a user-specified checkpoint filename.voidstatic voiddoQuit()Quits the program.voiddoSave()Lets the user checkpoint out a simulation to the last checkpoint filename.voiddoSaveAs()Lets the user checkpoint out a simulation to a file with a given name.voiddoSweep()Returns a list of all displays.Returns a list of all current inspectors.booleanDeprecated.renamed to getIncrementSeedOnStopbooleanReturn the model inspector so simulations can do things like updating the properties.intlongGets how long we should sleep between each step in the play thread (in milliseconds).intGets whether or not the current thread is PS_PLAYING, PS_STOPPED, or PS_PAUSED.booleanbooleanGet whether or not the simualtion should repeat when the stop button is pressed.doubleReturns the frame rate.Simulations can call this to get access to the tabPane -- to add tabbed panes as they like.intDeprecated.We may eliminate thread priority as an optionlongGet when the simulation should end.doubleGet when the simulation should end.longGet when the simulation should pause.doubleGet when the simulation should pause.voidHides all JFrames registered with the Console.static ImageIconReturns icons for a given filename, such as "NotPlaying.png".booleanbooleanbooleanbooleanstatic voidPops up a window allowing the user to enter in a class name to start a new simulation.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.voidsetNewMenuAllowed(boolean val) voidsetNumStepsPerStepButtonPress(int val) Sets the number of steps per stepp button press.voidsetOpenMenuAllowed(boolean val) voidsetPlaySleep(long sleep) Sets (in milliseconds) how long we should sleep between each step in the play thread.voidsetRequiresConfirmationToStop(boolean val) voidsetSaveMenuAllowed(boolean val) voidsetShouldRepeat(boolean val) Set whether or not the simualtion should repeat when the stop button is pressed.voidsetThreadPriority(int val) Deprecated.We may eliminate thread priority as an optionvoidsetWhenShouldEnd(long val) Set when the simulation should end.voidsetWhenShouldEndTime(double val) Set when the simulation should end.voidsetWhenShouldPause(long val) Sets when the simulation should pause.voidsetWhenShouldPauseTime(double val) Sets when the simulation should pause.voidShows and brings to front all JFrames registered with the Console.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 consoleMethods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
DEFAULT_WIDTH
public static final int DEFAULT_WIDTHDefault width of the Console.- See Also:
-
DEFAULT_HEIGHT
public static final int DEFAULT_HEIGHTDefault height of the Console.- See Also:
-
DEFAULT_GUTTER
public static final int DEFAULT_GUTTERWhen the Console is laid out to the right of some window, the space allocated between it and the window- See Also:
-
MAXIMUM_STEPS
public static final int MAXIMUM_STEPSDefault maximum number of steps in the step slider- See Also:
-
DEFAULT_PREFERENCES_KEY
- See Also:
-
DELAY_KEY
- See Also:
-
STEPS_KEY
- See Also:
-
AUTOMATIC_STOP_STEPS_KEY
- See Also:
-
AUTOMATIC_STOP_TIME_KEY
- See Also:
-
AUTOMATIC_PAUSE_STEPS_KEY
- See Also:
-
AUTOMATIC_PAUSE_TIME_KEY
- See Also:
-
INCREMENT_KEY
- See Also:
-
REPEAT_KEY
- See Also:
-
NUM_DISPLAYS_KEY
- See Also:
-
DISPLAY_X_KEY
- See Also:
-
DISPLAY_Y_KEY
- See Also:
-
DISPLAY_WIDTH_KEY
- See Also:
-
DISPLAY_HEIGHT_KEY
- See Also:
-
DISPLAY_SHOWN_KEY
- See Also:
-
CONSOLE_KEY
- See Also:
-
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:
-
allControllers
A weak container for all current consoles and other controllers which wish to be there. -
ONLY_INDICATOR
Used in the 'simulation.classes' file to indicate that nonstandard classes may not be accessed.- See Also:
-
NAME_INDICATOR
Used in the 'simulation.classes' file to specify a special name for a simulation.- See Also:
-
-
Constructor Details
-
Console
Creates a Console, using the default initial start behavior (INITIAL_BEHAVIOR_START). Sets the simulation's controller to point to this Console.
-
-
Method Details
-
getSimulation
-
setNewMenuAllowed
public void setNewMenuAllowed(boolean val) -
isNewMenuAllowed
public boolean isNewMenuAllowed() -
setSaveMenuAllowed
public void setSaveMenuAllowed(boolean val) -
isSaveMenuAllowed
public boolean isSaveMenuAllowed() -
setOpenMenuAllowed
public void setOpenMenuAllowed(boolean val) -
isOpenMenuAllowed
public boolean isOpenMenuAllowed() -
iconFor
Returns icons for a given filename, such as "NotPlaying.png". A utility function. -
setShouldRepeat
public void setShouldRepeat(boolean val) Set whether or not the simualtion should repeat when the stop button is pressed. -
getShouldRepeat
public boolean getShouldRepeat()Get whether or not the simualtion should repeat when the stop button is pressed. -
setThreadPriority
public void setThreadPriority(int val) Deprecated.We may eliminate thread priority as an optionSet the thread priority. -
getThreadPriority
public int getThreadPriority()Deprecated.We may eliminate thread priority as an optionGets the thread priority. -
setWhenShouldEnd
public void setWhenShouldEnd(long val) Set when the simulation should end. -
getWhenShouldEnd
public long getWhenShouldEnd()Get when the simulation should end. -
setWhenShouldPause
public void setWhenShouldPause(long val) Sets when the simulation should pause. -
getWhenShouldPause
public long getWhenShouldPause()Get when the simulation should pause. -
setWhenShouldEndTime
public void setWhenShouldEndTime(double val) Set when the simulation should end. -
getWhenShouldEndTime
public double getWhenShouldEndTime()Get when the simulation should end. -
setWhenShouldPauseTime
public void setWhenShouldPauseTime(double val) Sets when the simulation should pause. -
getWhenShouldPauseTime
public double getWhenShouldPauseTime()Get when the simulation should pause. -
setPlaySleep
public void setPlaySleep(long sleep) Sets (in milliseconds) how long we should sleep between each step in the play thread. Must be a value >= 0, else it will be set to 0. -
getPlaySleep
public long getPlaySleep()Gets how long we should sleep between each step in the play thread (in milliseconds). -
getPlayState
public int getPlayState()Gets whether or not the current thread is PS_PLAYING, PS_STOPPED, or PS_PAUSED. -
getTabPane
Simulations can call this to get access to the tabPane -- to add tabbed panes as they like. -
getModelInspector
Return the model inspector so simulations can do things like updating the properties. -
doQuit
public static void doQuit()Quits the program. Called by the Quit menu option. -
doClose
public void doClose()Closes the Console 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. -
main
Pops up a window allowing the user to enter in a class name to start a new simulation. -
doAbout
protected void doAbout() -
doNew
public void doNew()Pops up a window allowing the user to enter in a class name to start a new simulation. -
doSaveAs
public void doSaveAs()Lets the user checkpoint out a simulation to a file with a given name. -
doSave
public void doSave()Lets the user checkpoint out a simulation to the last checkpoint filename. -
doSweep
public void doSweep() -
isOptimizeInstalled
public boolean isOptimizeInstalled() -
doOptimize
public void doOptimize() -
doOpen
public void doOpen()Reverts the current simulation to the simulation stored at a user-specified checkpoint filename. -
getAllFrames
Returns a list of all displays. You own the resulting list and can do what you like with it.- Specified by:
getAllFramesin interfaceController
-
showAllFrames
public void showAllFrames()Shows and brings to front all JFrames registered with the Console. Note that this method should probably only be called from within the Swing event thread. -
hideAllFrames
public void hideAllFrames()Hides all JFrames registered with the Console. Note that this method should probably only be called from within the Swing event thread. -
setRequiresConfirmationToStop
public void setRequiresConfirmationToStop(boolean val) -
getRequiresConfirmationToStop
public boolean getRequiresConfirmationToStop() -
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. -
getNumStepsPerStepButtonPress
public int getNumStepsPerStepButtonPress() -
setNumStepsPerStepButtonPress
public void setNumStepsPerStepButtonPress(int val) Sets the number of steps per stepp button press. The value must be > 0. If not, it will be set to 1. -
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. -
getStepsPerSecond
public double getStepsPerSecond()Returns the frame rate. If val is invalid input: '<'= 0, then the frame rate is presently unknown. -
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
-
getAllInspectors
Returns a list of all current inspectors. Some of these inspectors may be stored in the Console 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 Console, 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
-
stopAllInspectors
public void stopAllInspectors(boolean killDraggedOutWindowsToo) Stops all inspectors. If killDraggedOutWindowsToo is true, then the detatched inspectors are stopped as well. Updates all inspectors once as well for good measure prior to stopping some. -
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.
-