Exporting JUNG graphs to hi-res images (preferably vector based)

前端 未结 4 1131
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 09:16

In one of my projects I use JUNG2 to visualize a very large multiple-parent hierarchy graph, displayed in an applet. I would need to export the whole/parts of the graph to h

4条回答
  •  Happy的楠姐
    2020-12-03 09:55

    Thanks for the suggestions but I have managed to get FreeHEP Vector Graphics library working the way I want to. I am sharing the code below in case anyone runs into the same questions.

    The above-named library has a very nice built-in export menu, which handles the export to a bunch of different formats. Code excerpt from the modified ´ModelGraphMouse´ class:

    protected void handlePopup(MouseEvent e) {
            final VisualizationViewer vv = (VisualizationViewer)e.getSource();
            Point2D p = e.getPoint();
            GraphElementAccessor pickSupport = vv.getPickSupport();
            if(pickSupport != null) {
                final MyNode v = pickSupport.getVertex(vv.getGraphLayout(), p.getX(), p.getY());
    
                // if clicked on a vertex -> show info popup
                // else show contexual menu
                if(v != null) {
                    JFrame popup = new JFrame("Node: " + v.getId());
                    popup.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    ...
                } else{
                    JPopupMenu menu = new JPopupMenu();
                    JMenuItem exportGraphMenuItem = new JMenuItem("Export graph to vector image...");
                    exportGraphMenuItem.addActionListener(new ExportActionListener((WritingVisualizationViewer) vv));
                    menu.add(exportGraphMenuItem);
                    menu.show(e.getComponent(), e.getX(), e.getY());
                } 
            }
        }
    

    and the action listener:

        public class ExportActionListener implements ActionListener{
    
        private VisualizationViewer wvv;
        public ExportActionListener(VisualizationViewer vv) {
            this.wvv = vv;
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            ExportDialog export = new ExportDialog();
            export.showExportDialog(wvv, "Export view as ...", wvv, "export");
        }
    }
    

提交回复
热议问题