edu.rice.cs.drjava.model
Class AbstractGlobalModel

java.lang.Object
  extended by edu.rice.cs.drjava.model.AbstractGlobalModel
All Implemented Interfaces:
OptionConstants, GlobalModel, ILoadDocuments, SingleDisplayModel, DocumentIterator
Direct Known Subclasses:
DefaultGlobalModel

public class AbstractGlobalModel
extends Object
implements SingleDisplayModel, OptionConstants, DocumentIterator

In simple terms, a DefaultGlobalModel without an interpreter, compiler, junit testing, debugger or javadoc. Hence, it only has only document handling functionality

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.rice.cs.drjava.config.OptionConstants
OptionConstants.AccessLevelChoices, OptionConstants.DefaultFont, OptionConstants.HeapSizeChoices, OptionConstants.LookAndFeels, OptionConstants.PlasticThemes, OptionConstants.VersionNotificationChoices
 
Field Summary
protected  ConcreteRegionManager<MovingDocumentRegion> _bookmarkManager
          Manager for bookmark regions.
protected  ConcreteRegionManager<Breakpoint> _breakpointManager
          Manager for breakpoint regions.
protected  BrowserHistoryManager _browserHistoryManager
          Manager for browser history regions.
protected  DocumentCache _cache
          A document cache that manages how many unmodified documents are open at once.
protected  ConsoleDocument _consoleDoc
          The document used to display System.out and System.err, and to read from System.in.
protected  InteractionsDJDocument _consoleDocAdapter
          The document adapter used in the console document.
protected  IDocumentNavigator<OpenDefinitionsDocument> _documentNavigator
          The abstract container which contains views of open documents and allows user to navigate document focus among this collection of open documents
protected  DefinitionsEditorKit _editorKit
          Factory for new definitions documents and views.
protected  LinkedList<RegionManager<MovingDocumentRegion>> _findResultsManagers
          Managers for find result regions.
static Log _log
           
 GlobalEventNotifier _notifier
          Keeps track of all listeners to the model, and has the ability to notify them of some event.
protected  PageFormat _pageFormat
          A PageFormat object for printing to paper.
protected  FileGroupingState _state
          Specifies the state of the navigator pane.
static int DIFF_THRESHOLD
           
static int WRITE_DELAY
          Number of milliseconds to wait after each println, to prevent the JVM from being flooded with print calls.
 
Fields inherited from interface edu.rice.cs.drjava.model.GlobalModel
RUNTIME_CLASS_PATH
 
Fields inherited from interface edu.rice.cs.drjava.config.OptionConstants
accessLevelChoices, ALLOW_PRIVATE_ACCESS, ALWAYS_COMPILE_BEFORE_JUNIT, ALWAYS_SAVE_BEFORE_COMPILE, ALWAYS_SAVE_BEFORE_DEBUG, ALWAYS_SAVE_BEFORE_JAVADOC, ALWAYS_SAVE_BEFORE_RUN, apiJavadocChoices, apiJavadocVersionChoices, AUTO_CLOSE_COMMENTS, BACKUP_FILES, BOOKMARK_COLOR, BROWSER_FILE, BROWSER_HISTORY_MAX_SIZE, BROWSER_STRING, choices, CLIPBOARD_HISTORY_SIZE, COMPILER_ERROR_COLOR, DEBUG_BREAKPOINT_COLOR, DEBUG_BREAKPOINT_DISABLED_COLOR, DEBUG_MESSAGE_COLOR, DEBUG_PANEL_HEIGHT, DEBUG_SOURCEPATH, DEBUG_STEP_DRJAVA, DEBUG_STEP_EXCLUDE, DEBUG_STEP_INTERPRETER, DEBUG_STEP_JAVA, DEBUG_THREAD_COLOR, DEFINITIONS_BACKGROUND_COLOR, DEFINITIONS_COMMENT_COLOR, DEFINITIONS_DOUBLE_QUOTED_COLOR, DEFINITIONS_KEYWORD_COLOR, DEFINITIONS_MATCH_COLOR, DEFINITIONS_NORMAL_COLOR, DEFINITIONS_NUMBER_COLOR, DEFINITIONS_SINGLE_QUOTED_COLOR, DEFINITIONS_TYPE_COLOR, DETACH_DEBUGGER, DETACH_TABBEDPANES, DIALOG_AUTOIMPORT_ENABLED, DIALOG_AUTOIMPORT_STATE, DIALOG_AUTOIMPORT_STORE_POSITION, DIALOG_CLIPBOARD_HISTORY_STATE, DIALOG_CLIPBOARD_HISTORY_STORE_POSITION, DIALOG_COMPLETE_JAVAAPI, DIALOG_COMPLETE_SCAN_CLASS_FILES, DIALOG_COMPLETE_WORD_STATE, DIALOG_COMPLETE_WORD_STORE_POSITION, DIALOG_DEBUGFRAME_STATE, DIALOG_DEBUGFRAME_STORE_POSITION, DIALOG_DRJAVA_ERROR_POPUP_ENABLED, DIALOG_DRJAVA_SURVEY_ENABLED, DIALOG_EDITEXTERNALPROCESS_STATE, DIALOG_EDITEXTERNALPROCESS_STORE_POSITION, DIALOG_EXTERNALPROCESS_STATE, DIALOG_EXTERNALPROCESS_STORE_POSITION, DIALOG_GOTOFILE_FULLY_QUALIFIED, DIALOG_GOTOFILE_STATE, DIALOG_GOTOFILE_STORE_POSITION, DIALOG_JAROPTIONS_STATE, DIALOG_JAROPTIONS_STORE_POSITION, DIALOG_LIGHTWEIGHT_PARSING_DELAY, DIALOG_OPENJAVADOC_STATE, DIALOG_OPENJAVADOC_STORE_POSITION, DIALOG_TABBEDPANES_STATE, DIALOG_TABBEDPANES_STORE_POSITION, DOC_LIST_WIDTH, DRJAVA_ERRORS_BUTTON_COLOR, DRJAVA_SURVEY_DAYS, DRJAVA_USE_FORCE_QUIT, EXTERNAL_SAVED_CMDLINES, EXTERNAL_SAVED_COUNT, EXTERNAL_SAVED_ENCLOSING_DJAPP_FILES, EXTERNAL_SAVED_NAMES, EXTERNAL_SAVED_PREFIX, EXTERNAL_SAVED_WORKDIRS, EXTPROCESS_FILE_EXTENSION, EXTPROCESS_FILE_NAME_INSIDE_JAR, EXTRA_CLASSPATH, EXTRA_COMPILERS, FIND_ALL_DOCUMENTS, FIND_MATCH_CASE, FIND_NO_COMMENTS_STRINGS, FIND_NO_TEST_CASES, FIND_REPLACE_FOCUS_IN_DEFPANE, FIND_RESULTS_COLOR1, FIND_RESULTS_COLOR2, FIND_RESULTS_COLOR3, FIND_RESULTS_COLOR4, FIND_RESULTS_COLOR5, FIND_RESULTS_COLOR6, FIND_RESULTS_COLOR7, FIND_RESULTS_COLOR8, FIND_RESULTS_COLORS, FIND_SEARCH_BACKWARDS, FIND_WHOLE_WORD, FOLLOW_FILE_DELAY, FOLLOW_FILE_LINES, FONT_DOCLIST, FONT_LINE_NUMBERS, FONT_MAIN, FONT_TOOLBAR, FORCE_TEST_SUFFIX, heapSizeChoices, HISTORY_MAX_SIZE, INDENT_LEVEL, INTERACTIONS_ERROR_COLOR, INTERACTIONS_EXIT_PROMPT, INTERACTIONS_RESET_PROMPT, JAVAC_LOCATION, JAVADOC_1_3_LINK, JAVADOC_1_3_TEXT, JAVADOC_1_4_LINK, JAVADOC_1_4_TEXT, JAVADOC_1_5_LINK, JAVADOC_1_5_TEXT, JAVADOC_1_6_LINK, JAVADOC_1_6_TEXT, JAVADOC_ACCESS_LEVEL, JAVADOC_API_REF_VERSION, JAVADOC_AUTO_TEXT, JAVADOC_CUSTOM_PARAMS, JAVADOC_DESTINATION, JAVADOC_FROM_ROOTS, JAVADOC_LINK_VERSION, JAVADOC_NONE_TEXT, JAVADOC_PROMPT_FOR_DESTINATION, KEY_ABOUT, KEY_BACKWARD, KEY_BEGIN_DOCUMENT, KEY_BEGIN_LINE, KEY_BOOKMARKS_PANEL, KEY_BOOKMARKS_TOGGLE, KEY_BROWSE_BACK, KEY_BROWSE_FORWARD, KEY_CHECK_NEW_VERSION, KEY_CLEAR_CONSOLE, KEY_CLEAR_HISTORY, KEY_CLEAR_LINE, KEY_CLOSE_ALL_FILES, KEY_CLOSE_FILE, KEY_CLOSE_PROJECT, KEY_CLOSING_BRACE, KEY_COMMENT_LINES, KEY_COMPILE, KEY_COMPILE_ALL, KEY_COMPLETE_FILE, KEY_COPY, KEY_CUT, KEY_CUT_LINE, KEY_DEBUG_BREAKPOINT_PANEL, KEY_DEBUG_BREAKPOINT_TOGGLE, KEY_DEBUG_CLEAR_ALL_BREAKPOINTS, KEY_DEBUG_MODE_TOGGLE, KEY_DEBUG_RESUME, KEY_DEBUG_STEP_INTO, KEY_DEBUG_STEP_OUT, KEY_DEBUG_STEP_OVER, KEY_DELETE_NEXT, KEY_DELETE_PREVIOUS, KEY_DETACH_DEBUGGER, KEY_DETACH_TABBEDPANES, KEY_DOWN, KEY_DRJAVA_ERRORS, KEY_DRJAVA_SURVEY, KEY_END_DOCUMENT, KEY_END_LINE, KEY_EXEC_PROCESS, KEY_EXECUTE_HISTORY, KEY_EXPORT_OLD, KEY_FIND_NEXT, KEY_FIND_PREV, KEY_FIND_REPLACE, KEY_FOLLOW_FILE, KEY_FORCE_QUIT, KEY_FORWARD, KEY_GOTO_FILE, KEY_GOTO_FILE_UNDER_CURSOR, KEY_GOTO_LINE, KEY_HELP, KEY_JAVADOC_ALL, KEY_JAVADOC_CURRENT, KEY_LIFT_CURRENT_INTERACTION, KEY_LOAD_HISTORY_SCRIPT, KEY_NEW_FILE, KEY_NEW_TEST, KEY_NEXT_DOCUMENT, KEY_NEXT_PANE, KEY_NEXT_WORD, KEY_OPEN_FILE, KEY_OPEN_FOLDER, KEY_OPEN_JAVADOC, KEY_OPEN_JAVADOC_UNDER_CURSOR, KEY_OPEN_PROJECT, KEY_OPENING_BRACE, KEY_PAGE_DOWN, KEY_PAGE_SETUP, KEY_PAGE_UP, KEY_PASTE, KEY_PASTE_FROM_HISTORY, KEY_PREFERENCES, KEY_PREVIOUS_DOCUMENT, KEY_PREVIOUS_PANE, KEY_PREVIOUS_WORD, KEY_PRINT, KEY_PRINT_CONSOLE, KEY_PRINT_INTERACTIONS, KEY_PRINT_PREVIEW, KEY_QUICKSTART, KEY_QUIT, KEY_REDO, KEY_RENAME_FILE, KEY_RESET_INTERACTIONS, KEY_REVERT_FILE, KEY_RUN, KEY_RUN_MAIN, KEY_SAVE_ALL_FILES, KEY_SAVE_FILE, KEY_SAVE_FILE_AS, KEY_SAVE_HISTORY, KEY_SELECT_ALL, KEY_SHIFT_DELETE_NEXT, KEY_SHIFT_DELETE_PREVIOUS, KEY_TEST, KEY_TEST_ALL, KEY_UNCOMMENT_LINES, KEY_UNDO, KEY_UP, KEY_VIEW_INTERACTIONS_CLASSPATH, LANGUAGE_LEVEL, LAST_DIRECTORY, LAST_DRJAVA_SURVEY, LAST_DRJAVA_SURVEY_RESULT, LAST_INTERACTIONS_DIRECTORY, LAST_NEW_VERSION_NOTIFICATION, LIGHTWEIGHT_PARSING_ENABLED, LINEENUM_ENABLED, linkVersionChoices, LOOK_AND_FEEL, MASK, MASTER_JVM_ARGS, MASTER_JVM_XMX, NEW_VERSION_NOTIFICATION, NEW_VERSION_NOTIFICATION_CHOICES, NEW_VERSION_NOTIFICATION_DAYS, OLD_PROJECT_FILE_EXTENSION, OPEN_FOLDER_RECURSIVE, PLASTIC_THEMES, PROJECT_FILE_EXTENSION, PROMPT_BEFORE_CLEAN, QUIT_PROMPT, RECENT_FILES, RECENT_FILES_MAX_SIZE, RECENT_PROJECTS, REMOTE_CONTROL_ENABLED, REMOTE_CONTROL_PORT, RESET_CLEAR_CONSOLE, RUN_WITH_ASSERT, SHOW_CODE_PREVIEW_POPUPS, SHOW_DEBUG_CONSOLE, SHOW_DEPRECATION_WARNINGS, SHOW_FALLTHROUGH_WARNINGS, SHOW_FINALLY_WARNINGS, SHOW_PATH_WARNINGS, SHOW_SERIAL_WARNINGS, SHOW_SOURCE_WHEN_SWITCHING, SHOW_UNCHECKED_WARNINGS, SLAVE_JVM_ARGS, SLAVE_JVM_XMX, STICKY_INTERACTIONS_DIRECTORY, SYSTEM_ERR_COLOR, SYSTEM_IN_COLOR, SYSTEM_OUT_COLOR, TABS_HEIGHT, TEXT_ANTIALIAS, TOOLBAR_ENABLED, TOOLBAR_ICONS_ENABLED, TOOLBAR_TEXT_ENABLED, WARN_BREAKPOINT_OUT_OF_SYNC, WARN_CHANGE_LAF, WARN_CHANGE_THEME, WARN_DEBUG_MODIFIED_FILE, WARN_PATH_CONTAINS_POUND, WINDOW_HEIGHT, WINDOW_STATE, WINDOW_STORE_POSITION, WINDOW_WIDTH, WINDOW_X, WINDOW_Y
 
Constructor Summary
AbstractGlobalModel()
          Constructs a new GlobalModel.
 
Method Summary
protected  edu.rice.cs.drjava.model.AbstractGlobalModel.ConcreteOpenDefDoc _createOpenDefinitionsDocument(File f)
          Creates a ConcreteOpenDefDoc for an existing file f.
protected  edu.rice.cs.drjava.model.AbstractGlobalModel.ConcreteOpenDefDoc _createOpenDefinitionsDocument(NullFile f)
          Creates a ConcreteOpenDefDoc for a NullFile object f (corresponding to a new empty document)
protected  void _docAppend(ConsoleDocument doc, String s, String style)
          Appends a string to the given document using a particular attribute set.
protected  OpenDefinitionsDocument _getOpenDocument(File file)
          Returns the OpenDefinitionsDocument corresponding to the given File, or null if that file is not open.
 ProjectProfile _makeProjectProfile(File file, HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
          Writes the project profile augmented by usage info to specified file.
 OpenDefinitionsDocument _openFile(File file)
          Creates a document from a file.
 void _toggleBookmark(int pos1, int pos2)
          Raw version of toggleBookmark.
 void aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
          If the document is untitled, brings it to the top so that the user will know which is being saved.
 void addAuxiliaryFile(OpenDefinitionsDocument doc)
          Adds a document to the list of auxiliary files.
protected  void addDocToClassPath(OpenDefinitionsDocument doc)
          Add a document to the classpath for the slave JVM.
protected  void addDocToNavigator(OpenDefinitionsDocument doc)
          Creates an iNavigatorItem for a document, and adds it to the navigator.
 void addListener(GlobalModelListener listener)
          Add a listener to this global model.
 void addToBrowserHistory()
          Add the current location to the browser history.
 void autoRefreshProject()
          Perform an auto-refresh of the project, adding new source files to the project.
 void cleanBuildDirectory()
          Cleans the build directory.
 void clearHistory()
          throws UnsupportedOperationException
 boolean closeAllFiles()
          Attempts to close all open documents.
 boolean closeAllFilesOnQuit()
          Closes all open documents.
 boolean closeFile(OpenDefinitionsDocument doc)
          Closes an open definitions document, prompting to save if the document has been changed.
protected  boolean closeFileHelper(OpenDefinitionsDocument doc)
          Helper for closeFile.
 boolean closeFiles(List<OpenDefinitionsDocument> docs)
          This function closes a group of files assuming that the files are contiguous in the enumeration provided by the document navigator.
 boolean closeFileWithoutPrompt(OpenDefinitionsDocument doc)
          Closes an open definitions document, without prompting to save if the document has been changed.
 void closeProject(boolean suppressReset)
          Performs any needed operations on the model after project files have been closed.
 void configNewProject()
          Configures a new project (created by createNewProject) and writes it to disk; only runs in event thread.
 RegionManager<MovingDocumentRegion> createFindResultsManager()
           
 void createNewProject(File projFile)
          Creates a new FileGroupingState for specificed project file and default values for other properties.
 void dispose()
          Prepares this model to be thrown away.
 void disposeExternalResources()
          Disposes of external resources.
 void exportOldProject(File file, HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
          Writes the project profile in the old project format.
 File findFileInPaths(String fileName, Iterable<File> paths)
          Searches for a file with the given name on the provided paths.
 String fixPathForNavigator(String path)
          Formats a string pathname for use in the document navigator.
 void forceQuit()
          Halts the program immediately.
 OpenDefinitionsDocument getActiveDocument()
          Returns the currently active document.
 boolean getAutoRefreshStatus()
          Gets autorfresh status of the project
 String getAuxiliaryBinTitle()
          Gives the title of the aux files bin for the navigator.
 List<OpenDefinitionsDocument> getAuxiliaryDocuments()
          Returns the OpenDefinitionsDocuments that are identified as auxiliary project source files.
 RegionManager<MovingDocumentRegion> getBookmarkManager()
           
 RegionManager<Breakpoint> getBreakpointManager()
           
 BrowserHistoryManager getBrowserHistoryManager()
           
 File getBuildDirectory()
           
 List<File> getClassFiles()
           
 Iterable<File> getClassPath()
          throws an UnsupportedOperationException
 CompilerModel getCompilerModel()
          Gets the CompilerModel, which provides all methods relating to compilers.
 ConsoleDocument getConsoleDocument()
          Gets the console document.
 File getCreateJarFile()
          Return the create jar file for the project.
 int getCreateJarFlags()
          Return the create jar flags for the project.
 Debugger getDebugger()
          throws UnsupportedOperationException
 int getDebugPort()
          throws UnsupportedOperationException
 Container getDocCollectionWidget()
           
 DocumentCache getDocumentCache()
          This method is for use only by test cases.
 int getDocumentCount()
          Returns the document count
 OpenDefinitionsDocument getDocumentForFile(File file)
          Gets the document for the specified file; may involve opening the file.
 DocumentIterator getDocumentIterator()
          Gets a DocumentIterator to allow navigating through open Swing Documents.
 IDocumentNavigator<OpenDefinitionsDocument> getDocumentNavigator()
          Gets the DocumentNavigator, which controls the document view.
 DefinitionsEditorKit getEditorKit()
          Fetches the EditorKit implementation for use in the definitions pane.
 File[] getExclFiles()
          Return an array of the files excluded from the current project
 String getExternalBinTitle()
          Gives the title of the external files bin for the navigator
 Iterable<File> getExtraClassPath()
          Returns a project's extra classpaths; empty for FlatFileGroupingState
 File[] getFilesInFolder(File dir, boolean rec)
           
 List<RegionManager<MovingDocumentRegion>> getFindResultsManagers()
           
 String getHistoryAsString()
          Throws UnsupportedOperationException
 String getHistoryAsStringWithSemicolons()
          Returns the entire history as a String with semicolons as needed.
 Iterable<File> getInteractionsClassPath()
          throws new UnsupportedOperationException
 InteractionsDocument getInteractionsDocument()
          throws UnsupportedOperationException
 DefaultInteractionsModel getInteractionsModel()
          throws UnsupportedOperationException
 JavadocModel getJavadocModel()
          throws UnsupportedOperationException
 JUnitModel getJUnitModel()
          throws UnsupportedOperationException
 File getMainClass()
          Return the main file for the project If not in project mode, returns null.
 File getMasterWorkingDirectory()
           
 File[] getNewFilesInProject()
          gets files in the project source directory that are not accounted for in the project file.
 OpenDefinitionsDocument getNextDocument(OpenDefinitionsDocument d)
          Returns the ODD preceding the given document in the document list.
 List<OpenDefinitionsDocument> getNonProjectDocuments()
          Returns the OpenDefinitionsDocuments that are NOT identified as project source files.
 GlobalEventNotifier getNotifier()
          Notifier list for the global model.
 int getNumCompErrors()
          throws UnsupportedOperationException
 OpenDefinitionsDocument getODDForDocument(AbstractDocumentInterface doc)
          Returns the OpenDefinitionsDocument corresponding to the INavigatorItem/DefinitionsDocument passed in.
 List<OpenDefinitionsDocument> getOpenDefinitionsDocuments()
          Returns a new collection of all documents currently open for editing.
protected static String getPackageName(String classname)
          Helper method used in subsequent anonymous inner class
 PageFormat getPageFormat()
           
 OpenDefinitionsDocument getPrevDocument(OpenDefinitionsDocument d)
          Returns the ODD preceding the given document in the document list.
 List<OpenDefinitionsDocument> getProjectDocuments()
          Returns the OpenDefinitionsDocuments that are identified as project source files.
 File getProjectFile()
           
 File[] getProjectFiles()
           
 File getProjectRoot()
           
 List<OpenDefinitionsDocument> getSortedOpenDefinitionsDocuments()
           
 String getSourceBinTitle()
          Gives the title of the source bin for the navigator.
 File getSourceFile(String fileName)
          Searches for a file with the given name on the current source roots and the augmented classpath.
 Iterable<File> getSourceRootSet()
          Gets an array of all sourceRoots for the open definitions documents, without duplicates.
 InteractionsDJDocument getSwingConsoleDocument()
          TODO: remove this swing dependency.
 InteractionsDJDocument getSwingInteractionsDocument()
          throws UnsupportedOperationException
 File getWorkingDirectory()
           
 boolean hasModifiedDocuments()
          Checks if any open definitions documents have been modified since last being saved.
 boolean hasModifiedDocuments(List<OpenDefinitionsDocument> lod)
          Checks if any given documents have been modified since last being saved.
 boolean hasOutOfSyncDocuments()
           
 boolean hasOutOfSyncDocuments(List<OpenDefinitionsDocument> lod)
           
 boolean hasUntitledDocuments()
          Checks if any open definitions documents are untitled.
 boolean inProject(File f)
          Returns true the given file is in the current project file.
 boolean inProjectPath(OpenDefinitionsDocument doc)
          A file is in the project if the source root is the same as the project root.
 void installActiveDocument()
          Invokes the activeDocumentChanged method in the global listener on the argument _activeDocument.
 void interpretCurrentInteraction()
          throw new UnsupportedOperationException
 boolean isAlreadyOpen(File file)
          Iterates over OpenDefinitionsDocuments, looking for this file.
 boolean isClassPathChanged()
           
 boolean isProjectActive()
           
 boolean isProjectChanged()
          Returns true if the project state has been changed
static boolean isUntitled(File f)
           
 void loadHistory(FileOpenSelector selector)
          throws UnsupportedOperationException
 InteractionsScriptModel loadHistoryAsScript(FileOpenSelector selector)
          throws UnsupportedOperationException
protected  FileGroupingState makeFlatFileGroupingState()
           
protected  FileGroupingState makeProjectFileGroupingState(File pr, File main, File bd, File wd, File project, File[] srcFiles, File[] auxFiles, File[] excludedFiles, Iterable<File> cp, File cjf, int cjflags, boolean refresh)
           
 OpenDefinitionsDocument newFile()
          Creates a new document, adds it to the list of open documents, and sets it to be active.
 OpenDefinitionsDocument newFile(File parentDir)
          Creates a new open definitions document and adds it to the list.
 OpenDefinitionsDocument newTestCase(String name, boolean makeSetUp, boolean makeTearDown)
          Creates a new junit test case.
 OpenDefinitionsDocument openFile(FileOpenSelector com)
          Open a file and add it to the pool of definitions documents.
protected  OpenDefinitionsDocument openFileHelper(FileOpenSelector com)
           
 OpenDefinitionsDocument[] openFiles(FileOpenSelector com)
          Open multiple files and add them to the pool of definitions documents.
protected  OpenDefinitionsDocument[] openFilesHelper(FileOpenSelector com)
           
 void openFolder(File dir, boolean rec)
          Opens all files in the specified folder dir and places them in the appropriate places in the document navigator.
 void openNewFilesInProject()
          Searches the source folder (recursively) for new files and opens them.
 void openProject(File projectFile)
          Parses the given project file and loads it into the document navigator and resets interactions pane.
protected static
<T> T
pop(ArrayList<T> stack)
          This pop method enables an ArrayList to serve as stack.
 void printDebugMessage(String s)
          throws UnsupportedOperationException
 void quit()
          Exits the program.
 void refreshActiveDocument()
          Makes the active document (in this model) the selection in the documentNavigator and invokes the activedocumentRefreshed method in the global listener on this document.
 void reloadProject(File file, HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
          Reloads a project without writing to disk.
 void removeAuxiliaryFile(OpenDefinitionsDocument doc)
          Removes a document from the list of auxiliary files.
 void removeFindResultsManager(RegionManager<MovingDocumentRegion> rm)
          Remove a manager from the model.
 void removeListener(GlobalModelListener listener)
          Remove a listener from this global model.
 void resetConsole()
          Resets the console.
 void resetInteractions(File wd)
          A degenerate operation since this has no slave JVM and no interactions model.
 void resetInteractions(File wd, boolean forceReset)
          A degenerate operation since this has no slave JVM and no interactions model.
 void saveAllFiles(FileSaveSelector com)
          Saves all open files, prompting for names if necessary.
protected  void saveAllFilesHelper(FileSaveSelector com)
          Called by saveAllFiles in DefaultGlobalModel
 void saveHistory(FileSaveSelector selector)
          throws UnsupportedOperationException
 void saveHistory(FileSaveSelector selector, String editedVersion)
          throws UnsupportedOperationException
 void saveProject(File file, HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
          Writes the project profile augmented by usage info to specified file.
 void setActiveDocument(OpenDefinitionsDocument doc)
          Sets the currently active document by updating the selection model.
 void setActiveFirstDocument()
          Selects the first document as the active document.
 void setActiveNextDocument()
          Sets the active document to be the next one in the collection.
 void setActivePreviousDocument()
          Sets the active document to be the previous one in the collection.
 void setAutoRefreshStatus(boolean status)
          Sets autofresh status of the project
 void setBuildDirectory(File f)
          Sets the class with the project's main method.
 void setClassPathChanged(boolean changed)
          Updates the classpath state.
 void setCreateJarFile(File f)
          Sets the create jar file of the project.
 void setCreateJarFlags(int f)
          Sets the create jar flags of the project.
 void setDocumentNavigator(IDocumentNavigator<OpenDefinitionsDocument> newnav)
           
 void setExcludedFiles(File[] fs)
          Sets the array of files excluded from the current project
 void setExtraClassPath(Iterable<File> cp)
          Sets the set of classpath entries to use as the projects set of classpath entries.
 void setFileGroupingState(FileGroupingState state)
           
 void setMainClass(File f)
          Sets the class with the project's main method.
 void setNumCompErrors(int num)
          throws UnsupportedOperationException
 void setPageFormat(PageFormat format)
           
 void setProjectChanged(boolean changed)
          Notifies the project state that the project has been changed.
 void setProjectFile(File f)
          Sets project file to specifed value; used in "Save Project As ..." command in MainFrame.
 void setProjectRoot(File f)
          Sets the class with the project's main method.
 void setWorkingDirectory(File f)
          Sets the working directory for the project; ignored in flat file model.
 void systemErrPrint(String s)
          Prints System.err to the DrJava console.
 void systemInEcho(String s)
          Prints to the DrJava console as an echo of System.in.
 void systemOutPrint(String s)
          Prints System.out to the DrJava console.
 void toggleBookmark(int pos1, int pos2)
          Toogle the specified bookmark in the active document.
 void waitForInterpreter()
          throw new UnsupportedOperationException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

public static final Log _log

DIFF_THRESHOLD

public static final int DIFF_THRESHOLD
See Also:
Constant Field Values

_cache

protected DocumentCache _cache
A document cache that manages how many unmodified documents are open at once.


_notifier

public final GlobalEventNotifier _notifier
Keeps track of all listeners to the model, and has the ability to notify them of some event. Originally used a Command Pattern style, but this has been replaced by having EventNotifier directly implement all listener interfaces it supports. Set in constructor so that subclasses can install their own notifier with additional methods.


_editorKit

protected final DefinitionsEditorKit _editorKit
Factory for new definitions documents and views.


_consoleDoc

protected final ConsoleDocument _consoleDoc
The document used to display System.out and System.err, and to read from System.in.


_consoleDocAdapter

protected final InteractionsDJDocument _consoleDocAdapter
The document adapter used in the console document.


WRITE_DELAY

public static final int WRITE_DELAY
Number of milliseconds to wait after each println, to prevent the JVM from being flooded with print calls. TODO: why is this here, and why is it public?

See Also:
Constant Field Values

_pageFormat

protected volatile PageFormat _pageFormat
A PageFormat object for printing to paper.


_documentNavigator

protected volatile IDocumentNavigator<OpenDefinitionsDocument> _documentNavigator
The abstract container which contains views of open documents and allows user to navigate document focus among this collection of open documents


_breakpointManager

protected final ConcreteRegionManager<Breakpoint> _breakpointManager
Manager for breakpoint regions.


_bookmarkManager

protected final ConcreteRegionManager<MovingDocumentRegion> _bookmarkManager
Manager for bookmark regions.


_findResultsManagers

protected final LinkedList<RegionManager<MovingDocumentRegion>> _findResultsManagers
Managers for find result regions.


_browserHistoryManager

protected final BrowserHistoryManager _browserHistoryManager
Manager for browser history regions.


_state

protected volatile FileGroupingState _state
Specifies the state of the navigator pane. The global model delegates the compileAll command to the _state, a FileGroupingState.nSynchronization is handled by the compilerModel.

Constructor Detail

AbstractGlobalModel

public AbstractGlobalModel()
Constructs a new GlobalModel. Creates a new MainJVM and starts its Interpreter JVM.

Method Detail

addAuxiliaryFile

public void addAuxiliaryFile(OpenDefinitionsDocument doc)
Adds a document to the list of auxiliary files. The LinkedList class is not thread safe, so the add operation is synchronized.

Specified by:
addAuxiliaryFile in interface GlobalModel

removeAuxiliaryFile

public void removeAuxiliaryFile(OpenDefinitionsDocument doc)
Removes a document from the list of auxiliary files. The LinkedList class is not thread safe, so operations on _auxiliaryFiles are synchronized.

Specified by:
removeAuxiliaryFile in interface GlobalModel

getNotifier

public GlobalEventNotifier getNotifier()
Notifier list for the global model.

Specified by:
getNotifier in interface GlobalModel

getBreakpointManager

public RegionManager<Breakpoint> getBreakpointManager()
Specified by:
getBreakpointManager in interface GlobalModel
Returns:
manager for breakpoint regions.

getBookmarkManager

public RegionManager<MovingDocumentRegion> getBookmarkManager()
Specified by:
getBookmarkManager in interface GlobalModel
Returns:
manager for bookmark regions.

getFindResultsManagers

public List<RegionManager<MovingDocumentRegion>> getFindResultsManagers()
Returns:
new copy of list of find results managers for find result regions.

createFindResultsManager

public RegionManager<MovingDocumentRegion> createFindResultsManager()
Specified by:
createFindResultsManager in interface GlobalModel
Returns:
new manager for find result regions.

removeFindResultsManager

public void removeFindResultsManager(RegionManager<MovingDocumentRegion> rm)
Remove a manager from the model.

Specified by:
removeFindResultsManager in interface GlobalModel

getBrowserHistoryManager

public BrowserHistoryManager getBrowserHistoryManager()
Specified by:
getBrowserHistoryManager in interface GlobalModel
Returns:
manager for browser history regions.

setFileGroupingState

public void setFileGroupingState(FileGroupingState state)
Parameters:
state - the new file grouping state.

makeProjectFileGroupingState

protected FileGroupingState makeProjectFileGroupingState(File pr,
                                                         File main,
                                                         File bd,
                                                         File wd,
                                                         File project,
                                                         File[] srcFiles,
                                                         File[] auxFiles,
                                                         File[] excludedFiles,
                                                         Iterable<File> cp,
                                                         File cjf,
                                                         int cjflags,
                                                         boolean refresh)

isClassPathChanged

public boolean isClassPathChanged()
Returns:
true if the class path state has been changed.

setClassPathChanged

public void setClassPathChanged(boolean changed)
Updates the classpath state.


setProjectChanged

public void setProjectChanged(boolean changed)
Notifies the project state that the project has been changed.

Specified by:
setProjectChanged in interface GlobalModel

isProjectChanged

public boolean isProjectChanged()
Description copied from interface: GlobalModel
Returns true if the project state has been changed

Specified by:
isProjectChanged in interface GlobalModel
Returns:
true if the project state has been changed.

isProjectActive

public boolean isProjectActive()
Specified by:
isProjectActive in interface GlobalModel
Returns:
true if the model has a project open, false otherwise.

getProjectFile

public File getProjectFile()
Specified by:
getProjectFile in interface GlobalModel
Returns:
the file that points to the current project file. Null if not currently in project view

getProjectFiles

public File[] getProjectFiles()
Specified by:
getProjectFiles in interface GlobalModel
Returns:
all files currently saved as source files in the project file. If _state not in project mode, returns null

inProject

public boolean inProject(File f)
Description copied from interface: GlobalModel
Returns true the given file is in the current project file.

Specified by:
inProject in interface GlobalModel
Returns:
true the given file is in the current project file.

inProjectPath

public boolean inProjectPath(OpenDefinitionsDocument doc)
A file is in the project if the source root is the same as the project root. this means that project files must be saved at the source root. (we query the model through the model's state)

Specified by:
inProjectPath in interface GlobalModel

setMainClass

public void setMainClass(File f)
Sets the class with the project's main method.

Specified by:
setMainClass in interface GlobalModel

getMainClass

public File getMainClass()
Description copied from interface: GlobalModel
Return the main file for the project If not in project mode, returns null.

Specified by:
getMainClass in interface GlobalModel
Returns:
the class with the project's main method.

setCreateJarFile

public void setCreateJarFile(File f)
Sets the create jar file of the project.

Specified by:
setCreateJarFile in interface GlobalModel

getCreateJarFile

public File getCreateJarFile()
Return the create jar file for the project. If not in project mode, returns null.

Specified by:
getCreateJarFile in interface GlobalModel

setCreateJarFlags

public void setCreateJarFlags(int f)
Sets the create jar flags of the project.

Specified by:
setCreateJarFlags in interface GlobalModel

getCreateJarFlags

public int getCreateJarFlags()
Return the create jar flags for the project. If not in project mode, returns 0.

Specified by:
getCreateJarFlags in interface GlobalModel

getProjectRoot

public File getProjectRoot()
Specified by:
getProjectRoot in interface GlobalModel
Returns:
the root of the project sourc tree (assuming one exists).

setProjectRoot

public void setProjectRoot(File f)
Sets the class with the project's main method. Degenerate version overridden in DefaultGlobalModel.

Specified by:
setProjectRoot in interface GlobalModel

setProjectFile

public void setProjectFile(File f)
Sets project file to specifed value; used in "Save Project As ..." command in MainFrame.

Specified by:
setProjectFile in interface GlobalModel

getBuildDirectory

public File getBuildDirectory()
Specified by:
getBuildDirectory in interface GlobalModel
Returns:
the build directory for the project (assuming one exists).

setBuildDirectory

public void setBuildDirectory(File f)
Sets the class with the project's main method. Degenerate version overridden in DefaultGlobalModel.

Specified by:
setBuildDirectory in interface GlobalModel

getAutoRefreshStatus

public boolean getAutoRefreshStatus()
Gets autorfresh status of the project

Specified by:
getAutoRefreshStatus in interface GlobalModel

setAutoRefreshStatus

public void setAutoRefreshStatus(boolean status)
Sets autofresh status of the project

Specified by:
setAutoRefreshStatus in interface GlobalModel

getMasterWorkingDirectory

public File getMasterWorkingDirectory()
Specified by:
getMasterWorkingDirectory in interface GlobalModel
Returns:
the working directory for the Master JVM (editor and GUI).

getWorkingDirectory

public File getWorkingDirectory()
Specified by:
getWorkingDirectory in interface GlobalModel
Returns:
the working directory for the Slave (Interactions) JVM

setWorkingDirectory

public void setWorkingDirectory(File f)
Sets the working directory for the project; ignored in flat file model.

Specified by:
setWorkingDirectory in interface GlobalModel

cleanBuildDirectory

public void cleanBuildDirectory()
Description copied from interface: GlobalModel
Cleans the build directory.

Specified by:
cleanBuildDirectory in interface GlobalModel

getClassFiles

public List<File> getClassFiles()
Specified by:
getClassFiles in interface GlobalModel
Returns:
a list of class files.

getPackageName

protected static String getPackageName(String classname)
Helper method used in subsequent anonymous inner class


makeFlatFileGroupingState

protected FileGroupingState makeFlatFileGroupingState()

getSourceBinTitle

public String getSourceBinTitle()
Gives the title of the source bin for the navigator.

Specified by:
getSourceBinTitle in interface GlobalModel
Returns:
The text used for the source bin in the tree navigator

getExternalBinTitle

public String getExternalBinTitle()
Gives the title of the external files bin for the navigator

Specified by:
getExternalBinTitle in interface GlobalModel
Returns:
The text used for the external files bin in the tree navigator.

getAuxiliaryBinTitle

public String getAuxiliaryBinTitle()
Gives the title of the aux files bin for the navigator.

Specified by:
getAuxiliaryBinTitle in interface GlobalModel
Returns:
The text used for the aux files bin in the tree navigator.

addListener

public void addListener(GlobalModelListener listener)
Add a listener to this global model.

Specified by:
addListener in interface GlobalModel
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.

Specified by:
removeListener in interface GlobalModel
Parameters:
listener - a listener that reacts on events generated by the GlobalModel This method is synchronized using the readers/writers event protocol incorporated in EventNotifier.

getEditorKit

public DefinitionsEditorKit getEditorKit()
Description copied from interface: GlobalModel
Fetches the EditorKit implementation for use in the definitions pane.

Specified by:
getEditorKit in interface GlobalModel

getInteractionsModel

public DefaultInteractionsModel getInteractionsModel()
throws UnsupportedOperationException

Specified by:
getInteractionsModel in interface GlobalModel

getSwingInteractionsDocument

public InteractionsDJDocument getSwingInteractionsDocument()
throws UnsupportedOperationException

Specified by:
getSwingInteractionsDocument in interface GlobalModel
Returns:
InteractionsDJDocument in use by the InteractionsDocument.

getInteractionsDocument

public InteractionsDocument getInteractionsDocument()
throws UnsupportedOperationException

Specified by:
getInteractionsDocument in interface GlobalModel

getConsoleDocument

public ConsoleDocument getConsoleDocument()
Description copied from interface: GlobalModel
Gets the console document.

Specified by:
getConsoleDocument in interface GlobalModel

getSwingConsoleDocument

public InteractionsDJDocument getSwingConsoleDocument()
Description copied from interface: GlobalModel
TODO: remove this swing dependency.

Specified by:
getSwingConsoleDocument in interface GlobalModel
Returns:
InteractionsDJDocument in use by the ConsoleDocument.

getPageFormat

public PageFormat getPageFormat()
Specified by:
getPageFormat in interface GlobalModel

setPageFormat

public void setPageFormat(PageFormat format)
Specified by:
setPageFormat in interface GlobalModel

getCompilerModel

public CompilerModel getCompilerModel()
Description copied from interface: GlobalModel
Gets the CompilerModel, which provides all methods relating to compilers.

Specified by:
getCompilerModel in interface GlobalModel

getNumCompErrors

public int getNumCompErrors()
throws UnsupportedOperationException

Specified by:
getNumCompErrors in interface GlobalModel

setNumCompErrors

public void setNumCompErrors(int num)
throws UnsupportedOperationException

Specified by:
setNumCompErrors in interface GlobalModel

getJUnitModel

public JUnitModel getJUnitModel()
throws UnsupportedOperationException

Specified by:
getJUnitModel in interface GlobalModel

getJavadocModel

public JavadocModel getJavadocModel()
throws UnsupportedOperationException

Specified by:
getJavadocModel in interface GlobalModel

getDocumentNavigator

public IDocumentNavigator<OpenDefinitionsDocument> getDocumentNavigator()
Description copied from interface: GlobalModel
Gets the DocumentNavigator, which controls the document view.

Specified by:
getDocumentNavigator in interface GlobalModel

setDocumentNavigator

public void setDocumentNavigator(IDocumentNavigator<OpenDefinitionsDocument> newnav)
Specified by:
setDocumentNavigator in interface GlobalModel

toggleBookmark

public void toggleBookmark(int pos1,
                           int pos2)
Toogle the specified bookmark in the active document.

Parameters:
pos1 - first selection position
pos2 - second selection position

_toggleBookmark

public void _toggleBookmark(int pos1,
                            int pos2)
Raw version of toggleBookmark. ASSUMES that read lock is already held

Parameters:
pos1 - first selection position
pos2 - second selection position

newFile

public OpenDefinitionsDocument newFile(File parentDir)
Creates a new open definitions document and adds it to the list. Public for testing purposes. Only runs in the event thread.

Returns:
The new open document

newFile

public OpenDefinitionsDocument newFile()
Creates a new document, adds it to the list of open documents, and sets it to be active.

Specified by:
newFile in interface GlobalModel
Returns:
The new open document

newTestCase

public OpenDefinitionsDocument newTestCase(String name,
                                           boolean makeSetUp,
                                           boolean makeTearDown)
Creates a new junit test case.

Specified by:
newTestCase in interface GlobalModel
Parameters:
name - the name of the new test case
makeSetUp - true iff an empty setUp() method should be included
makeTearDown - true iff an empty tearDown() method should be included
Returns:
the new open test case

getDocumentCache

public DocumentCache getDocumentCache()
This method is for use only by test cases.


openFile

public OpenDefinitionsDocument openFile(FileOpenSelector com)
                                 throws IOException,
                                        OperationCanceledException,
                                        AlreadyOpenException
Open a file and add it to the pool of definitions documents. The provided file selector chooses a file, and on a successful open, the fileOpened() event is fired. This method also checks if there was previously a single unchanged, untitled document open, and if so, closes it after a successful opening.

Specified by:
openFile in interface ILoadDocuments
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

openFileHelper

protected OpenDefinitionsDocument openFileHelper(FileOpenSelector com)
                                          throws IOException,
                                                 OperationCanceledException,
                                                 AlreadyOpenException
Throws:
IOException
OperationCanceledException
AlreadyOpenException

openFiles

public OpenDefinitionsDocument[] openFiles(FileOpenSelector com)
                                    throws IOException,
                                           OperationCanceledException,
                                           AlreadyOpenException
Open multiple files and add them to the pool of definitions documents. The provided file selector chooses a collection of files, and on successfully opening each file, the fileOpened() event is fired. This method also checks if there was previously a single unchanged, untitled document open, and if so, closes it after a successful opening.

Specified by:
openFiles in interface ILoadDocuments
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

openFilesHelper

protected OpenDefinitionsDocument[] openFilesHelper(FileOpenSelector com)
                                             throws IOException,
                                                    OperationCanceledException,
                                                    AlreadyOpenException
Throws:
IOException
OperationCanceledException
AlreadyOpenException

openFolder

public void openFolder(File dir,
                       boolean rec)
                throws IOException,
                       OperationCanceledException,
                       AlreadyOpenException
Opens all files in the specified folder dir and places them in the appropriate places in the document navigator. If "open folders recursively" is checked, this operation opens all files in the subtree rooted at dir.

Specified by:
openFolder in interface GlobalModel
Throws:
IOException
OperationCanceledException
AlreadyOpenException

getFilesInFolder

public File[] getFilesInFolder(File dir,
                               boolean rec)
                        throws IOException,
                               OperationCanceledException,
                               AlreadyOpenException
Throws:
IOException
OperationCanceledException
AlreadyOpenException

getNewFilesInProject

public File[] getNewFilesInProject()
gets files in the project source directory that are not accounted for in the project file.

Returns:
null if not in project mode

openNewFilesInProject

public void openNewFilesInProject()
Searches the source folder (recursively) for new files and opens them.


saveAllFiles

public void saveAllFiles(FileSaveSelector com)
                  throws IOException
Saves all open files, prompting for names if necessary. When prompting (i.e., untitled document), set that document as active.

Specified by:
saveAllFiles in interface GlobalModel
Parameters:
com - a FileSaveSelector
Throws:
IOException

saveAllFilesHelper

protected void saveAllFilesHelper(FileSaveSelector com)
                           throws IOException
Called by saveAllFiles in DefaultGlobalModel

Throws:
IOException

createNewProject

public void createNewProject(File projFile)
Creates a new FileGroupingState for specificed project file and default values for other properties.

Specified by:
createNewProject in interface GlobalModel
Parameters:
projFile - the new project file (which does not yet exist in the file system)

configNewProject

public void configNewProject()
                      throws IOException
Configures a new project (created by createNewProject) and writes it to disk; only runs in event thread.

Specified by:
configNewProject in interface GlobalModel
Throws:
IOException

_makeProjectProfile

public ProjectProfile _makeProjectProfile(File file,
                                          HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
                                   throws IOException
Writes the project profile augmented by usage info to specified file. Assumes DrJava is in project mode.

Parameters:
file - where to save the project
info -
Throws:
IOException

saveProject

public void saveProject(File file,
                        HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
                 throws IOException
Writes the project profile augmented by usage info to specified file. Assumes DrJava is in project mode.

Specified by:
saveProject in interface GlobalModel
Parameters:
file - where to save the project
info - Extra view-related information that should be included in the project file
Throws:
IOException

exportOldProject

public void exportOldProject(File file,
                             HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
                      throws IOException
Writes the project profile in the old project format. Assumes DrJava is in project mode.

Parameters:
file - where to save the project
Throws:
IOException

reloadProject

public void reloadProject(File file,
                          HashMap<OpenDefinitionsDocument,DocumentInfoGetter> info)
                   throws IOException
Description copied from interface: GlobalModel
Reloads a project without writing to disk.

Specified by:
reloadProject in interface GlobalModel
Parameters:
file - project file; does not actually get touched
Throws:
IOException

openProject

public void openProject(File projectFile)
                 throws IOException,
                        MalformedProjectFileException
Parses the given project file and loads it into the document navigator and resets interactions pane. Assumes preceding project, if any, has already been closed.

Specified by:
openProject in interface GlobalModel
Parameters:
projectFile - The project file to parse
Throws:
IOException
MalformedProjectFileException

autoRefreshProject

public void autoRefreshProject()
Perform an auto-refresh of the project, adding new source files to the project.


closeProject

public void closeProject(boolean suppressReset)
Performs any needed operations on the model after project files have been closed. This method is not responsible for closing any files; both the files in the project and the project file have already been closed (by MainFrame._closeProject()). Resets interations unless suppressReset is true.

Specified by:
closeProject in interface GlobalModel

aboutToSaveFromSaveAll

public void aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
If the document is untitled, brings it to the top so that the user will know which is being saved.


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. Also ensures the invariant that there is always at least one open document holds by creating a new file if necessary.

Specified by:
closeFile in interface GlobalModel
Returns:
true if the document was closed

closeAllFiles

public boolean closeAllFiles()
Attempts to close all open documents. Also ensures the invariant that there is always at least one open document holds by creating a new file if necessary. Resets interactions iff operation succeeds.

Specified by:
closeAllFiles in interface GlobalModel
Returns:
true if all documents were closed

closeFiles

public boolean closeFiles(List<OpenDefinitionsDocument> docs)
This function closes a group of files assuming that the files are contiguous in the enumeration provided by the document navigator. This assumption is used in selecting which remaining document (if any) to activate.

The corner cases in which the file that is being closed had been externally deleted have been addressed in a few places, namely DefaultGlobalModel.canAbandonFile() and MainFrame.ModelListener.canAbandonFile(). If the DefinitionsDocument for the OpenDefinitionsDocument being closed is not in the cache (see model.cache.DocumentCache) then it is closed without prompting the user to save it. If it is in the cache, then we can successfully notify the user that the file is selected for closing and ask whether to saveAs, close, or cancel.

Specified by:
closeFiles in interface SingleDisplayModel
Parameters:
docs - the list od OpenDefinitionsDocuments to close
Returns:
whether all files were closed

closeFileHelper

protected boolean closeFileHelper(OpenDefinitionsDocument doc)
Helper for closeFile. This method was the closeFile(...) method before projects were added to DrJava.


closeFileWithoutPrompt

public boolean closeFileWithoutPrompt(OpenDefinitionsDocument doc)
Closes an open definitions document, without prompting to save if the document has been changed. Returns whether the file was successfully closed. NOTE: This method should not be called unless it can be absolutely known that the document being closed is not the active document. The closeFile() method in SingleDisplayModel ensures that a new active document is set, but closeFileWithoutPrompt does not.

Specified by:
closeFileWithoutPrompt in interface GlobalModel
Returns:
true if the document was closed.

closeAllFilesOnQuit

public boolean closeAllFilesOnQuit()
Closes all open documents. This operation can be cancelled by the user since it checks if all files can be abandoned BEFORE it actually modifies the project state.

Specified by:
closeAllFilesOnQuit in interface SingleDisplayModel
Returns:
false if the user cancelled

quit

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

Specified by:
quit in interface GlobalModel

forceQuit

public void forceQuit()
Halts the program immediately.

Specified by:
forceQuit in interface GlobalModel

dispose

public void dispose()
Prepares this model to be thrown away. Never called outside of tests. This version ignores the slave JVM.

Specified by:
dispose in interface SingleDisplayModel

disposeExternalResources

public void disposeExternalResources()
Disposes of external resources. This is a no op in AbstractGlobalModel.

Specified by:
disposeExternalResources in interface SingleDisplayModel

getDocumentForFile

public OpenDefinitionsDocument getDocumentForFile(File file)
                                           throws IOException
Gets the document for the specified file; may involve opening the file.

Specified by:
getDocumentForFile in interface GlobalModel
Parameters:
file - File contained by the document to be returned
Returns:
OpenDefinitionsDocument containing file
Throws:
IOException

isAlreadyOpen

public boolean isAlreadyOpen(File file)
Iterates over OpenDefinitionsDocuments, looking for this file. TODO: This is not very efficient!


getODDForDocument

public OpenDefinitionsDocument getODDForDocument(AbstractDocumentInterface doc)
Returns the OpenDefinitionsDocument corresponding to the INavigatorItem/DefinitionsDocument passed in.

Specified by:
getODDForDocument in interface GlobalModel
Parameters:
doc - the searched for Document
Returns:
its corresponding OpenDefinitionsDocument

getDocumentIterator

public DocumentIterator getDocumentIterator()
Gets a DocumentIterator to allow navigating through open Swing Documents.

Specified by:
getDocumentIterator in interface GlobalModel

getNextDocument

public OpenDefinitionsDocument getNextDocument(OpenDefinitionsDocument d)
Returns the ODD preceding the given document in the document list.

Specified by:
getNextDocument in interface DocumentIterator
Parameters:
d - the current Document
Returns:
the next Document

getPrevDocument

public OpenDefinitionsDocument getPrevDocument(OpenDefinitionsDocument d)
Returns the ODD preceding the given document in the document list.

Specified by:
getPrevDocument in interface DocumentIterator
Parameters:
d - the current Document
Returns:
the previous Document

getDocumentCount

public int getDocumentCount()
Description copied from interface: GlobalModel
Returns the document count

Specified by:
getDocumentCount in interface GlobalModel
Specified by:
getDocumentCount in interface DocumentIterator
Returns:
the size of the collection of OpenDefinitionsDocuments

getOpenDefinitionsDocuments

public List<OpenDefinitionsDocument> getOpenDefinitionsDocuments()
Returns a new collection of all documents currently open for editing. This is equivalent to the results of getDocumentForFile for the set of all files for which isAlreadyOpen returns true.

Specified by:
getOpenDefinitionsDocuments in interface GlobalModel
Returns:
a random-access List of the open definitions documents..

getSortedOpenDefinitionsDocuments

public List<OpenDefinitionsDocument> getSortedOpenDefinitionsDocuments()

hasOutOfSyncDocuments

public boolean hasOutOfSyncDocuments()
Specified by:
hasOutOfSyncDocuments in interface GlobalModel
Returns:
true if all open documents are in sync with their primary class files.

hasOutOfSyncDocuments

public boolean hasOutOfSyncDocuments(List<OpenDefinitionsDocument> lod)
Specified by:
hasOutOfSyncDocuments in interface GlobalModel
Returns:
true iff no document in given list is out of sync with its primary class file.

resetInteractions

public void resetInteractions(File wd)
A degenerate operation since this has no slave JVM and no interactions model.

Specified by:
resetInteractions in interface GlobalModel

resetInteractions

public void resetInteractions(File wd,
                              boolean forceReset)
A degenerate operation since this has no slave JVM and no interactions model.

Specified by:
resetInteractions in interface GlobalModel

resetConsole

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

Specified by:
resetConsole in interface GlobalModel

interpretCurrentInteraction

public void interpretCurrentInteraction()
throw new UnsupportedOperationException

Specified by:
interpretCurrentInteraction in interface GlobalModel

loadHistory

public void loadHistory(FileOpenSelector selector)
                 throws IOException
throws UnsupportedOperationException

Specified by:
loadHistory in interface GlobalModel
Throws:
IOException

loadHistoryAsScript

public InteractionsScriptModel loadHistoryAsScript(FileOpenSelector selector)
                                            throws IOException,
                                                   OperationCanceledException
throws UnsupportedOperationException

Specified by:
loadHistoryAsScript in interface GlobalModel
Throws:
IOException
OperationCanceledException

clearHistory

public void clearHistory()
throws UnsupportedOperationException

Specified by:
clearHistory in interface GlobalModel

saveHistory

public void saveHistory(FileSaveSelector selector)
                 throws IOException
throws UnsupportedOperationException

Specified by:
saveHistory in interface GlobalModel
Parameters:
selector - File to save to
Throws:
IOException

saveHistory

public void saveHistory(FileSaveSelector selector,
                        String editedVersion)
                 throws IOException
throws UnsupportedOperationException

Specified by:
saveHistory in interface GlobalModel
Parameters:
selector - File to save to
editedVersion - Edited verison of the history which will be saved to file instead of the lines saved in the history. The saved file will still include any tags needed to recognize it as a saved interactions file.
Throws:
IOException

getHistoryAsStringWithSemicolons

public String getHistoryAsStringWithSemicolons()
Returns the entire history as a String with semicolons as needed.

Specified by:
getHistoryAsStringWithSemicolons in interface GlobalModel

getHistoryAsString

public String getHistoryAsString()
Throws UnsupportedOperationException

Specified by:
getHistoryAsString in interface GlobalModel

_docAppend

protected void _docAppend(ConsoleDocument doc,
                          String s,
                          String style)
Appends a string to the given document using a particular attribute set. Also waits for a small amount of time (WRITE_DELAY) to prevent any one writer from flooding the model with print calls to the point that the user interface could become unresponsive. Only runs in event thread.

Parameters:
doc - Document to append to
s - String to append to the end of the document
style - the style to print with

systemOutPrint

public void systemOutPrint(String s)
Prints System.out to the DrJava console. This method can safely be run outside the event thread.

Specified by:
systemOutPrint in interface GlobalModel

systemErrPrint

public void systemErrPrint(String s)
Prints System.err to the DrJava console. This method can safely be run outside the event thread.

Specified by:
systemErrPrint in interface GlobalModel

systemInEcho

public void systemInEcho(String s)
Prints to the DrJava console as an echo of System.in. This method can safely be run outside the event thread.

Specified by:
systemInEcho in interface GlobalModel

printDebugMessage

public void printDebugMessage(String s)
throws UnsupportedOperationException

Specified by:
printDebugMessage in interface GlobalModel

waitForInterpreter

public void waitForInterpreter()
throw new UnsupportedOperationException

Specified by:
waitForInterpreter in interface GlobalModel

getInteractionsClassPath

public Iterable<File> getInteractionsClassPath()
throws new UnsupportedOperationException

Specified by:
getInteractionsClassPath in interface GlobalModel

getExtraClassPath

public Iterable<File> getExtraClassPath()
Returns a project's extra classpaths; empty for FlatFileGroupingState

Specified by:
getExtraClassPath in interface GlobalModel
Returns:
The classpath entries loaded along with the project

setExtraClassPath

public void setExtraClassPath(Iterable<File> cp)
Sets the set of classpath entries to use as the projects set of classpath entries. This is normally used by the project preferences..

Specified by:
setExtraClassPath in interface GlobalModel

getExclFiles

public File[] getExclFiles()
Return an array of the files excluded from the current project

Specified by:
getExclFiles in interface SingleDisplayModel

setExcludedFiles

public void setExcludedFiles(File[] fs)
Sets the array of files excluded from the current project

Specified by:
setExcludedFiles in interface SingleDisplayModel

getSourceRootSet

public Iterable<File> getSourceRootSet()
Gets an array of all sourceRoots for the open definitions documents, without duplicates.

Specified by:
getSourceRootSet in interface GlobalModel

getDebugger

public Debugger getDebugger()
throws UnsupportedOperationException

Specified by:
getDebugger in interface GlobalModel

getDebugPort

public int getDebugPort()
                 throws IOException
throws UnsupportedOperationException

Specified by:
getDebugPort in interface GlobalModel
Throws:
IOException - if unable to get a valid port number.

hasModifiedDocuments

public boolean hasModifiedDocuments()
Checks if any open definitions documents have been modified since last being saved.

Specified by:
hasModifiedDocuments in interface GlobalModel
Returns:
whether any documents have been modified

hasModifiedDocuments

public boolean hasModifiedDocuments(List<OpenDefinitionsDocument> lod)
Checks if any given documents have been modified since last being saved.

Specified by:
hasModifiedDocuments in interface GlobalModel
Returns:
whether any documents have been modified

hasUntitledDocuments

public boolean hasUntitledDocuments()
Checks if any open definitions documents are untitled.

Specified by:
hasUntitledDocuments in interface GlobalModel
Returns:
whether any documents are untitled

getSourceFile

public File getSourceFile(String fileName)
Searches for a file with the given name on the current source roots and the augmented classpath.

Specified by:
getSourceFile in interface GlobalModel
Parameters:
fileName - name of the source file to look for
Returns:
the file corresponding to the given name, or null if it cannot be found

findFileInPaths

public File findFileInPaths(String fileName,
                            Iterable<File> paths)
Searches for a file with the given name on the provided paths. Returns NULL_FILE if the file is not found.

Specified by:
findFileInPaths in interface GlobalModel
Parameters:
fileName - Name of the source file to look for
paths - An array of directories to search
Returns:
the file if it is found, or null otherwise

addToBrowserHistory

public void addToBrowserHistory()
Add the current location to the browser history. Only runs in event thread. Assumes that doc is not null.

Specified by:
addToBrowserHistory in interface GlobalModel

getClassPath

public Iterable<File> getClassPath()
throws an UnsupportedOperationException

Specified by:
getClassPath in interface GlobalModel

isUntitled

public static boolean isUntitled(File f)

_createOpenDefinitionsDocument

protected edu.rice.cs.drjava.model.AbstractGlobalModel.ConcreteOpenDefDoc _createOpenDefinitionsDocument(NullFile f)
Creates a ConcreteOpenDefDoc for a NullFile object f (corresponding to a new empty document)

Returns:
OpenDefinitionsDocument object for a new document

_createOpenDefinitionsDocument

protected edu.rice.cs.drjava.model.AbstractGlobalModel.ConcreteOpenDefDoc _createOpenDefinitionsDocument(File f)
                                                                                                  throws IOException
Creates a ConcreteOpenDefDoc for an existing file f.

Returns:
OpenDefinitionsDocument object for f
Throws:
FileNotFoundException - if file f does not exist
IOException

_getOpenDocument

protected OpenDefinitionsDocument _getOpenDocument(File file)
Returns the OpenDefinitionsDocument corresponding to the given File, or null if that file is not open.

Parameters:
file - File object to search for
Returns:
Corresponding OpenDefinitionsDocument, or null

getNonProjectDocuments

public List<OpenDefinitionsDocument> getNonProjectDocuments()
Returns the OpenDefinitionsDocuments that are NOT identified as project source files.

Specified by:
getNonProjectDocuments in interface GlobalModel

getAuxiliaryDocuments

public List<OpenDefinitionsDocument> getAuxiliaryDocuments()
Returns the OpenDefinitionsDocuments that are identified as auxiliary project source files.

Specified by:
getAuxiliaryDocuments in interface GlobalModel

getProjectDocuments

public List<OpenDefinitionsDocument> getProjectDocuments()
Returns the OpenDefinitionsDocuments that are identified as project source files.

Specified by:
getProjectDocuments in interface GlobalModel

fixPathForNavigator

public String fixPathForNavigator(String path)
                           throws IOException
Description copied from interface: GlobalModel
Formats a string pathname for use in the document navigator.

Specified by:
fixPathForNavigator in interface GlobalModel
Throws:
IOException

pop

protected static <T> T pop(ArrayList<T> stack)
This pop method enables an ArrayList to serve as stack.


addDocToNavigator

protected void addDocToNavigator(OpenDefinitionsDocument doc)
Creates an iNavigatorItem for a document, and adds it to the navigator. A helper for opening a file or creating a new file.

Parameters:
doc - the document to add to the navigator

addDocToClassPath

protected void addDocToClassPath(OpenDefinitionsDocument doc)
Add a document to the classpath for the slave JVM. Does nothing here because there is no slave JVM. Overridden in DefaultGlobalModel.


_openFile

public OpenDefinitionsDocument _openFile(File file)
                                  throws IOException,
                                         AlreadyOpenException
Creates a document from a file.

Parameters:
file - File to read document from
Returns:
openened document
Throws:
IOException
AlreadyOpenException

getActiveDocument

public OpenDefinitionsDocument getActiveDocument()
Returns the currently active document.

Specified by:
getActiveDocument in interface SingleDisplayModel
Returns:
the currently active document.

setActiveDocument

public void setActiveDocument(OpenDefinitionsDocument doc)
Sets the currently active document by updating the selection model.

Specified by:
setActiveDocument in interface SingleDisplayModel
Parameters:
doc - Document to set as active

getDocCollectionWidget

public Container getDocCollectionWidget()
Specified by:
getDocCollectionWidget in interface SingleDisplayModel
Returns:
the IDocumentNavigator container expressed as an AWT component.

setActiveNextDocument

public void setActiveNextDocument()
Sets the active document to be the next one in the collection.

Specified by:
setActiveNextDocument in interface SingleDisplayModel

setActivePreviousDocument

public void setActivePreviousDocument()
Sets the active document to be the previous one in the collection.

Specified by:
setActivePreviousDocument in interface SingleDisplayModel

setActiveFirstDocument

public void setActiveFirstDocument()
Selects the first document as the active document.

Specified by:
setActiveFirstDocument in interface SingleDisplayModel

installActiveDocument

public void installActiveDocument()
Invokes the activeDocumentChanged method in the global listener on the argument _activeDocument. This process sets up _activeDocument as the document in the definitions pane.


refreshActiveDocument

public void refreshActiveDocument()
Makes the active document (in this model) the selection in the documentNavigator and invokes the activedocumentRefreshed method in the global listener on this document. The latter process refreshes the state of the _activeDocument as the document in the definitions pane.

Specified by:
refreshActiveDocument in interface GlobalModel
Specified by:
refreshActiveDocument in interface SingleDisplayModel