addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
/* Create the tree model with a root node. The latter is
* invisible but it must be present because a tree model
* always needs a root. */
rootNode = new DefaultMutableTreeNode("POI Filesystems");
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
/* Create the tree UI element. */
final JTree treeUI = new JTree(treeModel);
getContentPane().add(new JScrollPane(treeUI));
/* Add the POI filesystems to the tree. */
int displayedFiles = 0;
for (int i = 0; i < args.length; i++)
{
final String filename = args[i];
try
{
POIFSReader r = new POIFSReader();
r.registerListener(new TreeReaderListener(filename, rootNode));
r.read(new FileInputStream(filename));
displayedFiles++;
}
catch (IOException ex)
{
System.err.println(filename + ": " + ex);
}
catch (Throwable t)
{
System.err.println("Unexpected exception while reading \"" +
filename + "\":");
t.printStackTrace(System.err);
}
}
/* Exit if there is no file to display (none specified or only
* files with problems). */
if (displayedFiles == 0)
{
System.out.println("No POI filesystem(s) to display.");
System.exit(0);
}
/* Make the tree UI element visible. */
treeUI.setRootVisible(true);
treeUI.setShowsRootHandles(true);
ExtendableTreeCellRenderer etcr = new ExtendableTreeCellRenderer();
etcr.register(DocumentDescriptor.class,
new DocumentDescriptorRenderer());
etcr.register(PropertySetDescriptor.class,
new PropertySetDescriptorRenderer());
treeUI.setCellRenderer(etcr);
setSize(600, 450);
setTitle("POI Browser 0.09");
setVisible(true);