1 2 17 18 19 package org.apache.poi.contrib.poibrowser; 20 21 import java.awt.event.WindowAdapter ; 22 import java.awt.event.WindowEvent ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 26 import javax.swing.JFrame ; 27 import javax.swing.JScrollPane ; 28 import javax.swing.JTree ; 29 import javax.swing.tree.DefaultMutableTreeNode ; 30 import javax.swing.tree.DefaultTreeModel ; 31 import javax.swing.tree.MutableTreeNode ; 32 33 import org.apache.poi.poifs.eventfilesystem.POIFSReader; 34 35 47 public class POIBrowser extends JFrame 48 { 49 50 53 protected MutableTreeNode rootNode; 54 55 56 57 62 public static void main(String [] args) 63 { 64 new POIBrowser().run(args); 65 } 66 67 68 69 protected void run(String [] args) 70 { 71 addWindowListener(new WindowAdapter () 72 { 73 public void windowClosing(WindowEvent e) 74 { 75 System.exit(0); 76 } 77 }); 78 79 82 rootNode = new DefaultMutableTreeNode ("POI Filesystems"); 83 DefaultTreeModel treeModel = new DefaultTreeModel (rootNode); 84 85 86 final JTree treeUI = new JTree (treeModel); 87 getContentPane().add(new JScrollPane (treeUI)); 88 89 90 int displayedFiles = 0; 91 for (int i = 0; i < args.length; i++) 92 { 93 final String filename = args[i]; 94 try 95 { 96 POIFSReader r = new POIFSReader(); 97 r.registerListener(new TreeReaderListener(filename, rootNode)); 98 r.read(new FileInputStream (filename)); 99 displayedFiles++; 100 } 101 catch (IOException ex) 102 { 103 System.err.println(filename + ": " + ex); 104 } 105 catch (Throwable t) 106 { 107 System.err.println("Unexpected exception while reading \"" + 108 filename + "\":"); 109 t.printStackTrace(System.err); 110 } 111 } 112 113 115 if (displayedFiles == 0) 116 { 117 System.out.println("No POI filesystem(s) to display."); 118 System.exit(0); 119 } 120 121 122 treeUI.setRootVisible(true); 123 treeUI.setShowsRootHandles(true); 124 ExtendableTreeCellRenderer etcr = new ExtendableTreeCellRenderer(); 125 etcr.register(DocumentDescriptor.class, 126 new DocumentDescriptorRenderer()); 127 etcr.register(PropertySetDescriptor.class, 128 new PropertySetDescriptorRenderer()); 129 treeUI.setCellRenderer(etcr); 130 setSize(600, 450); 131 setTitle("POI Browser 0.08"); 132 setVisible(true); 133 } 134 135 } 136 | Popular Tags |