Package diva.gui
Class AbstractDocument
- java.lang.Object
-
- diva.gui.AbstractDocument
-
- All Implemented Interfaces:
Document
- Direct Known Subclasses:
MultipageDocument,TextDocument
public abstract class AbstractDocument extends java.lang.Object implements Document
An abstract implementation of the Document interface. This class implements the common elements of the Document abstraction, and takes care of listener notification for properties.- Version:
- $Id$
- Author:
- John Reekie
-
-
Constructor Summary
Constructors Constructor Description AbstractDocument(Application a)Construct a document that is owned by the given application
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add a property change listener to this document.voidclose()Close the document.ApplicationgetApplication()Get the application that this document belongs to.javax.swing.undo.UndoableEditSupportgetEditSupport()Return the undoable edit support.java.io.FilegetFile()Get the file object that this document is associated with.java.lang.StringgetShortTitle()Get the short title of this document.java.lang.StringgetTitle()Get the title of this document.javax.swing.undo.UndoManagergetUndoManager()Return the undo manager of this document.java.net.URLgetURL()Get the URL that this document is associated with.booleanisDirty()Test the "dirty" flag.booleanisEditable()Test the "editable" flag.booleanisWritable()Test the "writable" flag.abstract voidopen()Open the document from its current file or URL.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Remove a property change listener from this document.abstract voidsave()Save the document to its current file or URL.abstract voidsaveAs(java.io.File file)Save the document to the given file.abstract voidsaveAs(java.net.URL url)Save the document to the given file.voidsetDirty(boolean flag)Set the "dirty" flag.voidsetEditable(boolean flag)Set the "editable" flag.voidsetFile(java.io.File file)Set the file that this document saves itself to.voidsetURL(java.net.URL url)Set the URL that this document saves itself to.voidsetWritable(boolean flag)Set the "writable" flag.
-
-
-
Constructor Detail
-
AbstractDocument
public AbstractDocument(Application a)
Construct a document that is owned by the given application
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this document. Changes to certain elements of the state will cause all registered property listeners to be notified.- Specified by:
addPropertyChangeListenerin interfaceDocument
-
getEditSupport
public javax.swing.undo.UndoableEditSupport getEditSupport()
Return the undoable edit support. You need this to post edits.- Specified by:
getEditSupportin interfaceDocument
-
getUndoManager
public javax.swing.undo.UndoManager getUndoManager()
Return the undo manager of this document.- Specified by:
getUndoManagerin interfaceDocument
-
close
public void close() throws java.lang.ExceptionClose the document. Do not attempt to save the document first or do any other user-interface things like that. This method must never "fail." Note that actions such as querying the user to save a modified document and so on are the responsibility of the application, not the Document implementation. Return true if the operation was successful, otherwise false. In this base class do nothing.
-
getApplication
public Application getApplication()
Get the application that this document belongs to.- Specified by:
getApplicationin interfaceDocument
-
getFile
public java.io.File getFile()
Get the file object that this document is associated with. If the document has multiple file objects, then get the one that can be considered the "primary" one. This field may be null.
-
getShortTitle
public java.lang.String getShortTitle()
Get the short title of this document. By default this is the tail of the filename.- Specified by:
getShortTitlein interfaceDocument
-
getTitle
public java.lang.String getTitle()
Get the title of this document. By default it is equal to the file or URL path.
-
getURL
public java.net.URL getURL()
Get the URL that this document is associated with. If the document has multiple URL objects, then get the one that can be considered the "primary" one. This field may be null.
-
isDirty
public boolean isDirty()
Test the "dirty" flag. If changes made to a document haven't been saved, this flag is set to true.
-
isEditable
public boolean isEditable()
Test the "editable" flag. In general, editors should only allow a document's data to be changed if this flag is set. This flag is true by default.- Specified by:
isEditablein interfaceDocument
-
isWritable
public boolean isWritable()
Test the "writable" flag. In general, editors should only allow a document's data to be written to storage if this flag is set. This flag is true by default.- Specified by:
isWritablein interfaceDocument
-
open
public abstract void open() throws java.lang.ExceptionOpen the document from its current file or URL. Throw an exception if the operation failed.
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this document.- Specified by:
removePropertyChangeListenerin interfaceDocument
-
save
public abstract void save() throws java.lang.ExceptionSave the document to its current file or URL. Throw an exception if the operation failed.
-
saveAs
public abstract void saveAs(java.io.File file) throws java.lang.ExceptionSave the document to the given file. Return true if successful, false if not. Do not change the file attribute to the new File object as that is the responsibility of the application, which it will do according to its storage policy.
-
saveAs
public abstract void saveAs(java.net.URL url) throws java.lang.ExceptionSave the document to the given file. Throw an exception if the operation failed. Return true if successful, false if not. Do not change the file attribute to the new File object as that is the responsibility of the application, which it will do according to its storage policy.
-
setFile
public void setFile(java.io.File file)
Set the file that this document saves itself to. This is a low-level method and should only be used by storage policy classes. Fire a property change listener to registered listeners.
-
setURL
public void setURL(java.net.URL url)
Set the URL that this document saves itself to. This is a low-level method and should only be used by storage policy classes. Fire a property change listener to registered listeners.
-
setEditable
public void setEditable(boolean flag)
Set the "editable" flag. Fire a property change event to registered listeners.- Specified by:
setEditablein interfaceDocument
-
setDirty
public void setDirty(boolean flag)
Set the "dirty" flag. Fire a property change event to registered listeners.
-
setWritable
public void setWritable(boolean flag)
Set the "writable" flag. Fire a property change event to registered listeners.- Specified by:
setWritablein interfaceDocument
-
-