JGraphpad Pro
v6.0.5.0


com.jgraph.editor
Class JGraphEditorSettings

java.lang.Object
  extended bycom.jgraph.editor.JGraphEditorSettings

public class JGraphEditorSettings
extends Object

Manages configuration files for a JGraph editor, namely XML documents and properties files and holds references to configured objects.


Nested Class Summary
static interface JGraphEditorSettings.ShutdownHook
          Defines the requiements for a class that may act as a shutdown hook, ie.
 
Field Summary
static String ATTRIBUTENAME_BEFORE
          XML attribute name for the before attribute.
static String ATTRIBUTENAME_KEY
          XML attribute name for the key attribute.
static DocumentBuilderFactory documentBuilderFactory
          Document builder factory for parsing XML files.
protected  Map documents
          Holds maps of (document, name), (properties, name) and (key, Object) pairs respectively.
protected  Map objects
          Holds maps of (document, name), (properties, name) and (key, Object) pairs respectively.
protected  Map properties
          Holds maps of (document, name), (properties, name) and (key, Object) pairs respectively.
protected  List shutdownHooks
          List of hooks that are to be called on shutdown.
 
Constructor Summary
JGraphEditorSettings()
          Constructs new settings using an empty object map.
JGraphEditorSettings(Map objects)
          Constructs new settings using the passed-in object map.
 
Method Summary
 void add(String name, Document doc)
          Adds the document under the specified name or merges doc into an existing document for name.
 void add(String name, InputStream s)
          Adds the properties under a specified name from an input stream.
 void add(String name, Properties props)
          Registers the specified properties under the specified name.
 void addShutdownHook(JGraphEditorSettings.ShutdownHook hook)
          Adds a shutdown hook which is called from shutdown() normally when the program terminates.
static String getAttributeValue(Node node, String attributeName)
          Returns the textual representation of the attribute in node whos name is attributeName or null if no such attribute exists.
 Document getDocument(String name)
          Returns the document for the specified name or null if no such document exists.
static String getKeyAttributeValue(Node node)
          Returns the textual representation of the attribute in node whos name is equal to ATTRIBUTENAME_KEYor null if no such node exists.
static Node getNodeByAttribute(NodeList nodeList, String attributeName, String value)
          Returns the node in nodeList whos attribute named attributeName equals value or null if no such node exists.
static Node getNodeByName(NodeList nodeList, String name)
          Returns the first node in nodeList whos name equals name or null if no such node exists.
 Node getNodeByName(String documentName, String name)
          Returns the first node for name in the document registered under documentName.
 Object getObject(String key)
          Returns the object for the specified key.
 Properties getProperties(String name)
          Returns the properties registered under the specified name or null if no such properties exist.
 Rectangle getRectangleProperty(String name, String key)
          Gets the rectangle made up by 4 entries for the key -property from the properties called name.
protected  void merge(Document document, Node parent, NodeList children, boolean useNames)
          Recursively replaces or appends children in parent for equal keys (ATTRIBUTENAME_KEY or node names, depending on useNames.
static Document parse(InputStream in)
          Constructs a document object for an XML input stream using the documentBuilderFactory.
 void pushListEntryProperty(String name, String key, String value, int maxCount)
          Pushes a new entry into the list for key in the properties called name with value, making sure the list has no more than maxCount entries.
 void putObject(String key, Object obj)
          Adds the specified object under key.
 void putRectangleProperty(String name, String key, Rectangle rect)
          Puts the rectangle as 4 entries for the key -property plus a suffix of .x, .y, .width and .height into the properties called name.
 void restoreSplitPane(String name, String key)
          Restores the divider location for the split pane found in objects under key from the integer stored in the properties registered under name for the key property.
 void restoreWindow(String name, String key)
          Restores the window bounds for the window found in objects under key from the rectangle stored in the properties registered under name for the key property.
 void shutdown()
          Invokes all hooks that have previously been added using addShutdownHook in reverse order (last added first).
 void storeSplitPane(String name, String key)
          Stores the dividerlocation of the splitpane found in objects under key in the properties called name as a int property under key.
 void storeWindow(String name, String key)
          Stores the bounds of the window found in objects under key in the properties called name as a rectangle property under key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

documentBuilderFactory

public static DocumentBuilderFactory documentBuilderFactory
Document builder factory for parsing XML files.

See Also:
DocumentBuilderFactory.newInstance()

ATTRIBUTENAME_KEY

public static final String ATTRIBUTENAME_KEY
XML attribute name for the key attribute.

See Also:
Constant Field Values

ATTRIBUTENAME_BEFORE

public static final String ATTRIBUTENAME_BEFORE
XML attribute name for the before attribute.

See Also:
Constant Field Values

shutdownHooks

protected List shutdownHooks
List of hooks that are to be called on shutdown.


documents

protected Map documents
Holds maps of (document, name), (properties, name) and (key, Object) pairs respectively.


properties

protected Map properties
Holds maps of (document, name), (properties, name) and (key, Object) pairs respectively.


objects

protected Map objects
Holds maps of (document, name), (properties, name) and (key, Object) pairs respectively.

Constructor Detail

JGraphEditorSettings

public JGraphEditorSettings()
Constructs new settings using an empty object map.


JGraphEditorSettings

public JGraphEditorSettings(Map objects)
Constructs new settings using the passed-in object map.

Parameters:
objects - The map to use as the initial objects map.
Method Detail

getDocument

public Document getDocument(String name)
Returns the document for the specified name or null if no such document exists.

Parameters:
name - The name of the document to be returned.
Returns:
Returns the backing document.

add

public void add(String name,
                Document doc)
Adds the document under the specified name or merges doc into an existing document for name.

Parameters:
name - The name under which the document should be added.
doc - The document to add.

merge

protected void merge(Document document,
                     Node parent,
                     NodeList children,
                     boolean useNames)
Recursively replaces or appends children in parent for equal keys (ATTRIBUTENAME_KEY or node names, depending on useNames. If the node to be added provides a before attribute and the node for the specified key exists in the parent's node list then the new node is inserted before the referenced node.

Parameters:
document - The document to import the nodes into.
parent - The parent node to replace or add ports.
children - The children to add or replace.
useNames - If names or keys should be used to check for node equality.

getNodeByName

public Node getNodeByName(String documentName,
                          String name)
Returns the first node for name in the document registered under documentName.

Parameters:
documentName - The string that identifies the document to be used.
name - The name of the node to be returned.
Returns:
Returns the first node for name in documentName.

parse

public static Document parse(InputStream in)
                      throws ParserConfigurationException,
                             SAXException,
                             IOException
Constructs a document object for an XML input stream using the documentBuilderFactory.

Parameters:
in - The input stream that represents the XML data.
Returns:
Return the parsed input stream as an XML document.
Throws:
ParserConfigurationException
SAXException
IOException

getNodeByName

public static Node getNodeByName(NodeList nodeList,
                                 String name)
Returns the first node in nodeList whos name equals name or null if no such node exists.

Parameters:
nodeList - The list of nodes to scan for the name.
name - The name of the node to search for.
Returns:
Returns the first node for name in nodeList .
See Also:
Node.getNodeName()

getNodeByAttribute

public static Node getNodeByAttribute(NodeList nodeList,
                                      String attributeName,
                                      String value)
Returns the node in nodeList whos attribute named attributeName equals value or null if no such node exists.

Parameters:
nodeList - The nodes to scan for the attribute value.
attributeName - The name of the attribute to scan for.
value - The value of the attribute to scan for.
Returns:
Returns the first node that matches the search criteria.
See Also:
getAttributeValue(Node, String)

getAttributeValue

public static String getAttributeValue(Node node,
                                       String attributeName)
Returns the textual representation of the attribute in node whos name is attributeName or null if no such attribute exists.

Parameters:
node - The node whos attribute should be returned.
attributeName - The name of the attribute whos value should be returned.
Returns:
Returns the value of attributeName in node.
See Also:
Node.getAttributes(), NamedNodeMap.getNamedItem(java.lang.String), Node.getNodeValue()

getKeyAttributeValue

public static String getKeyAttributeValue(Node node)
Returns the textual representation of the attribute in node whos name is equal to ATTRIBUTENAME_KEYor null if no such node exists.

Parameters:
node - The node whos attribute should be returned.
Returns:
Returns the value of ATTRIBUTENAME_KEYin node.
See Also:
getAttributeValue(Node, String)

getProperties

public Properties getProperties(String name)
Returns the properties registered under the specified name or null if no such properties exist.

Parameters:
name - The name of the properties to return.
Returns:
Returns the properties for name.

add

public void add(String name,
                Properties props)
Registers the specified properties under the specified name.

Parameters:
name - The name to register the properties under.
props - The properties to register.

add

public void add(String name,
                InputStream s)
         throws IOException
Adds the properties under a specified name from an input stream. This method creates the properties using Properties.load(java.io.InputStream)and adds the properties using add(String, Properties).

Parameters:
name - The name to register the properties under.
s - The input stream to read the properties from.
Throws:
IOException - If the input stream cannot be read.

putObject

public void putObject(String key,
                      Object obj)
Adds the specified object under key.

Parameters:
key - The key to register the object under.
obj - The object to register.

getObject

public Object getObject(String key)
Returns the object for the specified key.

Parameters:
key - The key to return the object for.
Returns:
Returns the object for key.

restoreWindow

public void restoreWindow(String name,
                          String key)
Restores the window bounds for the window found in objects under key from the rectangle stored in the properties registered under name for the key property. This implementation assumes that the key property is a rectangle, ie. consists of 4 entries in the file.

Parameters:
name - The name of the properties to use.
key - The key of the object and rectangle property.
See Also:
getRectangleProperty(String, String)

restoreSplitPane

public void restoreSplitPane(String name,
                             String key)
Restores the divider location for the split pane found in objects under key from the integer stored in the properties registered under name for the key property.

Parameters:
name - The name of the properties to use.
key - The key of the object and integer property.
See Also:
getRectangleProperty(String, String)

storeWindow

public void storeWindow(String name,
                        String key)
Stores the bounds of the window found in objects under key in the properties called name as a rectangle property under key.

Parameters:
name - The name of the properties to store the bounds.
key - The name of the key to store the rectangle property.

storeSplitPane

public void storeSplitPane(String name,
                           String key)
Stores the dividerlocation of the splitpane found in objects under key in the properties called name as a int property under key.

Parameters:
name - The name of the properties to store the divider location.
key - The name of the key to store the divider location.

pushListEntryProperty

public void pushListEntryProperty(String name,
                                  String key,
                                  String value,
                                  int maxCount)
Pushes a new entry into the list for key in the properties called name with value, making sure the list has no more than maxCount entries. If the list is longer than maxCount, then the oldest entry will be removed.

Parameters:
name - The name of the properties to store the list.
key - The name of the key to store the list entries.
value - The value of the new list entry.
maxCount - The maximum number of elemnts in the list.

putRectangleProperty

public void putRectangleProperty(String name,
                                 String key,
                                 Rectangle rect)
Puts the rectangle as 4 entries for the key -property plus a suffix of .x, .y, .width and .height into the properties called name.

Parameters:
name - The name of the properties to store the rectangle.
key - The name of the key to store the rectangle size and location.
rect - The rectangle to put into the properties.

getRectangleProperty

public Rectangle getRectangleProperty(String name,
                                      String key)
Gets the rectangle made up by 4 entries for the key -property from the properties called name.

Parameters:
name - The name of the properties to get the rectangle from.
key - The key to retrieve the rectangle values.
Returns:
Returns the rectangle for key in name.
See Also:
putRectangleProperty(String, String, Rectangle)

shutdown

public void shutdown()
Invokes all hooks that have previously been added using addShutdownHook in reverse order (last added first).


addShutdownHook

public void addShutdownHook(JGraphEditorSettings.ShutdownHook hook)
Adds a shutdown hook which is called from shutdown() normally when the program terminates.

Parameters:
hook - The shutdown hook to be added.

JGraphpad Pro
v6.0.5.0


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