问题
I need to visualize a tree which I have gotten from an ANTLR parser and written to a .dot file by catching console output that the ANLR dot generator produces.
MyDOTTreeGenerator generator = new MyDOTTreeGenerator();
PrintStream old = System.out;
try {
System.setOut(new PrintStream(new FileOutputStream(graphFile)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(generator.toDOT(root));
System.out.flush();
System.setOut(old);
Question is:
1. Is there a way to visualize the .dot file in my program, Swing component for example.
2. I have read/tried to visualize with the help of Grappa library + Graphviz toolkit using this approach => is there a way I can pack the Graphviz toolkit in my program, so that I can visualize the graph without the end user having to download and/or install something.
回答1:
- I would start by googling something like dot files java, actually there seem to be multiple solutions, like ZGRViewer
- It is possible to start external programs from Java, and there are many ways to create installers that install additional programs.
来源:https://stackoverflow.com/questions/18991143/visualize-tree-from-dot-file