Java Reference
In-Depth Information
21.3.4
Conversions and scale objects
The class
Conversions
provides methods to convert between pixel and real coor-
dinates. To this end the methods have to know the relevant parameters, e.g. the
dimensions of the drawing and the size of the panel. These values are supplied in
an object of class
ScaleObject
. The conversion methods expect a pixel or real
point and a scale object as arguments. They compute the coordinates of the real
or pixel point, respectively, from the point they received and return this.
Whenever a re-drawing of the panel is initiated, the parameters of the scale
object are set to the current values by class
Drawing
. The
draw
-methods of the
classes derived from
GraphicalObject
receive the scale object as a parameter.
The coordinates of the graphical objects are real coordinates. With the scale object
at hand, the conversions can be used to convert those to the pixel coordinates
needed for drawing into the panel.
Two screen shots of a test application
GenericDrawingDemo
are shown in
Figure 21.1.
Search WWH ::
Custom Search