I am new to GraphStream and have built a minimal application with a GraphStream 2.0 graph embedded into a Swing application.
In my application, the mouse pointer is apparently offset by about half the panel size (both vertically and horizontically) when I am trying to drag nodes.
This is the code:
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();
}
});
}
}
The picture below shows the mouse pointer position when dragging the rectangle node in the center (encircled in red).
Any ideas on the cause of this issue?
Edit:
Here is a short GIF animation showing the problem (the shown application is the code above):