edu.rice.cs.drjava.ui
Class InteractionsController

java.lang.Object
  extended by edu.rice.cs.drjava.ui.AbstractConsoleController
      extended by edu.rice.cs.drjava.ui.InteractionsController

public class InteractionsController
extends AbstractConsoleController

This class installs listeners and actions between an InteractionsDocument (the model) and an InteractionsPane (the view). We may want to refactor this class into a different package.

(The PopupConsole was introduced in version 1.29 of this file and subsequently removed.)

Version:
$Id: InteractionsController.java 5362 2010-08-14 01:49:04Z mgricken $

Nested Class Summary
static interface InteractionsController.ConsoleStateListener
          A listener interface that allows for others outside the interactions controller to be notified when the input console is enabled in the interactions pane.
private static class InteractionsController.InputBox
          A box that can be inserted into the interactions pane for separate input.
 
Field Summary
private  InteractionsController.InputBox _box
          A temporary variable used to hold a box allocated inside getConsoleInput below.
private  ArrayList<InteractionsController.ConsoleStateListener> _consoleStateListeners
           
private  SimpleAttributeSet _debugStyle
          Style to use for debug messages.
private static Runnable _defaultInputCompletionCommand
          Default implementation of the input completion command
private static Lambda<String,String> _defaultInsertTextCommand
          Default implementation of the insert text in input command
private  Runnable _disableCloseSystemInMenuItemCommand
          Runnable command that disables the "Close System.in" menu command.
private  InteractionsDocument _doc
          GUI-agnostic interactions document from the model.
private  boolean _endOfStream
          A variable indicating whether the input stream has been closed.
private  SimpleAttributeSet _errStyle
          Style to use for error messages.
private  Runnable _inputCompletionCommand
          Runnable command used to force the System.in input to complete
protected  InputListener _inputListener
          Listens for input requests from System.in, displaying an input box as needed.
private  Lambda<String,String> _insertTextCommand
          Lambda used to input text into the embedded System.in input box.
private  OptionListener<Vector<KeyStroke>> _keyBindingOptionListener
          OptionListener responding to changes for the undo/redo key bindings.
private  InteractionsModel _model
          InteractionsModel to handle interpretation.
private  DelegatingAction _redoAction
           
private  String _result
          A temporary variable used to hold the result fetched from _box in getConsoleInput below.
private  DelegatingAction _undoAction
           
private  ArrayList<FocusListener> _undoRedoInteractionFocusListeners
           
private  InteractionsListener _viewListener
           
(package private)  Action defaultDownAction
           
(package private)  Action defaultUpAction
           
(package private)  AbstractAction evalAction
          Evaluates the interaction on the current line.
(package private)  AbstractAction historyForwardSearchAction
          Forward searches in the history.
(package private)  AbstractAction historyNextAction
          Recalls the next command from the history.
(package private)  AbstractAction historyPrevAction
          Recalls the previous command from the history.
(package private)  AbstractAction historyReverseSearchAction
          Reverse searches in the history.
(package private)  AbstractAction indentKeyActionLine
          Indents in preparation for typing next line
(package private)  AbstractAction indentKeyActionTab
          Indents the selected text.
static String INPUT_BOX_STYLE
          Style for System.in box
static String INPUT_BOX_SYMBOL
          The symbol used in the document for the input box.
private static String INPUT_ENTERED_NAME
           
private static String INSERT_END_OF_STREAM
           
private static String INSERT_NEWLINE_NAME
           
(package private)  AbstractAction moveDownAction
          Added feature for down.
(package private)  AbstractAction moveLeftAction
          Moves the caret left or wraps around.
(package private)  AbstractAction moveRightAction
          Moves the caret right or wraps around.
(package private)  AbstractAction moveUpAction
          Added feature for up.
(package private)  AbstractAction nextWordAction
          Skips forward one word.
(package private)  AbstractAction prevWordAction
          Skips back one word.
private static String REDO_NAME
           
private static String UNDO_NAME
           
 
Fields inherited from class edu.rice.cs.drjava.ui.AbstractConsoleController
_defaultStyle, _interactionsDJDocument, _pane, _systemErrStyle, _systemOutStyle, clearCurrentAction, copyAction, cutAction, gotoEndAction, gotoPromptPosAction, newLineAction, selectToEndAction, selectToPromptPosAction, switchToNextPaneAction, switchToPrevPaneAction
 
Constructor Summary
InteractionsController(InteractionsModel model, InteractionsDJDocument adapter, InteractionsPane pane, Runnable disableCloseSystemInMenuItemCommand)
          Glue together the given model and view.
InteractionsController(InteractionsModel model, InteractionsDJDocument adapter, Runnable disableCloseSystemInMenuItemCommand)
          Glue together the given model and a new view.
 
Method Summary
protected  void _addDocumentStyles()
          Adds AttributeSets as named styles to the document adapter.
private  boolean _isCursorAfterPrompt()
           
private  void _setConsoleInputCommands(Runnable inputCompletionCommand, Lambda<String,String> insertTextCommand)
          Sets the commands used to manipulate the console input process.
protected  void _setupModel()
          Adds listeners to the model.
protected  void _setupView()
          Adds actions to the view.
private  boolean _shouldGoIntoHistory(int start, int end)
          Tests whether or not to move into the history.
 void addConsoleStateListener(InteractionsController.ConsoleStateListener listener)
           
 void addFocusListener(FocusListener listener)
          Add a focus listener to the Interactions Pane and the Input Box.
private  void fireConsoleInputCompleted(String text)
           
private  void fireConsoleInputStarted()
           
 ConsoleDocument getConsoleDoc()
          Allows the abstract superclass to use the document.
 InteractionsDocument getDocument()
          Accessor method for the InteractionsDocument.
 InputListener getInputListener()
          Gets the input listener for console input requests.
 InteractionsModel getInteractionsModel()
          Accessor method for the InteractionsModel.
 Action getRedoAction()
           
 Action getUndoAction()
           
 void insertConsoleText(String input)
          Inserts text into the console.
 void interruptConsoleInput()
          Forces console input to complete without the user hitting .
 void removeConsoleStateListener(InteractionsController.ConsoleStateListener listener)
           
 void setEndOfStream(boolean tf)
          Sets the end of stream flag.
 
Methods inherited from class edu.rice.cs.drjava.ui.AbstractConsoleController
_busy, _init, getDocumentAdapter, getPane, moveToEnd, moveToPrompt, resetView, setNextPaneAction, setPrevPaneAction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INPUT_ENTERED_NAME

private static final String INPUT_ENTERED_NAME
See Also:
Constant Field Values

INSERT_NEWLINE_NAME

private static final String INSERT_NEWLINE_NAME
See Also:
Constant Field Values

INSERT_END_OF_STREAM

private static final String INSERT_END_OF_STREAM
See Also:
Constant Field Values

UNDO_NAME

private static final String UNDO_NAME
See Also:
Constant Field Values

REDO_NAME

private static final String REDO_NAME
See Also:
Constant Field Values

INPUT_BOX_STYLE

public static final String INPUT_BOX_STYLE
Style for System.in box

See Also:
Constant Field Values

INPUT_BOX_SYMBOL

public static final String INPUT_BOX_SYMBOL
The symbol used in the document for the input box.

See Also:
Constant Field Values

_model

private volatile InteractionsModel _model
InteractionsModel to handle interpretation.


_doc

private volatile InteractionsDocument _doc
GUI-agnostic interactions document from the model.


_errStyle

private volatile SimpleAttributeSet _errStyle
Style to use for error messages.


_debugStyle

private final SimpleAttributeSet _debugStyle
Style to use for debug messages.


_insertTextCommand

private volatile Lambda<String,String> _insertTextCommand
Lambda used to input text into the embedded System.in input box.


_inputCompletionCommand

private volatile Runnable _inputCompletionCommand
Runnable command used to force the System.in input to complete

NOTE: This command must be executed on swing's event handling thread.


_disableCloseSystemInMenuItemCommand

private final Runnable _disableCloseSystemInMenuItemCommand
Runnable command that disables the "Close System.in" menu command.


_defaultInsertTextCommand

private static final Lambda<String,String> _defaultInsertTextCommand
Default implementation of the insert text in input command


_defaultInputCompletionCommand

private static final Runnable _defaultInputCompletionCommand
Default implementation of the input completion command


_box

private volatile InteractionsController.InputBox _box
A temporary variable used to hold a box allocated inside getConsoleInput below.


_result

private volatile String _result
A temporary variable used to hold the result fetched from _box in getConsoleInput below.


_endOfStream

private volatile boolean _endOfStream
A variable indicating whether the input stream has been closed.


_inputListener

protected volatile InputListener _inputListener
Listens for input requests from System.in, displaying an input box as needed.


_consoleStateListeners

private ArrayList<InteractionsController.ConsoleStateListener> _consoleStateListeners

_viewListener

private InteractionsListener _viewListener

evalAction

AbstractAction evalAction
Evaluates the interaction on the current line.


historyPrevAction

AbstractAction historyPrevAction
Recalls the previous command from the history.


historyNextAction

AbstractAction historyNextAction
Recalls the next command from the history.


moveUpAction

AbstractAction moveUpAction
Added feature for up. If the cursor is on the first line of the current interaction, it goes into the history. Otherwise, stays within the current interaction


moveDownAction

AbstractAction moveDownAction
Added feature for down. If the cursor is on the last line of the current interaction, it goes into the history. Otherwise, stays within the current interaction


defaultUpAction

Action defaultUpAction

defaultDownAction

Action defaultDownAction

historyReverseSearchAction

AbstractAction historyReverseSearchAction
Reverse searches in the history.


historyForwardSearchAction

AbstractAction historyForwardSearchAction
Forward searches in the history.


moveLeftAction

AbstractAction moveLeftAction
Moves the caret left or wraps around.


moveRightAction

AbstractAction moveRightAction
Moves the caret right or wraps around.


prevWordAction

AbstractAction prevWordAction
Skips back one word. Doesn't move past the prompt.


nextWordAction

AbstractAction nextWordAction
Skips forward one word. Doesn't move past the prompt.


indentKeyActionTab

AbstractAction indentKeyActionTab
Indents the selected text.


indentKeyActionLine

AbstractAction indentKeyActionLine
Indents in preparation for typing next line


_undoAction

private final DelegatingAction _undoAction

_redoAction

private final DelegatingAction _redoAction

_undoRedoInteractionFocusListeners

private final ArrayList<FocusListener> _undoRedoInteractionFocusListeners

_keyBindingOptionListener

private final OptionListener<Vector<KeyStroke>> _keyBindingOptionListener
OptionListener responding to changes for the undo/redo key bindings.

Constructor Detail

InteractionsController

public InteractionsController(InteractionsModel model,
                              InteractionsDJDocument adapter,
                              Runnable disableCloseSystemInMenuItemCommand)
Glue together the given model and a new view.

Parameters:
model - An InteractionsModel
adapter - InteractionsDJDocument being used by the model's doc

InteractionsController

public InteractionsController(InteractionsModel model,
                              InteractionsDJDocument adapter,
                              InteractionsPane pane,
                              Runnable disableCloseSystemInMenuItemCommand)
Glue together the given model and view.

Parameters:
model - An InteractionsModel
adapter - InteractionsDJDocument being used by the model's doc
pane - An InteractionsPane
Method Detail

addConsoleStateListener

public void addConsoleStateListener(InteractionsController.ConsoleStateListener listener)

removeConsoleStateListener

public void removeConsoleStateListener(InteractionsController.ConsoleStateListener listener)

fireConsoleInputStarted

private void fireConsoleInputStarted()

fireConsoleInputCompleted

private void fireConsoleInputCompleted(String text)

setEndOfStream

public void setEndOfStream(boolean tf)
Sets the end of stream flag.


getInputListener

public InputListener getInputListener()
Gets the input listener for console input requests. ONLY used in unit tests.

Returns:
the input listener for console input requests.

interruptConsoleInput

public void interruptConsoleInput()
Forces console input to complete without the user hitting . Called by MainFrame when reset is called so that this lock is released. This method is thread safe.

Throws:
UnsupportedOperationException - If the interactions pane is not receiving console input

insertConsoleText

public void insertConsoleText(String input)
Inserts text into the console. Can only be called from the event thread. ONLY used in unit tests.

Parameters:
input - The text to insert into the console input box
Throws:
UnsupportedOperationException - If the the interactions pane is not receiving console input

getInteractionsModel

public InteractionsModel getInteractionsModel()
Accessor method for the InteractionsModel.

Returns:
the interactions model

getConsoleDoc

public ConsoleDocument getConsoleDoc()
Allows the abstract superclass to use the document.

Specified by:
getConsoleDoc in class AbstractConsoleController
Returns:
the InteractionsDocument

getDocument

public InteractionsDocument getDocument()
Accessor method for the InteractionsDocument.


_addDocumentStyles

protected void _addDocumentStyles()
Adds AttributeSets as named styles to the document adapter.

Overrides:
_addDocumentStyles in class AbstractConsoleController

_setupModel

protected void _setupModel()
Adds listeners to the model.

Specified by:
_setupModel in class AbstractConsoleController

_setupView

protected void _setupView()
Adds actions to the view.

Overrides:
_setupView in class AbstractConsoleController

_setConsoleInputCommands

private void _setConsoleInputCommands(Runnable inputCompletionCommand,
                                      Lambda<String,String> insertTextCommand)
Sets the commands used to manipulate the console input process. Only runs in the event thread.


_shouldGoIntoHistory

private boolean _shouldGoIntoHistory(int start,
                                     int end)
Tests whether or not to move into the history. Should be executed in the event thread to ensure that caret and prompt positions are in consistent states.

Returns:
true iff there are no "\n" characters between the start and the end

_isCursorAfterPrompt

private boolean _isCursorAfterPrompt()

addFocusListener

public void addFocusListener(FocusListener listener)
Add a focus listener to the Interactions Pane and the Input Box.


getUndoAction

public Action getUndoAction()
Returns:
the undo action.

getRedoAction

public Action getRedoAction()
Returns:
the redo action.