Java Reference
In-Depth Information
}
Directory "Sketcher 10 moving and rotating elements"
This is basically just an assembly of the code fragments in the last section for calculating the angle. The
only addition is the if statement that returns a zero angle if either of the lengths are very small — less
than 1. This is to avoid complications in the angle calculation.
You need an import statement for Line2D in the source file for SketcherView :
import java.awt.geom.Line2D;
Recompile Sketcher and try out the new context menus. Having a rotate capability adds a lot of flexibil-
ity, and with the move operation giving you much more precision in positioning elements relative to one
another, this should enable a massive leap forward in the quality of your artwork. Figure 20-22 shows the
sort of standard you might be able to achieve after many months of practice.
FIGURE 20-22
How It Works
The total rotation angle for a Rotate operation is accumulated in angle throughout a sequence of suc-
cessive mouse dragged events. The total rotation during each event is added to any existing rotation for
the element that is obtained by calling getRotation() for the element. The result is set as the element's
rotation by calling setRotation() for the element before repainting the view to present the element in
its new orientation.
 
 
Search WWH ::




Custom Search