/* File: AdapterNode.java University of Applied Science Berne,HTA-Biel/Bienne, Computer Science Department. Diploma thesis J3D Solar System Simulator Originally written by Marcel Portner & Bernhard Hari (c) 2000 CVS - Information : $Header: /var/cvsreps/projects/c450/2000/sss3d/source_diploma/sss3d/gui/infobox/AdapterNode.java,v 1.3 2000/12/12 09:07:47 harib Exp $ $Author: harib $ $Date: 2000/12/12 09:07:47 $ $State: Exp $ */ package sss3d.gui.infobox; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.JTree; import java.awt.Component; import javax.swing.ImageIcon; import javax.swing.JLabel; import sss3d.utils.SSS3dConstants; import sss3d.utils.xmlparser.XMLConstants; /** * This class wraps a DOM node and returns the text we want to * display in the tree. It also returns children, index values, * and child counts. * * @author Marcel Portner & Bernhard Hari * @version $Revision: 1.3 $ */ public class AdapterNode extends DefaultMutableTreeNode { public org.w3c.dom.Node domNode; // show tree in compressed mode private boolean compress = true; private boolean treeElement(String elementName) { for (int i = 0; i < XMLConstants.treeElementNames.length; i++) { if ( elementName.equals(XMLConstants.treeElementNames[i]) ) return true; } return false; } /** * Constructor * * @param node construct an Adapter node from a DOM node ( org.w3c.dom.Node ) */ public AdapterNode(org.w3c.dom.Node node) { domNode = node; } /** * Return a string that identifies this node in the tree * * @return String identification string from this node */ public String toString() { String s = XMLConstants.typeName[domNode.getNodeType()]; String nodeName = domNode.getNodeName(); if (! nodeName.startsWith("#")) { s += ": " + nodeName; } if (compress) { String t = content().trim(); int x = t.indexOf("\n"); if (x >= 0) t = t.substring(0, x); s += " " + t; return s; } if (domNode.getNodeValue() != null) { if (s.startsWith("ProcInstr")) s += ", "; else s += ": "; // Trim the value to get rid of NL's at the front String t = domNode.getNodeValue().trim(); int x = t.indexOf("\n"); if (x >= 0) t = t.substring(0, x); s += t; } return s; } /** * Returns the content from this node (value) * * @return String content from this node */ public String content() { String s = ""; org.w3c.dom.NodeList nodeList = domNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); int type = node.getNodeType(); AdapterNode adpNode = new AdapterNode(node); //inefficient, but works if (type == XMLConstants.ELEMENT_TYPE) { // Skip subelements that are displayed in the tree. if ( treeElement(node.getNodeName()) ) continue; // EXTRA-CREDIT HOMEWORK: // Special case the SLIDE element to use the TITLE text // and ignore TITLE element when constructing the tree. // EXTRA-CREDIT // Convert ITEM elements to html lists using //