Java Reference
In-Depth Information
We get the rectangle bounding the sketch by calling the getModelExtent() method that we put
together just now. We then use rect in the second statement that calls translate() for the
Graphics2D object to position the top left corner of rect at the origin. We could have combined
these two translations into one, but we will keep them separate, first to make it easier to see what is
going on, and second because we will be adding some other transformations later in between these
translations. There is a potentially puzzling aspect to the second translation - why are the arguments to
the translate() method negative?
To understand this, it is important to be clear about what we are doing. It's easy to get confused by this
so we'll take it step by step. First of all, remember that the paper is a physical entity with given
dimensions and its coordinate system just defines where each point will end up on the paper when you
print something. Of course, we can move the coordinate system about in relation to the paper, and we
can scale or even rotate it to get something printed where we want.
Now consider our sketch. The point ( rect.x,rect.y ) is the top left corner of the rectangle bounding
our sketch, the area we want to transfer to the page, and this point is fixed - we can't change it to make
it the origin for instance. With the current paper coordinates at the top left of the printable area, it might
print something like that shown here:
rect.x,rect.y
The Paper
0.0
The Printable
Area on the Page
The Sketch
Initial Position of Paper Coordinates
When we print our sketch we really want the point ( rect.x,rect.y ) to end up at the top left corner
of the printable area on the page. In other words, we have to move the origin of the coordinate system
for the paper so that the point ( rect.x,rect.y ) in the new coordinate system is the top left corner of
the printable area. To do this we must move the origin to the new position shown.
Search WWH ::




Custom Search