JGraphpad Pro
v6.0.5.0


com.jgraph.editor
Class JGraphEditorModel

java.lang.Object
  extended byjavax.swing.tree.DefaultTreeModel
      extended bycom.jgraph.editor.JGraphEditorModel
All Implemented Interfaces:
Serializable, TreeModel

public class JGraphEditorModel
extends DefaultTreeModel

Default document model for JGraph editors. This class is in charge of preparing the bean info classes and has a map of persistence delegate for XML encoding. You should use the writeObject and readObject method of this class for file I/O to properly use the registered peristence delegates.
Note: The API refers to the children of the rootNodeas roots.

See Also:
Serialized Form

Field Summary
protected  Map persistenceDelegates
          Holds the (class, persistence delegate) pairs.
protected  DefaultMutableTreeNode rootNode
          Reference to the mutable root node.
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Constructor Summary
JGraphEditorModel()
          Constructs a new JGraph editor model adding persistence delegates for the DefaultGraphModel, GraphLayoutCache and DefaultEdge.DefaultRouting classes.
 
Method Summary
 MutableTreeNode addChild(MutableTreeNode child, MutableTreeNode parent)
          Adds the specified child to parent.
 Object addFile(String uri)
          Reads the specified URI and adds it as a root.
 Object addPersistenceDelegate(Class clazz, PersistenceDelegate delegate)
          Associates the specified persistence delegate with clazz for XML encoding.
 MutableTreeNode addRoot(MutableTreeNode node)
          Adds the specified root as a child to rootNode.
protected  void configureEncoder(XMLEncoder enc)
          Hook for subclassers to configure a new XML encoder for writing an object.
 JGraphEditorFile getFileByFilename(String filename)
          Returns the file for the specified filename if it is in the model or null if no such file exists.
 InputStream getInputStream(String uri)
          Hook for subclassers to create an input stream for the specified URI.
 OutputStream getOutputStream(String uri)
          Hook for subclassers to create an output stream for the specified URI.
static JGraphEditorFile getParentFile(TreeNode node)
          Returns the parent file for node or the node itself, if it is a file.
 PersistenceDelegate getPersistenceDelegate(Class clazz)
          Returns the associated persistence delegate for clazz or null if no association exists.
protected  void installDiagramListeners(JGraphEditorDiagram diagram)
          Installs the listeners required to update the modified state of the parent file node to diagram.
protected  void installListeners(TreeNode node)
          Hook for subclassers to install the required listeners in new tree nodes.
static void makeCellViewFieldsTransient(Class clazz)
          Makes all fields but cell and attributes transient in the bean info of clazz.
static void makeTransient(Class clazz, String field)
          Makes the specified field transient in the bean info of clazz.
 Object readFile(String uri)
          Reads the specified URI and returns the deserialized object.
 Object readObject(InputStream in)
          Returns a new object from the specified stream using a new XML decoder.
 Enumeration roots()
          Returns the first generation of childs, aka roots.
 void setFilename(JGraphEditorFile file, String filename)
          Sets the filename of the specified file and dispatches a notification event.
 void setModified(JGraphEditorFile file, boolean modified)
          Sets the modified state of the specified file and dispatches a notification event.
 void setName(JGraphEditorDiagram diagram, String name)
          Sets the name of the specified diagram and dispatches a notification event.
 void setUserObject(TreeNode node, Object userObject)
          Sets the user object of the specified node and dispatches a notification event.
 void writeObject(Object object, OutputStream out)
          Writes the specified object to the output stream using an xml encoder which was configured using configureEncoder(XMLEncoder).
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistenceDelegates

protected Map persistenceDelegates
Holds the (class, persistence delegate) pairs.


rootNode

protected DefaultMutableTreeNode rootNode
Reference to the mutable root node.

Constructor Detail

JGraphEditorModel

public JGraphEditorModel()
Constructs a new JGraph editor model adding persistence delegates for the DefaultGraphModel, GraphLayoutCache and DefaultEdge.DefaultRouting classes. This also adds a tree model listener to this model to update the modified state of parent files for child changes.

Method Detail

roots

public Enumeration roots()
Returns the first generation of childs, aka roots. This usually returns the documents and repositories, eg files that are currently open.

Returns:
Returns the children of rootNode.

addPersistenceDelegate

public Object addPersistenceDelegate(Class clazz,
                                     PersistenceDelegate delegate)
Associates the specified persistence delegate with clazz for XML encoding.

Parameters:
clazz - The class to associate the delegate with.
Returns:
Returns the previous delegate for clazz.

getPersistenceDelegate

public PersistenceDelegate getPersistenceDelegate(Class clazz)
Returns the associated persistence delegate for clazz or null if no association exists.

Parameters:
clazz - The clazz to return the delegate for.
Returns:
Returns the persistence delegate for clazz or null.

addRoot

public MutableTreeNode addRoot(MutableTreeNode node)
Adds the specified root as a child to rootNode. Calls installListeners(TreeNode)on the node.

Parameters:
node - The node to add to rootNode.
Returns:
Returns the node that has been added.

addChild

public MutableTreeNode addChild(MutableTreeNode child,
                                MutableTreeNode parent)
Adds the specified child to parent. Calls installListeners(TreeNode)on the child.

Parameters:
child - The node to add to parent.
parent - The parent to add child to.
Returns:
Returns the child that has been added.

readFile

public Object readFile(String uri)
                throws MalformedURLException,
                       IOException
Reads the specified URI and returns the deserialized object.

Parameters:
uri - The URI to read the object from.
Returns:
Returns the object stat was added.
Throws:
MalformedURLException
IOException

addFile

public Object addFile(String uri)
               throws MalformedURLException,
                      IOException
Reads the specified URI and adds it as a root.

Parameters:
uri - The URI to read the object from.
Returns:
Returns the object stat was added.
Throws:
MalformedURLException
IOException

installListeners

protected void installListeners(TreeNode node)
Hook for subclassers to install the required listeners in new tree nodes. This is invoked recursively for tree nodes and calls installDiagramListeners(JGraphEditorDiagram)on all diagrams that are found along the invocation chain.

Parameters:
node - The node to scan for diagrams.

installDiagramListeners

protected void installDiagramListeners(JGraphEditorDiagram diagram)
Installs the listeners required to update the modified state of the parent file node to diagram. This implementation adds a graph layout cache listener and a graph model listener.

Parameters:
diagram - The diagram to install the listeners to.

setUserObject

public void setUserObject(TreeNode node,
                          Object userObject)
Sets the user object of the specified node and dispatches a notification event.

Parameters:
node - The node to change the user object for.
userObject - The new user object.

setFilename

public void setFilename(JGraphEditorFile file,
                        String filename)
Sets the filename of the specified file and dispatches a notification event.

Parameters:
file - The file to change the filename for.
filename - The new filename.

setName

public void setName(JGraphEditorDiagram diagram,
                    String name)
Sets the name of the specified diagram and dispatches a notification event.

Parameters:
diagram - The diagram to change the name for.
name - The new name.

setModified

public void setModified(JGraphEditorFile file,
                        boolean modified)
Sets the modified state of the specified file and dispatches a notification event.

Parameters:
file - The file to change the modified state for.
modified - The new modified state.

getFileByFilename

public JGraphEditorFile getFileByFilename(String filename)
Returns the file for the specified filename if it is in the model or null if no such file exists.

Parameters:
filename - The filename to return the file for.
Returns:
Returns the file for filename or null.

writeObject

public void writeObject(Object object,
                        OutputStream out)
Writes the specified object to the output stream using an xml encoder which was configured using configureEncoder(XMLEncoder). The exceptions that are thrown during encoding are caught by a local handler and passed to the caller as a RuntimeException with description of the encoding problems.
Note: You should use this method as a global hook to write all XML files.

Parameters:
object - The object to be written.
out - The output strem to write to.
Throws:
RuntimeException - If there are problems during encoding.

configureEncoder

protected void configureEncoder(XMLEncoder enc)
Hook for subclassers to configure a new XML encoder for writing an object. This implementation sets all registered persistence delegates and installs default mappings for classes (eg. it assigns the list persistence delegates to array lists).

Parameters:
enc - The encoder to be configured.

getInputStream

public InputStream getInputStream(String uri)
                           throws MalformedURLException,
                                  FileNotFoundException,
                                  IOException
Hook for subclassers to create an input stream for the specified URI. This implementation creates an input stream using JGraphEditorResources.getInputStream(String) and wraps it in a GZIPInputStream if the URI ends with .gz.

Parameters:
uri - The URI to return the input stream for.
Returns:
Return an input stream for the specified URI.
Throws:
MalformedURLException
FileNotFoundException
IOException

getOutputStream

public OutputStream getOutputStream(String uri)
                             throws IOException
Hook for subclassers to create an output stream for the specified URI. This implementation creates an output stream using JGraphEditorResources.getOutputStream(String) and wraps it in a GZIPOutputStream if the URI ends with .gz.

Parameters:
uri - The URI to return the output stream for.
Returns:
Returns an output stream for the specified URI.
Throws:
IOException

readObject

public Object readObject(InputStream in)
Returns a new object from the specified stream using a new XML decoder. This method does nothing special. Subclassers can override this method if they need to do anything special with opened files.
Note: You should use this method as a global hook to read all XML files.

Returns:
Returns a new object from the specified stream.

makeTransient

public static void makeTransient(Class clazz,
                                 String field)
Makes the specified field transient in the bean info of clazz.

Parameters:
clazz - The class whos field should be made transient.
field - The name of the field that should be made transient.

makeCellViewFieldsTransient

public static void makeCellViewFieldsTransient(Class clazz)
Makes all fields but cell and attributes transient in the bean info of clazz.

Parameters:
clazz - The cell view class who fields should be made transient.

getParentFile

public static JGraphEditorFile getParentFile(TreeNode node)
Returns the parent file for node or the node itself, if it is a file. This method returns null if no parent file is found for node.

Parameters:
node - The node to find the parent file for.
Returns:
Returns the parent file for node, the node itself or null.

JGraphpad Pro
v6.0.5.0


Copyright (C) 2005 JGraph.com. All rights reserved.