< prev index next >

src/demo/share/jfc/Notepad/ElementTreePanel.java

Print this page




  98 
  99         // Create the tree.
 100         treeModel = new ElementTreeModel(document);
 101         tree = new JTree(treeModel) {
 102 
 103             @Override
 104             public String convertValueToText(Object value, boolean selected,
 105                     boolean expanded, boolean leaf,
 106                     int row, boolean hasFocus) {
 107                 // Should only happen for the root
 108                 if (!(value instanceof Element)) {
 109                     return value.toString();
 110                 }
 111 
 112                 Element e = (Element) value;
 113                 AttributeSet as = e.getAttributes().copyAttributes();
 114                 String asString;
 115 
 116                 if (as != null) {
 117                     StringBuilder retBuffer = new StringBuilder("[");
 118                     Enumeration names = as.getAttributeNames();
 119 
 120                     while (names.hasMoreElements()) {
 121                         Object nextName = names.nextElement();
 122 
 123                         if (nextName != StyleConstants.ResolveAttribute) {
 124                             retBuffer.append(" ");
 125                             retBuffer.append(nextName);
 126                             retBuffer.append("=");
 127                             retBuffer.append(as.getAttribute(nextName));
 128                         }
 129                     }
 130                     retBuffer.append(" ]");
 131                     asString = retBuffer.toString();
 132                 } else {
 133                     asString = "[ ]";
 134                 }
 135 
 136                 if (e.isLeaf()) {
 137                     return e.getName() + " [" + e.getStartOffset() + ", " + e.
 138                             getEndOffset() + "] Attributes: " + asString;




  98 
  99         // Create the tree.
 100         treeModel = new ElementTreeModel(document);
 101         tree = new JTree(treeModel) {
 102 
 103             @Override
 104             public String convertValueToText(Object value, boolean selected,
 105                     boolean expanded, boolean leaf,
 106                     int row, boolean hasFocus) {
 107                 // Should only happen for the root
 108                 if (!(value instanceof Element)) {
 109                     return value.toString();
 110                 }
 111 
 112                 Element e = (Element) value;
 113                 AttributeSet as = e.getAttributes().copyAttributes();
 114                 String asString;
 115 
 116                 if (as != null) {
 117                     StringBuilder retBuffer = new StringBuilder("[");
 118                     Enumeration<?> names = as.getAttributeNames();
 119 
 120                     while (names.hasMoreElements()) {
 121                         Object nextName = names.nextElement();
 122 
 123                         if (nextName != StyleConstants.ResolveAttribute) {
 124                             retBuffer.append(" ");
 125                             retBuffer.append(nextName);
 126                             retBuffer.append("=");
 127                             retBuffer.append(as.getAttribute(nextName));
 128                         }
 129                     }
 130                     retBuffer.append(" ]");
 131                     asString = retBuffer.toString();
 132                 } else {
 133                     asString = "[ ]";
 134                 }
 135 
 136                 if (e.isLeaf()) {
 137                     return e.getName() + " [" + e.getStartOffset() + ", " + e.
 138                             getEndOffset() + "] Attributes: " + asString;


< prev index next >