NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
> I am writing customized mouse handling by extending the MouseHelper class. > Depending on a display button selectable by the user, I need the application > to toggle between different MouseHelper classes (the old one and my new > one(s) ). I've created an extended MouseHelper class called > MouseGateHelper, and when the user clicks the appropriate display button, > the program creates a new DefaultDisplayRendererJ2D that uses this > MouseHelper subclass. But I can't find a method for telling display to use > this new display renderer (DisplayImpl only has a getRenderer(), not a > setRenderer() methods). Once a DisplayImpl is constructed, don't try to changes its DisplayRenderer, MouseBehavior or MouseHelper. Rather, do as I describe below. > When a user selects the alternative mousehandling, the application > constructs MouseGateHelper, but then continues to handle mouse events using > the old MouseHelper. I may be overlooking something obvious--here's the > code: > > //MouseGateHelper extends MouseHelper for customized mouse events > > DisplayImpl display = ... > > DefaultDisplayRendererJ2D dr = new > DefaultDisplayRendererJ2D(MouseGateHelper.class); > try{ > dr.setDisplay(display); > } catch (VisADException e) {} > > MouseBehaviorJ2D mb = new > MouseBehaviorJ2D(dr,surrogate2.MouseGateHelper.class); > > display.setMouseBehavior(mb); Don't call setMouseBehavior(). Instead define your MouseGateHelper class, and an extension of MouseBehaviorJ2D, perhaps named surrogate2.MouseGateBehaviorJ2D, that is nothing more than the constructor: public MouseGateBehaviorJ2D(DisplayRendererJ2D displayRenderer) { super(displayRenderer, surrogate2.MouseGateHelper.class); } Then in your application, construct your DisplayRenderer and DisplayImpl as: DisplayRendererJ2D displayRenderer new DefaultDisplayRendererJ2D(surrogate2.MouseGateBehaviorJ2D.class); DisplayImplJ2D display = new DisplayImplJ2D("display", displayRenderer); Now display will be constructed with your MouseGateBehaviorJ2D. It should make any dynamic changes internally, rather than having your application try to replace it. Cheers, Bill
visad
archives: