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 void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this document.void
close()
Close the document.Application
getApplication()
Get the application that this document belongs to.javax.swing.undo.UndoableEditSupport
getEditSupport()
Return the undoable edit support.java.io.File
getFile()
Get the file object that this document is associated with.java.lang.String
getShortTitle()
Get the short title of this document.java.lang.String
getTitle()
Get the title of this document.javax.swing.undo.UndoManager
getUndoManager()
Return the undo manager of this document.java.net.URL
getURL()
Get the URL that this document is associated with.boolean
isDirty()
Test the "dirty" flag.boolean
isEditable()
Test the "editable" flag.boolean
isWritable()
Test the "writable" flag.abstract void
open()
Open the document from its current file or URL.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this document.abstract void
save()
Save the document to its current file or URL.abstract void
saveAs(java.io.File file)
Save the document to the given file.abstract void
saveAs(java.net.URL url)
Save the document to the given file.void
setDirty(boolean flag)
Set the "dirty" flag.void
setEditable(boolean flag)
Set the "editable" flag.void
setFile(java.io.File file)
Set the file that this document saves itself to.void
setURL(java.net.URL url)
Set the URL that this document saves itself to.void
setWritable(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:
addPropertyChangeListener
in interfaceDocument
-
getEditSupport
public javax.swing.undo.UndoableEditSupport getEditSupport()
Return the undoable edit support. You need this to post edits.- Specified by:
getEditSupport
in interfaceDocument
-
getUndoManager
public javax.swing.undo.UndoManager getUndoManager()
Return the undo manager of this document.- Specified by:
getUndoManager
in interfaceDocument
-
close
public void close() throws java.lang.Exception
Close 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:
getApplication
in 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:
getShortTitle
in 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:
isEditable
in 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:
isWritable
in interfaceDocument
-
open
public abstract void open() throws java.lang.Exception
Open 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:
removePropertyChangeListener
in interfaceDocument
-
save
public abstract void save() throws java.lang.Exception
Save 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.Exception
Save 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.Exception
Save 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:
setEditable
in 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:
setWritable
in interfaceDocument
-
-