Hi Éric,
Maybe you should have a look to this alternative MouseManager that handle mouse over/exited events on elements :
By the way, Viewer contains all views. You can retrieve a view you add in the viewer using Viewer#getView(viewId). But a "View" is a view of the whole graph, not of a single element. That is why there is usually only the default view.
Hope it helps...
Cheers
Hello everyone,
I read many things about how to attach a ViewerListener to a to the ViewerPipe, and was able to successfully retrieve button clicks. Here is that code:
public NetworkGraph()
{
System.setProperty("gs.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
graph = new DefaultGraph(UUID.randomUUID().toString());
graph.setStrict(false);
String styleSheet = ""
+ "graph {padding: 125px;}"
+ "node {size: 250px, 50px, 0px; shape: rounded-box; text-alignment: center; text-size: 20; text-color: #78DE57;}"
+ "node.accessPoint {icon-mode: at-left; icon: url('./resources/access_point.png');}"
+ "edge {shape: line; size: 5; arrow-size: 30,10; fill-color: #55CBF2;}"
+ "";
graph.addAttribute("ui.stylesheet", styleSheet);
deviceMap = new HashMap<>();
viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
viewer.enableAutoLayout();
mouseListener = new NetworkViewerListener(this);
final ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(mouseListener);
fromViewer.addSink(graph);
pumpTimer = new Timer();
pumpTimer.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
fromViewer.pump();
}
}, 60, 60);
graphView = viewer.addDefaultView(false);
}
My problem is that I want to act on mouseEntered and mouseExited events using a MouseInputAdapter. Currently my implementation of ViewerListener extends MouseInputAdapter. Here is the code where I try to add a MouseInputAdapter:
private void addComputerNode(NetworkDevice device)
{
Node child = graph.addNode(device.getId());
child.addAttribute("ui.label", device.getMacAddress());
Node parent = graph.getNode(device.getParentId());
graph.addEdge(UUID.randomUUID().toString(), parent, child);
addListeners(child);
}
private void addListeners(final Node input)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
View view = viewer.getView(input.getId());
view.addMouseListener(mouseListener);
}
});
}
I expected to find the Views in the Viewer, but the Viewer only contains the DefaultView. By the time addListeners() gets called, there are already like 7 nodes and 6 edges attached to the graph. Am I doing something fundamentally wrong? All I want to do is add standard mouse listeners to my nodes. Thanks for your help on this.
Eric Hargitt
Archives gérées par MHonArc 2.6.16.