次のように、Abstract-Syntax-Tree ビジュアライゼーションを作成するために書いている小さなコンパイラでグラフストリームをいじっていました。
// ASTNode is the root to to the AST tree. Given that node, this just displays
// the AST on-screen.
public static void visualize(ASTNode ast) throws IOException, URISyntaxException {
Path file = Path.of(VisualizeAbstractSyntaxTree.class.getResource("graph.css").toURI());
String css = Files.readString(file);
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Graph graph = new SingleGraph("AST");
graph.addAttribute("ui.stylesheet", css);
construct(ast, "0", graph); // construct the tree from the AST root node.
Viewer viewer = graph.display();
}
プログラムを実行すると、自動位置決めマジックが表示されます。ただし、ノードをマウスでドラッグすると、他のノードは静止したままになります。ノードがマウスでドラッグされた場合に、他のノードを反応させる (引っ張る) 簡単な方法はありますか?
これはサポートされている必要がありますが、これに関する例や API 参照が見つからないようです。