Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: Spread Sheet Mouse Listeners

Hi Rick,

It may be simpler to get mouse events than I described
earlier.  If your FancySSCell uses Java2D, then you
can probably just do:

  FancySSCell cell = ...
  Component comp = cell.getDisplay().getComponent();
  MouseListener ml = new MouseAdapter() {
    public void mouseEntered(MouseEvent e) {
      // process event
    }
    public void mouseExited(MouseEvent e) {
      // process event
    }
    public void mousePressed(MouseEvent e) {
      // process event
    }
    public void mouseReleased(MouseEvent e) {
      // process event
    }
  };
  comp.addMouseListener(ml);
  MouseMotionListener mml = new MouseMotionAdapter() {
    public void mouseDragged(MouseEvent e) {
      // process event
    }
  };
  comp.addMouseMotionListener(mml);

If your FancySSCell uses Java3D, then you can define
your own extension of javax.media.j3d.Behavior whose
processStimulus() method processes mouse events.  If you
name it MyMouseBehavior, it can follow the pattern of
visad.java3d.MouseBehaviorJ3D except that it doesn't
have any MouseHelper, DisplayRendererJ3D or DisplayImpl
variables - it just processes mouse events for you
application.  You'd link MyMouseBehavior into the Java3D
scene graph as follows:

  DisplayImplJ3D display = ...;
  DisplayRendererJ3D display_renderer
    (DisplayRendererJ3D) display.getDisplayRenderer();
  TransformGroup trans = display_renderer.getTrans();
  MyMouseBehavior my_mouse = new MyMouseBehavior();
  BoundingSphere bounds
    new BoundingSphere(new Point3d(0.0,0.0,0.0), 2000000.0);
  my_mouse.setSchedulingBounds(bounds);
  BranchGroup group = new BranchGroup();
  group.addChild(my_mouse);
  trans.addChild(group);

If you don't know ahead of time whether your FancySSCell will
use Java2D or Java3D, you could do something like:

  FancySSCell cell = ...
  if (cell.getDisplay() instanceof DisplayImplJ2D) {
    // its Java2D
  }
  else if (cell.getDisplay() instanceof DisplayImplJ3D) {
    // its Java3D
  }

Cheers,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html

 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690