edu.princeton.toy
Class TFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by edu.princeton.toy.TFrame
All Implemented Interfaces:
TVirtualMachine.ExecutionController, ActionListener, TextListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ChangeListener, ListSelectionListener, RootPaneContainer, WindowConstants

public class TFrame
extends JFrame
implements ActionListener, ChangeListener, TextListener, ListSelectionListener, TVirtualMachine.ExecutionController

See Also:
Serialized Form

Nested Class Summary
protected static class TFrame.Runner
          Runner is the implementation of Runnable which updates the warnings of all TFrames (if the program had changed since the last syntax check).
protected  class TFrame.TFrameAction
          TFrameAction is a generalizable action for the TFrame; basically, it relays all ActionEvents to the doCommand() method.
static class TFrame.WorkspaceMenuItem
          TWorkspaceMenuItem is a simple subclass of JRadioButtonMenuItem which keeps an index property.
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String AUTOCOMMENT_COMMAND
           
static int CASCADE_X
          The displacement in the x direction between cascaded windows.
static int CASCADE_Y
          The displacement in the y direction between cascaded windows.
static String CHANGE_CHECKING_COMMAND
           
static String CHANGE_EXECUTION_COMMAND
           
static String CHECK_SYNTAX_COMMAND
           
static String CLEAR_ODOMETER_COMMAND
           
static String CLOSE_COMMAND
           
static String DEBUG_MODE_COMMAND
           
static String EDIT_MODE_COMMAND
           
static String ENTER_COMMAND
           
static String FUNCTION_COMMAND
           
static String HIDE_WARNINGS_COMMAND
           
static String INTERRUPT_COMMAND
           
static String LOAD_COMMAND
           
static String LOOK_COMMAND
           
static String NEW_COMMAND
           
static String OPEN_COMMAND
           
static String OPEN_EXAMPLE_COMMAND
           
static String OPEN_STDIN_COMMAND
           
static String QUIT_COMMAND
           
static String RESET_COMMAND
           
static String REVERT_COMMAND
           
static String RUN_COMMAND
           
static String SAVE_ALL_COMMAND
           
static String SAVE_AS_COMMAND
           
static String SAVE_COMMAND
           
static String SAVE_CORE_DUMP_COMMAND
           
static String SAVE_MEM_DUMP_COMMAND
           
static String SAVE_STDIN_COMMAND
           
static String SAVE_STDOUT_COMMAND
           
static String SIM_MODE_COMMAND
           
static String STEP_COMMAND
           
static String STRIP_COMMENTS_COMMAND
           
static String WORKSPACE_COMMAND
           
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields 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_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TFrame()
           
TFrame(TProgramDocument program)
           
TFrame(TProgramDocument program, File file)
           
 
Method Summary
 void actionPerformed(ActionEvent e)
          Implement ActionListener to pass the command onto doCommand().
static TFrame createInitialFrame()
          Creates the first frame, initializing locations and bounds from the TOptionFrame's memory of the last closed TFrame.
 void dispose()
          Override this method to prevent unclean disposals.
 boolean doCommand(String command, Object extraInfo)
          Performs a command based on the argument.
 int getClockPeriod()
          This function is called by the TVirtualMachine's runner after it has recieved an order for a batch of steps to be run.
protected  void processWindowEvent(WindowEvent e)
          Intercept WindowEvents to pick up WINDOW_CLOSING events.
static void setAutoCheck(boolean autoCheck)
          Starts or stops the auto-syntax-check runner.
 void stateChanged(ChangeEvent e)
          Implement ChangeListener to listen to changes in the state of the virtual machine.
 int statusUpdate(TVirtualMachine virtualMachine, int n, int elapsedTime, boolean willStop)
          This function is called by the TVirtualMachine's runner when it has completed the previous batch of steps.
 void textValueChanged(TextEvent e)
          Implement TextListener to update the other components when the document changes.
 void valueChanged(ListSelectionEvent e)
          Implement ListSelectionListener to update the editTextArea selection when the list's selection changes.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods 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, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, 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, isOpaque, 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, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

CASCADE_X

public static final int CASCADE_X
The displacement in the x direction between cascaded windows.

See Also:
Constant Field Values

CASCADE_Y

public static final int CASCADE_Y
The displacement in the y direction between cascaded windows.

See Also:
Constant Field Values

NEW_COMMAND

public static final String NEW_COMMAND

OPEN_COMMAND

public static final String OPEN_COMMAND

OPEN_EXAMPLE_COMMAND

public static final String OPEN_EXAMPLE_COMMAND

CLOSE_COMMAND

public static final String CLOSE_COMMAND

REVERT_COMMAND

public static final String REVERT_COMMAND

SAVE_COMMAND

public static final String SAVE_COMMAND

SAVE_ALL_COMMAND

public static final String SAVE_ALL_COMMAND

SAVE_AS_COMMAND

public static final String SAVE_AS_COMMAND

QUIT_COMMAND

public static final String QUIT_COMMAND

EDIT_MODE_COMMAND

public static final String EDIT_MODE_COMMAND

DEBUG_MODE_COMMAND

public static final String DEBUG_MODE_COMMAND

SIM_MODE_COMMAND

public static final String SIM_MODE_COMMAND

LOOK_COMMAND

public static final String LOOK_COMMAND

LOAD_COMMAND

public static final String LOAD_COMMAND

RESET_COMMAND

public static final String RESET_COMMAND

STEP_COMMAND

public static final String STEP_COMMAND

RUN_COMMAND

public static final String RUN_COMMAND

INTERRUPT_COMMAND

public static final String INTERRUPT_COMMAND

ENTER_COMMAND

public static final String ENTER_COMMAND

OPEN_STDIN_COMMAND

public static final String OPEN_STDIN_COMMAND

SAVE_STDIN_COMMAND

public static final String SAVE_STDIN_COMMAND

SAVE_STDOUT_COMMAND

public static final String SAVE_STDOUT_COMMAND

SAVE_MEM_DUMP_COMMAND

public static final String SAVE_MEM_DUMP_COMMAND

SAVE_CORE_DUMP_COMMAND

public static final String SAVE_CORE_DUMP_COMMAND

WORKSPACE_COMMAND

public static final String WORKSPACE_COMMAND

CHECK_SYNTAX_COMMAND

public static final String CHECK_SYNTAX_COMMAND

FUNCTION_COMMAND

public static final String FUNCTION_COMMAND

AUTOCOMMENT_COMMAND

public static final String AUTOCOMMENT_COMMAND

STRIP_COMMENTS_COMMAND

public static final String STRIP_COMMENTS_COMMAND

CHANGE_EXECUTION_COMMAND

public static final String CHANGE_EXECUTION_COMMAND

CLEAR_ODOMETER_COMMAND

public static final String CLEAR_ODOMETER_COMMAND

CHANGE_CHECKING_COMMAND

public static final String CHANGE_CHECKING_COMMAND

HIDE_WARNINGS_COMMAND

public static final String HIDE_WARNINGS_COMMAND
Constructor Detail

TFrame

public TFrame()

TFrame

public TFrame(TProgramDocument program)

TFrame

public TFrame(TProgramDocument program,
              File file)
Method Detail

dispose

public void dispose()
Override this method to prevent unclean disposals.

Overrides:
dispose in class Window

setAutoCheck

public static void setAutoCheck(boolean autoCheck)
Starts or stops the auto-syntax-check runner.

Parameters:
autoCheck - Wheter or not the auto-syntax-check runner should be running.

createInitialFrame

public static TFrame createInitialFrame()
Creates the first frame, initializing locations and bounds from the TOptionFrame's memory of the last closed TFrame. The frame is also shown and broght to the front.

Returns:
The frame that was instantiated.

doCommand

public boolean doCommand(String command,
                         Object extraInfo)
Performs a command based on the argument.

Parameters:
command - A string representing the command. Note that pointer equality (not string equality) is tested here, so it is important to use the string constants defined in this class. TFrame.WORKSPACE_COMMAND requires an integer to be appended to it in order to distinguish between the arbitrarily large number of other workspaces. An IllegalArgumentException will be thrown if the argument is invalid.
extraInfo - Any extra information necessary. This is specific to the command:
  • TFrame.WORKSPACE_COMMAND needs an Integer object to decide which workspace to launch.
  • TFrame.OPEN_COMMAND and TFrame.SAVE_AS_COMMAND can take a java.io.File object to read from. If null is passed, a JFileDialog will be used to obtain the file to save to.
Returns:
True iff the command was executed sucessfully.

actionPerformed

public void actionPerformed(ActionEvent e)
Implement ActionListener to pass the command onto doCommand().

Specified by:
actionPerformed in interface ActionListener
See Also:
doCommand(String, Object)

textValueChanged

public void textValueChanged(TextEvent e)
Implement TextListener to update the other components when the document changes.

Specified by:
textValueChanged in interface TextListener

valueChanged

public void valueChanged(ListSelectionEvent e)
Implement ListSelectionListener to update the editTextArea selection when the list's selection changes.

Specified by:
valueChanged in interface ListSelectionListener

stateChanged

public void stateChanged(ChangeEvent e)
Implement ChangeListener to listen to changes in the state of the virtual machine.

Specified by:
stateChanged in interface ChangeListener

statusUpdate

public int statusUpdate(TVirtualMachine virtualMachine,
                        int n,
                        int elapsedTime,
                        boolean willStop)
This function is called by the TVirtualMachine's runner when it has completed the previous batch of steps.

Specified by:
statusUpdate in interface TVirtualMachine.ExecutionController
Parameters:
virtualMachine - The virtual machine whose status is being reported.
n - The number of steps taken since the last update.
elapsedTime - The number of milliseconds between the lastUpdate and the present.
willStop - Wheter or not the TVirtualMachine will stop after this status update.
Returns:
The number of additional steps to take before fireing more ChangeEvents and producing another status update. If this is 0, the virtualMachine will stop. If this is negative, a stack trace will be written to stderr and the virtualMachine will stop.

getClockPeriod

public int getClockPeriod()
This function is called by the TVirtualMachine's runner after it has recieved an order for a batch of steps to be run. The next status update will not occur until after n * getClockPeriod() milliseconds, where n was the number of steps taken. If the preferred clock period is too fast, the next status update will occur as soon the batch of steps is completed.

Specified by:
getClockPeriod in interface TVirtualMachine.ExecutionController
Returns:
The preferred number of milliseconds each step should take.

processWindowEvent

protected void processWindowEvent(WindowEvent e)
Intercept WindowEvents to pick up WINDOW_CLOSING events.

Overrides:
processWindowEvent in class JFrame