/**
   * Request the renderer that suits the given value type and for the given tree.
   *
   * @param tree The source tree this node comes from
   * @param value The DOMTreeNode to be rendered
   * @param selected True if the node is selected
   * @param expanded True if expanded
   * @param row The row this node is on
   * @param hasFocus True if the node currently has focus
   */
  public Component getTreeCellRendererComponent(
      JTree tree,
      Object value,
      boolean selected,
      boolean expanded,
      boolean leaf,
      int row,
      boolean hasFocus) {

    this.selected = selected;
    this.focused = hasFocus;

    Node node = ((DOMTreeNode) value).getNode();
    String name = (String) nodeNameMap.get(node.getNodeType());
    setIcon(null);

    switch (node.getNodeType()) {
      case Node.ATTRIBUTE_NODE:
        setText(node.getNodeName() + "=" + node.getNodeValue());
        break;

      case Node.TEXT_NODE:
      case Node.COMMENT_NODE:
      case Node.CDATA_SECTION_NODE:
        StringBuffer txt = new StringBuffer(name);
        txt.append(" \"");
        txt.append(node.getNodeValue());
        txt.append('\"');
        setText(txt.toString());
        break;

      case Node.DOCUMENT_FRAGMENT_NODE:
      case Node.DOCUMENT_NODE:
        // I'd really like to put the name of the document here.
        setText(name);
        break;

      case Node.DOCUMENT_TYPE_NODE:
      case Node.ENTITY_NODE:
      case Node.ENTITY_REFERENCE_NODE:
      case Node.NOTATION_NODE:
      case Node.PROCESSING_INSTRUCTION_NODE:
        setText(node.getNodeName());
        break;

      case Node.ELEMENT_NODE:
        String nn = node.getNodeName();
        setText(nn);

        // Check to see if we have an icon too.
        Icon icon = IconLoader.loadIcon(nn, null);
        if (icon != null) setIcon(icon);
    }

    setComponentOrientation(tree.getComponentOrientation());

    return this;
  }
  /**
   * Static initialisation of the class. Sets up the node type to node name string mapping that is
   * used each time this class is instantiated.
   */
  static {
    nodeNameMap = new ShortHashMap();

    nodeNameMap.put(Node.ATTRIBUTE_NODE, "Attribute");
    nodeNameMap.put(Node.CDATA_SECTION_NODE, "CDATA Section");
    nodeNameMap.put(Node.COMMENT_NODE, "Comment");
    nodeNameMap.put(Node.DOCUMENT_FRAGMENT_NODE, "Document Fragment");
    nodeNameMap.put(Node.DOCUMENT_NODE, "Document");
    nodeNameMap.put(Node.DOCUMENT_TYPE_NODE, "Document Type");
    nodeNameMap.put(Node.ELEMENT_NODE, "Element");
    nodeNameMap.put(Node.ENTITY_NODE, "Entity");
    nodeNameMap.put(Node.ENTITY_REFERENCE_NODE, "Entity Reference");
    nodeNameMap.put(Node.NOTATION_NODE, "Notation");
    nodeNameMap.put(Node.PROCESSING_INSTRUCTION_NODE, "Processing Instruction");
    nodeNameMap.put(Node.TEXT_NODE, "Text");
  }