Java Reference
In-Depth Information
How It Works
This uses the
remove()
method in
SketchModel
to remove the highlighted element, and then calls
the
add()
method to put it back - it will automatically be added to the end of the elements in the list.
We switch off the highlighting of the element to indicate that it's gone to the back of the queue, and
reset
highlightElement
back to
null
.
We have run out of easy ones. We must now deal with a not quite so easy one - the move operation. To
handle this we must look into a new topic - transforming the user coordinate system. If you are not of a
mathematical bent, some of what we will discuss here can sound complicated. Even if your math may be
very rusty, you should not have too many problems. Like a lot of things it's the unfamiliarity of the
jargon that makes it seem more difficult than it is.
Transforming the User Coordinate System
We said when we started learning how to draw on a component that the drawing operations are
specified in a user-coordinate system, and the user coordinates are converted to a device coordinate
system. The conversion of coordinates from user system to device system is taken care of by the
methods in the graphics context object that we use to do the drawing, and they do this by applying a
transformation
to the user coordinates. The term 'transformation' refers to the computational operations
that result in the conversion.
By default, the origin, the (0, 0) point, in the user coordinate system corresponds to the (0, 0) point in
the device coordinates system. The axes are also coincident too, with positive
x
heading from left to
right, and positive
y
from top to bottom. However you can move the origin of the user coordinate
system relative to its default position. Such a move is called a
translation
.
Device Coordinates
Device Coordinates
x
x
here
deltaY
Default mapping
deltaX
x
User Coordinates
here
x
This appears
User Coordinates
y
y
x
This appears
y
y
y
Default Mapping
User Coordinates Translated by deltaX, deltaY
A fixed value,
deltaX
say, is added to each
x
coordinate, and another value,
deltaY
say, is added to
every
y
coordinate and the effect of this is to move the origin of the user coordinate system relative to
the device coordinate system: everything will be shifted to the right and down compared to where it
would have been without the translation. Of course, the
deltaX
and
deltaY
values can be negative, in
which case it would shift things to the left and up.