Search code examples
javamousejung

mouseEntered a JUNG2 vertex


I am looking for the "correct" way to show a custom Component as a popup when I mouseover a Vertex in JUNG2.

This question is essentially the same as

Jung2: How to implement displaying details of a node on mouse over of a Node?

but that person seems to be content with a simple tooltip popup, whereas I am not.

NOTE: I am currently using an implementation of PluggableGraphMouse with a MouseMotionListener plugin which does something like this (I have Note objects as vertices):

    @Override
    public void mouseMoved(MouseEvent e) {
        Note note = graphVisualiser.getPickSupport().getVertex(getGraphLayout(), e.getX(), e.getY());
        if (note != null && note != lastMouseOverNote) {
            lastMouseOverNote = note;
            // my handling code here
        }
    }

It works when I mouse over a vertex, and I can also expand on the above to turn off the popup when the mouse goes away, but I am concerned that this approach is incredibly inefficient: it is essentially checking to see if I'm mousing over a vertex every time the mouse moves.

I'd rather have a Listener approach - is there a way to register mouseEntered/mouseExited event to the vertices? (from what I can tell, this is all happening through raw painting and there is no Component that I could register with).


Solution

  • It cannot be done, because the vertices are being drawn as primitives and don't have listeners for mouse movements - only selection/deselection.