edu.rice.cs.drjava.model
Interface OpenDefinitionsDocument

All Known Implementing Classes:
DefaultGlobalModel.DefinitionsDocumentHandler

public interface OpenDefinitionsDocument

Interface for the GlobalModel's handler of an open DefinitionsDocument. Provides a means to interact with the document.

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

Method Summary
 void addBreakpoint(Breakpoint breakpoint)
          Add the supplied Breakpoint to the hashtable, keyed by its BreakpointRequest
 int balanceBackward()
          Forwarding method to find the match for the closing brace immediately to the left, assuming there is such a brace.
 int balanceForward()
          Forwarding method to find the match for the open brace immediately to the right, assuming there is such a brace.
 boolean canAbandonFile()
          Returns whether the GlobalModel can abandon this document, asking the listeners if isModifiedSinceSave() is true.
 boolean checkIfClassFileInSync()
          Checks if the document is modified.
 void cleanUpPrintJob()
           
 void clearBreakpoints()
          Tells the document to remove all breakpoints
 FindReplaceMachine createFindReplaceMachine()
          Create a find and replace mechanism starting at the current character offset in the definitions.
 Breakpoint getBreakpointAt(int lineNumber)
          Returns the Breakpoint in this OpenDefinitionsDocument at the given linenumber, or null if one does not exist.
 gj.util.Vector getBreakpoints()
          Returns a Vector that contains all of the Breakpoint objects that this document contains
 CompilerErrorModel getCompilerErrorModel()
          Returns the model responsible for maintaining all current errors within this OpenDefinitionsDocument's file.
 int getCurrentDefinitionsLocation()
          Get the location of the cursor in the definitions according to the definitions document.
 DefinitionsDocument getDocument()
          Gets the definitions document being handled.
 File getFile()
          Returns the file for this document.
 String getFilename()
          Returns the name of this file, or "(untitled)" if no file.
 String getFirstTopLevelClassName()
          Returns the name of the top level class, if any.
 JUnitErrorModel getJUnitErrorModel()
          Returns the model responsible for maintaining all current JUnit errors within this OpenDefinitionsDocument.
 Pageable getPageable()
           
 File getSourceRoot()
          Finds the root directory of the source files.
 int gotoLine(int line)
          Moves the definitions document to the given line, and returns the character position in the document it's gotten to.
 void indentLinesInDefinitions(int selStart, int selEnd)
          A forwarding method to indent the current line or selection in the definitions.
 boolean isModifiedOnDisk()
          Determines if this definitions document has changed since the last save.
 boolean isModifiedSinceSave()
          Determines if this definitions document has changed since the last save.
 boolean isUntitled()
          Returns whether this document is currently untitled (indicating whether it has a file yet or not).
 void preparePrintJob()
           
 void print()
           
 void removeBreakpoint(Breakpoint breakpoint)
          Remove the given Breakpoint from the hashtable.
 void removeFromDebugger()
          Called to indicate the document is being closed, so to remove all related state from the debug manager.
 void revertFile()
          Revert the document to the version saved on disk.
 boolean revertIfModifiedOnDisk()
          Asks the GlobalModel if it can revert current definitions to version on disk.
 void saveFile(FileSaveSelector com)
          Saves the document with a FileWriter.
 void saveFileAs(FileSaveSelector com)
          Saves the document with a FileWriter.
 void setCompilerErrorModel(CompilerErrorModel model)
          Sets this OpenDefinitionsDocument's notion of all current errors within the corresponding file.
 void setDefinitionsIndent(int indent)
          Set the indent tab size for this document.
 void setJUnitErrorModel(JUnitErrorModel model)
          Sets the OpenDefinitionDocument's notion of all JUnit errors within this current document.
 void startCompile()
          Starts compiling the source.
 void startJUnit()
          Starts testing the source using JUnit.
 void syncCurrentLocationWithDefinitions(int location)
          Forwarding method to sync the definitions with whatever view component is representing them.
 

Method Detail

getDocument

public DefinitionsDocument getDocument()
Gets the definitions document being handled.
Returns:
document being handled

getFirstTopLevelClassName

public String getFirstTopLevelClassName()
                                 throws ClassNameNotFoundException
Returns the name of the top level class, if any.
Throws:
ClassNameNotFoundException - if no top level class name found.

isUntitled

public boolean isUntitled()
Returns whether this document is currently untitled (indicating whether it has a file yet or not).
Returns:
true if the document is untitled and has no file

getFile

public File getFile()
             throws IllegalStateException,
                    FileMovedException
Returns the file for this document. If the document is untitled and has no file, it throws an IllegalStateException.
Returns:
the file for this document
Throws:
IllegalStateException - if document never had a file
FileMovedException - if the document's file no longer exists

getFilename

public String getFilename()
Returns the name of this file, or "(untitled)" if no file.

saveFile

public void saveFile(FileSaveSelector com)
              throws IOException
Saves the document with a FileWriter. If the file name is already set, the method will use that name instead of whatever selector is passed in.
Parameters:
com - a selector that picks the file name
Throws:
IOException -  

revertFile

public void revertFile()
                throws IOException
Revert the document to the version saved on disk.

saveFileAs

public void saveFileAs(FileSaveSelector com)
                throws IOException
Saves the document with a FileWriter. The FileSaveSelector will either provide a file name or prompt the user for one. It is up to the caller to decide what needs to be done to choose a file to save to. Once the file has been saved succssfully, this method fires fileSave(File). If the save fails for any reason, the event is not fired.
Parameters:
com - a selector that picks the file name.
Throws:
IOException -  

startCompile

public void startCompile()
                  throws IOException
Starts compiling the source. Demands that the definitions be saved before proceeding with the compile. Fires the appropriate events as the compiliation proceeds and finishes.
Throws:
IOException - if a file with errors cannot be opened

startJUnit

public void startJUnit()
                throws ClassNotFoundException,
                       IOException
Starts testing the source using JUnit. Demands that the definitions be saved and compiled before proceeding with testing. Fires the appropriate events as the testing proceeds and finishes.
Throws:
IOException - if a file with errors cannot be opened
ClassNotFoundException - when the class is compiled to a location not on the classpath.

getCompilerErrorModel

public CompilerErrorModel getCompilerErrorModel()
Returns the model responsible for maintaining all current errors within this OpenDefinitionsDocument's file.

setCompilerErrorModel

public void setCompilerErrorModel(CompilerErrorModel model)
Sets this OpenDefinitionsDocument's notion of all current errors within the corresponding file.
Parameters:
model - CompilerErrorModel containing all errors for this file

getJUnitErrorModel

public JUnitErrorModel getJUnitErrorModel()
Returns the model responsible for maintaining all current JUnit errors within this OpenDefinitionsDocument.

setJUnitErrorModel

public void setJUnitErrorModel(JUnitErrorModel model)
Sets the OpenDefinitionDocument's notion of all JUnit errors within this current document.
Parameters:
model - JUnitErrorModel containing all JUnit errors for this file.

isModifiedSinceSave

public boolean isModifiedSinceSave()
Determines if this definitions document has changed since the last save.
Returns:
true if the document has been modified

isModifiedOnDisk

public boolean isModifiedOnDisk()
Determines if this definitions document has changed since the last save.
Returns:
true if the document has been modified

revertIfModifiedOnDisk

public boolean revertIfModifiedOnDisk()
                               throws IOException
Asks the GlobalModel if it can revert current definitions to version on disk. If ok, it reverts the file to the version on disk.
Returns:
true if the document has been reverted

canAbandonFile

public boolean canAbandonFile()
Returns whether the GlobalModel can abandon this document, asking the listeners if isModifiedSinceSave() is true.
Returns:
true if this document can be abandoned

gotoLine

public int gotoLine(int line)
Moves the definitions document to the given line, and returns the character position in the document it's gotten to.
Parameters:
line - Number of the line to go to. If line exceeds the number of lines in the document, it is interpreted as the last line.
Returns:
Index into document of where it moved

syncCurrentLocationWithDefinitions

public void syncCurrentLocationWithDefinitions(int location)
Forwarding method to sync the definitions with whatever view component is representing them.

getCurrentDefinitionsLocation

public int getCurrentDefinitionsLocation()
Get the location of the cursor in the definitions according to the definitions document.

balanceBackward

public int balanceBackward()
Forwarding method to find the match for the closing brace immediately to the left, assuming there is such a brace.
Returns:
the relative distance backwards to the offset before the matching brace.

balanceForward

public int balanceForward()
Forwarding method to find the match for the open brace immediately to the right, assuming there is such a brace.
Returns:
the relative distance forwards to the offset after the matching brace.

setDefinitionsIndent

public void setDefinitionsIndent(int indent)
Set the indent tab size for this document.
Parameters:
indent - the number of spaces to make per level of indent

indentLinesInDefinitions

public void indentLinesInDefinitions(int selStart,
                                     int selEnd)
A forwarding method to indent the current line or selection in the definitions.

createFindReplaceMachine

public FindReplaceMachine createFindReplaceMachine()
Create a find and replace mechanism starting at the current character offset in the definitions.

getSourceRoot

public File getSourceRoot()
                   throws InvalidPackageException
Finds the root directory of the source files.
Returns:
The root directory of the source files, based on the package statement.
Throws:
InvalidPackageException - If the package statement is invalid, or if it does not match up with the location of the source file.

preparePrintJob

public void preparePrintJob()
                     throws BadLocationException,
                            FileMovedException

print

public void print()
           throws PrinterException,
                  BadLocationException,
                  FileMovedException

getPageable

public Pageable getPageable()
                     throws IllegalStateException

cleanUpPrintJob

public void cleanUpPrintJob()

checkIfClassFileInSync

public boolean checkIfClassFileInSync()
Checks if the document is modified. If not, searches for the class file corresponding to this document and compares the timestamps of the class file to that of the source file.
Returns:
is the class file and this OpenDefinitionsDocument are in sync

getBreakpointAt

public Breakpoint getBreakpointAt(int lineNumber)
Returns the Breakpoint in this OpenDefinitionsDocument at the given linenumber, or null if one does not exist.
Parameters:
lineNumber - the line number of the breakpoint
Returns:
the Breakpoint at the given lineNumber, or null if it does not exist.

addBreakpoint

public void addBreakpoint(Breakpoint breakpoint)
Add the supplied Breakpoint to the hashtable, keyed by its BreakpointRequest
Parameters:
breakpoint - the Breakpoint to be inserted into the hashtable

removeBreakpoint

public void removeBreakpoint(Breakpoint breakpoint)
Remove the given Breakpoint from the hashtable.
Parameters:
breakpoint - the Breakpoint to be removed.

getBreakpoints

public gj.util.Vector getBreakpoints()
Returns a Vector that contains all of the Breakpoint objects that this document contains

clearBreakpoints

public void clearBreakpoints()
Tells the document to remove all breakpoints

removeFromDebugger

public void removeFromDebugger()
Called to indicate the document is being closed, so to remove all related state from the debug manager.