Package diva.gui

Class 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.
      • 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​(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 interface Document
      • getEditSupport

        public javax.swing.undo.UndoableEditSupport getEditSupport()
        Return the undoable edit support. You need this to post edits.
        Specified by:
        getEditSupport in interface Document
      • getUndoManager

        public javax.swing.undo.UndoManager getUndoManager()
        Return the undo manager of this document.
        Specified by:
        getUndoManager in interface Document
      • 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.
        Specified by:
        close in interface Document
        Throws:
        java.lang.Exception - If the close operation fails.
      • 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.
        Specified by:
        getFile in interface Document
        See Also:
        getURL()
      • 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 interface Document
      • getTitle

        public java.lang.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 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.
        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 java.lang.Exception
        Open the document from its current file or URL. Throw an exception if the operation failed.
        Specified by:
        open in interface Document
        Throws:
        java.lang.Exception - If the close operation fails.
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Remove a property change listener from this document.
        Specified by:
        removePropertyChangeListener in interface Document
      • 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.
        Specified by:
        save in interface Document
        Throws:
        java.lang.Exception - If the save operation fails.
      • 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.
        Specified by:
        saveAs in interface Document
        Throws:
        java.lang.Exception - If the save-as operation fails.
        See Also:
        save()
      • 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.
        Specified by:
        saveAs in interface Document
        Throws:
        java.lang.Exception - If the save-as operation fails.
        See Also:
        save()
      • 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.
        Specified by:
        setFile in interface Document
      • 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.
        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