1 2 17 18 19 package org.apache.poi.contrib.poibrowser; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.awt.Font ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import javax.swing.JPanel ; 28 import javax.swing.JTextArea ; 29 import javax.swing.JTree ; 30 import javax.swing.tree.DefaultMutableTreeNode ; 31 32 import org.apache.poi.hpsf.Property; 33 import org.apache.poi.hpsf.PropertySet; 34 import org.apache.poi.hpsf.Section; 35 import org.apache.poi.hpsf.SummaryInformation; 36 37 46 public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer 47 { 48 49 public Component getTreeCellRendererComponent(final JTree tree, 50 final Object value, 51 final boolean selected, 52 final boolean expanded, 53 final boolean leaf, 54 final int row, 55 final boolean hasFocus) 56 { 57 final PropertySetDescriptor d = (PropertySetDescriptor) 58 ((DefaultMutableTreeNode ) value).getUserObject(); 59 final PropertySet ps = d.getPropertySet(); 60 final JPanel p = new JPanel (); 61 final JTextArea text = new JTextArea (); 62 text.setBackground(new Color (200, 255, 200)); 63 text.setFont(new Font ("Monospaced", Font.PLAIN, 10)); 64 text.append(renderAsString(d)); 65 text.append("\nByte order: " + 66 Codec.hexEncode((short) ps.getByteOrder())); 67 text.append("\nFormat: " + 68 Codec.hexEncode((short) ps.getFormat())); 69 text.append("\nOS version: " + 70 Codec.hexEncode(ps.getOSVersion())); 71 text.append("\nClass ID: " + 72 Codec.hexEncode(ps.getClassID())); 73 text.append("\nSection count: " + ps.getSectionCount()); 74 text.append(sectionsToString(ps.getSections())); 75 p.add(text); 76 77 if (ps instanceof SummaryInformation) 78 { 79 80 final SummaryInformation si = (SummaryInformation) ps; 81 text.append("\n"); 82 text.append("\nTitle: " + si.getTitle()); 83 text.append("\nSubject: " + si.getSubject()); 84 text.append("\nAuthor: " + si.getAuthor()); 85 text.append("\nKeywords: " + si.getKeywords()); 86 text.append("\nComments: " + si.getComments()); 87 text.append("\nTemplate: " + si.getTemplate()); 88 text.append("\nLast Author: " + si.getLastAuthor()); 89 text.append("\nRev. Number: " + si.getRevNumber()); 90 text.append("\nEdit Time: " + si.getEditTime()); 91 text.append("\nLast Printed: " + si.getLastPrinted()); 92 text.append("\nCreate Date/Time: " + si.getCreateDateTime()); 93 text.append("\nLast Save Date/Time: " + si.getLastSaveDateTime()); 94 text.append("\nPage Count: " + si.getPageCount()); 95 text.append("\nWord Count: " + si.getWordCount()); 96 text.append("\nChar Count: " + si.getCharCount()); 97 text.append("\nApplication Name: " + si.getApplicationName()); 99 text.append("\nSecurity: " + si.getSecurity()); 100 } 101 102 if (selected) 103 Util.invert(text); 104 return p; 105 } 106 107 108 109 113 protected String sectionsToString(final List sections) 114 { 115 final StringBuffer b = new StringBuffer (); 116 int count = 1; 117 for (Iterator i = sections.iterator(); i.hasNext();) 118 { 119 Section s = (Section) i.next(); 120 String d = toString(s, "Section " + count++); 121 b.append(d); 122 } 123 return b.toString(); 124 } 125 126 127 128 131 protected String toString(final Section s, final String name) 132 { 133 final StringBuffer b = new StringBuffer (); 134 b.append("\n" + name + " Format ID: "); 135 b.append(Codec.hexEncode(s.getFormatID())); 136 b.append("\n" + name + " Offset: " + s.getOffset()); 137 b.append("\n" + name + " Section size: " + s.getSize()); 138 b.append("\n" + name + " Property count: " + s.getPropertyCount()); 139 140 final Property[] properties = s.getProperties(); 141 for (int i = 0; i < properties.length; i++) 142 { 143 final Property p = properties[i]; 144 final Object value = p.getValue(); 145 b.append("\n" + name + " "); 146 b.append("PID_"); 147 b.append(p.getID()); 148 b.append(' '); 149 b.append(s.getPIDString(p.getID()) + ": "); 150 if (value instanceof byte[]) 151 { 152 byte[] b2 = (byte[]) value; 153 b.append("0x" + Codec.hexEncode(b2, 0, 4)); 154 b.append(' '); 155 b.append("0x" + Codec.hexEncode(b2, 4, b2.length - 4)); 156 } 157 else if (value != null) 158 b.append(value.toString()); 159 else 160 b.append("null"); 161 } 162 return b.toString(); 163 } 164 165 } 166 | Popular Tags |