/**
   * 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;
  }