corefx - updated node labels for easier visibility with backgrounds

This commit is contained in:
Blake J. Harnden 2018-11-29 15:00:19 -08:00
parent 55e56e992f
commit fb71e55b0b
2 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,36 @@
package com.core.graph;
import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
public class CoreVertexLabelRenderer extends DefaultVertexLabelRenderer {
CoreVertexLabelRenderer(Color pickedVertexLabelColor) {
super(pickedVertexLabelColor);
}
@Override
public <V> Component getVertexLabelRendererComponent(JComponent vv, Object value, Font font, boolean isSelected, V vertex) {
super.setForeground(Color.WHITE);
if (isSelected) {
this.setForeground(this.pickedVertexLabelColor);
}
super.setBackground(Color.BLACK);
if (font != null) {
this.setFont(font);
} else {
this.setFont(vv.getFont());
}
this.setIcon(null);
EmptyBorder padding = new EmptyBorder(5, 5, 5, 5);
this.setBorder(padding);
this.setValue(value);
setFont(getFont().deriveFont(Font.BOLD));
return this;
}
}

View file

@ -70,6 +70,7 @@ public class NetworkGraph {
// node render properties
renderContext.setVertexLabelTransformer(CoreNode::getName);
renderContext.setVertexLabelRenderer(new CoreVertexLabelRenderer(Color.YELLOW));
renderContext.setVertexShapeTransformer(node -> {
double offset = -(IconUtils.ICON_SIZE / 2.0);
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);