我正在使用 graphstream 库来构建应用程序。当我使用 view.getCamera().setPercent() 缩放图形时,一些节点将被隐藏,直到现在没有问题。我的问题是当缩放图形后隐藏由边缘连接的两个节点时,它的边缘也会被隐藏。即使它的四肢被隐藏,我也想保持这个边缘的出现。我试过这段代码来解释我的问题:
public class Zoom {
public static void main(String[] args) {
//create a simple graph
Graph graph = new SingleGraph("Zoom");
graph.setAttribute("ui.stylesheet", "node{size:30px; fill-color:red; text-size:20;}");
Node[] nodes = new Node[2];
for (int i = 0; i < 2; i++) {
nodes[i] = graph.addNode("" + i);
nodes[i].setAttribute("ui.label", "" + i);
}
graph.addEdge("01", "0", "1");
//create the viewer
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
viewer.enableAutoLayout();
ViewPanel view_panel = viewer.addDefaultView(false);
//create the main frame
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout());
frame.setLocation(new Point(200, 200));
frame.setPreferredSize(new Dimension(600, 400));
//the function responsible of zooming
frame.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent mwe) {
double scaleZoom;
if (Event.ALT_MASK != 0) {
scaleZoom = viewer.getDefaultView().getCamera().getViewPercent();
if (mwe.getWheelRotation() > 0) {
scaleZoom += 0.05;
viewer.getDefaultView().getCamera().setViewPercent(scaleZoom);
} else if (mwe.getWheelRotation() < 0) {
if (scaleZoom > 0.05) {
scaleZoom -= 0.05;
viewer.getDefaultView().getCamera().setViewPercent(scaleZoom);
}
}
}
}
});
view_panel.setPreferredSize(new Dimension(frame.getPreferredSize()));
frame.add(view_panel);
frame.pack();
frame.setVisible(true);
}
}
请提供任何帮助。