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