edu.rice.cs.drjava.model
Interface OpenDefinitionsDocument

All Superinterfaces:
AbstractDocumentInterface, Comparable<OpenDefinitionsDocument>, DJDocument, Document, Finalizable<DefinitionsDocument>, INavigatorItem, StyledDocument, SwingDocumentInterface
All Known Implementing Classes:
DummyOpenDefDoc

public interface OpenDefinitionsDocument
extends DJDocument, Finalizable<DefinitionsDocument>, Comparable<OpenDefinitionsDocument>, INavigatorItem

Interface for an open document in DrJava. It may not be resident (in DocumentCache).

Version:
$Id: OpenDefinitionsDocument.java 4691 2008-12-02 23:33:27Z dlsmith $

Field Summary
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Method Summary
 int _getOffset(int lineNum)
           
 void addBrowserRegion(BrowserDocumentRegion r)
          Adds region r to the browserRegions collection for this
 boolean canAbandonFile()
          Returns whether the GlobalModel can abandon this document, asking listeners if isModifiedSinceSave() is true.
 boolean checkIfClassFileInSync()
          Checks if the document is modified.
 void cleanUpPrintJob()
           
 void clearBrowserRegions()
          Remove the browser regions for this document from the browser history manager.
 void close()
          Should be called when closing an ODD to let the ODD clean up after itself.
 int commentLines(int selStart, int selEnd)
          The following methods are forwarding methods required by the rest of the program in order for the OpenDefinitionsDocument to handle DefinitionsDocuments
 Position createUnwrappedPosition(int offs)
          Creates a WrappedPosition in the document.
 void documentModified()
          Called when this document is modified so it can notify the cache.
 void documentReset()
          Called when this document is reset so it can notify the cache.
 void documentSaved()
          Called when this document is saved so it can notify the cache.
 boolean fileExists()
          Returns true if the file exists on disk, or if the user has located it on disk.
 void generateJavadoc(FileSaveSelector saver)
          Generates Javadoc for this document, saving the output to a temporary directory.
 RegionManager<MovingDocumentRegion> getBookmarkManager()
           
 RegionManager<Breakpoint> getBreakpointManager()
           
 File getCachedClassFile()
           
 String getCanonicalPath()
          Returns canonical path for well-formed file, "(Untitled)" if no file exists, and absolute path if ill-formed.
 boolean getClassFileInSync()
           
 String getCompletePath()
          Returns canonical path (as defined above) followed by " *" if modified.
 int getCurrentCol()
           
 int getCurrentLine()
           
 DefinitionsDocument getDocument()
          Gets the associated DefinitionsDocument which may force materializing it.
 DocumentListener[] getDocumentListeners()
           
 String getEnclosingClassName(int pos, boolean qual)
          Searching backwards finds the name of the enclosing named class or interface.
 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.
 int getInitialHorizontalScroll()
           
 int getInitialSelectionEnd()
           
 int getInitialSelectionStart()
           
 int getInitialVerticalScroll()
           
 String getLexiName()
           
 int getLineOfOffset(int offset)
          Translates an offset into the components text to a line number.
 int getNumberOfLines()
           
 int getOffsetOfLine(int line)
          Translates a line number into an offset.
 String getPackageName()
           
 String getPackageNameFromDocument()
           
 Pageable getPageable()
           
 File getParentDirectory()
          Returns the parent directory of this file, null if it has none.
 String getQualifiedClassName()
           
 String getQualifiedClassName(int pos)
           
 File getRawFile()
          Returns the file for this document; does not check whether the file exists.
 File getSourceRoot()
          Finds the root directory of the source files.
 long getTimestamp()
          Returns the date that this document was last modified.
 UndoableEditListener[] getUndoableEditListeners()
           
 CompoundUndoManager getUndoManager()
           
 int gotoLine(int line)
          Moves the definitions document to the given line, and returns the resulting character position.
 boolean inNewProjectPath(File root)
          Determines if this document in the file system tree below the specified root.
 boolean inProject()
           
 boolean inProjectPath()
          Determines if this document in the file system tree below the active project root.
 boolean isAuxiliaryFile()
           
 boolean isEmpty()
          Determines if the document is empty.
 boolean isModifiedSinceSave()
          Determines if this definitions document has changed since the last save.
 boolean isReady()
          Returns whether this document is resident in memory.
 boolean isShadowed(int pos)
          Determines if pos in document is inside a comment or a string.
 boolean isSourceFile()
           
 boolean isUntitled()
          Returns whether this document is currently untitled (indicating whether it has a file yet or not).
 boolean modifiedOnDisk()
          Determines if this definitions document has changed since the last save.
 void preparePrintJob()
           
 void print()
           
 boolean quitFile()
          Saves file at user's discretion before quitting.
 void removeBrowserRegion(BrowserDocumentRegion r)
          Removes region r from the browserRegions collection
 void removeFromDebugger()
          Called when this document is being closed, removing related state from the debug manager.
 void resetModification()
          Resets the document to be unmodified.
 void resetUndoManager()
           
 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 runMain()
          Runs the main method in this document in the interactions pane.
 boolean saveFile(FileSaveSelector com)
          Saves the document with a FileWriter.
 boolean saveFileAs(FileSaveSelector com)
          Saves the document with a FileWriter.
 void setCachedClassFile(File f)
           
 void setClassFileInSync(boolean val)
           
 void setFile(File file)
          Sets this document's file
 void setPackage(String s)
          Sets the cached package name returned by getPackageName();
 void startCompile()
          Starts compiling the source.
 void startJUnit()
          Starts testing the source using JUnit.
 int uncommentLines(int selStart, int selEnd)
           
 boolean undoManagerCanRedo()
           
 boolean undoManagerCanUndo()
           
 void updateModifiedSinceSave()
          Sets the document as modified.
 boolean verifyExists()
          If the file exists, returns true.
 
Methods inherited from interface edu.rice.cs.drjava.model.DJDocument
_getIndentOfCurrStmt, _getIndentOfCurrStmt, _getIndentOfCurrStmt, _getLineEndPos, _getLineFirstCharPos, _getLineStartPos, balanceBackward, balanceForward, clear, findCharOnLine, findNextEnclosingBrace, findPrevDelimiter, findPrevDelimiter, findPrevEnclosingBrace, getCurrentLocation, getFirstNonWSCharPos, getFirstNonWSCharPos, getFirstNonWSCharPos, getHighlightStatus, getIndent, getIntelligentBeginLinePos, getReduced, getStateAtCurrent, getText, indentLines, indentLines, insertString, move, remove, setCurrentLocation, setIndent
 
Methods inherited from interface edu.rice.cs.util.text.AbstractDocumentInterface
append, createPosition, getLength, getText
 
Methods inherited from interface javax.swing.text.StyledDocument
addStyle, getBackground, getCharacterElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, removeStyle, setCharacterAttributes, setLogicalStyle, setParagraphAttributes
 
Methods inherited from interface javax.swing.text.Document
addDocumentListener, addUndoableEditListener, createPosition, getDefaultRootElement, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, removeDocumentListener, removeUndoableEditListener, render
 
Methods inherited from interface edu.rice.cs.drjava.model.Finalizable
addFinalizationListener, getFinalizationListeners
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface edu.rice.cs.util.docnavigation.INavigatorItem
getName
 

Method Detail

commentLines

int commentLines(int selStart,
                 int selEnd)
The following methods are forwarding methods required by the rest of the program in order for the OpenDefinitionsDocument to handle DefinitionsDocuments


uncommentLines

int uncommentLines(int selStart,
                   int selEnd)

getDocument

DefinitionsDocument getDocument()
Gets the associated DefinitionsDocument which may force materializing it.


getClassFileInSync

boolean getClassFileInSync()

setClassFileInSync

void setClassFileInSync(boolean val)

getCurrentLine

int getCurrentLine()

getCurrentCol

int getCurrentCol()

_getOffset

int _getOffset(int lineNum)

getQualifiedClassName

String getQualifiedClassName()
                             throws ClassNameNotFoundException
Throws:
ClassNameNotFoundException

getQualifiedClassName

String getQualifiedClassName(int pos)
                             throws ClassNameNotFoundException
Throws:
ClassNameNotFoundException

getLexiName

String getLexiName()

getUndoManager

CompoundUndoManager getUndoManager()

resetUndoManager

void resetUndoManager()

getCachedClassFile

File getCachedClassFile()

setCachedClassFile

void setCachedClassFile(File f)

getDocumentListeners

DocumentListener[] getDocumentListeners()

getUndoableEditListeners

UndoableEditListener[] getUndoableEditListeners()

getRawFile

File getRawFile()
Returns the file for this document; does not check whether the file exists.


getFile

File getFile()
             throws FileMovedException
Returns the file for this document.

Returns:
the file for this document
Throws:
FileMovedException - if the document's file no longer exists

setFile

void setFile(File file)
Sets this document's file

Parameters:
file - the file that this OpenDefinitionsDocument is associated with

getFileName

String getFileName()
Returns the name of this file, or "(Untitled)" if no file.


getCanonicalPath

String getCanonicalPath()
Returns canonical path for well-formed file, "(Untitled)" if no file exists, and absolute path if ill-formed.


getCompletePath

String getCompletePath()
Returns canonical path (as defined above) followed by " *" if modified.


getParentDirectory

File getParentDirectory()
Returns the parent directory of this file, null if it has none.


getPageable

Pageable getPageable()
                     throws IllegalStateException
Throws:
IllegalStateException

undoManagerCanUndo

boolean undoManagerCanUndo()
Returns:
whether the undo manager can perform any undos.

undoManagerCanRedo

boolean undoManagerCanRedo()
Returns:
whether the undo manager can perform any redos.

inProjectPath

boolean inProjectPath()
Determines if this document in the file system tree below the active project root.


inNewProjectPath

boolean inNewProjectPath(File root)
Determines if this document in the file system tree below the specified root.


isEmpty

boolean isEmpty()
Determines if the document is empty.


isAuxiliaryFile

boolean isAuxiliaryFile()
Specified by:
isAuxiliaryFile in interface INavigatorItem
Returns:
true if the document's file is a project auxiliary file.

isSourceFile

boolean isSourceFile()
Returns:
true if the document's filename ends with the extension ".java", ".dj0", "dj1", or "dj2".

inProject

boolean inProject()
Specified by:
inProject in interface INavigatorItem
Returns:
true if the documents file is saved in the current project file.

isReady

boolean isReady()
Returns whether this document is resident in memory.


isUntitled

boolean isUntitled()
Returns whether this document is currently untitled (indicating whether it has a file yet or not).

Specified by:
isUntitled in interface INavigatorItem
Returns:
true if the document is untitled and has no file

fileExists

boolean fileExists()
Returns true if the file exists on disk, or if the user has located it on disk. Returns false if the file has been moved or deleted

Specified by:
fileExists in interface INavigatorItem

modifiedOnDisk

boolean modifiedOnDisk()
Determines if this definitions document has changed since the last save.

Returns:
true if the document has been modified

resetModification

void resetModification()
Resets the document to be unmodified.


getTimestamp

long getTimestamp()
Returns the date that this document was last modified.


addBrowserRegion

void addBrowserRegion(BrowserDocumentRegion r)
Adds region r to the browserRegions collection for this


removeBrowserRegion

void removeBrowserRegion(BrowserDocumentRegion r)
Removes region r from the browserRegions collection


getFirstTopLevelClassName

String getFirstTopLevelClassName()
                                 throws ClassNameNotFoundException
Returns the name of the top level class, if any.

Throws:
ClassNameNotFoundException - if no top level class name found.

verifyExists

boolean verifyExists()
If the file exists, returns true. If it does not exist, prompts the user to look it up. If the user chooses a file, returns true, false otherwise.


saveFile

boolean 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
Returns:
true if the file was saved, false if the operation was canceled
Throws:
IOException

revertFile

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

Throws:
IOException

saveFileAs

boolean 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.
Returns:
true if the file was saved, false if the operation was canceled
Throws:
IOException

startCompile

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. Only executes in the event thread.

Throws:
IOException - if a file with errors cannot be opened

runMain

void runMain()
             throws ClassNameNotFoundException,
                    IOException
Runs the main method in this document in the interactions pane. Demands that the definitions be saved and compiled before proceeding. Fires an event to signal when execution is about to begin.

Throws:
ClassNameNotFoundException - propagated from getFirstTopLevelClass()
IOException - propagated from GlobalModel.compileAll()

startJUnit

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. TODO: this method is redundant and should be deprecated

Throws:
IOException - if a file with errors cannot be opened
ClassNotFoundException - when the class is compiled to a location not on the classpath.

generateJavadoc

void generateJavadoc(FileSaveSelector saver)
                     throws IOException
Generates Javadoc for this document, saving the output to a temporary directory. The location is provided to the javadocEnded event on the given listener.

Parameters:
saver - FileSaveSelector for saving the file if it needs to be saved
Throws:
IOException

isModifiedSinceSave

boolean isModifiedSinceSave()
Determines if this definitions document has changed since the last save.

Returns:
true if the document has been modified

revertIfModifiedOnDisk

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
Throws:
IOException

canAbandonFile

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

Returns:
true if this document can be abandoned

quitFile

boolean quitFile()
Saves file at user's discretion before quitting.

Returns:
true if quitting should continue, false if the user cancelled

gotoLine

int gotoLine(int line)
Moves the definitions document to the given line, and returns the resulting character position.

Parameters:
line - Destination line number. 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

getSourceRoot

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.

getPackageNameFromDocument

String getPackageNameFromDocument()
Returns:
the name of the package currently embedded in document. Forwards to wrapped DefinitionsDocument.

getPackageName

String getPackageName()
Returns:
the name of the package at the time of the most recent save or load operation.

setPackage

void setPackage(String s)
Sets the cached package name returned by getPackageName();


getEnclosingClassName

String getEnclosingClassName(int pos,
                             boolean qual)
                             throws BadLocationException,
                                    ClassNameNotFoundException
Searching backwards finds the name of the enclosing named class or interface. NB: ignores comments. WARNING: In long source files and when contained in anonymous inner classes, this function might take a LONG time.

Parameters:
pos - Position to start from
qual - true to find the fully qualified class name
Returns:
name of the enclosing named class or interface
Throws:
BadLocationException
ClassNameNotFoundException

preparePrintJob

void preparePrintJob()
                     throws BadLocationException,
                            FileMovedException
Throws:
BadLocationException
FileMovedException

print

void print()
           throws PrinterException,
                  BadLocationException,
                  FileMovedException
Throws:
PrinterException
BadLocationException
FileMovedException

cleanUpPrintJob

void cleanUpPrintJob()

checkIfClassFileInSync

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.

Specified by:
checkIfClassFileInSync in interface INavigatorItem
Returns:
is the class file and this OpenDefinitionsDocument are in sync

documentSaved

void documentSaved()
Called when this document is saved so it can notify the cache.


documentModified

void documentModified()
Called when this document is modified so it can notify the cache.


documentReset

void documentReset()
Called when this document is reset so it can notify the cache.


getBreakpointManager

RegionManager<Breakpoint> getBreakpointManager()
Returns:
the breakpoint region manager.

getBookmarkManager

RegionManager<MovingDocumentRegion> getBookmarkManager()
Returns:
the bookmark region manager.

clearBrowserRegions

void clearBrowserRegions()
Remove the browser regions for this document from the browser history manager.


removeFromDebugger

void removeFromDebugger()
Called when this document is being closed, removing related state from the debug manager.


updateModifiedSinceSave

void updateModifiedSinceSave()
Sets the document as modified.


close

void close()
Should be called when closing an ODD to let the ODD clean up after itself.


getInitialVerticalScroll

int getInitialVerticalScroll()
Returns:
the initial vertical scroll the pane should use when initialized.

getInitialHorizontalScroll

int getInitialHorizontalScroll()
Returns:
the initial vertical scroll the pane should use when initialized.

getInitialSelectionStart

int getInitialSelectionStart()
Returns:
the starting location of the cursor selection that should be set in the pane when initialized.

getInitialSelectionEnd

int getInitialSelectionEnd()
Returns:
the final location of the cursor selection that should be set in the pane when it is initialized.

getNumberOfLines

int getNumberOfLines()
Returns:
the number of lines in this document.

getLineOfOffset

int getLineOfOffset(int offset)
Translates an offset into the components text to a line number.

Parameters:
offset - the offset >= 0
Returns:
the line number >= 0

getOffsetOfLine

int getOffsetOfLine(int line)
Translates a line number into an offset.

Parameters:
line - number >= 0
Returns:
offset >= 0

createUnwrappedPosition

Position createUnwrappedPosition(int offs)
                                 throws BadLocationException
Creates a WrappedPosition in the document.

Throws:
BadLocationException

isShadowed

boolean isShadowed(int pos)
Determines if pos in document is inside a comment or a string.