|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.rice.cs.drjava.model.DefaultGlobalModel | +--edu.rice.cs.drjava.ui.SingleDisplayModel
A GlobalModel that enforces invariants associated with having one active document at a time. Invariants:
DefaultGlobalModel.getDefinitionsDocuments()
will always return an array of
at least size 1.
getActiveDocument()
and setActiveDocument(edu.rice.cs.drjava.model.OpenDefinitionsDocument)
.
openFile(edu.rice.cs.drjava.model.FileOpenSelector)
, if there is currently only one open
document, and it is untitled and unchanged, it will be closed after the
new document is opened. This means that, in one atomic transaction, the
model goes from having one totally empty document open to having one
document (the requested one) open.
Inner Class Summary | |
private class |
SingleDisplayModel.SelectionModelListener
Listens to the selection model for the open documents. |
Inner classes inherited from class edu.rice.cs.drjava.model.DefaultGlobalModel |
DefaultGlobalModel.DefinitionsDocumentHandler, DefaultGlobalModel.EventNotifier, DefaultGlobalModel.EventPoller, DefaultGlobalModel.ExtraClasspathOptionListener |
Field Summary | |
private OpenDefinitionsDocument |
_activeDocument
The active document pointer, which will never be null once the constructor is done. |
private boolean |
_isClosingAllDocs
Denotes whether the model is currently trying to close all documents, and thus that a new one should not be created. |
private ListSelectionModel |
_selectionModel
Keeps track of the currently selected document in the list model. |
Constructor Summary | |
SingleDisplayModel(DefaultGlobalModel other)
Creates a SingleDisplayModel using the Interactions JVM from the given model. |
|
SingleDisplayModel(int rmiPort)
Creates a SingleDisplayModel. |
Method Summary | |
private void |
_ensureNotEmpty()
Creates a new document if there are currently no documents open. |
private int |
_getDocumentIndex(OpenDefinitionsDocument doc)
Returns the index of the first occurrence of the specified document in the list of open documents, or -1 if it is not found. |
private boolean |
_hasOneEmptyDocument()
Returns whether there is currently only one open document which is untitled and unchanged. |
private void |
_init()
Initiates this SingleDisplayModel. |
private void |
_setActiveDoc(int index)
Actually set the activeDocument field to the document at the given index, and fire an activeDocumentChanged event. |
void |
aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
If the document is untitled, brings it to the top so that the user will know which file she is saving |
void |
addListener(GlobalModelListener listener)
Add a listener to this global model. |
boolean |
closeAllFiles()
Attempts to close all open documents. |
boolean |
closeFile(OpenDefinitionsDocument doc)
Closes an open definitions document, prompting to save if the document has been changed. |
OpenDefinitionsDocument |
getActiveDocument()
Returns the currently active document. |
String |
getDisplayFilename(OpenDefinitionsDocument doc)
Return the name of the file, or "(untitled)" if no file exists. |
String |
getDisplayFullPath(int index)
Return the absolute path of the file with the given index, or "(untitled)" if no file exists. |
String |
getDisplayFullPath(OpenDefinitionsDocument doc)
Return the absolute path of the file, or "(untitled)" if no file exists. |
ListSelectionModel |
getDocumentSelectionModel()
Returns the selection model for the list of documents. |
boolean |
isClosingAllFiles()
Returns whether we are in the process of closing all documents. |
OpenDefinitionsDocument |
newFile()
Creates a new document, adds it to the list of open documents, and sets it to be active. |
OpenDefinitionsDocument |
openFile(FileOpenSelector com)
Open a file and read it into the definitions. |
OpenDefinitionsDocument |
openFiles(FileOpenSelector com)
Open multiple files and read it into the definitions. |
void |
saveAllFiles(FileSaveSelector com)
Saves all open files, prompting for names if necessary. |
void |
setActiveDocument(int index)
Sets the currently active document by updating the selection model. |
void |
setActiveDocument(OpenDefinitionsDocument doc)
Sets the currently active document by updating the selection model. |
void |
setNextActiveDocument()
Sets the active document to be the next one in the list. |
void |
setPreviousActiveDocument()
Sets the active document to be the previous one in the list. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
Field Detail |
private OpenDefinitionsDocument _activeDocument
private ListSelectionModel _selectionModel
private boolean _isClosingAllDocs
Constructor Detail |
public SingleDisplayModel(int rmiPort)
rmiPort
- The port on which to run the RMI registry,
or -1 for a unique port.public SingleDisplayModel(DefaultGlobalModel other)
other
- A model with a valid Interactions JVM to use.Method Detail |
private void _init()
public OpenDefinitionsDocument getActiveDocument()
public void setActiveDocument(OpenDefinitionsDocument doc)
doc
- Document to set as activepublic void setActiveDocument(int index)
index
- Index of active document in the list of documents.public ListSelectionModel getDocumentSelectionModel()
public void setNextActiveDocument()
public void setPreviousActiveDocument()
public String getDisplayFilename(OpenDefinitionsDocument doc)
public String getDisplayFullPath(OpenDefinitionsDocument doc)
public String getDisplayFullPath(int index)
public void addListener(GlobalModelListener listener)
addListener
in class DefaultGlobalModel
listener
- a listener that reacts on events generated by the GlobalModelpublic OpenDefinitionsDocument newFile()
newFile
in class DefaultGlobalModel
public OpenDefinitionsDocument openFile(FileOpenSelector com) throws IOException, OperationCanceledException, AlreadyOpenException
openFile
in class DefaultGlobalModel
com
- a command pattern command that selects what file
to openIOException
- OperationCanceledException
- if the open was canceledAlreadyOpenException
- if the file is already openpublic OpenDefinitionsDocument openFiles(FileOpenSelector com) throws IOException, OperationCanceledException, AlreadyOpenException
openFiles
in class DefaultGlobalModel
com
- a command pattern command that selects what file
to openIOException
- OperationCanceledException
- if the open was canceledAlreadyOpenException
- if the file is already openpublic void saveAllFiles(FileSaveSelector com) throws IOException
saveAllFiles
in class DefaultGlobalModel
com
- a FileSaveSelectorIOException
- public void aboutToSaveFromSaveAll(OpenDefinitionsDocument doc)
aboutToSaveFromSaveAll
in class DefaultGlobalModel
edu.rice.cs.drjava.model.DefaultGlobalModel
doc
- the document which is about to be saved by a save all
commandpublic boolean closeFile(OpenDefinitionsDocument doc)
closeFile
in class DefaultGlobalModel
public boolean closeAllFiles()
closeAllFiles
in class DefaultGlobalModel
public boolean isClosingAllFiles()
private int _getDocumentIndex(OpenDefinitionsDocument doc)
private boolean _hasOneEmptyDocument()
private void _ensureNotEmpty()
private void _setActiveDoc(int index)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |