Hi Vladimir,
> I want to draw a box in a 2D graphic when dragging
> mouse. (mouse clicked ->first point, mouse dragged->draw the box,
> mouse released-> end drawing)
>
> I'd want to know if I there is a method that changes appearence of
> cursor when dragging mouse, in order to draw the window... or if it
> is more difficult than this. In the second case, where should I draw the
> box? When using a DisplayImplJ2D, the graphic is drawn in a
> VisADCanvasJ2D,
> but it seems that ther's no way to access to the canvas...
You can access the canvas by:
DisplayImplJ2D display = ...
DisplayRendererJ2D dr =
(DisplayRendererJ2D) display.getDisplayRenderer();
VisADCanvasJ2D canvas = dr.getCanvas();
You can do custom cursors using direct manipulation of a
RealTuple data object with two RealType components mapped
to XAxis and YAxis, and another RealType component mapped
to Shape. visad/rabin/Rain.java and
visad/bom/TrackManipulation.java provide examples.
Note that visad/bom/RubberBandBoxRendererJ3D.java is a pretty
general way to draw rectangles in 2-D manifolds in Java3D
displays (try 'java visad.bom.RubberBandBoxRendererJ3D radius'
and click and drag the right mouse button on the sphere). If
you can use Java3D this would be a good way to solve your
problem (see the main() method of RubberBandBoxRendererJ3D.java
for an example of how to get the location of the dragged
rectangle in your code).
> Should I choose another solution, like drawing the bow in the glassPane
> of the JFrame
> containing my graphic?
You could make a DisplayListener that listens for mouse
pressed and mouse released events. I think that the
Unidata folks are working on support for mouse dragged
events. Perhaps they can comment?
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