Visualize tree from *.dot file

好久不见. 提交于 2020-01-14 05:39:10

问题


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:


  1. I would start by googling something like dot files java, actually there seem to be multiple solutions, like ZGRViewer
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!