edu.rice.cs.drjava.model
Class DefaultGlobalModel

java.lang.Object
  |
  +--edu.rice.cs.drjava.model.DefaultGlobalModel
All Implemented Interfaces:
GlobalModel, OptionConstants
Direct Known Subclasses:
SingleDisplayModel

public class DefaultGlobalModel
extends Object
implements GlobalModel, OptionConstants

Handles the bulk of DrJava's program logic. The UI components interface with the GlobalModel through its public methods, and GlobalModel responds via the GlobalModelListener interface. This removes the dependency on the UI for the logical flow of the program's features. With the current implementation, we can finally test the compile functionality of DrJava, along with many other things.

Version:
$Id: DefaultGlobalModel.java,v 1.97 2002/09/10 02:27:02 csreis Exp $

Inner Class Summary
private  class DefaultGlobalModel.DefinitionsDocumentHandler
          Inner class to handle operations on each of the open DefinitionsDocuments by the GlobalModel.
protected  class DefaultGlobalModel.EventNotifier
          Class model for notifying listeners of an event.
protected  class DefaultGlobalModel.EventPoller
          Class model for asking listeners a yes/no question.
private  class DefaultGlobalModel.ExtraClasspathOptionListener
           
 
Field Summary
private  CompilerError[] _compilerErrorsWithoutFiles
          An array of all current compiler errors which do not have files.
private  Object _compilerLock
          Lock to prevent multiple threads from accessing the compiler at the same time.
private  StyledDocument _consoleDoc
          The document used to display System.out and System.err.
private  DebugManager _debugManager
          Interface to the integrated debugger.
private  int _debugPort
          Port used by the debugger to connect to the Interactions JVM.
private  DefaultListModel _definitionsDocs
          ListModel for storing all OpenDefinitionsDocuments.
private  OpenDefinitionsDocument _docBeingTested
          If a JUnit test is currently running, this is the OpenDefinitionsDocument being tested.
private  DefinitionsEditorKit _editorKit
          Factory for new definitions documents and views.
private  InteractionsDocument _interactionsDoc
          The document used to interact with the repl.
(package private)  MainJVM _interpreterControl
          RMI interface to the Interactions JVM.
private  Object _interpreterLock
          Lock to prevent multiple threads from accessing the interpreter at the same time.
private  StyledDocument _junitDoc
          The document used to display JUnit test results.
private  LinkedList _listeners
          All GlobalModelListeners that are listening to this model.
private  int _numErrors
          The total number of current compiler errors, including both errors with and without files.
private  PageFormat _pageFormat
          A PageFormat object for printing.
private  boolean _waitingForFirstInterpreter
          Flag to indicate DrJava is first starting up, and that the interpreter JVM is connecting for the first time.
static AttributeSet DEBUG_STYLE
          Attributes for debug messages in the interactions document.
static Indenter INDENTER
          The instance of the indent decision tree used by Definitions documents.
static AttributeSet INTERACTIONS_ERR_STYLE
          Attributes for error messages in the interactions document.
static AttributeSet SYSTEM_ERR_CONSOLE_STYLE
          Attributes for System.err output in the console document.
static AttributeSet SYSTEM_ERR_INTERACTIONS_STYLE
          Attributes for System.err output in the interactions document.
static AttributeSet SYSTEM_OUT_CONSOLE_STYLE
          Attributes for System.out output in the console document.
static AttributeSet SYSTEM_OUT_INTERACTIONS_STYLE
          Attributes for System.out output in the interactions document.
 
Fields inherited from interface edu.rice.cs.drjava.config.OptionConstants
COMPILER_ERROR_COLOR, DEBUG_BREAKPOINT_COLOR, DEBUG_SHOW_THREADS, DEBUG_SOURCEPATH, DEBUG_STEP_DRJAVA, DEBUG_STEP_INTERPRETER, DEBUG_STEP_JAVA, DEBUG_THREAD_COLOR, DEFINITIONS_BACKGROUND_COLOR, DEFINITIONS_COMMENT_COLOR, DEFINITIONS_DOUBLE_QUOTED_COLOR, DEFINITIONS_KEYWORD_COLOR, DEFINITIONS_MATCH_COLOR, DEFINITIONS_NORMAL_COLOR, DEFINITIONS_NUMBER_COLOR, DEFINITIONS_SINGLE_QUOTED_COLOR, DEFINITIONS_TYPE_COLOR, EXTRA_CLASSPATH, FONT_DOCLIST, FONT_MAIN, FONT_TOOLBAR, HISTORY_MAX_SIZE, INDENT_LEVEL, INTERACTIONS_EXIT_PROMPT, JAVAC_ALLOW_ASSERT, JAVAC_LOCATION, JSR14_COLLECTIONSPATH, JSR14_LOCATION, KEY_BACKWARD, KEY_BEGIN_DOCUMENT, KEY_BEGIN_LINE, KEY_CLOSE_FILE, KEY_COMPILE, KEY_COMPILE_ALL, KEY_COPY, KEY_CUT, KEY_CUT_LINE, KEY_DEBUG_BREAKPOINT_TOGGLE, KEY_DEBUG_MODE_TOGGLE, KEY_DEBUG_RESUME, KEY_DEBUG_STEP_INTO, KEY_DEBUG_STEP_OUT, KEY_DEBUG_STEP_OVER, KEY_DELETE_NEXT, KEY_DELETE_PREVIOUS, KEY_DOWN, KEY_END_DOCUMENT, KEY_END_LINE, KEY_FIND_NEXT, KEY_FIND_REPLACE, KEY_FORWARD, KEY_GOTO_LINE, KEY_NEW_FILE, KEY_NEXT_DOCUMENT, KEY_NEXT_WORD, KEY_OPEN_FILE, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_PREVIOUS_DOCUMENT, KEY_PREVIOUS_WORD, KEY_PRINT, KEY_PRINT_PREVIEW, KEY_QUIT, KEY_REDO, KEY_SAVE_FILE, KEY_SAVE_FILE_AS, KEY_SELECT_ALL, KEY_UNDO, KEY_UP, LINEENUM_ENABLED, mask, QUIT_PROMPT, RECENT_FILES, RECENT_FILES_MAX_SIZE, TOOLBAR_ICONS_ENABLED, TOOLBAR_TEXT_ENABLED, WORKING_DIRECTORY
 
Constructor Summary
DefaultGlobalModel()
          Constructs a new GlobalModel.
DefaultGlobalModel(DefaultGlobalModel other)
          Constructor.
DefaultGlobalModel(int rmiPort)
          Constructs a new GlobalModel, using the given port for the RMI registry.
 
Method Summary
private  void _compileFiles(File[] sourceRoots, File[] files)
          Compile the given files (with the given sourceroots), and update the model with any errors that result.
private  void _createDebugger()
          Instantiates the integrated debugger if the "debugger.enabled" config option is set to true.
private  OpenDefinitionsDocument _createOpenDefinitionsDocument()
          Creates a DefinitionsDocumentHandler for a new DefinitionsDocument, using the DefinitionsEditorKit.
private  String _deleteSemiColon(String s)
          Deletes the last character of a string.
private  void _distributeErrors(CompilerError[] errors)
          Sorts the given array of CompilerErrors and divides it into groups based on the file, giving each group to the appropriate OpenDefinitionsDocument, opening files if necessary.
private  void _docAppend(Document doc, String s, AttributeSet set)
           
private  boolean _docIsOpen(File file)
          Returns true if a document corresponding to the given file is open, or false if that file is not open.
private static AttributeSet _getConsoleErrStyle()
           
private static AttributeSet _getDebugStyle()
           
private static AttributeSet _getInteractionsErrStyle()
           
private static AttributeSet _getInteractionsOutStyle()
           
private  OpenDefinitionsDocument _getOpenDocument(File file)
          Returns the OpenDefinitionsDocument corresponding to the given File, or null if that file is not open.
private  void _interactionIsOver()
           
private  OpenDefinitionsDocument _openFile(File file)
          Creates a document from a file.
private  void _resetInteractionsClasspath()
           
private  String _testClassCall(String s)
          Assumes a trimmed String.
(package private) static void ()
           
 void aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
          Does nothing in default model.
 void addListener(GlobalModelListener listener)
          Add a listener to this global model.
 boolean areAnyModifiedSinceSave()
          Checks if any open definitions documents have been modified since last being saved.
 void clearCurrentInteraction()
          Clears the current interaction text and then moves to the end of the command history.
 void clearHistory()
          Clears the interactions history
 boolean closeAllFiles()
          Attempts to close all open documents.
 boolean closeFile(OpenDefinitionsDocument doc)
          Closes an open definitions document, prompting to save if the document has been changed.
 void compileAll()
          Compiles all open documents, after ensuring that all are saved.
 CompilerInterface getActiveCompiler()
          Gets the compiler is the "active" compiler.
 CompilerInterface[] getAvailableCompilers()
          Returns all registered compilers that are actually available.
 String getClasspath()
          Returns the current classpath in use by the Interpreter JVM.
 CompilerError[] getCompilerErrorsWithoutFiles()
          Returns an array of all current compiler errors which do not have files.
 StyledDocument getConsoleDocument()
          Gets the console document.
 DebugManager getDebugManager()
          Gets the DebugManager, which interfaces with the integrated debugger.
 int getDebugPort()
          Returns an available port number to use for debugging the interactions JVM.
 ListModel getDefinitionsDocuments()
          Gets a ListModel of the open definitions documents.
 OpenDefinitionsDocument getDocBeingTested()
          Returns the document currently being tested (with JUnit) if there is one, otherwise null.
 OpenDefinitionsDocument getDocumentForFile(File file)
          Returns the OpenDefinitionsDocument for the specified File, opening a new copy if one is not already open.
 DefinitionsEditorKit getEditorKit()
          Fetches the javax.swing.EditorKit implementation for use in the definitions pane.
 String getHistoryAsString()
          Returns the entire history as a Vector
 StyledDocument getInteractionsDocument()
          Gets the interactions document.
 int getInteractionsFrozenPos()
          Returns the first location in the document where editing is allowed.
 StyledDocument getJUnitDocument()
          Gets the junit document.
 int getNumErrors()
          Returns the current total number of errors, both with and without files.
 PageFormat getPageFormat()
           
 File getSourceFileFromPaths(String filename, gj.util.Vector paths)
          Searches for a file with the given name on the provided paths.
 File[] getSourceRootSet()
          Gets an array of all sourceRoots for the open definitions documents, without duplicates.
 void interactionsReady()
          Called when a new interpreter has been registered.
 void interactionsResetting()
          Called when the interactions reset process begins.
 void interpretCurrentInteraction()
          Interprets the current given text at the prompt in the interactions pane.
 void loadHistory(FileOpenSelector selector)
          Interprets the file selected in the FileOpenSelector.
 OpenDefinitionsDocument newFile()
          Creates a new definitions document and adds it to the list.
 void nonTestCase()
          Called from the JUnitTestManager if its given className is not a test case.
protected  void notifyListeners(DefaultGlobalModel.EventNotifier n)
          Lets the listeners know some event has taken place.
 OpenDefinitionsDocument openFile(FileOpenSelector com)
          Open a file and read it into the definitions.
 OpenDefinitionsDocument openFiles(FileOpenSelector com)
          Opens multiple files and reads them into the definitions.
protected  boolean pollListeners(DefaultGlobalModel.EventPoller p)
          Allows the GlobalModel to ask its listeners a yes/no question and receive a response.
 void printDebugMessage(String s)
          Called when the debugger wants to print a message.
 void quit()
          Exits the program.
 void recallNextInteractionInHistory(Runnable failed)
          Forwarding method to remove logical dependency of InteractionsPane on the InteractionsDocument.
 void recallPreviousInteractionInHistory(Runnable failed)
          Forwarding method to remove logical dependency of InteractionsPane on the InteractionsDocument.
 void removeListener(GlobalModelListener listener)
          Remove a listener from this global model.
 void replCalledSystemExit(int status)
          Signifies that the most recent interpretation contained a call to System.exit.
 void replReturnedResult(String result)
          Signifies that the most recent interpretation completed successfully, returning a value.
 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 exceptionClass, String message, String stackTrace)
          Signifies that the most recent interpretation was ended due to an exception being thrown.
 void resetCompilerErrors()
          Resets the compiler error state to have no errors.
 void resetConsole()
          Resets the console.
 void resetInteractions()
          Clears and resets the interactions pane.
 void saveAllBeforeProceeding(GlobalModelListener.SaveReason reason)
          Called to demand that one or more listeners saves all the definitions documents before proceeding.
 void saveAllFiles(FileSaveSelector com)
          Saves all open files, prompting for names if necessary.
 void saveAllFiles(FileSaveSelector[] com)
          Saves all open files, prompting for names if necessary.
 void saveHistory(FileSaveSelector selector)
          Saves the current history to a file
 void setActiveCompiler(CompilerInterface compiler)
          Sets which compiler is the "active" compiler.
(package private)  void setDefinitionsIndent(int indent)
          Set the indent tab size for all definitions documents.
 void setPageFormat(PageFormat format)
           
 void systemErrPrint(String s)
          Prints System.err to the DrJava console.
 void systemOutPrint(String s)
          Prints System.out to the DrJava console.
 void testFinished(JUnitError[] errors)
          Called from the JUnitTestManager after the test finishes
 void waitForInterpreter()
          Blocks until the interpreter has registered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

_editorKit

private final DefinitionsEditorKit _editorKit
Factory for new definitions documents and views.

_definitionsDocs

private final DefaultListModel _definitionsDocs
ListModel for storing all OpenDefinitionsDocuments.

_interactionsDoc

private final InteractionsDocument _interactionsDoc
The document used to interact with the repl.

_consoleDoc

private final StyledDocument _consoleDoc
The document used to display System.out and System.err.

_junitDoc

private final StyledDocument _junitDoc
The document used to display JUnit test results.

_listeners

private final LinkedList _listeners
All GlobalModelListeners that are listening to this model. All accesses should be synchronized on this field.

_pageFormat

private PageFormat _pageFormat
A PageFormat object for printing.

_interpreterControl

final MainJVM _interpreterControl
RMI interface to the Interactions JVM. Final, but set differently in the two constructors. Package private so we can access it from test cases. All accesses should be synchronized on _interpreterLock.

_compilerErrorsWithoutFiles

private CompilerError[] _compilerErrorsWithoutFiles
An array of all current compiler errors which do not have files. Errors with files are stored on their respective OpenDefinitionsDocuments.

_numErrors

private int _numErrors
The total number of current compiler errors, including both errors with and without files.

_debugManager

private DebugManager _debugManager
Interface to the integrated debugger. If the JPDA classes are not available, this is set to null. TO DO: Would be nice to have a DebugManager interface and a DebugManagerUnavailable class instead of using null as a value...

_debugPort

private int _debugPort
Port used by the debugger to connect to the Interactions JVM. Uniquely created in getDebugPort().

_compilerLock

private Object _compilerLock
Lock to prevent multiple threads from accessing the compiler at the same time.

_interpreterLock

private Object _interpreterLock
Lock to prevent multiple threads from accessing the interpreter at the same time.

_docBeingTested

private OpenDefinitionsDocument _docBeingTested
If a JUnit test is currently running, this is the OpenDefinitionsDocument being tested. Otherwise this is null.

_waitingForFirstInterpreter

private boolean _waitingForFirstInterpreter
Flag to indicate DrJava is first starting up, and that the interpreter JVM is connecting for the first time.

INDENTER

public static final Indenter INDENTER
The instance of the indent decision tree used by Definitions documents.

SYSTEM_OUT_CONSOLE_STYLE

public static final AttributeSet SYSTEM_OUT_CONSOLE_STYLE
Attributes for System.out output in the console document.

SYSTEM_ERR_CONSOLE_STYLE

public static final AttributeSet SYSTEM_ERR_CONSOLE_STYLE
Attributes for System.err output in the console document.

SYSTEM_OUT_INTERACTIONS_STYLE

public static final AttributeSet SYSTEM_OUT_INTERACTIONS_STYLE
Attributes for System.out output in the interactions document.

SYSTEM_ERR_INTERACTIONS_STYLE

public static final AttributeSet SYSTEM_ERR_INTERACTIONS_STYLE
Attributes for System.err output in the interactions document.

DEBUG_STYLE

public static final AttributeSet DEBUG_STYLE
Attributes for debug messages in the interactions document.

INTERACTIONS_ERR_STYLE

public static final AttributeSet INTERACTIONS_ERR_STYLE
Attributes for error messages in the interactions document.
Constructor Detail

DefaultGlobalModel

public DefaultGlobalModel()
Constructs a new GlobalModel.

DefaultGlobalModel

public DefaultGlobalModel(int rmiPort)
Constructs a new GlobalModel, using the given port for the RMI registry. If port is -1, uses a unique port.

DefaultGlobalModel

public DefaultGlobalModel(DefaultGlobalModel other)
Constructor. Initializes all the documents, but take the interpreter from the given previous model. This is used only for test cases, since there is substantial overhead to initializing the interpreter. Reset the interpreter for good measure since it's an old one. (NOTE: I'm not sure this is still correct or effective any more, now that we're always restarting the JVM. Needs to be looked at...)
Method Detail

static void ()

_getConsoleErrStyle

private static AttributeSet _getConsoleErrStyle()

_getInteractionsOutStyle

private static AttributeSet _getInteractionsOutStyle()

_getDebugStyle

private static AttributeSet _getDebugStyle()

_getInteractionsErrStyle

private static AttributeSet _getInteractionsErrStyle()

addListener

public void addListener(GlobalModelListener listener)
Add a listener to this global model.
Specified by:
addListener in interface GlobalModel
Parameters:
listener - a listener that reacts on events generated by the GlobalModel

removeListener

public void removeListener(GlobalModelListener listener)
Remove a listener from this global model.
Specified by:
removeListener in interface GlobalModel
Parameters:
listener - a listener that reacts on events generated by the GlobalModel

getEditorKit

public DefinitionsEditorKit getEditorKit()
Description copied from interface: GlobalModel
Fetches the javax.swing.EditorKit implementation for use in the definitions pane.
Specified by:
getEditorKit in interface GlobalModel

getDefinitionsDocuments

public ListModel getDefinitionsDocuments()
Description copied from interface: GlobalModel
Gets a ListModel of the open definitions documents.
Specified by:
getDefinitionsDocuments in interface GlobalModel

getInteractionsDocument

public StyledDocument getInteractionsDocument()
Description copied from interface: GlobalModel
Gets the interactions document.
Specified by:
getInteractionsDocument in interface GlobalModel

getConsoleDocument

public StyledDocument getConsoleDocument()
Description copied from interface: GlobalModel
Gets the console document.
Specified by:
getConsoleDocument in interface GlobalModel

getJUnitDocument

public StyledDocument getJUnitDocument()
Description copied from interface: GlobalModel
Gets the junit document.
Specified by:
getJUnitDocument in interface GlobalModel

getPageFormat

public PageFormat getPageFormat()

setPageFormat

public void setPageFormat(PageFormat format)

getCompilerErrorsWithoutFiles

public CompilerError[] getCompilerErrorsWithoutFiles()
Returns an array of all current compiler errors which do not have files. All other errors are stored on their respective OpenDefinitionsDocuments.
Specified by:
getCompilerErrorsWithoutFiles in interface GlobalModel

getNumErrors

public int getNumErrors()
Returns the current total number of errors, both with and without files.
Specified by:
getNumErrors in interface GlobalModel

newFile

public OpenDefinitionsDocument newFile()
Creates a new definitions document and adds it to the list.
Specified by:
newFile in interface GlobalModel
Returns:
The new open document

openFile

public OpenDefinitionsDocument openFile(FileOpenSelector com)
                                 throws IOException,
                                        OperationCanceledException,
                                        AlreadyOpenException
Open a file and read it into the definitions. The provided file selector chooses a file, and on a successful open, the fileOpened() event is fired.
Specified by:
openFile in interface GlobalModel
Parameters:
com - a command pattern command that selects what file to open
Returns:
The open document, or null if unsuccessful. Note that .getFile called on the returned OpenDefinitionsDocument is guaranteed to return an absolute path, as this method makes it absolute.
Throws:
IOException - if an underlying I/O operation fails
OperationCanceledException - if the open was canceled
AlreadyOpenException - if the file is already open

openFiles

public OpenDefinitionsDocument openFiles(FileOpenSelector com)
                                  throws IOException,
                                         OperationCanceledException,
                                         AlreadyOpenException
Opens multiple files and reads them into the definitions. The provided file selector chooses multiple files, and for each successful open, the fileOpened() event is fired.
Specified by:
openFiles in interface GlobalModel
Parameters:
com - a command pattern command that selects which files to open
Returns:
The last opened document, or null if unsuccessful. Note that .getFile called on the returned OpenDefinitionsDocument is guaranteed to return an absolute path, as this method makes it absolute.
Throws:
IOException - if an underlying I/O operation fails
OperationCanceledException - if the open was canceled
AlreadyOpenException - if the file is already open

saveAllFiles

public void saveAllFiles(FileSaveSelector com)
                  throws IOException
Saves all open files, prompting for names if necessary. When prompting (ie, untitled document), set that document as active.
Specified by:
saveAllFiles in interface GlobalModel
Parameters:
com - a selector that picks the file name, used for each
Throws:
IOException -  

saveAllFiles

public void saveAllFiles(FileSaveSelector[] com)
                  throws IOException
Saves all open files, prompting for names if necessary. When prompting (ie, untitled document), set that document as active.
Specified by:
saveAllFiles in interface GlobalModel
Parameters:
com[] - selectors to pick file name; size = size of _definitionsDocs
Throws:
IOException -  

aboutToSaveFromSaveAll

public void aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
Does nothing in default model.
Parameters:
doc - the document which is about to be saved by a save all command

closeFile

public boolean closeFile(OpenDefinitionsDocument doc)
Closes an open definitions document, prompting to save if the document has been changed. Returns whether the file was successfully closed.
Specified by:
closeFile in interface GlobalModel
Returns:
true if the document was closed

closeAllFiles

public boolean closeAllFiles()
Attempts to close all open documents.
Specified by:
closeAllFiles in interface GlobalModel
Returns:
true if all documents were closed

quit

public void quit()
Exits the program. Only quits if all documents are successfully closed.
Specified by:
quit in interface GlobalModel

getDocumentForFile

public OpenDefinitionsDocument getDocumentForFile(File file)
                                           throws IOException
Returns the OpenDefinitionsDocument for the specified File, opening a new copy if one is not already open.
Specified by:
getDocumentForFile in interface GlobalModel
Parameters:
file - File contained by the document to be returned
Returns:
OpenDefinitionsDocument containing file
Throws:
IOException - if there are problems opening the file

setDefinitionsIndent

void setDefinitionsIndent(int indent)
Set the indent tab size for all definitions documents.
Parameters:
indent - the number of spaces to make per level of indent

resetInteractions

public void resetInteractions()
Clears and resets the interactions pane. Bug #576179 pointed out that this needs to end any threads that were running in the interactions JVM, so we completely restart the JVM now. Ideally, we'd like a way to end any running threads and cleanly reset the interpreter (to speed up this method), but that might be too complex...

(Old approach: First it makes sure it's in the right package given the package specified by the definitions. If it can't, the package for the interactions becomes the defualt top level. In either case, this method calls a helper which fires the interactionsReset() event.)

Specified by:
resetInteractions in interface GlobalModel

resetConsole

public void resetConsole()
Resets the console. Fires consoleReset() event.
Specified by:
resetConsole in interface GlobalModel

recallPreviousInteractionInHistory

public void recallPreviousInteractionInHistory(Runnable failed)
Forwarding method to remove logical dependency of InteractionsPane on the InteractionsDocument. Gets the previous interaction in the InteractionsDocument's history and replaces whatever is on the current interactions input line with this interaction.
Specified by:
recallPreviousInteractionInHistory in interface GlobalModel

recallNextInteractionInHistory

public void recallNextInteractionInHistory(Runnable failed)
Forwarding method to remove logical dependency of InteractionsPane on the InteractionsDocument. Gets the next interaction in the InteractionsDocument's history and replaces whatever is on the current interactions input line with this interaction.
Specified by:
recallNextInteractionInHistory in interface GlobalModel

getInteractionsFrozenPos

public int getInteractionsFrozenPos()
Returns the first location in the document where editing is allowed.
Specified by:
getInteractionsFrozenPos in interface GlobalModel

clearCurrentInteraction

public void clearCurrentInteraction()
Clears the current interaction text and then moves to the end of the command history.
Specified by:
clearCurrentInteraction in interface GlobalModel

interpretCurrentInteraction

public void interpretCurrentInteraction()
Interprets the current given text at the prompt in the interactions pane.
Specified by:
interpretCurrentInteraction in interface GlobalModel

loadHistory

public void loadHistory(FileOpenSelector selector)
                 throws IOException
Interprets the file selected in the FileOpenSelector. Assumes all strings have no trailing whitespace. Interprets the array all at once so if there are any errors, none of the statements after the first erroneous one are processed.

clearHistory

public void clearHistory()
Clears the interactions history

saveHistory

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

getHistoryAsString

public String getHistoryAsString()
Returns the entire history as a Vector

_docAppend

private void _docAppend(Document doc,
                        String s,
                        AttributeSet set)

systemOutPrint

public void systemOutPrint(String s)
Prints System.out to the DrJava console.
Specified by:
systemOutPrint in interface GlobalModel

systemErrPrint

public void systemErrPrint(String s)
Prints System.err to the DrJava console.
Specified by:
systemErrPrint in interface GlobalModel

replSystemOutPrint

public void replSystemOutPrint(String s)
Called when the repl prints to System.out.
Specified by:
replSystemOutPrint in interface GlobalModel

replSystemErrPrint

public void replSystemErrPrint(String s)
Called when the repl prints to System.err.
Specified by:
replSystemErrPrint in interface GlobalModel

printDebugMessage

public void printDebugMessage(String s)
Called when the debugger wants to print a message.
Specified by:
printDebugMessage in interface GlobalModel

_interactionIsOver

private void _interactionIsOver()

waitForInterpreter

public void waitForInterpreter()
Blocks until the interpreter has registered.
Specified by:
waitForInterpreter in interface GlobalModel

replReturnedVoid

public void replReturnedVoid()
Signifies that the most recent interpretation completed successfully, returning no value.
Specified by:
replReturnedVoid in interface GlobalModel

replReturnedResult

public void replReturnedResult(String result)
Signifies that the most recent interpretation completed successfully, returning a value.
Specified by:
replReturnedResult in interface GlobalModel
Parameters:
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.

replThrewException

public void replThrewException(String exceptionClass,
                               String message,
                               String stackTrace)
Signifies that the most recent interpretation was ended due to an exception being thrown.
Specified by:
replThrewException in interface GlobalModel
Parameters:
exceptionClass - The name of the class of the thrown exception
message - The exception's message
stackTrace - The stack trace of the exception

replCalledSystemExit

public void replCalledSystemExit(int status)
Signifies that the most recent interpretation contained a call to System.exit.
Specified by:
replCalledSystemExit in interface GlobalModel
Parameters:
status - The exit status that will be returned.

getAvailableCompilers

public CompilerInterface[] getAvailableCompilers()
Returns all registered compilers that are actually available. That is, for all elements in the returned array, .isAvailable() is true. This method will never return null or a zero-length array.
Specified by:
getAvailableCompilers in interface GlobalModel
See Also:
CompilerRegistry.getAvailableCompilers()

setActiveCompiler

public void setActiveCompiler(CompilerInterface compiler)
Sets which compiler is the "active" compiler.
Specified by:
setActiveCompiler in interface GlobalModel
Parameters:
compiler - Compiler to set active.
See Also:
getActiveCompiler(), CompilerRegistry.setActiveCompiler(edu.rice.cs.drjava.model.compiler.CompilerInterface)

getActiveCompiler

public CompilerInterface getActiveCompiler()
Gets the compiler is the "active" compiler.
Specified by:
getActiveCompiler in interface GlobalModel
See Also:
setActiveCompiler(edu.rice.cs.drjava.model.compiler.CompilerInterface), CompilerRegistry.getActiveCompiler()

getClasspath

public String getClasspath()
Returns the current classpath in use by the Interpreter JVM.
Specified by:
getClasspath in interface GlobalModel

getSourceRootSet

public File[] getSourceRootSet()
Gets an array of all sourceRoots for the open definitions documents, without duplicates. Note that if any of the open documents has an invalid package statement, it won't be added to the source root set. On 8.7.02 changed the sourceRootSet such that the directory DrJava was executed from is now after the sourceRoots of the currently open documents in order that whatever version the user is looking at corresponds to the class file the interactions window uses.
Specified by:
getSourceRootSet in interface GlobalModel
Following copied from interface: edu.rice.cs.drjava.model.GlobalModel
Throws:
InvalidPackageException - if the package statement in one of the open documents is invalid.

compileAll

public void compileAll()
                throws IOException
Compiles all open documents, after ensuring that all are saved.

_compileFiles

private void _compileFiles(File[] sourceRoots,
                           File[] files)
                    throws IOException
Compile the given files (with the given sourceroots), and update the model with any errors that result. Does not notify listeners; use compileAll or doc.startCompile instead.
Parameters:
sourceRoots - An array of all sourceroots for the files to be compiled
files - An array of all files to be compiled

getDebugManager

public DebugManager getDebugManager()
Gets the DebugManager, which interfaces with the integrated debugger.
Specified by:
getDebugManager in interface GlobalModel

getDebugPort

public int getDebugPort()
                 throws IOException
Returns an available port number to use for debugging the interactions JVM.
Specified by:
getDebugPort in interface GlobalModel
Throws:
IOException - if unable to get a valid port number.

saveAllBeforeProceeding

public void saveAllBeforeProceeding(GlobalModelListener.SaveReason reason)
Called to demand that one or more listeners saves all the definitions documents before proceeding. It is up to the caller of this method to check if the documents have been saved. Fires saveAllBeforeProceeding(SaveReason) if areAnyModifiedSinceSave() is true.
Specified by:
saveAllBeforeProceeding in interface GlobalModel
Parameters:
reason - the reason behind the demand to save the file

areAnyModifiedSinceSave

public boolean areAnyModifiedSinceSave()
Checks if any open definitions documents have been modified since last being saved.
Specified by:
areAnyModifiedSinceSave in interface GlobalModel
Returns:
whether any documents have been modified

getSourceFileFromPaths

public File getSourceFileFromPaths(String filename,
                                   gj.util.Vector paths)
Searches for a file with the given name on the provided paths. Returns null if the file is not found.
Specified by:
getSourceFileFromPaths in interface GlobalModel
Parameters:
filename - Name of the source file to look for
paths - An array of directories to search

nonTestCase

public void nonTestCase()
Called from the JUnitTestManager if its given className is not a test case.
Specified by:
nonTestCase in interface GlobalModel

testFinished

public void testFinished(JUnitError[] errors)
Called from the JUnitTestManager after the test finishes
Specified by:
testFinished in interface GlobalModel

getDocBeingTested

public OpenDefinitionsDocument getDocBeingTested()
Returns the document currently being tested (with JUnit) if there is one, otherwise null.

resetCompilerErrors

public void resetCompilerErrors()
Resets the compiler error state to have no errors. Also resets the JUnit error state.
Specified by:
resetCompilerErrors in interface GlobalModel

_distributeErrors

private void _distributeErrors(CompilerError[] errors)
                        throws IOException
Sorts the given array of CompilerErrors and divides it into groups based on the file, giving each group to the appropriate OpenDefinitionsDocument, opening files if necessary.

_createOpenDefinitionsDocument

private OpenDefinitionsDocument _createOpenDefinitionsDocument()
Creates a DefinitionsDocumentHandler for a new DefinitionsDocument, using the DefinitionsEditorKit.
Returns:
OpenDefinitionsDocument object for a new document

_getOpenDocument

private OpenDefinitionsDocument _getOpenDocument(File file)
Returns the OpenDefinitionsDocument corresponding to the given File, or null if that file is not open.
Parameters:
file - File object to search for
Returns:
Corresponding OpenDefinitionsDocument, or null

_docIsOpen

private boolean _docIsOpen(File file)
Returns true if a document corresponding to the given file is open, or false if that file is not open.
Parameters:
file - File object to search for
Returns:
boolean whether file is open

_openFile

private OpenDefinitionsDocument _openFile(File file)
                                   throws IOException,
                                          AlreadyOpenException
Creates a document from a file.
Parameters:
file - File to read document from
Returns:
openened document

_createDebugger

private void _createDebugger()
Instantiates the integrated debugger if the "debugger.enabled" config option is set to true. Leaves it at null if not.

_testClassCall

private String _testClassCall(String s)
Assumes a trimmed String. Returns a string of the main call that the interpretor can use.

_resetInteractionsClasspath

private void _resetInteractionsClasspath()

interactionsResetting

public void interactionsResetting()
Called when the interactions reset process begins. This will diabled the reset and make the interactions pane uneditable.
Specified by:
interactionsResetting in interface GlobalModel

interactionsReady

public void interactionsReady()
Called when a new interpreter has been registered. If the setup works and the package directory exists, interactionsReset() is fired.
Specified by:
interactionsReady in interface GlobalModel

_deleteSemiColon

private String _deleteSemiColon(String s)
Deletes the last character of a string. Assumes semicolon at the end, but does not check. Helper for _testClassCall(String).
Parameters:
s -  
Returns:
 

pollListeners

protected boolean pollListeners(DefaultGlobalModel.EventPoller p)
Allows the GlobalModel to ask its listeners a yes/no question and receive a response.
Parameters:
EventPoller - p the question being asked of the listeners
Returns:
the listeners' responses ANDed together, true if they all agree, false if some disagree

notifyListeners

protected void notifyListeners(DefaultGlobalModel.EventNotifier n)
Lets the listeners know some event has taken place.
Parameters:
EventNotifier - n tells the listener what happened