corefx - updated node labels for easier visibility with backgrounds
This commit is contained in:
parent
55e56e992f
commit
fb71e55b0b
2 changed files with 37 additions and 0 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -70,6 +70,7 @@ public class NetworkGraph {
|
||||||
|
|
||||||
// node render properties
|
// node render properties
|
||||||
renderContext.setVertexLabelTransformer(CoreNode::getName);
|
renderContext.setVertexLabelTransformer(CoreNode::getName);
|
||||||
|
renderContext.setVertexLabelRenderer(new CoreVertexLabelRenderer(Color.YELLOW));
|
||||||
renderContext.setVertexShapeTransformer(node -> {
|
renderContext.setVertexShapeTransformer(node -> {
|
||||||
double offset = -(IconUtils.ICON_SIZE / 2.0);
|
double offset = -(IconUtils.ICON_SIZE / 2.0);
|
||||||
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
||||||
|
|
Loading…
Reference in a new issue