edu.rice.cs.drjava.model.repl
Class InteractionsDocument

java.lang.Object
  extended by edu.rice.cs.util.text.ConsoleDocument
      extended by edu.rice.cs.drjava.model.repl.InteractionsDocument
All Implemented Interfaces:
ConsoleDocumentInterface, EditDocumentInterface

public class InteractionsDocument
extends ConsoleDocument

A GUI toolkit-agnostic document that supports console-like interaction with a Java interpreter. This class assumes that the embedded document supports readers/writers locking and uses that locking protocol to ensure the integrity of the data added in this class

Version:
$Id: InteractionsDocument.java 4691 2008-12-02 23:33:27Z dlsmith $

Field Summary
static String CHARACTER_RETURN_STYLE
           
static String DEBUGGER_STYLE
          Style for debugger messages
static String DEFAULT_PROMPT
          Default prompt.
static String ERROR_STYLE
          Style for error messages
static String NUMBER_RETURN_STYLE
           
static String OBJECT_RETURN_STYLE
           
static String STRING_RETURN_STYLE
           
 
Fields inherited from class edu.rice.cs.util.text.ConsoleDocument
_beep, _book, _document, _prompt, DEFAULT_CONSOLE_PROMPT, DEFAULT_STYLE, SYSTEM_ERR_STYLE, SYSTEM_IN_STYLE, SYSTEM_OUT_STYLE
 
Constructor Summary
InteractionsDocument(ConsoleDocumentInterface document)
          Reset the document on startUp.
InteractionsDocument(ConsoleDocumentInterface document, History history)
          Creates and resets the interactions document on DrJava startUp.
InteractionsDocument(ConsoleDocumentInterface document, int maxHistorySize)
          Reset the document on startUp.
 
Method Summary
 void addToHistory(String text)
          Adds the given text to the history of commands.
 void appendExceptionResult(String message, String styleName)
          Inserts the given exception data into the document with the given style.
 void appendSyntaxErrorResult(String message, String interaction, int startRow, int startCol, int endRow, int endCol, String styleName)
           
 void clearCurrentInteraction()
          Clears the current input text and then moves to the end of the command history.
 void clearHistory()
          Clears the history
 void forwardHistorySearch(String searchString)
          Forward searches the history for the given string.
 void forwardSearchInteractionsInHistory()
          Forward searches the history for interactions that started with the current interaction.
 String getCurrentInteraction()
          Returns the string that the user has entered at the current prompt.
 String getDefaultStyle()
          Gets the String identifying the default style for this document if one exists; null otherwise.
protected  History getHistory()
           
 String getHistoryAsString()
          Returns the entire history as a single string.
 String getHistoryAsStringWithSemicolons()
          Returns the entire history as a single string.
 OptionListener<Integer> getHistoryOptionListener()
          Accessor method for the history of commands.
 boolean hasHistoryNext()
          Returns whether there is a next command in the history.
 boolean inProgress()
          Returns whether an interaction is currently in progress.
 String lastEntry()
           
 void moveHistoryNext(String entry)
          Puts the next line from the history on the current line and moves the history forward one line.
 void moveHistoryPrevious(String entry)
          Puts the previous line from the history on the current line and moves the history back one line.
 void preparePrintJob()
          This method tells the document to prepare all the DrJavaBook and PagePrinter objects.
 boolean recallNextInteractionInHistory()
          Gets the next interaction in the history and replaces whatever is on the current interactions input line with this interaction.
 boolean recallPreviousInteractionInHistory()
          Gets the previous interaction in the history and replaces whatever is on the current interactions input line with this interaction.
 String removeLastFromHistory()
          Returns the last history item and then removes it, or returns null if the history is empty.
 void reset(String banner)
          Resets the document to a clean state.
 void reverseHistorySearch(String searchString)
          Reverse searches the history for the given string.
 void reverseSearchInteractionsInHistory()
          Reverse searches the history for interactions that started with the current interaction.
 void saveHistory(FileSaveSelector selector)
          Saves the unedited version of the current history to a file
 void saveHistory(FileSaveSelector selector, String editedVersion)
          Saves the edited version of the current history to a file
 void setBanner(String banner)
          Sets the banner in an empty docuemnt.
 void setInProgress(boolean inProgress)
          Lets this document know whether an interaction is in progress.
 
Methods inherited from class edu.rice.cs.util.text.ConsoleDocument
_clearCurrentInputText, append, cleanUpPrintJob, clearCurrentInput, disablePrompt, forceInsertText, forceRemoveText, getCurrentInput, getDocText, getEditCondition, getLength, getPageable, getPrompt, getPromptLength, getPromptPos, getText, hasPrompt, insertBeforeLastPrompt, insertNewline, insertPrompt, insertText, print, removeText, setBeep, setEditCondition, setHasPrompt, setPrompt, setPromptPos
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROMPT

public static final String DEFAULT_PROMPT
Default prompt.

See Also:
Constant Field Values

ERROR_STYLE

public static final String ERROR_STYLE
Style for error messages

See Also:
Constant Field Values

DEBUGGER_STYLE

public static final String DEBUGGER_STYLE
Style for debugger messages

See Also:
Constant Field Values

OBJECT_RETURN_STYLE

public static final String OBJECT_RETURN_STYLE
See Also:
Constant Field Values

STRING_RETURN_STYLE

public static final String STRING_RETURN_STYLE
See Also:
Constant Field Values

CHARACTER_RETURN_STYLE

public static final String CHARACTER_RETURN_STYLE
See Also:
Constant Field Values

NUMBER_RETURN_STYLE

public static final String NUMBER_RETURN_STYLE
See Also:
Constant Field Values
Constructor Detail

InteractionsDocument

public InteractionsDocument(ConsoleDocumentInterface document)
Reset the document on startUp. Uses a history with configurable size.

Parameters:
document - the edit document to use for the model

InteractionsDocument

public InteractionsDocument(ConsoleDocumentInterface document,
                            int maxHistorySize)
Reset the document on startUp. Uses a history with the given maximum size. This history will not use the config framework.

Parameters:
document - EditDocumentInterface to use for the model
maxHistorySize - Number of commands to remember in the history

InteractionsDocument

public InteractionsDocument(ConsoleDocumentInterface document,
                            History history)
Creates and resets the interactions document on DrJava startUp. Uses the given history.

Parameters:
document - EditDocumentInterface to use for the model
history - History of commands
Method Detail

setInProgress

public void setInProgress(boolean inProgress)
Lets this document know whether an interaction is in progress.

Parameters:
inProgress - whether an interaction is in progress

inProgress

public boolean inProgress()
Returns whether an interaction is currently in progress.


setBanner

public void setBanner(String banner)
Sets the banner in an empty docuemnt.


reset

public void reset(String banner)
Resets the document to a clean state. Does not reset the history.

Overrides:
reset in class ConsoleDocument

getHistoryOptionListener

public OptionListener<Integer> getHistoryOptionListener()
Accessor method for the history of commands.


addToHistory

public void addToHistory(String text)
Adds the given text to the history of commands.


removeLastFromHistory

public String removeLastFromHistory()
Returns the last history item and then removes it, or returns null if the history is empty.


saveHistory

public void saveHistory(FileSaveSelector selector)
                 throws IOException
Saves the unedited version of the current history to a file

Parameters:
selector - File to save to
Throws:
IOException

saveHistory

public void saveHistory(FileSaveSelector selector,
                        String editedVersion)
                 throws IOException
Saves the edited version of the current history to a file

Parameters:
selector - File to save to
editedVersion - Edited version of the history which will be saved to file instead of the lines saved in the history. The saved file will still include any tags needed to recognize it as a saved interactions file.
Throws:
IOException

getHistoryAsStringWithSemicolons

public String getHistoryAsStringWithSemicolons()
Returns the entire history as a single string. Commands should be separated by semicolons. If an entire command does not end in a semicolon, one is added.


getHistoryAsString

public String getHistoryAsString()
Returns the entire history as a single string. Commands should be separated by semicolons.


clearHistory

public void clearHistory()
Clears the history


lastEntry

public String lastEntry()

moveHistoryPrevious

public void moveHistoryPrevious(String entry)
Puts the previous line from the history on the current line and moves the history back one line.

Parameters:
entry - the current entry (perhaps edited from what is in history)

moveHistoryNext

public void moveHistoryNext(String entry)
Puts the next line from the history on the current line and moves the history forward one line.

Parameters:
entry - the current entry (perhaps edited from what is in history)

hasHistoryNext

public boolean hasHistoryNext()
Returns whether there is a next command in the history. Only runs in event thread.


reverseHistorySearch

public void reverseHistorySearch(String searchString)
Reverse searches the history for the given string.

Parameters:
searchString - the string to search for

forwardHistorySearch

public void forwardHistorySearch(String searchString)
Forward searches the history for the given string.

Parameters:
searchString - the string to search for

recallPreviousInteractionInHistory

public boolean recallPreviousInteractionInHistory()
Gets the previous interaction in the history and replaces whatever is on the current interactions input line with this interaction. Only runs in event thread.


recallNextInteractionInHistory

public boolean recallNextInteractionInHistory()
Gets the next interaction in the history and replaces whatever is on the current interactions input line with this interaction.


reverseSearchInteractionsInHistory

public void reverseSearchInteractionsInHistory()
Reverse searches the history for interactions that started with the current interaction.


forwardSearchInteractionsInHistory

public void forwardSearchInteractionsInHistory()
Forward searches the history for interactions that started with the current interaction.


appendExceptionResult

public void appendExceptionResult(String message,
                                  String styleName)
Inserts the given exception data into the document with the given style.

Parameters:
message - Message contained in the exception
styleName - name of the style for formatting the exception

appendSyntaxErrorResult

public void appendSyntaxErrorResult(String message,
                                    String interaction,
                                    int startRow,
                                    int startCol,
                                    int endRow,
                                    int endCol,
                                    String styleName)

clearCurrentInteraction

public void clearCurrentInteraction()
Clears the current input text and then moves to the end of the command history.


getCurrentInteraction

public String getCurrentInteraction()
Returns the string that the user has entered at the current prompt. Forwards to getCurrentInput().


getDefaultStyle

public String getDefaultStyle()
Description copied from interface: EditDocumentInterface
Gets the String identifying the default style for this document if one exists; null otherwise.

Specified by:
getDefaultStyle in interface EditDocumentInterface
Overrides:
getDefaultStyle in class ConsoleDocument

preparePrintJob

public void preparePrintJob()
This method tells the document to prepare all the DrJavaBook and PagePrinter objects.

Overrides:
preparePrintJob in class ConsoleDocument

getHistory

protected History getHistory()