GraphStream Users

Archives de la liste Aide


RE: Trouble with MouseListeners


Chronologique Discussions 
  • From: "Hargitt, Eric" <ehargitt AT srcinc.com>
  • To: guilhelm savin <guilhelm.savin AT gmail.com>, "graphstream-users AT litislab.fr" <graphstream-users AT litislab.fr>
  • Subject: RE: Trouble with MouseListeners
  • Date: Wed, 4 May 2016 18:02:39 +0000
  • Accept-language: en-US
  • Authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=srcinc.com;
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:23

Thank you for this information. This seems to be working, although I did modify the mouseMoved method in the MouseOverMouseManager. Here is the code:

 

public void mouseMoved(MouseEvent event) {
79 
try {
80     
hoverLock.lockInterruptibly();
81      boolean
stayedOnElement = false;
82     
GraphicElement currentElement = view.findNodeOrSpriteAt(event.getX(), event.getY());
83      if
(hoveredElement != null) {
84         
// currentElement.equals(hoveredElement) was throwing many NullPointerExceptions due to null currentElement
85          //stayedOnElement = currentElement.equals(hoveredElement);
86          
stayedOnElement = currentElement == hoveredElement;
            if
(!stayedOnElement && hoveredElement.hasAttribute("ui.mouseOver")) {
                mouseLeftElement(
hoveredElement);
           
}
        }
       
if (!stayedOnElement && currentElement != null) {
           
if (delay <= 0) {
                mouseOverElement(currentElement)
;
           
} else {
               
hoveredElement = currentElement;
               
hoveredElementLastChanged = event.getWhen();
                if
(latestHoverTimerTask != null) {
                   
latestHoverTimerTask.cancel();
               
}
               
latestHoverTimerTask = new HoverTimerTask(hoveredElementLastChanged, hoveredElement);
               
hoverTimer.schedule(latestHoverTimerTask, delay);
           
}
        }

    }
catch(InterruptedException iex) {
       
// NOP
   
} finally {
       
hoverLock.unlock();
   
}

}

 

On line 86, I changed from using the GraphNode.equals() to using the ‘==’ operator. I did this because there were TONS of NullPointerExceptions being thrown when currentElement was null. Since GraphicNode nor its parents override the .equals() method, using ‘==’ is the same comparison at .equals(), but with an added null check.

 

Also, I’m currently having trouble with the nodeAttributeAdded and nodeAttributeRemoved methods. I’ve created my class that extends AttributeSink and overloaded the aforementioned methods. I’ve added my AttributeSink and it works. The problem is when I try to mouse over the same node twice. Here are some examples:

 

This does not work:

1.       I hover my mouse on Node1 for the required amount of time

o   MouseOverMouseManager.mouseOverElement() is called

2.       I remove my mouse pointer from Node1

o   MouseOverMouseManager.mouseLeftElement() is called

3.       I hover my mouse again over Node1 for the required amount of time

o   MouseOverMouseManager.mouseOverElement() is NOT called

4.       Since MouseOverMouseManager.mouseOverElement() is not called, mouseLeftElement() is also not called

 

This does work:

1.       I hover my mouse on Node1 for the required amount of time

o   MouseOverMouseManager.mouseOverElement() is called

2.       I remove my mouse pointer from Node1

o   MouseOverMouseManager.mouseLeftElement() is called

3.       I hover my mouse on Node2 for the required amount of time

o   MouseOverMouseManager.mouseOverElement() is called

4.       I remove my mouse pointer from Node2

o   MouseOverMouseManager.mouseLeftElement() is called

5.       I hover my mouse again over Node1 for the required amount of time

o   MouseOverMouseManager.mouseOverElement() is called as expected

6.       I remove my mouse pointer from Node1 again and mouseLeftElement() is called. All is well.

 

Is there something that I need to do differently to make this work? Please let me know if the ‘==’ change is acceptable and if you find out why this new issue is happening. Thanks!

 

Eric Hargitt

 

 

From: guilhelm savin [mailto:guilhelm.savin AT gmail.com]
Sent: Wednesday, May 04, 2016 10:19 AM
To: Hargitt, Eric <ehargitt AT srcinc.com>; graphstream-users AT litislab.fr
Subject: Re: Trouble with MouseListeners

 

Notice: This message originated outside of SRC.

Hi Éric,

Maybe you should have a look to this alternative MouseManager that handle mouse over/exited events on elements :

https://github.com/graphstream/gs-core/blob/master/src/org/graphstream/ui/view/util/MouseOverMouseManager.java

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

Le 4 mai 2016 4:01 PM, "Hargitt, Eric" <ehargitt AT srcinc.com> a écrit :

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.

Top of page