public class FigureTransform extends Object
Details:
FigureTransform
manages the conversion of coordinates between the physical view and the logical figure.
The transformation is based on a focus, scale, and rotation.
The focus is the logical figure coordinate displayed at the center of the physical view.
The scale controls the magnification of the figure in the view.
The rotation controls the viewing angle.
Each of these properties can be independently configured, and adjustments to these properties result in live changes to the view.
Modifier and Type | Field and Description |
---|---|
static double |
MAX_SCALE
Maximum supported scale.
|
static double |
MIN_SCALE
Minimum supported scale.
|
Constructor and Description |
---|
FigureTransform(FigureView iDrawPanel) |
Modifier and Type | Method and Description |
---|---|
void |
componentResized() |
Point2D |
getFocus()
Returns view's focus.
|
double |
getPixelSize()
Returns logical size of pixel.
|
double |
getRotation()
Returns viewing angle.
|
int |
getRotationStep()
Returns current rotation value.
|
double |
getScale()
Returns current viewing scale.
|
int |
getScaleStep()
Returns current viewing scale step.
|
AffineTransform |
getTransform() |
void |
interactiveRotate(int iTicks) |
void |
interactiveScale(int iTicks) |
void |
interactiveTranslate(Point iFrom,
Point iTo)
Translates view.
|
void |
resumeRepainting()
Enables repaint events.
|
void |
rotateGestured(int iTicks)
Deprecated.
Use interactiveRotate.
|
void |
scaleGestured(int iTicks)
Deprecated.
Use interactiveScale.
|
void |
setFocus(Point2D iPoint)
Centers view on point.
|
void |
setRotation(double iRotation)
Sets viewing angle.
|
void |
setRotationStep(int iRotation)
Sets new rotation value.
|
void |
setScale(double iScale)
Sets viewing scale.
|
void |
setScaleStep(int iStep)
Sets viewing scale step.
|
void |
suspendRepainting()
Temporarily suspends repaint events.
|
void |
transformToLogical(Point2D ioPoint)
Changes physical point to logical point.
|
void |
translateGestured(Point iFrom,
Point iTo)
Deprecated.
Use interactiveTranslate.
|
void |
viewArea(Area iArea) |
public static final double MIN_SCALE
Details:
MIN_SCALE
is the minimum scale allowed in setScale(double)
.
public static final double MAX_SCALE
Details:
MAX_SCALE
is the maximum scale allowed in setScale(double)
.
public FigureTransform(FigureView iDrawPanel)
public void suspendRepainting()
Details:
Normally, when the transform is changed, this class will generate a repaint event so the view can redraw the figure according to the new transform.
There are some instances, however, where you may wish to temporarily disable repaint events.
This is useful, for instance, when you need to make multiple transform changes and you would like the repaint event to occur after the final change.
Use this method to temporarily suspend repainting.
Don't forget to resume repainting with resumeRepainting()
.
public void resumeRepainting()
Details:
Use this method to resume painting after suspending it with suspendRepainting()
.
Calling this method generates a "catch up" repaint event, whether one is actually needed or not.
public Point2D getFocus()
Details:
By default, the view is centered, or focused, on the figure's origin (i.e., point (0, 0)).
However, views can focus on any position in the figure.
getFocus
returns the logical point in the figure on which the view is focused, or in other words, the logical point displayed at the center of the view.
setFocus(Point2D)
public void setFocus(Point2D iPoint)
Details:
setFocus
centers the view on the given logical point in the figure.
The display is refreshed automatically.
iPoint
- the new focusgetFocus()
public double getRotation()
Details:
getRotation
returns the viewing angle.
The value returned is expressed in radians, between -pi and +pi.
public void setRotation(double iRotation)
Details:
setRotation
sets the current viewing angle to the supplied value, expressed in radians.
The display is updated.
The new angle may be expressed in values outside of the -pi to +pi range. However, the farther away from this range the angle is, the less accurate the result. In any case, the angle is normalized before it is used.
iRotation
- new viewing anglepublic int getRotationStep()
Details:
In order to avoid rounding error, it may be desirable to process the viewing angle using discrete values.
getRotationStep
returns the current viewing angle in degrees, rounded to the nearest whole number.
The value returned is normalized so that it falls between -180 and +180.
setRotationStep(int)
public void setRotationStep(int iRotation)
Details:
In order to avoid rounding errors, it may be desirable to process the viewing angle using discrete values.
setRotationStep
sets the current viewing angle to the given value, which is expressed in degrees.
iRotation
- new rotation valuegetRotationStep()
public double getScale()
Details:
getScale
returns the current viewing scale.
This value is the ratio of physical viewing units to logical figure units.
The value 1.0 indicates that the view is displaying the figure exactly to scale.
Values greater than 1 indicate that the view is "zoomed in."
Values smaller than 1 indicate that the view is "zoomed out."
public void setScale(double iScale)
Details:
setScale
sets the current viewing scale to the given value.
(See getScale()
for the interpretation of scale values.)
The view is immediately refreshed.
iScale
- new scale valuepublic int getScaleStep()
Details:
Using setScale(double)
, the view can be configured to display the figure at any scale.
However, to avoid cumulative floating point rounding error, it may be desirable to process the scale value using discrete values.
The "scale steps" map discrete integer values to a subset of all available viewing scales.
The map is defined as follows:
scale = 2step / 10
In particular, observe that step 0 sets the scale to 1.0. Positive steps magnify, and negative steps reduce.
getScaleStep
returns the closest step to the current scale.
setScaleStep(int)
public void setScaleStep(int iStep)
Details:
setScaleStep
sets the viewing scale step to the given value.
See getScaleStep()
for an explanation of scale steps.
iStep
- the new scale stepgetScaleStep()
public double getPixelSize()
Details:
getPixelSize
returns the logical size (width or height) of one physical pixel in the view.
public void componentResized()
public AffineTransform getTransform()
public void transformToLogical(Point2D ioPoint)
Details: This method transforms the given point from the physical coordinate system of the view to the logical coordinate system of the figure. The fields of the original point are overwritten with the transformed values.
ioPoint
- point to transformpublic void viewArea(Area iArea)
public void translateGestured(Point iFrom, Point iTo)
Details:
translateGestured
translates the current figure view in both the X and Y directions, according to the mouse gesture reflected in the parameters.
This method supports only the drag style of translate gesture.
Thus, when this method is called with iFrom
and iTo
set to the physical coordinates of the mouse gesture, it will convert the the drag gesture into a corresponding logical translation of the view, regardless of the current view transform.
A repaint notice will also be sent to the widget so that the figure can be redrawn in the new position.
iFrom
- the beginning drag pointiTo
- the ending drag pointpublic void interactiveTranslate(Point iFrom, Point iTo)
Details: This method translates the current view in both the X and Y directions, according to the user interaction reflected in the parameters. The two points given are interpreted as if they are the beginning and ending mouse coordinates of a drag event that took place in the view. These points are converted into logical coordinates in order to determine the direction and amount of view translation that has been commanded. A repaint notice is automatically sent to the view so the the figure will be redrawn in the new position.
iFrom
- the beginning drag pointiTo
- the ending drag pointpublic void scaleGestured(int iTicks)
public void interactiveScale(int iTicks)
public void rotateGestured(int iTicks)
public void interactiveRotate(int iTicks)
Copyright © 2013. All Rights Reserved.