org.merlotxml.merlot
Class MerlotDOMNode

java.lang.Object
  |
  +--org.merlotxml.merlot.MerlotDOMNode
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.

Author:
Kelly A. Campbell

Field Summary
protected  java.util.Vector _children
          cached list of child nodes
protected  MerlotDOMNode[] _clonedFrom
          The node we were cloned from if any...
protected  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
           
static java.awt.datatransfer.DataFlavor DOM_TREENODE_FLAVOR
           
 
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
 void delete()
           
 boolean equals(java.lang.Object o)
           
 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()
           
 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 getDisplayText()
           
 org.w3c.dom.Document getDocument()
           
 java.util.Enumeration getDTDAttributes()
           
 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()
           
 MerlotDOMNode getFirstChild()
          Gets the first child that is non-empty text, or returns null if none
 javax.swing.Icon getIcon()
          Gets a large icon
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)
           
 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)
           
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
 XMLFile getXMLFile()
          returns the XML file object
 int hashCode()
           
 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)
          Returns true if the child is a valid type to be a child of this according to the DTD
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
           
 boolean isElement()
          Element nodes should overload this to return true.
 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)
           
protected  void setParentNode(MerlotDOMNode nd)
           
protected  void setParentNode(MerlotDOMNode nd, boolean updateChildren)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_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 DTDPluginConfig _dtdPluginConfig
the plugin this node is associated with

DOM_TREENODE_FLAVOR

public static final java.awt.datatransfer.DataFlavor DOM_TREENODE_FLAVOR
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 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

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()

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)
Returns true if the child is a valid type to be a child of this according to the DTD

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

protected 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()

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()
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
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable

clone

public java.lang.Object clone()
provides a deep copy
Overrides:
clone in class java.lang.Object

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()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getDisplayText

public java.lang.String getDisplayText()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

printNode

public void printNode()

printNode

public void printNode(java.lang.String prepend)

getChildText

public java.lang.String getChildText(boolean suppressWhiteSpace)