|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.rice.cs.drjava.model.DefaultGlobalModel
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.
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. |
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 |
private final DefinitionsEditorKit _editorKit
private final DefaultListModel _definitionsDocs
private final InteractionsDocument _interactionsDoc
private final StyledDocument _consoleDoc
private final StyledDocument _junitDoc
private final LinkedList _listeners
private PageFormat _pageFormat
final MainJVM _interpreterControl
private CompilerError[] _compilerErrorsWithoutFiles
private int _numErrors
private DebugManager _debugManager
private int _debugPort
private Object _compilerLock
private Object _interpreterLock
private OpenDefinitionsDocument _docBeingTested
private boolean _waitingForFirstInterpreter
public static final Indenter INDENTER
public static final AttributeSet SYSTEM_OUT_CONSOLE_STYLE
public static final AttributeSet SYSTEM_ERR_CONSOLE_STYLE
public static final AttributeSet SYSTEM_OUT_INTERACTIONS_STYLE
public static final AttributeSet SYSTEM_ERR_INTERACTIONS_STYLE
public static final AttributeSet DEBUG_STYLE
public static final AttributeSet INTERACTIONS_ERR_STYLE
Constructor Detail |
public DefaultGlobalModel()
public DefaultGlobalModel(int rmiPort)
public DefaultGlobalModel(DefaultGlobalModel other)
Method Detail |
static void()
private static AttributeSet _getConsoleErrStyle()
private static AttributeSet _getInteractionsOutStyle()
private static AttributeSet _getDebugStyle()
private static AttributeSet _getInteractionsErrStyle()
public void addListener(GlobalModelListener listener)
addListener
in interface GlobalModel
listener
- a listener that reacts on events generated by the GlobalModelpublic void removeListener(GlobalModelListener listener)
removeListener
in interface GlobalModel
listener
- a listener that reacts on events generated by the GlobalModelpublic DefinitionsEditorKit getEditorKit()
GlobalModel
javax.swing.EditorKit
implementation for use
in the definitions pane.getEditorKit
in interface GlobalModel
public ListModel getDefinitionsDocuments()
GlobalModel
getDefinitionsDocuments
in interface GlobalModel
public StyledDocument getInteractionsDocument()
GlobalModel
getInteractionsDocument
in interface GlobalModel
public StyledDocument getConsoleDocument()
GlobalModel
getConsoleDocument
in interface GlobalModel
public StyledDocument getJUnitDocument()
GlobalModel
getJUnitDocument
in interface GlobalModel
public PageFormat getPageFormat()
public void setPageFormat(PageFormat format)
public CompilerError[] getCompilerErrorsWithoutFiles()
getCompilerErrorsWithoutFiles
in interface GlobalModel
public int getNumErrors()
getNumErrors
in interface GlobalModel
public OpenDefinitionsDocument newFile()
newFile
in interface GlobalModel
public OpenDefinitionsDocument openFile(FileOpenSelector com) throws IOException, OperationCanceledException, AlreadyOpenException
openFile
in interface GlobalModel
com
- a command pattern command that selects what file
to openIOException
- if an underlying I/O operation failsOperationCanceledException
- if the open was canceledAlreadyOpenException
- if the file is already openpublic OpenDefinitionsDocument openFiles(FileOpenSelector com) throws IOException, OperationCanceledException, AlreadyOpenException
openFiles
in interface GlobalModel
com
- a command pattern command that selects which files
to openIOException
- if an underlying I/O operation failsOperationCanceledException
- if the open was canceledAlreadyOpenException
- if the file is already openpublic void saveAllFiles(FileSaveSelector com) throws IOException
saveAllFiles
in interface GlobalModel
com
- a selector that picks the file name, used for eachIOException
- public void saveAllFiles(FileSaveSelector[] com) throws IOException
saveAllFiles
in interface GlobalModel
com[]
- selectors to pick file name; size = size of _definitionsDocsIOException
- public void aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
doc
- the document which is about to be saved by a save all
commandpublic boolean closeFile(OpenDefinitionsDocument doc)
closeFile
in interface GlobalModel
public boolean closeAllFiles()
closeAllFiles
in interface GlobalModel
public void quit()
quit
in interface GlobalModel
public OpenDefinitionsDocument getDocumentForFile(File file) throws IOException
getDocumentForFile
in interface GlobalModel
file
- File contained by the document to be returnedIOException
- if there are problems opening the filevoid setDefinitionsIndent(int indent)
indent
- the number of spaces to make per level of indentpublic void resetInteractions()
(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.)
resetInteractions
in interface GlobalModel
public void resetConsole()
resetConsole
in interface GlobalModel
public void recallPreviousInteractionInHistory(Runnable failed)
recallPreviousInteractionInHistory
in interface GlobalModel
public void recallNextInteractionInHistory(Runnable failed)
recallNextInteractionInHistory
in interface GlobalModel
public int getInteractionsFrozenPos()
getInteractionsFrozenPos
in interface GlobalModel
public void clearCurrentInteraction()
clearCurrentInteraction
in interface GlobalModel
public void interpretCurrentInteraction()
interpretCurrentInteraction
in interface GlobalModel
public void loadHistory(FileOpenSelector selector) throws IOException
public void clearHistory()
public void saveHistory(FileSaveSelector selector) throws IOException
public String getHistoryAsString()
private void _docAppend(Document doc, String s, AttributeSet set)
public void systemOutPrint(String s)
systemOutPrint
in interface GlobalModel
public void systemErrPrint(String s)
systemErrPrint
in interface GlobalModel
public void replSystemOutPrint(String s)
replSystemOutPrint
in interface GlobalModel
public void replSystemErrPrint(String s)
replSystemErrPrint
in interface GlobalModel
public void printDebugMessage(String s)
printDebugMessage
in interface GlobalModel
private void _interactionIsOver()
public void waitForInterpreter()
waitForInterpreter
in interface GlobalModel
public void replReturnedVoid()
replReturnedVoid
in interface GlobalModel
public void replReturnedResult(String result)
replReturnedResult
in interface GlobalModel
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 exceptionClass, String message, String stackTrace)
replThrewException
in interface GlobalModel
exceptionClass
- The name of the class of the thrown exceptionmessage
- The exception's messagestackTrace
- The stack trace of the exceptionpublic void replCalledSystemExit(int status)
replCalledSystemExit
in interface GlobalModel
status
- The exit status that will be returned.public CompilerInterface[] getAvailableCompilers()
getAvailableCompilers
in interface GlobalModel
CompilerRegistry.getAvailableCompilers()
public void setActiveCompiler(CompilerInterface compiler)
setActiveCompiler
in interface GlobalModel
compiler
- Compiler to set active.getActiveCompiler()
,
CompilerRegistry.setActiveCompiler(edu.rice.cs.drjava.model.compiler.CompilerInterface)
public CompilerInterface getActiveCompiler()
getActiveCompiler
in interface GlobalModel
setActiveCompiler(edu.rice.cs.drjava.model.compiler.CompilerInterface)
,
CompilerRegistry.getActiveCompiler()
public String getClasspath()
getClasspath
in interface GlobalModel
public File[] getSourceRootSet()
getSourceRootSet
in interface GlobalModel
edu.rice.cs.drjava.model.GlobalModel
InvalidPackageException
- if the package statement in one
of the open documents is invalid.public void compileAll() throws IOException
private void _compileFiles(File[] sourceRoots, File[] files) throws IOException
sourceRoots
- An array of all sourceroots for the files to be compiledfiles
- An array of all files to be compiledpublic DebugManager getDebugManager()
getDebugManager
in interface GlobalModel
public int getDebugPort() throws IOException
getDebugPort
in interface GlobalModel
IOException
- if unable to get a valid port number.public void saveAllBeforeProceeding(GlobalModelListener.SaveReason reason)
saveAllBeforeProceeding
in interface GlobalModel
reason
- the reason behind the demand to save the filepublic boolean areAnyModifiedSinceSave()
areAnyModifiedSinceSave
in interface GlobalModel
public File getSourceFileFromPaths(String filename, gj.util.Vector paths)
getSourceFileFromPaths
in interface GlobalModel
filename
- Name of the source file to look forpaths
- An array of directories to searchpublic void nonTestCase()
nonTestCase
in interface GlobalModel
public void testFinished(JUnitError[] errors)
testFinished
in interface GlobalModel
public OpenDefinitionsDocument getDocBeingTested()
public void resetCompilerErrors()
resetCompilerErrors
in interface GlobalModel
private void _distributeErrors(CompilerError[] errors) throws IOException
private OpenDefinitionsDocument _createOpenDefinitionsDocument()
private OpenDefinitionsDocument _getOpenDocument(File file)
file
- File object to search forprivate boolean _docIsOpen(File file)
file
- File object to search forprivate OpenDefinitionsDocument _openFile(File file) throws IOException, AlreadyOpenException
file
- File to read document fromprivate void _createDebugger()
private String _testClassCall(String s)
private void _resetInteractionsClasspath()
public void interactionsResetting()
interactionsResetting
in interface GlobalModel
public void interactionsReady()
interactionsReady
in interface GlobalModel
private String _deleteSemiColon(String s)
s
- protected boolean pollListeners(DefaultGlobalModel.EventPoller p)
EventPoller
- p the question being asked of the listenersprotected void notifyListeners(DefaultGlobalModel.EventNotifier n)
EventNotifier
- n tells the listener what happened
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |