1 2 17 18 19 package org.apache.poi.contrib.poibrowser; 20 21 import java.awt.*; 22 import javax.swing.*; 23 import javax.swing.tree.*; 24 25 35 public class DocumentDescriptorRenderer extends DefaultTreeCellRenderer 36 { 37 38 public Component getTreeCellRendererComponent(final JTree tree, 39 final Object value, 40 final boolean selected, 41 final boolean expanded, 42 final boolean leaf, 43 final int row, 44 final boolean hasFocus) 45 { 46 final DocumentDescriptor d = (DocumentDescriptor) 47 ((DefaultMutableTreeNode) value).getUserObject(); 48 final JPanel p = new JPanel(); 49 final JTextArea text = new JTextArea(); 50 text.append(renderAsString(d)); 51 text.setFont(new Font("Monospaced", Font.PLAIN, 10)); 52 p.add(text); 53 if (selected) 54 Util.invert(text); 55 return p; 56 } 57 58 59 62 protected String renderAsString(final DocumentDescriptor d) 63 { 64 final StringBuffer b = new StringBuffer (); 65 b.append("Name: "); 66 b.append(d.name); 67 b.append(" ("); 68 b.append(Codec.hexEncode(d.name)); 69 b.append(") \n"); 70 71 b.append("Size: "); 72 b.append(d.size); 73 b.append(" bytes\n"); 74 75 b.append("First bytes: "); 76 b.append(Codec.hexEncode(d.bytes)); 77 78 return b.toString(); 79 } 80 81 } 82 | Popular Tags |