感谢您的建议,但我设法使FreeHEP矢量图库以我想要的方式工作。如果有人遇到相同的问题,我将分享下面的代码。
上面提到的库具有一个非常不错的内置导出菜单,该菜单可处理多种不同格式的导出。修改后的“ ModelGraphMouse”类的代码摘录:
protected void handlePopup(MouseEvent e) { final VisualizationViewer<MyNode, MyEdge> vv = (VisualizationViewer<MyNode, MyEdge>)e.getSource(); Point2D p = e.getPoint(); GraphElementAccessor<MyNode, MyEdge> 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<V, E>) vv)); menu.add(exportGraphMenuItem); menu.show(e.getComponent(), e.getX(), e.getY()); } } }和动作监听器:
public class ExportActionListener implements ActionListener{ private VisualizationViewer<V, E> wvv; public ExportActionListener(VisualizationViewer<V, E> vv) { this.wvv = vv; } @Override public void actionPerformed(ActionEvent e) { ExportDialog export = new ExportDialog(); export.showExportDialog(wvv, "Export view as ...", wvv, "export"); }}


