Re: drawing a box when dagging mouse

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/ and
visad/bom/ provide examples.

Note that visad/bom/ is a pretty
general way to draw rectangles in 2-D manifolds in Java3D
displays (try 'java 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
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?

Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738

  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: