Index: ViewResultsFullVisualizer.java =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java,v retrieving revision 1.49 diff -u -r1.49 ViewResultsFullVisualizer.java --- ViewResultsFullVisualizer.java 2 May 2005 14:55:43 -0000 1.49 +++ ViewResultsFullVisualizer.java 7 May 2005 09:57:09 -0000 @@ -44,6 +44,7 @@ import javax.swing.JTextArea; import javax.swing.JTextPane; import javax.swing.JTree; +import javax.swing.ToolTipManager; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.text.BadLocationException; @@ -796,186 +797,6 @@ } } - /** - *A extended class of DefaultMutableTreeNode except that it also attached - *XML node and convert XML document into DefaultMutableTreeNode - * author Dave Maung - * - */ - public class XMLDefaultMutableTreeNode extends DefaultMutableTreeNode - { - - boolean isRoot; - private Node xmlNode; - public XMLDefaultMutableTreeNode(Node root) throws SAXException - { - super(root.getNodeName()); - initRoot(root); - - } - - public XMLDefaultMutableTreeNode(String name,Node xmlNode) - { - super(name); - this.xmlNode = xmlNode; - - } - /** - * init root - * @param root - * @throws SAXException - */ - private void initRoot(Node xmlRoot) throws SAXException { - - - NodeList childNodes = xmlRoot.getChildNodes(); - if(childNodes == null) - initAttributeNode(xmlRoot, this); - - for (int i = 0; i < childNodes.getLength(); i++) { - Node childNode = childNodes.item(i); - initNode(childNode, this); - } - - } - /** - * init node - * @param node - * @param mTreeNode - * @throws SAXException - */ - private void initNode(Node node, XMLDefaultMutableTreeNode mTreeNode) - throws SAXException - { - - switch (node.getNodeType()) - { - case Node.ELEMENT_NODE: - initElementNode(node, mTreeNode); - break; - - case Node.TEXT_NODE: - initTextNode((Text)node, mTreeNode); - break; - - - case Node.CDATA_SECTION_NODE: - initCDATASectionNode((CDATASection)node, mTreeNode); - break; - case Node.COMMENT_NODE: - initCommentNode((Comment)node,mTreeNode); - break; - - default: - //if other node type, we will just skip it - break; - - } - - } - /** - * init element node - * @param node - * @param mTreeNode - * @throws SAXException - */ - private void initElementNode(Node node, DefaultMutableTreeNode mTreeNode) - throws SAXException { - String nodeName = node.getNodeName(); - - NodeList childNodes = node.getChildNodes(); - XMLDefaultMutableTreeNode childTreeNode = new XMLDefaultMutableTreeNode(nodeName - ,node); - - mTreeNode.add(childTreeNode); - initAttributeNode(node, childTreeNode); - for (int i = 0; i < childNodes.getLength(); i++) - { - Node childNode = childNodes.item(i); - initNode(childNode, childTreeNode); - } - - } - /** - * init attribute node - * @param node - * @param mTreeNode - * @throws SAXException - */ - private void initAttributeNode(Node node, DefaultMutableTreeNode mTreeNode) - throws SAXException { - NamedNodeMap nm = node.getAttributes(); - for (int i = 0; i < nm.getLength(); i++) - { - Attr nmNode = (Attr)nm.item(i); - String value = nmNode.getName() + " = \"" + nmNode.getValue() + "\""; - XMLDefaultMutableTreeNode attributeNode = new XMLDefaultMutableTreeNode( - value,nmNode); - mTreeNode.add(attributeNode); - - } - } - /** - * init comment Node - * @param node - * @param mTreeNode - * @throws SAXException - */ - private void initCommentNode(Comment node, DefaultMutableTreeNode mTreeNode) throws SAXException{ - String data = node.getData(); - if(data != null || data.length() > 0) - { - String value = ""; - XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node); - mTreeNode.add(commentNode); - } - } - /** - * init CDATASection Node - * @param node - * @param mTreeNode - * @throws SAXException - */ - private void initCDATASectionNode(CDATASection node, DefaultMutableTreeNode mTreeNode) throws SAXException - { - String data = node.getData(); - if(data != null || data.length() > 0) - { - String value = ""; - XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node); - mTreeNode.add(commentNode); - } - } - /** - * init the TextNode - * @param node - * @param mTreeNode - * @throws SAXException - */ - private void initTextNode(Text node, DefaultMutableTreeNode mTreeNode) throws SAXException - { - String text = node.getNodeValue().trim(); - if(text != null && text.length() > 0) - { - XMLDefaultMutableTreeNode textNode = new XMLDefaultMutableTreeNode(node - .getNodeValue(),node); - mTreeNode.add(textNode); - } - } - - - - /** - * get the xml node - * @return - */ - public Node getXMLNode() - { - return xmlNode; - } - - - } /** @@ -992,7 +813,6 @@ public DOMTreePanel(org.w3c.dom.Document document) { super(new GridLayout(1, 0)); try { - Node firstElement = getFirstElement(document); DefaultMutableTreeNode top = new XMLDefaultMutableTreeNode( firstElement); @@ -1004,7 +824,8 @@ JScrollPane domJScrollPane = new JScrollPane(domJTree); domJTree.setAutoscrolls(true); this.add(domJScrollPane); - this.setSize(800, 600); + ToolTipManager.sharedInstance().registerComponent(domJTree); + domJTree.setCellRenderer(new DomTreeRenderer()); this.setPreferredSize(new Dimension(800, 600)); } catch (SAXException e) { log.warn("",e); @@ -1029,11 +850,82 @@ } return toReturn; } - - - - + /** + * This class is to view as tooltext. This is very useful, when + * the contents has long string and does not fit in the view. + * it will also automatically wrap line for each + * 100 characters since tool tip support html. + * author Dave Maung + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ + private class DomTreeRenderer extends DefaultTreeCellRenderer { + public Component getTreeCellRendererComponent( + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) + { + super.getTreeCellRendererComponent( + tree, value, sel, + expanded, leaf, row, + hasFocus); + + DefaultMutableTreeNode valueTreeNode = (DefaultMutableTreeNode)value; + setToolTipText(getHTML(valueTreeNode.toString(),"
",100)); + return this; + } + + /** + * get the html + * @param str + * @param separator + * @param maxChar + * @return + */ + private String getHTML(String str,String separator, int maxChar) + { + StringBuffer strBuf = new StringBuffer(""); + char[] chars = str.toCharArray(); + for(int i=0; i< chars.length; i++) { + + if(i % maxChar == 0 && i != 0) + strBuf.append(separator); + strBuf.append(encode(chars[i])); + + } + strBuf.append(""); + return strBuf.toString(); + + } + private String encode(char c) + { + String toReturn = String.valueOf(c); + switch(c) { + case '<': + toReturn = "<"; + break; + case '>': + toReturn = ">"; + break; + case '\'': + toReturn = "'"; + break; + case '\"': + toReturn = """; + break; + + } + return toReturn; + } + } } + + private static void showErrorMessageDialog(String message,int messageType) { JOptionPane.showMessageDialog(null, message, "Error", messageType); @@ -1121,4 +1013,5 @@ } } + } Index: XMLDefaultMutableTreeNode.java =================================================================== RCS file: XMLDefaultMutableTreeNode.java diff -N XMLDefaultMutableTreeNode.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ XMLDefaultMutableTreeNode.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,191 @@ +/* + * Created on May 7, 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.apache.jmeter.visualizers; + +import javax.swing.tree.DefaultMutableTreeNode; +import org.w3c.dom.Attr; +import org.w3c.dom.CDATASection; +import org.w3c.dom.Comment; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; +import org.xml.sax.SAXException; + +/** + *A extended class of DefaultMutableTreeNode except that it also attached + *XML node and convert XML document into DefaultMutableTreeNode + * author Dave Maung + * + */ + public class XMLDefaultMutableTreeNode extends DefaultMutableTreeNode + { + private static final int LIMIT_STR_SIZE = 100; + boolean isRoot; + private Node xmlNode; + public XMLDefaultMutableTreeNode(Node root) throws SAXException + { + super(root.getNodeName()); + initAttributeNode(root, this); + initRoot(root); + + } + + public XMLDefaultMutableTreeNode(String name,Node xmlNode) + { + super(name); + this.xmlNode = xmlNode; + + } + /** + * init root + * @param root + * @throws SAXException + */ + private void initRoot(Node xmlRoot) throws SAXException { + + + NodeList childNodes = xmlRoot.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + initNode(childNode, this); + } + + } + /** + * init node + * @param node + * @param mTreeNode + * @throws SAXException + */ + private void initNode(Node node, XMLDefaultMutableTreeNode mTreeNode) + throws SAXException + { + + switch (node.getNodeType()) + { + case Node.ELEMENT_NODE: + initElementNode(node, mTreeNode); + break; + + case Node.TEXT_NODE: + initTextNode((Text)node, mTreeNode); + break; + + + case Node.CDATA_SECTION_NODE: + initCDATASectionNode((CDATASection)node, mTreeNode); + break; + case Node.COMMENT_NODE: + initCommentNode((Comment)node,mTreeNode); + break; + + default: + //if other node type, we will just skip it + break; + + } + + } + /** + * init element node + * @param node + * @param mTreeNode + * @throws SAXException + */ + private void initElementNode(Node node, DefaultMutableTreeNode mTreeNode) + throws SAXException { + String nodeName = node.getNodeName(); + + NodeList childNodes = node.getChildNodes(); + XMLDefaultMutableTreeNode childTreeNode = new XMLDefaultMutableTreeNode(nodeName + ,node); + + mTreeNode.add(childTreeNode); + initAttributeNode(node, childTreeNode); + for (int i = 0; i < childNodes.getLength(); i++) + { + Node childNode = childNodes.item(i); + initNode(childNode, childTreeNode); + } + + } + /** + * init attribute node + * @param node + * @param mTreeNode + * @throws SAXException + */ + private void initAttributeNode(Node node, DefaultMutableTreeNode mTreeNode) + throws SAXException { + NamedNodeMap nm = node.getAttributes(); + for (int i = 0; i < nm.getLength(); i++) + { + Attr nmNode = (Attr)nm.item(i); + String value = nmNode.getName() + " = \"" + nmNode.getValue() + "\""; + XMLDefaultMutableTreeNode attributeNode = new XMLDefaultMutableTreeNode( + value,nmNode); + mTreeNode.add(attributeNode); + + } + } + /** + * init comment Node + * @param node + * @param mTreeNode + * @throws SAXException + */ + private void initCommentNode(Comment node, DefaultMutableTreeNode mTreeNode) throws SAXException{ + String data = node.getData(); + if(data != null || data.length() > 0) + { + String value = ""; + XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node); + mTreeNode.add(commentNode); + } + } + /** + * init CDATASection Node + * @param node + * @param mTreeNode + * @throws SAXException + */ + private void initCDATASectionNode(CDATASection node, DefaultMutableTreeNode mTreeNode) throws SAXException + { + String data = node.getData(); + if(data != null || data.length() > 0) + { + String value = ""; + XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node); + mTreeNode.add(commentNode); + } + } + /** + * init the TextNode + * @param node + * @param mTreeNode + * @throws SAXException + */ + private void initTextNode(Text node, DefaultMutableTreeNode mTreeNode) throws SAXException + { + String text = node.getNodeValue().trim(); + if(text != null && text.length() > 0) + { + XMLDefaultMutableTreeNode textNode = new XMLDefaultMutableTreeNode(text,node); + mTreeNode.add(textNode); + } + } + + /** + * get the xml node + * @return + */ + public Node getXMLNode() + { + return xmlNode; + } +}