当我缩放图表时,它的一半消失了。我试图修改 ViewPort 没有任何结果。这是代码。
public static void printGraph(final Program program) {
final ViewPanel graphViewNew;
final Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
final JFrame mainFrame = new JFrame();
SCGraph graph = new SCGraph(new SingleGraph("CFG"), pred, succ);
Viewer viewer;
program.graphLayout(graph);
program.printGraph(graph);
viewer = new Viewer(graph.getGraphForView(), Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
graphViewNew = viewer.addDefaultView(false);
mainFrame.getContentPane().add(graphViewNew);
mainFrame.setBounds(0, 0, 1300, 1300);
mainFrame.setLocation(dim.width / 2 - mainFrame.getSize().width / 2,
dim.height / 2 - mainFrame.getSize().height / 2);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
graphViewNew.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent mwe) {
zoomGraphMouseWheelMoved(mwe, graphViewNew);
}
});
}
这是处理事件的函数:
public static void zoomGraphMouseWheelMoved(MouseWheelEvent mwe, ViewPanel view_panel) {
if (ALT_MASK != 0) {
if (mwe.getWheelRotation() > 0) {
double new_view_percent = view_panel.getCamera().getViewPercent() + 0.05;
view_panel.getCamera().setViewPercent(new_view_percent);
} else if (mwe.getWheelRotation() < 0) {
double current_view_percent = view_panel.getCamera().getViewPercent();
if (current_view_percent > 0.05) {
view_panel.getCamera().setViewPercent(current_view_percent - 0.05);
}
}
}
}
此外,如果我使用内置键(up.down、left、right、page-down、page-up)导航到视图中,我也会遇到同样的问题。