Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.merlotxml.merlot
Class MerlotDOMNode  view MerlotDOMNode download MerlotDOMNode.java

java.lang.Object
  extended byorg.merlotxml.merlot.MerlotDOMNode
All Implemented Interfaces:
java.lang.Cloneable, MerlotConstants, java.awt.datatransfer.Transferable
Direct Known Subclasses:
MerlotDOMComment, MerlotDOMDoctype, MerlotDOMDocument, MerlotDOMElement, MerlotDOMFragment, MerlotDOMProcessingInstruction, MerlotDOMText

public class MerlotDOMNode
extends java.lang.Object
implements java.awt.datatransfer.Transferable, java.lang.Cloneable, MerlotConstants

DOM node container for Merlot. Contains a DOM node, handles getting an icon for a particular node, getting the editor for a node, etc. Also implements transferable so that the node can be drag and dropped, or cut and pasted.


Field Summary
(package private)  javax.swing.Icon _bean_gif
           
(package private)  javax.swing.Icon _bean_gif_lg
           
protected  java.util.Vector _children
          cached list of child nodes
protected  MerlotDOMNode[] _clonedFrom
          The node we were cloned from if any...
protected  org.merlotxml.merlot.plugin.dtd.DTDPluginConfig _dtdPluginConfig
          the plugin this node is associated with
protected  XMLFile _file
          The file this node came from
protected  java.util.Vector _listeners
          Listeners of for actions on this node
protected  MerlotDOMNode _parent
           
protected  org.w3c.dom.Node _theNode
           
private static boolean DEBUG
           
static java.awt.datatransfer.DataFlavor DOM_TREENODE_FLAVOR
           
(package private) static java.awt.datatransfer.DataFlavor[] flavors
           
(package private) static int PLAIN_TEXT
           
(package private) static int STRING
           
(package private) static int TREE
           
 
Fields inherited from interface org.merlotxml.merlot.MerlotConstants
ACTION_MENU_ACCELERATOR, ACTION_MENU_ICON, ACTION_NAME, ACTION_SHORT_DESCRIPTION, ACTION_SMALL_ICON, AFTER, BEFORE, ERR, INTO, UI, XML
 
Constructor Summary
MerlotDOMNode(org.w3c.dom.Node data, XMLFile file)
           
 
Method Summary
 void addMerlotNodeListener(MerlotNodeListener l)
           
 void appendChild(MerlotDOMNode child)
           
 java.lang.String array2String(int[] array)
           
 java.lang.String array2String(java.lang.Object[] array)
           
 java.lang.Object clone()
          provides a deep copy
private  MerlotDOMNode createDOMNode(org.w3c.dom.Node nd)
           
private  MerlotDOMNode createDOMNode(java.lang.String nodename)
           
 void delete()
           
 boolean equals(java.lang.Object o)
          Determine whether this Object is semantically equal to another Object.
 void fireNodeChanged()
           
 void fireNodeDeleted()
          This handles the case of notifying anything editing the node that it is deleted.
 void fireNodeInserted(MerlotDOMNode parent, int[] childindices, MerlotDOMNode[] newchildren)
           
 void fireNodeRemoved(MerlotDOMNode parent, int[] childindices, MerlotDOMNode[] oldchildren)
          This one handles the case of keeping the tree view up to date.
 java.util.Enumeration getAppendableElements()
          returns an enumeration of DTDElements
 org.w3c.dom.NamedNodeMap getAttributes()
           
 java.util.Vector getAttributesOfType(int type)
          Gets only the attributes (org.w3c.dom.Node) that have the specified type.
 java.util.Vector getChildElements()
           
 int getChildIndex(MerlotDOMNode child)
          Returns the index of the location of the child in the parent
 MerlotDOMNode[] getChildNodes()
          gets a list of child nodes and creates an array of merlotDOMNodes.
 java.lang.String getChildText(boolean suppressWhiteSpace)
           
protected  MerlotDOMNode[] getClonedFrom()
           
 java.lang.String getDescriptiveText()
          Determines the most descriptive text for a node based on priorities set in plugin.xml.
 java.lang.String getDescriptiveText(java.util.Map nodeProperties, java.util.List defaultOrder)
           
 java.lang.String getDisplayText()
           
 org.w3c.dom.Document getDocument()
           
 java.util.Enumeration getDTDAttributes()
           
 org.merlotxml.merlot.plugin.dtd.DTDPluginConfig getDTDPluginConfig()
          Returns the dtd plugin config for this node if it exists
 MerlotDOMEditor getEditor()
          This should return the editor object for this type of element if one is found, otherwise a default one should be returned.
 javax.swing.JPanel getEditPanel()
           
 java.lang.String getFirstAttributeOfType(int attrType)
          Gets all the attributes (org.w3c.dom.Node) that have the specified type.
 MerlotDOMNode getFirstChild()
          Gets the first child that is non-empty text, or returns null if none
 javax.swing.Icon getIcon()
          Gets a large icon
 IDManager getIdManager()
          Return THE IDManager specific to the document containing this node.
protected  int[] getIndices()
          this gets the index of this child or if it's a fragment, then the indices of all the nodes in the top level of the fragment
 java.util.Enumeration getInsertableElements(int index)
          returns the nodes that are insertable at the given index.
 MerlotDOMDocument getMerlotDOMDocument()
          this goes up the tree recursively until it finds the merlot dom document
protected  java.util.Vector getMerlotNodeListeners()
           
 java.lang.String getNodeName()
           
protected  MerlotDOMNode[] getNodes()
           
 MerlotDOMNode getParentNode()
           
 MerlotDOMNode getPreviousSibling()
          Returns the previous sibling or null if this is the first sibling
 MerlotDOMNode getPreviousSibling(MerlotDOMNode child)
           
 java.lang.String getProperty(java.lang.Object property)
          Property must either be a String containing the attribute name, or an Integer with a DTDConstant specifying an attribute type.
 org.w3c.dom.Node getRealNode()
           
 javax.swing.Icon getSmallIcon()
          Gets a small icon for this node based on its type
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
          Returns the data in the specified DataFlavor.
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
          This method returns a list of available data flavors for the data being transferred.
 XMLFile getXMLFile()
          returns the XML file object
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 MerlotDOMNode importChild(MerlotDOMNode child)
          imports a child node from another document
 MerlotDOMNode importChildAfter(MerlotDOMNode child)
          imports a node and places it after this one
 MerlotDOMNode importChildBefore(MerlotDOMNode child)
          imports a node and places it before this one
 void insertAfter(MerlotDOMNode sibling)
          inserts this after the sibling
 void insertBefore(MerlotDOMNode sibling)
          inserts this before the sibling
 void insertChildAt(MerlotDOMNode child, int loc)
           
 boolean isAllowableChild(MerlotDOMNode child, boolean newChild)
          Returns true if the child is a valid type to be a child of this according to the DTD
 boolean isAllowableChild(MerlotDOMNode child, int index, boolean newChild)
           
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
          Tests whether or not this data can be delivered in the specified data flavor.
 boolean isElement()
          Element nodes should overload this to return true.
 boolean isRootElement()
           
 boolean isSpecialNode()
           
 boolean isValid()
           
 boolean locationIsValid(boolean checkParents)
           
 MerlotDOMNode newChild(org.w3c.dom.Node nd)
           
 MerlotDOMNode newChild(java.lang.String nodename)
          creates a new child and adds it to the end of the list
 MerlotDOMNode newSiblingAfter(org.w3c.dom.Node nd)
          creates a new sibling and inserts it after this node
 MerlotDOMNode newSiblingAfter(java.lang.String nodename)
           
 MerlotDOMNode newSiblingBefore(org.w3c.dom.Node nd)
          creates a new sibling and inserts it after this node
 MerlotDOMNode newSiblingBefore(java.lang.String nodename)
           
 void printNode()
           
 void printNode(java.lang.String prepend)
           
 void removeAllMerlotDOMNodeListeners()
          Removes all listeners from this node
 void removeChild(MerlotDOMNode nd)
          Removes a child node
 void removeMerlotNodeListener(MerlotNodeListener l)
           
protected  void resetCache()
           
 void setAttributes(java.util.HashMap h)
          Sets the attributes according the given hashtable.
protected  void setClonedFrom(MerlotDOMNode[] nd)
           
 void setParentNode(MerlotDOMNode nd)
           
protected  void setParentNode(MerlotDOMNode nd, boolean updateChildren)
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

_bean_gif

javax.swing.Icon _bean_gif

_bean_gif_lg

javax.swing.Icon _bean_gif_lg

_theNode

protected org.w3c.dom.Node _theNode

_file

protected XMLFile _file
The file this node came from


_parent

protected MerlotDOMNode _parent

_clonedFrom

protected MerlotDOMNode[] _clonedFrom
The node we were cloned from if any... used for dnd moves so we can delete the original node that was being moved.


_listeners

protected java.util.Vector _listeners
Listeners of for actions on this node


_children

protected java.util.Vector _children
cached list of child nodes


_dtdPluginConfig

protected org.merlotxml.merlot.plugin.dtd.DTDPluginConfig _dtdPluginConfig
the plugin this node is associated with


TREE

static final int TREE
See Also:
Constant Field Values

STRING

static final int STRING
See Also:
Constant Field Values

PLAIN_TEXT

static final int PLAIN_TEXT
See Also:
Constant Field Values

DOM_TREENODE_FLAVOR

public static final java.awt.datatransfer.DataFlavor DOM_TREENODE_FLAVOR

flavors

static java.awt.datatransfer.DataFlavor[] flavors
Constructor Detail

MerlotDOMNode

public MerlotDOMNode(org.w3c.dom.Node data,
                     XMLFile file)
Method Detail

getDocument

public org.w3c.dom.Document getDocument()

getMerlotDOMDocument

public MerlotDOMDocument getMerlotDOMDocument()
this goes up the tree recursively until it finds the merlot dom document


getSmallIcon

public javax.swing.Icon getSmallIcon()
Gets a small icon for this node based on its type


getIcon

public javax.swing.Icon getIcon()
Gets a large icon


isElement

public boolean isElement()
Element nodes should overload this to return true.


getXMLFile

public XMLFile getXMLFile()
returns the XML file object


getDTDPluginConfig

public org.merlotxml.merlot.plugin.dtd.DTDPluginConfig getDTDPluginConfig()
Returns the dtd plugin config for this node if it exists


getEditor

public MerlotDOMEditor getEditor()
This should return the editor object for this type of element if one is found, otherwise a default one should be returned.


getNodeName

public java.lang.String getNodeName()

getChildIndex

public int getChildIndex(MerlotDOMNode child)
                  throws org.w3c.dom.DOMException
Returns the index of the location of the child in the parent


getFirstChild

public MerlotDOMNode getFirstChild()
Gets the first child that is non-empty text, or returns null if none


getChildElements

public java.util.Vector getChildElements()

getChildNodes

public MerlotDOMNode[] getChildNodes()
gets a list of child nodes and creates an array of merlotDOMNodes. Returns null if no children are available


resetCache

protected void resetCache()

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()

getFirstAttributeOfType

public java.lang.String getFirstAttributeOfType(int attrType)
Gets all the attributes (org.w3c.dom.Node) that have the specified type.


getAttributesOfType

public java.util.Vector getAttributesOfType(int type)
Gets only the attributes (org.w3c.dom.Node) that have the specified type.


setAttributes

public void setAttributes(java.util.HashMap h)
Sets the attributes according the given hashtable. (probably should make getAttributes consistent with this at some point


getAppendableElements

public java.util.Enumeration getAppendableElements()
returns an enumeration of DTDElements


getInsertableElements

public java.util.Enumeration getInsertableElements(int index)
returns the nodes that are insertable at the given index.


isAllowableChild

public boolean isAllowableChild(MerlotDOMNode child,
                                boolean newChild)
Returns true if the child is a valid type to be a child of this according to the DTD


isAllowableChild

public boolean isAllowableChild(MerlotDOMNode child,
                                int index,
                                boolean newChild)

getPreviousSibling

public MerlotDOMNode getPreviousSibling()
Returns the previous sibling or null if this is the first sibling


getPreviousSibling

public MerlotDOMNode getPreviousSibling(MerlotDOMNode child)
                                 throws org.w3c.dom.DOMException

getParentNode

public MerlotDOMNode getParentNode()

setParentNode

public void setParentNode(MerlotDOMNode nd)

setParentNode

protected void setParentNode(MerlotDOMNode nd,
                             boolean updateChildren)

setClonedFrom

protected void setClonedFrom(MerlotDOMNode[] nd)

getClonedFrom

protected MerlotDOMNode[] getClonedFrom()

newChild

public MerlotDOMNode newChild(java.lang.String nodename)
                       throws org.w3c.dom.DOMException
creates a new child and adds it to the end of the list


newChild

public MerlotDOMNode newChild(org.w3c.dom.Node nd)

newSiblingAfter

public MerlotDOMNode newSiblingAfter(org.w3c.dom.Node nd)
creates a new sibling and inserts it after this node


newSiblingAfter

public MerlotDOMNode newSiblingAfter(java.lang.String nodename)

newSiblingBefore

public MerlotDOMNode newSiblingBefore(org.w3c.dom.Node nd)
creates a new sibling and inserts it after this node


newSiblingBefore

public MerlotDOMNode newSiblingBefore(java.lang.String nodename)

insertAfter

public void insertAfter(MerlotDOMNode sibling)
inserts this after the sibling


insertBefore

public void insertBefore(MerlotDOMNode sibling)
inserts this before the sibling


insertChildAt

public void insertChildAt(MerlotDOMNode child,
                          int loc)

appendChild

public void appendChild(MerlotDOMNode child)

importChild

public MerlotDOMNode importChild(MerlotDOMNode child)
imports a child node from another document


importChildBefore

public MerlotDOMNode importChildBefore(MerlotDOMNode child)
imports a node and places it before this one


importChildAfter

public MerlotDOMNode importChildAfter(MerlotDOMNode child)
imports a node and places it after this one


removeChild

public void removeChild(MerlotDOMNode nd)
                 throws org.w3c.dom.DOMException
Removes a child node


getIndices

protected int[] getIndices()
this gets the index of this child or if it's a fragment, then the indices of all the nodes in the top level of the fragment


getNodes

protected MerlotDOMNode[] getNodes()

createDOMNode

private MerlotDOMNode createDOMNode(java.lang.String nodename)

createDOMNode

private MerlotDOMNode createDOMNode(org.w3c.dom.Node nd)

delete

public void delete()

getDTDAttributes

public java.util.Enumeration getDTDAttributes()

getEditPanel

public javax.swing.JPanel getEditPanel()
                                throws java.lang.InstantiationException,
                                       java.lang.IllegalAccessException

getRealNode

public org.w3c.dom.Node getRealNode()

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Description copied from interface: java.awt.datatransfer.Transferable
This method returns a list of available data flavors for the data being transferred. The array returned will be sorted from most preferred flavor at the beginning to least preferred at the end.

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Description copied from interface: java.awt.datatransfer.Transferable
Returns the data in the specified DataFlavor.

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Description copied from interface: java.awt.datatransfer.Transferable
Tests whether or not this data can be delivered in the specified data flavor.

Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

clone

public java.lang.Object clone()
provides a deep copy


addMerlotNodeListener

public void addMerlotNodeListener(MerlotNodeListener l)

removeMerlotNodeListener

public void removeMerlotNodeListener(MerlotNodeListener l)

removeAllMerlotDOMNodeListeners

public void removeAllMerlotDOMNodeListeners()
Removes all listeners from this node


getMerlotNodeListeners

protected java.util.Vector getMerlotNodeListeners()

array2String

public java.lang.String array2String(int[] array)

array2String

public java.lang.String array2String(java.lang.Object[] array)

fireNodeInserted

public void fireNodeInserted(MerlotDOMNode parent,
                             int[] childindices,
                             MerlotDOMNode[] newchildren)

fireNodeDeleted

public void fireNodeDeleted()
This handles the case of notifying anything editing the node that it is deleted.


fireNodeRemoved

public void fireNodeRemoved(MerlotDOMNode parent,
                            int[] childindices,
                            MerlotDOMNode[] oldchildren)
This one handles the case of keeping the tree view up to date.


fireNodeChanged

public void fireNodeChanged()

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


equals

public boolean equals(java.lang.Object o)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


getDisplayText

public java.lang.String getDisplayText()

getDescriptiveText

public java.lang.String getDescriptiveText()
Determines the most descriptive text for a node based on priorities set in plugin.xml.


getDescriptiveText

public java.lang.String getDescriptiveText(java.util.Map nodeProperties,
                                           java.util.List defaultOrder)

getProperty

public java.lang.String getProperty(java.lang.Object property)
Property must either be a String containing the attribute name, or an Integer with a DTDConstant specifying an attribute type.


hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


printNode

public void printNode()

printNode

public void printNode(java.lang.String prepend)

getChildText

public java.lang.String getChildText(boolean suppressWhiteSpace)

isSpecialNode

public boolean isSpecialNode()

getIdManager

public IDManager getIdManager()
Return THE IDManager specific to the document containing this node.


isRootElement

public boolean isRootElement()

isValid

public boolean isValid()

locationIsValid

public boolean locationIsValid(boolean checkParents)