|
||||||||||
| 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.
| Nested Class Summary | |
|---|---|
private static class |
InteractionsModel.NoInputListener
Singleton InputListener which should never be asked for input. |
| Field Summary | |
|---|---|
protected HashSet<String> |
_autoImportSet
Set of classes or packages to import again when a breakpoint is hit. |
private String |
_banner
Banner displayed at top of the interactions document |
protected ConsoleDocumentInterface |
_cDoc
The embedded interactions document (a SwingDocument in native DrJava) |
private int |
_debugPort
Port used by the debugger to connect to the Interactions JVM. |
private boolean |
_debugPortSet
Whether the debug port has already been set. |
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
|
private String |
_toAddToHistory
The String added to history when the interaction is complete or an error is thrown |
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. |
private int |
_writeDelay
Number of milliseconds to wait after each println, to prevent the JVM from being flooded with print calls. |
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. |
private static int |
DELAY_INTERVAL
|
private int |
delayCount
|
static int |
WRITE_DELAY
Number of milliseconds to wait after each println, to prevent the JVM from being flooded with print calls. |
| 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 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 |
_interpreterWontStart(Exception e)
Action to perform when the interpreter won't start. |
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 |
_notifySyntaxErrorOccurred(int offset,
int length)
Handles a syntax error being returned from an interaction |
private void |
_prepareToInterpret(String text)
Performs pre-interpretation preparation of the interactions document and notifies the view. |
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,
boolean force)
Resets the Java interpreter. |
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 |
autoImport()
Executes import statements for the classes and packages in the auto-import set. |
void |
changeInputListener(InputListener oldListener,
InputListener newListener)
Changes the input listener. |
private String |
generateBanner(File wd)
|
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 Pair<String,String> |
getVariableToString(String var)
Gets the string representation of the value 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 |
interpreterWontStart(Exception e)
Called when the slave JVM fails to startup |
void |
loadHistory(FileOpenSelector selector)
Interprets the files selected in the FileOpenSelector. |
InteractionsScriptModel |
loadHistoryAsScript(FileOpenSelector selector)
|
void |
performDefaultImports()
Perform the default imports of the classes and packages listed in the INTERACTIONS_AUTO_IMPORT_CLASSES. |
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. |
StackTraceElement[] |
replaceLLException(StackTraceElement[] sT)
Default behavior set to return what it's given. |
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 |
replThrewException(String message,
StackTraceElement[] stackTrace)
Signifies that the most recent interpretation was ended due to an exception being thrown. |
void |
resetInterpreter(File wd,
boolean force)
Resets the Java interpreter with working directory 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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface edu.rice.cs.drjava.model.repl.InteractionsModelCallback |
|---|
getCompilerBootClassPath, transformCommands |
| Field Detail |
|---|
public static final String BANNER_PREFIX
public static final int WRITE_DELAY
protected final InteractionsEventNotifier _notifier
protected volatile InteractionsDocument _document
protected volatile boolean _waitingForFirstInterpreter
protected volatile File _workingDirectory
public final Object _writerLock
private final int _writeDelay
private volatile int _debugPort
private volatile boolean _debugPortSet
private volatile String _toAddToHistory
protected volatile InputListener _inputListener
protected final ConsoleDocumentInterface _cDoc
public volatile InteractionsPane _pane
private volatile String _banner
protected volatile String _lastError
protected volatile String _secondToLastError
protected final HashSet<String> _autoImportSet
private static final int DELAY_INTERVAL
private volatile int delayCount
| 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 println| Method 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 autoImport()
private void _prepareToInterpret(String text)
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 Pair<String,String> getVariableToString(String var)
var - the name of the variable
null if the variable is not defined.
public final void resetInterpreter(File wd,
boolean force)
protected abstract void _resetInterpreter(File wd,
boolean force)
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 add
protected 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
OperationCanceledExceptionprotected 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 InteractionsModelCallbackIOException - 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 InteractionsModelCallbacks - String to printpublic void replSystemErrPrint(String s)
replSystemErrPrint in interface InteractionsModelCallbacks - String to printpublic String getConsoleInput()
getConsoleInput in interface InteractionsModelCallbackpublic void setInputListener(InputListener listener)
setInputListener in interface InteractionsModelCallbacklistener - a listener that reacts to input requests
IllegalStateException - if the input listener is locked
public void changeInputListener(InputListener oldListener,
InputListener newListener)
changeInputListener in interface InteractionsModelCallbackoldListener - 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 InteractionsModelCallbackresult - 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 StackTraceElement[] replaceLLException(StackTraceElement[] sT)
sT - the stackTrace to replace line number and file name
public void replThrewException(String message,
StackTraceElement[] stackTrace)
replThrewException in interface InteractionsModelCallbackmessage - The exception's messagepublic void replThrewException(String message)
replThrewException in interface InteractionsModelCallbackmessage - The exception's message
public void replReturnedSyntaxError(String errorMessage,
String interaction,
int startRow,
int startCol,
int endRow,
int endCol)
replReturnedSyntaxError in interface InteractionsModelCallbackerrorMessage - 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 InteractionsModelCallbackstatus - 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 InteractionsModelCallbackprotected abstract void _notifyInterpreterResetting()
public void interpreterResetFailed(Throwable t)
interpreterResetFailed in interface InteractionsModelCallbackt - The Throwable thrown by System.exitpublic void interpreterWontStart(Exception e)
InteractionsModelCallback
interpreterWontStart in interface InteractionsModelCallbackprotected abstract void _interpreterResetFailed(Throwable t)
t - The Throwable thrown by System.exitprotected abstract void _notifyInterpreterResetFailed(Throwable t)
t - Throwable explaining why the reset failed.protected abstract void _interpreterWontStart(Exception e)
public String getBanner()
public String getStartUpBanner()
public static String getBanner(File wd)
private String generateBanner(File wd)
protected void scrollToCaret()
public void interpreterReady(File wd)
interpreterReady in interface InteractionsModelCallbackpublic void performDefaultImports()
public abstract void _notifyInterpreterReady(File wd)
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 | |||||||||