@Override
public JComponent render(SimilarityResult result) {
final DCPanel panel = new DCPanel();
panel.setLayout(new BorderLayout());
final DefaultTreeRenderer rendererDelegate = new DefaultTreeRenderer();
final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Similarity groups");
final List<SimilarityGroup> similarityGroups = result.getSimilarityGroups();
for (SimilarityGroup sg : similarityGroups) {
rootNode.add(new DefaultMutableTreeNode(sg));
}
final DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
final JXTree tree = new JXTree();
tree.setCellRenderer(new TreeCellRenderer() {
@Override
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);