JUNGグラフの視覚化でカスタム頂点ラベルを使用するには?
私は、頂点にラベルを付けるために使用できることがわかったJung 2.0チュートリアルsetVertexLabelTransformer()
に従っていますが、私の知る限り、これらのラベルはカスタマイズできません。
たとえば、次のコードは、頂点ラベル 1、2、4 を持つ 3 つの頂点を生成します。
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import java.awt.Dimension;
import javax.swing.JFrame;
public class SimpleGraphView {
Graph<Integer, String> g;
public SimpleGraphView() {
g = new SparseMultigraph<Integer, String>();
g.addVertex((Integer)1);
g.addVertex((Integer)2);
g.addVertex((Integer)4);
}
public static void main(String[] args) {
SimpleGraphView sgv = new SimpleGraphView();
Layout<Integer, String> layout = new CircleLayout(sgv.g);
layout.setSize(new Dimension(800,800));
BasicVisualizationServer<Integer,String> vv =
new BasicVisualizationServer<Integer,String>(layout);
vv.setPreferredSize(new Dimension(850,850));
JFrame frame = new JFrame("Simple Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
}
「q0」などのラベルを追加するにはどうすればよいですか?