this.treeModel = new ComponentTreeModel(new ComponentTreeNode("Components"));
this.tree = new JTree(this.treeModel);
// Add a tool tip.
ToolTipManager.sharedInstance().registerComponent(this.tree);
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
@Override
public java.awt.Component getTreeCellRendererComponent(JTree t, Object value, boolean sel,
boolean expanded, boolean leaf, int row, boolean focus) {
super.getTreeCellRendererComponent(t, value, sel, expanded, leaf, row, focus);
ComponentTreeNode node = (ComponentTreeNode) value;
if (node.getComponentReference() == null) {
setToolTipText(null);
} else {
setToolTipText("Drag a component to the composer to add");
}
return this;
}
};
// Change icons
try {
renderer.setOpenIcon(SwingUtil.createImageIcon("opened.gif"));
renderer.setClosedIcon(SwingUtil.createImageIcon("closed.gif"));
renderer.setLeafIcon(SwingUtil.createImageIcon("leaf.gif"));
} catch (RuntimeException e) {
logger.warn("Failed to load image icons. " + "It will use the default icons instead.", e);
}
this.tree.setCellRenderer(renderer);