Re: Responding to MouseClicks on plots

Jim, et al-

Since that message was written, the ability to get events
from other Mouse movements has been added.  So, you could
do something like:


       DisplayImpl display = new DisplayImplJ3D();
       display.enableEvent(DisplayEvent.MOUSE_MOVED);
       display.enableEvent(DisplayEvent.MOUSE_DRAGGED);
       addDisplayListener(new DisplayListener() {
           public void displayChanged(DisplayEvent event) {
               int id = event.getId();
               try {
                   if (id == event.MOUSE_MOVED) {
                       pointerMoved(event.getX(), event.getY());
                   }
               }
           }
       });

where pointerMoved would be something like:

    /**
     * Handles a change in the position of the mouse-pointer.
     */
    protected void pointerMoved(int x, int y)
            throws UnitException, VisADException, RemoteException {

        /*
         * Convert from (pixel, line) Java Component coordinates to (latitude,
         * longitude)
         */
VisADRay ray display.getDisplayRenderer().getMouseBehavior().findRay(x,y);
        <....code from Jim's example, using ray.position instead of
         cursor location....>
    }

Don

Jim Koutsovasilis wrote:
Hello Oliver,

this question has come up before, so you can the previous
reply at:

http://www.unidata.ucar.edu/staff/russ/visad/msg00862.html

PS. I also use this method and it works well.

Hope this helps,
Jim.
---
Jim Koutsovasilis
Bureau of Meteorology, Australia
jimk@xxxxxxxxxx




Oliver Mather wrote:

Hi,
I have a fairly complex application producing several 2D visad plots.
I notice that clicking the middle mouse button on the plot prints the
current X,Y values for that point. I want to extend this so that I can
be notified or these x,y values when the user clicks on the plot  and
then perform some additional tasks.

Is there a way to listen for this kind of event?

I have found that DisplayEvents are triggered when the user clicks on
the plot, but these events are only aware of the X,Y coors of the plot,
not the corresponding values.

I would very much appreciate any advice or tips.

Thanks, Oliver Mather
Software Engineer, omather@xxxxxxxxxx








--
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************