diva.graph.schematic
Class GraphDocument

java.lang.Object
  extended by diva.gui.AbstractDocument
      extended by diva.graph.schematic.GraphDocument
All Implemented Interfaces:
Document

public class GraphDocument
extends AbstractDocument

A class representing graph-structured documents. This class can read files to construct an instance of GraphModel, and write a GraphModel out to a file.

This is one of two classes that must be provided to produce a complete application using the diva.gui framework. (The other is diva.gui.Application -- see the CanvasDemo class.) Generally, the easiest way to implement diva.gui.Document is to extend diva.gui.AbstractDocument.

This class implements those methods that are left abstract in diva.gui.AbstractDocument. This is a set of methods that deal with loading the document from a file or URL and vice versa, such as close(), open(), save(), and saveAs(). These methods simply implement the "raw" functionality implied by the method names; they do not perform functions such as querying the user for whether to save a file before closing. (That function is performed by an instance of diva.gui.StoragePolicy.)

To read and write canvas data, it uses the diva.util.xml utility package. In general, there is no need for applications to use the XML utilities; however, it does make it very simple and fast to construct a working application with complete file I/O. See the various method comments for further imformation.

Version:
$Revision: 1.5 $
Author:
John Reekie (johnr@eecs.berkeley.edu)

Nested Class Summary
static class GraphDocument.Factory
          GraphDocument.Factory is a factory for graph documents.
 
Constructor Summary
GraphDocument(Application a)
          Construct a graph document that is owned by the given application.
 
Method Summary
 void close()
          Close the document.
 BasicGraphModel getGraphModel()
          Get the graph data model.
 XmlDocument getXmlDocument()
          Get the XML document that contains the raw XML data.
 void open()
          Open the document from its current file.
 void save()
          Save the document to the current file.
 void saveAs(File file)
          Save the document to the given file.
 void saveAs(URL url)
          Save the document to the given file.
 void setGraphModel(BasicGraphModel m)
          Set the graph data model.
 String toString()
          Print information about the graph document
 
Methods inherited from class diva.gui.AbstractDocument
addPropertyChangeListener, getApplication, getEditSupport, getFile, getShortTitle, getTitle, getUndoManager, getURL, isDirty, isEditable, isWritable, removePropertyChangeListener, setDirty, setEditable, setFile, setURL, setWritable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphDocument

public GraphDocument(Application a)
Construct a graph document that is owned by the given application. It contains an empty BasicGraph as its data.

Method Detail

close

public void close()
           throws Exception
Close the document. This method doesn't do anything, as graph data doesn't change.

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

getGraphModel

public BasicGraphModel getGraphModel()
Get the graph data model.


getXmlDocument

public XmlDocument getXmlDocument()
Get the XML document that contains the raw XML data.


open

public void open()
          throws Exception
Open the document from its current file. If successful, create and remember a Graph model.

The implementation of this method uses the diva.xml package:

Specified by:
open in interface Document
Specified by:
open in class AbstractDocument
Throws:
Exception - If there is no file, or if the I/O operation failed.

save

public void save()
          throws Exception
Save the document to the current file. See the saveAs() method for more information.

Specified by:
save in interface Document
Specified by:
save in class AbstractDocument
Throws:
Exception - If there is no file, or if the I/O operation failed.

saveAs

public void saveAs(File file)
            throws Exception
Save the document to the given file. Note that this method does not change the file attribute to the new File object.

The implementation of this class uses the diva.util.xml package:

Specified by:
saveAs in interface Document
Specified by:
saveAs in class AbstractDocument
Throws:
Exception - If the I/O operation failed.
See Also:
AbstractDocument.save()

saveAs

public void saveAs(URL url)
            throws Exception
Save the document to the given file. This method uses diva.util.xml to do the work -- see the saveAs(File) method for more description. It will probably fail if the URL is not a file-based url.

Specified by:
saveAs in interface Document
Specified by:
saveAs in class AbstractDocument
Throws:
Exception - Always
See Also:
AbstractDocument.save()

setGraphModel

public void setGraphModel(BasicGraphModel m)
Set the graph data model.


toString

public String toString()
Print information about the graph document

Overrides:
toString in class Object


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