diva.gui
Class AbstractDocument

java.lang.Object
  extended by diva.gui.AbstractDocument
All Implemented Interfaces:
Document
Direct Known Subclasses:
GraphDocument, MultipageDocument, TextDocument

public abstract class AbstractDocument
extends 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:
$Revision: 1.15 $
Author:
John Reekie (johnr@eecs.berkeley.edu)

Constructor Summary
AbstractDocument(Application a)
          Construct a document that is owned by the given application
 
Method Summary
 void addPropertyChangeListener(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.
 UndoableEditSupport getEditSupport()
          Return the undoable edit support.
 File getFile()
          Get the file object that this document is associated with.
 String getShortTitle()
          Get the short title of this document.
 String getTitle()
          Get the title of this document.
 UndoManager getUndoManager()
          Return the undo manager of this document.
 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(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(File file)
          Save the document to the given file.
abstract  void saveAs(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(File file)
          Set the file that this document saves itself to.
 void setURL(URL url)
          Set the URL that this document saves itself to.
 void setWritable(boolean flag)
          Set the "writable" flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDocument

public AbstractDocument(Application a)
Construct a document that is owned by the given application

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(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 interface Document

getEditSupport

public UndoableEditSupport getEditSupport()
Return the undoable edit support. You need this to post edits.

Specified by:
getEditSupport in interface Document

getUndoManager

public UndoManager getUndoManager()
Return the undo manager of this document.

Specified by:
getUndoManager in interface Document

close

public void close()
           throws 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 responsbility of the application, not the Document implementation. Return true if the operation was successful, otherwise false. In this base class do nothing.

Specified by:
close in interface Document
Throws:
Exception - If the close operation fails.

getApplication

public Application getApplication()
Get the application that this document belongs to.

Specified by:
getApplication in interface Document

getFile

public 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.

Specified by:
getFile in interface Document
See Also:
getURL()

getShortTitle

public String getShortTitle()
Get the short title of this document. By default this is the tail of the filename.

Specified by:
getShortTitle in interface Document

getTitle

public String getTitle()
Get the title of this document. By default it is equal to the file or URL path.

Specified by:
getTitle in interface Document

getURL

public 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.

Specified by:
getURL in interface Document
See Also:
getFile()

isDirty

public boolean isDirty()
Test the "dirty" flag. If changes made to a document haven't been saved, this flag is set to true.

Specified by:
isDirty in interface Document

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 interface Document

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 interface Document

open

public abstract void open()
                   throws Exception
Open the document from its current file or URL. Throw an exception if the operation failed.

Specified by:
open in interface Document
Throws:
Exception - If the close operation fails.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this document.

Specified by:
removePropertyChangeListener in interface Document

save

public abstract void save()
                   throws Exception
Save the document to its current file or URL. Throw an exception if the operation failed.

Specified by:
save in interface Document
Throws:
Exception - If the save operation fails.

saveAs

public abstract void saveAs(File file)
                     throws 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.

Specified by:
saveAs in interface Document
Throws:
Exception - If the save-as operation fails.
See Also:
save()

saveAs

public abstract void saveAs(URL url)
                     throws 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.

Specified by:
saveAs in interface Document
Throws:
Exception - If the save-as operation fails.
See Also:
save()

setFile

public void setFile(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.

Specified by:
setFile in interface Document

setURL

public void setURL(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.

Specified by:
setURL in interface Document

setEditable

public void setEditable(boolean flag)
Set the "editable" flag. Fire a property change event to registered listeners.

Specified by:
setEditable in interface Document

setDirty

public void setDirty(boolean flag)
Set the "dirty" flag. Fire a property change event to registered listeners.

Specified by:
setDirty in interface Document

setWritable

public void setWritable(boolean flag)
Set the "writable" flag. Fire a property change event to registered listeners.

Specified by:
setWritable in interface Document


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.