我现在被 Java 库 Jung 困住了。
我显示顶点和边,只是我找不到任何顶点着色函数,我需要顶点值而不是鼠标。
import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.decorators.PickableVertexPaintTransformer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import org.apache.commons.collections15.Transformer;
import org.apache.commons.collections15.functors.ConstantTransformer;
public class Design {
public Graph<String, Integer> g;
public Design() {
this.g = ProjectTools.readNet("SmallTown.net");
}
public static <Paint> void main(String[] args) {
Design sgv = new Design();
Layout<Integer, String> layout = new FRLayout(sgv.g);
layout.setSize(new Dimension(800,800));
BasicVisualizationServer<Integer, String> vv =
new BasicVisualizationServer<Integer, String>(layout);
Transformer<Integer,Paint> vertexPaint = new Transformer<Integer,Paint>() {
public Paint transform(Integer i) {
return (Paint) Color.GREEN;
}
};
vv.setPreferredSize(new Dimension(850,850));
vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.green));
vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.white));
vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));
vv.getRenderContext().setVertexFillPaintTransformer((Transformer<Integer, java.awt.Paint>) vertexPaint);
vv.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.green, Color.yellow));
vv.setBackground(Color.gray);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
JFrame frame = new JFrame("Projet Algo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
}
我的渲染: