edu.rice.cs.drjava.model
Interface GlobalModel

All Known Implementing Classes:
DefaultGlobalModel

public interface GlobalModel

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: GlobalModel.java,v 1.47 2002/09/10 02:27:02 csreis Exp $

Method Summary
 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.
 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.
 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()
          Gets the array of all compile errors without 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 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.
 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()
          Gets the total number of current errors.
 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 InteractionsJVM has registered as is ready for use.
 void interactionsResetting()
          Called when the interactionsJVM has begun to be resetted
 void interpretCurrentInteraction()
          Interprets the current given text at the prompt in the interactions pane.
 OpenDefinitionsDocument newFile()
          Creates a new document in the definitions pane and adds it to the list of open documents.
 void nonTestCase()
          Called from the JUnitTestManager if its given className is not a test case.
 OpenDefinitionsDocument openFile(FileOpenSelector com)
          Open a file and read it into the definitions.
 OpenDefinitionsDocument openFiles(FileOpenSelector com)
           
 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 documents, prompting when necessary.
 void saveAllFiles(FileSaveSelector[] com)
          Saves all open documents, used for testing
 void setActiveCompiler(CompilerInterface compiler)
          Sets which compiler is the "active" compiler.
 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.
 

Method Detail

addListener

public void addListener(GlobalModelListener listener)
Add a listener to this global model.
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.
Parameters:
listener - a listener that reacts on events generated by the GlobalModel

getEditorKit

public DefinitionsEditorKit getEditorKit()
Fetches the javax.swing.EditorKit implementation for use in the definitions pane.

getDefinitionsDocuments

public ListModel getDefinitionsDocuments()
Gets a ListModel of the open definitions documents.

getInteractionsDocument

public StyledDocument getInteractionsDocument()
Gets the interactions document.

getJUnitDocument

public StyledDocument getJUnitDocument()
Gets the junit document.

getConsoleDocument

public StyledDocument getConsoleDocument()
Gets the console document.

getCompilerErrorsWithoutFiles

public CompilerError[] getCompilerErrorsWithoutFiles()
Gets the array of all compile errors without Files.

getNumErrors

public int getNumErrors()
Gets the total number of current errors.

resetCompilerErrors

public void resetCompilerErrors()
Resets the compiler error state to have no errors.

newFile

public OpenDefinitionsDocument newFile()
Creates a new document in the definitions pane and adds it to the list of open documents.
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.
Parameters:
com - a command pattern command that selects what file to open
Returns:
The open document, or null if unsuccessful
Throws:
IOException -  
OperationCanceledException - if the open was canceled
AlreadyOpenException - if the file is already open

openFiles

public OpenDefinitionsDocument openFiles(FileOpenSelector com)
                                  throws IOException,
                                         OperationCanceledException,
                                         AlreadyOpenException

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.
Returns:
true if the document was closed

closeAllFiles

public boolean closeAllFiles()
Attempts to close all open documents.
Returns:
true if all documents were closed

saveAllFiles

public void saveAllFiles(FileSaveSelector com)
                  throws IOException
Saves all open documents, prompting when necessary.

saveAllFiles

public void saveAllFiles(FileSaveSelector[] com)
                  throws IOException
Saves all open documents, used for testing

quit

public void quit()
Exits the program. Only quits if all documents are successfully closed.

getDocumentForFile

public OpenDefinitionsDocument getDocumentForFile(File file)
                                           throws IOException,
                                                  OperationCanceledException
Returns the OpenDefinitionsDocument for the specified File, opening a new copy if one is not already open.
Parameters:
file - File contained by the document to be returned
Returns:
OpenDefinitionsDocument containing file

resetInteractions

public void resetInteractions()
Clears and resets the interactions pane. 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.

interactionsResetting

public void interactionsResetting()
Called when the interactionsJVM has begun to be resetted

interactionsReady

public void interactionsReady()
Called when a new InteractionsJVM has registered as is ready for use.

resetConsole

public void resetConsole()
Resets the console. Fires consoleReset() event.

clearCurrentInteraction

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

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.

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.

interpretCurrentInteraction

public void interpretCurrentInteraction()
Interprets the current given text at the prompt in the interactions pane.

getInteractionsFrozenPos

public int getInteractionsFrozenPos()
Returns the first location in the document where editing is allowed.

systemOutPrint

public void systemOutPrint(String s)
Prints System.out to the DrJava console.

systemErrPrint

public void systemErrPrint(String s)
Prints System.err to the DrJava console.

replSystemOutPrint

public void replSystemOutPrint(String s)
Called when the repl prints to System.out.

replSystemErrPrint

public void replSystemErrPrint(String s)
Called when the repl prints to System.err.

printDebugMessage

public void printDebugMessage(String s)
Called when the debugger wants to print a message.

waitForInterpreter

public void waitForInterpreter()
Blocks until the interpreter has registered.

replReturnedVoid

public void replReturnedVoid()
Signifies that the most recent interpretation completed successfully, returning no value.

replReturnedResult

public void replReturnedResult(String result)
Signifies that the most recent interpretation completed successfully, returning a value.
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.
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.
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.
See Also:
CompilerRegistry.getAvailableCompilers()

setActiveCompiler

public void setActiveCompiler(CompilerInterface compiler)
Sets which compiler is the "active" compiler.
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.
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.

getSourceRootSet

public File[] getSourceRootSet()
Gets an array of all sourceRoots for the open definitions documents, without duplicates.
Throws:
InvalidPackageException - if the package statement in one of the open documents is invalid.

getDebugManager

public DebugManager getDebugManager()
Gets the DebugManager, which interfaces with the integrated debugger.

getDebugPort

public int getDebugPort()
                 throws IOException
Returns an available port number to use for debugging the interactions JVM.
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.
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.
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.
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.

testFinished

public void testFinished(JUnitError[] errors)
Called from the JUnitTestManager after the test finishes