我是 GraphStream 的新手,并且已经构建了一个最小的应用程序,其中 GraphStream 2.0 图形嵌入到了 Swing 应用程序中。
在我的应用程序中,当我尝试拖动节点时,鼠标指针显然偏移了面板大小的大约一半(垂直和水平)。
这是代码:
package gstest;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.layout.Layout;
import org.graphstream.ui.layout.springbox.implementations.SpringBox;
import org.graphstream.ui.swing_viewer.DefaultView;
import org.graphstream.ui.swing_viewer.SwingViewer;
import org.graphstream.ui.view.Viewer;
public class GSTest {
private static void createAndShowGUI() {
JFrame frame = new JFrame("GS Test");
frame.setMinimumSize(new Dimension(1000, 500));
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new GridLayout(1, 1));
frame.getContentPane().add(makeMainPanel());
}
private static JPanel makeMainPanel() {
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
Layout graphLayout = new SpringBox(false);
Graph graph = new SingleGraph("embedded");
SwingViewer viewer = new SwingViewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
JPanel graphPanel = new JPanel();
DefaultView view = (DefaultView) viewer.addDefaultView(false);
view.setPreferredSize(new Dimension(980, 460));
graph.addSink(graphLayout);
graphLayout.addAttributeSink(graph);
graph.setAttribute("ui.quality");
graph.setAttribute("ui.antialias");
for (int i = 0; i < 10; i++) {
Node n = graph.addNode(String.valueOf(i));
n.setAttribute("ui.style", "shape: box;");
n.setAttribute("ui.style", "size: 50px,30px;");
n.setAttribute("ui.style", "fill-color: blue;");
}
graphLayout.compute();
graphPanel.add(view);
return graphPanel;
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
下图为拖动中间矩形节点时鼠标指针的位置(红色圈出)。
关于这个问题的原因有什么想法吗?
编辑:
这是一个显示问题的简短 GIF 动画(显示的应用程序是上面的代码):