edu.rice.cs.drjava.model
Interface OpenDefinitionsDocument

All Superinterfaces:
AbstractDocumentInterface, java.lang.Comparable<OpenDefinitionsDocument>, DJDocument, javax.swing.text.Document, Finalizable<DefinitionsDocument>, INavigatorItem, javax.swing.text.StyledDocument, SwingDocumentInterface
All Known Implementing Classes:
AbstractGlobalModel.ConcreteOpenDefDoc, DefaultGlobalModel.ConcreteOpenDefDoc, DummyOpenDefDoc, TestDocGetter.TestOpenDoc

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

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

Version:
$Id: OpenDefinitionsDocument.java 5377 2010-08-25 16:58:40Z mgricken $

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
 boolean containsClassOrInterfaceOrEnum()
          Returns true if one of the words 'class', 'interface' or 'enum' is found in non-comment text.
 javax.swing.text.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()
           
 java.io.File getCachedClassFile()
           
 java.lang.String getCanonicalPath()
          Returns canonical path for well-formed file, "(Untitled)" if no file exists, and absolute path if ill-formed.
 int getCaretPosition()
           
 boolean getClassFileInSync()
           
 java.lang.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.
 javax.swing.event.DocumentListener[] getDocumentListeners()
           
 java.lang.String getEnclosingClassName(int pos, boolean qual)
          Searching backwards finds the name of the enclosing named class or interface.
 java.io.File getFile()
          Returns the file for this document.
 java.lang.String getFileName()
          Returns the name of this file, or "(Untitled)" if no file.
 java.lang.String getFirstTopLevelClassName()
          Returns the name of the top level class, if any.
 int getInitialHorizontalScroll()
           
 int getInitialSelectionEnd()
           
 int getInitialSelectionStart()
           
 int getInitialVerticalScroll()
           
 java.lang.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.
 java.lang.String getPackageName()
           
 java.lang.String getPackageNameFromDocument()
           
 java.awt.print.Pageable getPageable()
           
 java.io.File getParentDirectory()
          Returns the parent directory of this file, null if it has none.
 java.lang.String getQualifiedClassName()
           
 java.lang.String getQualifiedClassName(int pos)
           
 java.io.File getRawFile()
          Returns the file for this document; does not check whether the file exists.
 java.io.File getSourceRoot()
          Finds the root directory of the source files.
 long getTimestamp()
          Returns the date that this document was last modified.
 javax.swing.event.UndoableEditListener[] getUndoableEditListeners()
           
 CompoundUndoManager getUndoManager()
           
 int gotoLine(int line)
          Moves the definitions document to the given line, and returns the resulting character position.
 boolean inNewProjectPath(java.io.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 runApplet(java.lang.String qualifiedClassName)
          Runs this document as applet in the interactions pane.
 void runMain(java.lang.String qualifiedClassName)
          Runs the main method in this document in the interactions pane.
 void runSmart(java.lang.String qualifiedClassName)
          Runs this document, and tries to be smart about it.
 boolean saveFile(FileSaveSelector com)
          Saves the document with a FileWriter.
 boolean saveFileAs(FileSaveSelector com)
          Saves the document with a FileWriter.
 void setCachedClassFile(java.io.File f)
           
 void setClassFileInSync(boolean val)
           
 void setFile(java.io.File file)
          Sets this document's file
 void setPackage(java.lang.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.
 void updateSyntaxHighlighting()
          Update the syntax highlighting for the file type.
 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

java.lang.String getQualifiedClassName()
                                       throws ClassNameNotFoundException
Throws:
ClassNameNotFoundException

getQualifiedClassName

java.lang.String getQualifiedClassName(int pos)
                                       throws ClassNameNotFoundException
Throws:
ClassNameNotFoundException

getLexiName

java.lang.String getLexiName()

getUndoManager

CompoundUndoManager getUndoManager()

resetUndoManager

void resetUndoManager()

getCachedClassFile

java.io.File getCachedClassFile()

setCachedClassFile

void setCachedClassFile(java.io.File f)

getDocumentListeners

javax.swing.event.DocumentListener[] getDocumentListeners()

getUndoableEditListeners

javax.swing.event.UndoableEditListener[] getUndoableEditListeners()

getRawFile

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


getFile

java.io.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(java.io.File file)
Sets this document's file

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

getFileName

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


getCanonicalPath

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


getCompletePath

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


getParentDirectory

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


getPageable

java.awt.print.Pageable getPageable()
                                    throws java.lang.IllegalStateException
Throws:
java.lang.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(java.io.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", ".dj", ".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

java.lang.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 java.io.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:
java.io.IOException

revertFile

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

Throws:
java.io.IOException

saveFileAs

boolean saveFileAs(FileSaveSelector com)
                   throws java.io.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:
java.io.IOException

startCompile

void startCompile()
                  throws java.io.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:
java.io.IOException - if a file with errors cannot be opened

runMain

void runMain(java.lang.String qualifiedClassName)
             throws ClassNameNotFoundException,
                    java.io.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.

Parameters:
qualifiedClassName - - the fully qualified name of the class contained in this document to run the main(String[]) method of
Throws:
ClassNameNotFoundException - propagated from getFirstTopLevelClass()
java.io.IOException - propagated from GlobalModel.compileAll()

runApplet

void runApplet(java.lang.String qualifiedClassName)
               throws ClassNameNotFoundException,
                      java.io.IOException
Runs this document as applet 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. The class that will be run must have a default (zero-argument) constructor.

Parameters:
qualifiedClassName - - the fully qualified name of the class contained in this document that will be run as applet
Throws:
ClassNameNotFoundException - propagated from getFirstTopLevelClass()
java.io.IOException - propagated from GlobalModel.compileAll()

runSmart

void runSmart(java.lang.String qualifiedClassName)
              throws ClassNameNotFoundException,
                     java.io.IOException
Runs this document, and tries to be smart about it. It detects if the class is a regular Java class with a main method, if it is an applet, or if it is an ACM Java Task Force program. It runs the program appropriately in the interactions pane after resetting interactions with the source root for this document as the working directory. Warns the use if the class files for the doucment are not up to date. Fires an event to signal when execution is about to begin. NOTE: this code normally runs in the event thread; it cannot block waiting for an event that is triggered by event thread execution!

Parameters:
qualifiedClassName - the qualified name of the class (in this document) to run. If NULL, it is the name of the top level class.
Throws:
ClassNameNotFoundException - propagated from getFirstTopLevelClass()
java.io.IOException - propagated from GlobalModel.compileAll()

startJUnit

void startJUnit()
                throws java.lang.ClassNotFoundException,
                       java.io.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:
java.io.IOException - if a file with errors cannot be opened
java.lang.ClassNotFoundException - when the class is compiled to a location not on the classpath.

generateJavadoc

void generateJavadoc(FileSaveSelector saver)
                     throws java.io.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:
java.io.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 java.io.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:
java.io.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

java.io.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

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

getPackageName

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

setPackage

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


getEnclosingClassName

java.lang.String getEnclosingClassName(int pos,
                                       boolean qual)
                                       throws javax.swing.text.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:
javax.swing.text.BadLocationException
ClassNameNotFoundException

preparePrintJob

void preparePrintJob()
                     throws javax.swing.text.BadLocationException,
                            FileMovedException
Throws:
javax.swing.text.BadLocationException
FileMovedException

print

void print()
           throws java.awt.print.PrinterException,
                  javax.swing.text.BadLocationException,
                  FileMovedException
Throws:
java.awt.print.PrinterException
javax.swing.text.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

getCaretPosition

int getCaretPosition()
Returns:
the caret position as set by the view.

createUnwrappedPosition

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

Throws:
javax.swing.text.BadLocationException

isShadowed

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


containsClassOrInterfaceOrEnum

boolean containsClassOrInterfaceOrEnum()
                                       throws javax.swing.text.BadLocationException
Returns true if one of the words 'class', 'interface' or 'enum' is found in non-comment text.

Throws:
javax.swing.text.BadLocationException

updateSyntaxHighlighting

void updateSyntaxHighlighting()
Update the syntax highlighting for the file type.