public PdfInspectorSample(
)
{
super(new GridLayout(1,0));
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
{
Dimension minimumSize = new Dimension(200, 100);
JScrollPane treeScrollPane;
{
tree = new JTree();
{
tree.setModel(new DefaultTreeModel(null));
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION
);
tree.addTreeSelectionListener(
new TreeSelectionListener()
{
@Override
public void valueChanged(TreeSelectionEvent event)
{
// Clear the attributes table!
DefaultTableModel model = (DefaultTableModel)table.getModel();
model.setRowCount(0);
DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
if(node == null)
return;
// Show the current node attributes into the table!
Object nodeValue = node.getUserObject();
if(nodeValue instanceof ContentNodeValue)
{showContentAttributes(((ContentNodeValue)nodeValue).getContent(), model);}
else if(nodeValue instanceof PageNodeValue)
{showPageAttributes(((PageNodeValue)nodeValue).getPage().getContents(), model);}
pack(table);
}
}
);
tree.addTreeWillExpandListener(
new TreeWillExpandListener()
{
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException
{/* NOOP */}
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)event.getPath().getLastPathComponent();
Object nodeValue = node.getUserObject();
if(nodeValue instanceof PageNodeValue)
{
// Content placeholder?
if(((DefaultMutableTreeNode)node.getFirstChild()).getUserObject() == null)
{
// Remove the content placeholder!
node.removeAllChildren();
// Create the page content nodes!
createContentNodes(
((PageNodeValue)nodeValue).getPage().getContents(),
node
);
}
}
}
}
);
}
treeScrollPane = new JScrollPane(tree);
treeScrollPane.setMinimumSize(minimumSize);
}
splitPane.setLeftComponent(treeScrollPane);
JScrollPane tableScrollPane;
{
table = new JTable(new DefaultTableModel(null, new String[]{"Attribute","Value"}));
{
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
TableColumn column0 = table.getColumnModel().getColumn(0);
{
column0.setCellRenderer(new CellRenderer());
column0.setMinWidth(200);
column0.setMaxWidth(200);
}
TableColumn column1 = table.getColumnModel().getColumn(1);
{
column1.setCellRenderer(new CellRenderer());
}
table.getColumnModel().addColumnModelListener(
new TableColumnModelListener()
{
@Override
public void columnAdded(TableColumnModelEvent event)
{/* NOOP */}
@Override
public void columnMarginChanged(ChangeEvent event)
{pack(table);}
@Override
public void columnMoved(TableColumnModelEvent event)
{/* NOOP */}
@Override
public void columnRemoved(TableColumnModelEvent event)
{/* NOOP */}
@Override
public void columnSelectionChanged(ListSelectionEvent event)
{/* NOOP */}
}
);
}
tableScrollPane = new JScrollPane(table);
tableScrollPane.setMinimumSize(minimumSize);
}
splitPane.setRightComponent(tableScrollPane);
}
add(splitPane);
}