public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof SimilarityGroup) {
final SimilarityGroup similarityGroup = (SimilarityGroup) userObject;
final String[] values = similarityGroup.getValues();
final StringBuilder sb = new StringBuilder();
sb.append(values.length);
sb.append(": [");
for (int i = 0; i < values.length; i++) {
if (i != 0) {
sb.append(',');
}
sb.append('\"');
sb.append(values[i]);
sb.append('\"');
if (sb.length() > 17) {
sb.delete(17, sb.length());
sb.append(",...");
break;
}
}
sb.append(']');
value = sb.toString();
}
}
return rendererDelegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
}
});
tree.setModel(treeModel);
final DCPanel centerPanel = new DCPanel(WidgetUtils.BG_COLOR_BRIGHT, WidgetUtils.BG_COLOR_LESS_BRIGHT);
centerPanel.setBorder(WidgetUtils.BORDER_EMPTY);
centerPanel.setLayout(new BorderLayout());
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.add(WidgetUtils.scrolleable(tree));
splitPane.add(WidgetUtils.scrolleable(centerPanel));
splitPane.setDividerLocation(180);
panel.add(splitPane, BorderLayout.CENTER);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path == null) {
return;
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object userObject = node.getUserObject();
if (userObject instanceof SimilarityGroup) {
SimilarityGroup similarValues = (SimilarityGroup) userObject;
AnnotatedRowsResult annotatedRowsResult = similarValues.getAnnotatedRows();
AnnotatedRowsResultSwingRenderer renderer = new AnnotatedRowsResultSwingRenderer();
JPanel comp = renderer.render(annotatedRowsResult);
centerPanel.removeAll();
centerPanel.add(comp, BorderLayout.NORTH);
centerPanel.updateUI();