|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rice.cs.drjava.model.repl.InteractionsModel
public abstract class InteractionsModel
A Swing specific model for the DrJava InteractionsPane. It glues together an InteractionsDocument, an InteractionsPane and a JavaInterpreter. This abstract class provides common functionality for all such models. The methods in this class generally can be executed only in the event thread once the model has been constructed.
Field Summary | |
---|---|
protected ConsoleDocumentInterface |
_cDoc
The embedded interactions document (a SwingDocument in native DrJava) |
protected InteractionsDocument |
_document
InteractionsDocument containing the commands and history. |
protected InputListener |
_inputListener
The input listener to listen for requests to System.in. |
protected String |
_lastError
Last error, or null if successful. |
protected InteractionsEventNotifier |
_notifier
Keeps track of any listeners to the model. |
InteractionsPane |
_pane
The interactions pane bundled with this document. |
protected String |
_secondToLastError
|
protected boolean |
_waitingForFirstInterpreter
Whether we are waiting for the interpreter to register for the first time. |
protected File |
_workingDirectory
The working directory for the current interpreter. |
Object |
_writerLock
A lock object to prevent print calls to System.out or System.err from flooding the JVM, ensuring the UI remains responsive. |
static String |
BANNER_PREFIX
Banner prefix. |
Constructor Summary | |
---|---|
InteractionsModel(ConsoleDocumentInterface cDoc,
File wd,
int historySize,
int writeDelay)
Constructs an InteractionsModel. |
Method Summary | |
---|---|
void |
_addNewline()
Appends a newLine to _document assuming that the Write Lock is already held. |
protected void |
_createNewDebugPort()
Generates an available port for use with the debugger. |
protected static String |
_deleteSemiColon(String s)
Deletes the last character of a string. |
protected static ArrayList<String> |
_getHistoryText(FileOpenSelector selector)
Opens the files chosen in the given file selector, and returns an ArrayList with one history string for each selected file. |
void |
_interactionIsOver()
Performs the common behavior when an interaction ends. |
protected abstract void |
_interpret(String toEval)
Interprets the given command. |
protected abstract void |
_interpreterResetFailed(Throwable t)
Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset. |
protected abstract void |
_notifyInteractionEnded()
Notifies listeners that an interaction has ended. |
protected abstract void |
_notifyInteractionIncomplete()
Notifies the view that the current interaction is incomplete. |
abstract void |
_notifyInteractionStarted()
Notifies listeners that an interaction has started. |
protected abstract void |
_notifyInterpreterExited(int status)
Notifies listeners that the interpreter has exited unexpectedly. |
abstract void |
_notifyInterpreterReady(File wd)
Notifies listeners that the interpreter is ready. |
protected abstract void |
_notifyInterpreterResetFailed(Throwable t)
Notifies listeners that the interpreter reset failed. |
protected abstract void |
_notifyInterpreterResetting()
Notifies listeners that the interpreter is resetting. |
protected abstract void |
_notifySlaveJVMUsed()
Notifies listeners that the slave JVM has been used. |
protected abstract void |
_notifySyntaxErrorOccurred(int offset,
int length)
Handles a syntax error being returned from an interaction |
protected static ArrayList<String> |
_removeSeparators(String text)
Removes the interaction-separator comments from a history, so that they will not appear when executing the history. |
protected abstract void |
_resetInterpreter(File wd)
Resets the Java interpreter. |
protected static String |
_testClassCall(String s)
Assumes a trimmed String. |
void |
_writerDelay()
Waits for a small amount of time on a shared writer lock. |
abstract void |
addBuildDirectoryClassPath(File f)
These add the given path to the build directory classpaths used in the interpreter. |
abstract void |
addExternalFilesClassPath(File f)
These add the given path to the external files classpaths used in the interpreter. |
abstract void |
addExtraClassPath(File f)
These add the given path to the extra classpaths used in the interpreter. |
void |
addListener(InteractionsListener listener)
Adds an InteractionsListener to the model. |
abstract void |
addProjectClassPath(File f)
These add the given path to the classpaths used in the interpreter. |
abstract void |
addProjectFilesClassPath(File f)
These add the given path to the project files classpaths used in the interpreter. |
void |
append(String s,
String styleName)
Appends a string to the given document using a named style. |
void |
changeInputListener(InputListener oldListener,
InputListener newListener)
Changes the input listener. |
String |
getBanner()
|
static String |
getBanner(File wd)
|
abstract ConsoleDocument |
getConsoleDocument()
Gets the console tab document for this interactions model |
String |
getConsoleInput()
Returns a line of text entered by the user at the equivalent of System.in. |
int |
getDebugPort()
Returns the port number to use for debugging the interactions JVM. |
InteractionsDocument |
getDocument()
Returns the InteractionsDocument stored by this model. |
String |
getLastError()
Return the last error, or null if successful. |
String |
getSecondToLastError()
Return the second to last error, or null if successful. |
String |
getStartUpBanner()
|
abstract String |
getVariableToString(String var)
Gets the string representation of the value of a variable in the current interpreter. |
abstract String |
getVariableType(String var)
Gets the class name of a variable in the current interpreter. |
File |
getWorkingDirectory()
Returns the working directory for the current interpreter. |
void |
interactionContinues()
|
void |
interpret(String toEval)
Interprets the given command. |
void |
interpretCurrentInteraction()
Interprets the current given text at the prompt in the interactions doc. |
void |
interpreterReady(File wd)
Called when a new Java interpreter has registered and is ready for use. |
void |
interpreterResetFailed(Throwable t)
This method is called by the Main JVM if the Interpreter JVM cannot be exited |
void |
interpreterResetting()
Called when the interpreter starts to reset. |
void |
loadHistory(FileOpenSelector selector)
Interprets the files selected in the FileOpenSelector. |
InteractionsScriptModel |
loadHistoryAsScript(FileOpenSelector selector)
|
void |
removeAllInteractionListeners()
Removes all InteractionsListeners from this model. |
String |
removeLastFromHistory()
Returns the last history item and then removes it, or returns null if the history is empty. |
void |
removeListener(InteractionsListener listener)
Removea an InteractionsListener from the model. |
void |
replCalledSystemExit(int status)
Signifies that the most recent interpretation contained a call to System.exit. |
void |
replReturnedResult(String result,
String style)
Appends the returned result to the interactions document, inserts a prompt in the interactions document, and advances the caret in the interactions pane. |
void |
replReturnedSyntaxError(String errorMessage,
String interaction,
int startRow,
int startCol,
int endRow,
int endCol)
Signifies that the most recent interpretation was preempted by a syntax error. |
void |
replReturnedVoid()
Signifies that the most recent interpretation completed successfully, returning no value. |
void |
replSystemErrPrint(String s)
Called when the repl prints to System.err. |
void |
replSystemOutPrint(String s)
Called when the repl prints to System.out. |
void |
replThrewException(String message)
Signifies that the most recent interpretation was ended due to an exception being thrown. |
void |
resetInterpreter(File wd)
Resets the Java interpreter with working directry wd. |
void |
resetLastErrors()
Reset the information about the last and second to last error. |
protected void |
scrollToCaret()
|
void |
setDebugPort(int port)
Sets the port number to use for debugging the interactions JVM. |
void |
setInputListener(InputListener listener)
Sets the listener for any type of single-source input event. |
void |
setUpPane(InteractionsPane pane)
Sets the _pane field and initializes the caret position in the pane. |
void |
setWaitingForFirstInterpreter(boolean waiting)
Sets this model's notion of whether it is waiting for the first interpreter to connect. |
void |
slaveJVMUsed()
Called when the slave JVM has been used for interpretation or unit testing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String BANNER_PREFIX
protected final InteractionsEventNotifier _notifier
protected volatile InteractionsDocument _document
protected volatile boolean _waitingForFirstInterpreter
protected volatile File _workingDirectory
public final Object _writerLock
protected volatile InputListener _inputListener
protected final ConsoleDocumentInterface _cDoc
public volatile InteractionsPane _pane
protected volatile String _lastError
protected volatile String _secondToLastError
Constructor Detail |
---|
public InteractionsModel(ConsoleDocumentInterface cDoc, File wd, int historySize, int writeDelay)
cDoc
- document to use in the InteractionsDocumentwd
- Working directory for the interpreterhistorySize
- Number of lines to store in the historywriteDelay
- Number of milliseconds to wait after each printlnMethod Detail |
---|
public void setUpPane(InteractionsPane pane)
public void addListener(InteractionsListener listener)
listener
- a listener that reacts to Interactions events.public void removeListener(InteractionsListener listener)
listener
- a listener that reacts to Interactions eventspublic void removeAllInteractionListeners()
public InteractionsDocument getDocument()
public void interactionContinues()
public void setWaitingForFirstInterpreter(boolean waiting)
public void interpretCurrentInteraction()
public void _addNewline()
public final void interpret(String toEval)
toEval
- command to be evaluated.protected abstract void _interpret(String toEval)
toEval
- command to be evaluatedprotected abstract void _notifyInteractionIncomplete()
public abstract void _notifyInteractionStarted()
public abstract String getVariableToString(String var)
var
- the name of the variable
null
if the variable is not defined.public abstract String getVariableType(String var)
var
- the name of the variablepublic final void resetInterpreter(File wd)
protected abstract void _resetInterpreter(File wd)
public File getWorkingDirectory()
public abstract void addProjectClassPath(File f)
f
- the path to addpublic abstract void addBuildDirectoryClassPath(File f)
f
- the path to addpublic abstract void addProjectFilesClassPath(File f)
f
- the path to addpublic abstract void addExternalFilesClassPath(File f)
f
- the path to addpublic abstract void addExtraClassPath(File f)
f
- the path to addprotected abstract void _notifySyntaxErrorOccurred(int offset, int length)
offset
- the first character of the error in the InteractionsDocumentlength
- the length of the error.public void loadHistory(FileOpenSelector selector) throws IOException
IOException
protected static ArrayList<String> _getHistoryText(FileOpenSelector selector) throws IOException, OperationCanceledException
selector
- A file selector supporting multiple file selection
IOException
OperationCanceledException
public InteractionsScriptModel loadHistoryAsScript(FileOpenSelector selector) throws IOException, OperationCanceledException
IOException
OperationCanceledException
protected static ArrayList<String> _removeSeparators(String text)
text
- The full, formatted text of an interactions history (obtained from _getHistoryText)
public int getDebugPort() throws IOException
getDebugPort
in interface InteractionsModelCallback
IOException
- if unable to get a valid port number.protected void _createNewDebugPort() throws IOException
IOException
- if unable to get a valid port number.public void setDebugPort(int port)
port
- Port to use to debug the interactions JVMpublic void replSystemOutPrint(String s)
replSystemOutPrint
in interface InteractionsModelCallback
s
- String to printpublic void replSystemErrPrint(String s)
replSystemErrPrint
in interface InteractionsModelCallback
s
- String to printpublic String getConsoleInput()
getConsoleInput
in interface InteractionsModelCallback
public void setInputListener(InputListener listener)
setInputListener
in interface InteractionsModelCallback
listener
- a listener that reacts to input requests
IllegalStateException
- if the input listener is lockedpublic void changeInputListener(InputListener oldListener, InputListener newListener)
changeInputListener
in interface InteractionsModelCallback
oldListener
- the listener that was installednewListener
- the listener to be installedpublic void _interactionIsOver()
protected abstract void _notifyInteractionEnded()
public void append(String s, String styleName)
s
- String to append to the end of the documentstyleName
- Name of the style to use for spublic void _writerDelay()
public void replReturnedVoid()
replReturnedVoid
in interface InteractionsModelCallback
public void replReturnedResult(String result, String style)
replReturnedResult
in interface InteractionsModelCallback
result
- The .toString-ed version of the value that was returned by the interpretation. We must return the
String form because returning the Object directly would require the data type to be serializable.public void replThrewException(String message)
replThrewException
in interface InteractionsModelCallback
message
- The exception's messagepublic void replReturnedSyntaxError(String errorMessage, String interaction, int startRow, int startCol, int endRow, int endCol)
replReturnedSyntaxError
in interface InteractionsModelCallback
errorMessage
- The syntax error messagestartRow
- The starting row of the errorstartCol
- The starting column of the errorendRow
- The end row of the error
param endCol The end column of the errorendCol
- The end column of the errorpublic void replCalledSystemExit(int status)
replCalledSystemExit
in interface InteractionsModelCallback
status
- The exit status that will be returned.protected abstract void _notifyInterpreterExited(int status)
status
- Status code of the dead processpublic void interpreterResetting()
interpreterResetting
in interface InteractionsModelCallback
protected abstract void _notifyInterpreterResetting()
public void interpreterResetFailed(Throwable t)
interpreterResetFailed
in interface InteractionsModelCallback
t
- The Throwable thrown by System.exitprotected abstract void _interpreterResetFailed(Throwable t)
t
- The Throwable thrown by System.exitprotected abstract void _notifyInterpreterResetFailed(Throwable t)
t
- Throwable explaining why the reset failed.public String getBanner()
public String getStartUpBanner()
public static String getBanner(File wd)
protected void scrollToCaret()
public void interpreterReady(File wd)
interpreterReady
in interface InteractionsModelCallback
public abstract void _notifyInterpreterReady(File wd)
public void slaveJVMUsed()
slaveJVMUsed
in interface InteractionsModelCallback
protected abstract void _notifySlaveJVMUsed()
protected static String _testClassCall(String s)
protected static String _deleteSemiColon(String s)
s
- the String containing the semicolon
public abstract ConsoleDocument getConsoleDocument()
public String getLastError()
public String getSecondToLastError()
public void resetLastErrors()
public String removeLastFromHistory()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |