DESY ACOP Beans Home

com.cosylab.gui.components.gauger
Class ScaleTransform

java.lang.Object
  extended by com.cosylab.gui.components.gauger.ScaleTransform
Direct Known Subclasses:
LinearHorizontalTransform, LinearVerticalTransform, PolarTransform

public abstract class ScaleTransform
extends java.lang.Object

Abstract utility class that provides the mathematic foundation for drawing the Gauger scales. Scale is defined in its own coordinate system with the axis (u, v). In this system the extents of the scale are defined to be (0, 0) and (1, 1), meaning that any point on this scale can be specified with the (u, v) parameter value between 0 and 1. This class is the implementation of this transformation and the component cartesian coordinate system.

Version:
$id$
Author:
Ales Pucelj

Nested Class Summary
 class ScaleTransform.ArcSegment
          Definition of arc scale segment.
 class ScaleTransform.LineSegment
          Class defining linear scale segment.
 class ScaleTransform.RectangleSegment
          Defines rectangular scale segment.
 class ScaleTransform.ScaleSegment
          Abstract base class for scale segments.
 
Constructor Summary
ScaleTransform()
          Creates a new ScaleTransform object.
 
Method Summary
protected  void addSegment(ScaleTransform.ScaleSegment segment)
          Adds segment to this transform.
 double getAngle(double x)
          Returns angle between horizontal and specified relative position in scale space.
 java.awt.Point getLabelPosition()
          Returns the point where the label should be positioned.
 ScaleTransform.ScaleSegment getSegment(int i)
          Returns scale segment at specified index.
 int getSegmentCount()
          Returns the number of segments describing this scale.
 boolean isPolar()
          Returns whether this scale is polar.
 java.awt.geom.Point2D mapUVtoXY(double u, double v)
          Maps point specified with (u, v) coordinates in scale space to cartesian space with coordinates (x, y)
 void mapUVtoXY(double u, double v, java.awt.geom.Point2D cartesianSpace)
          Maps the point specified with (u, v) coordinates in the scale space to cartesian space with coordinates (x, y).
abstract  void mapUVtoXY(java.awt.geom.Point2D scaleSpace, java.awt.geom.Point2D cartesianSpace)
          Maps the point specified with (u, v) coordinates in the scale space to cartesian space with coordinates (x, y).
abstract  int measureTick(java.awt.Graphics g, double x, java.lang.String text)
          Measues the width of tick label.
abstract  double scaleHeight(double u)
          Returns the height of scale in pixels at the specified location u in the scale space.
abstract  double scaleWidth(double v)
          Returns the width of scale in pixels at the specified location v in the scale space.
protected  void setLabelPosition(int x, int y)
          Sets position of value label.
abstract  void setParameters(int w, int h, int marginX, int marginY, int tickOffset)
          Sets the component parameters for this transformation.
 void setPolar(boolean value)
          Sets whether this transform is polar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScaleTransform

public ScaleTransform()
Creates a new ScaleTransform object.

Method Detail

setPolar

public void setPolar(boolean value)
Sets whether this transform is polar. A polar scale will be rendered in polar coordinates rather then cartesian. Lines will be rendered as arcs and text will be rotated.

Parameters:
value - True if polar.

isPolar

public boolean isPolar()
Returns whether this scale is polar.

Returns:
True if polar.
See Also:
setPolar(boolean)

setParameters

public abstract void setParameters(int w,
                                   int h,
                                   int marginX,
                                   int marginY,
                                   int tickOffset)
Sets the component parameters for this transformation.

Parameters:
w - width of the component that will display this transformation
h - height of the component that will display this transformation
marginX - not used
marginY - not used
tickOffset - space between the edge of the scale and the first tick

mapUVtoXY

public abstract void mapUVtoXY(java.awt.geom.Point2D scaleSpace,
                               java.awt.geom.Point2D cartesianSpace)
Maps the point specified with (u, v) coordinates in the scale space to cartesian space with coordinates (x, y). (u, v) values must be in [0..1] range, the (x, y) points will be in (0..w-1, 0..h-1) range.

Parameters:
scaleSpace - point in scale space
cartesianSpace - point in cartesian space

mapUVtoXY

public void mapUVtoXY(double u,
                      double v,
                      java.awt.geom.Point2D cartesianSpace)
Maps the point specified with (u, v) coordinates in the scale space to cartesian space with coordinates (x, y). (u, v) values must be in [0..1] range, the (x, y) points will be in (0..w-1, 0..h-1) range.

Parameters:
u - coordinate in scale space
v - coordinate in scale space
cartesianSpace - point in cartesian space

mapUVtoXY

public java.awt.geom.Point2D mapUVtoXY(double u,
                                       double v)
Maps point specified with (u, v) coordinates in scale space to cartesian space with coordinates (x, y)

Parameters:
u - coordinate in scale space.
v - coordinate in scale space.
Returns:
Point2D cartesianSpace point.
See Also:
mapUVtoXY(u, v, Point2D)

getAngle

public final double getAngle(double x)
Returns angle between horizontal and specified relative position in scale space. This angle is defined as angle between X axis and line from point (x, 0.0) to point (x, 100.0). This is the angle at which vertical straight line in polar mode is rotated in cartesian space.

Parameters:
x - Relative point in scale space in range 0.0 to 1.0.
Returns:
double angle in radians

scaleWidth

public abstract double scaleWidth(double v)
Returns the width of scale in pixels at the specified location v in the scale space. Although the scale for v is only defined in the range [0..1], this value can generaly return even values outside this range, although this is not guaranteed.

Returns:
Width of scale in pixels.

scaleHeight

public abstract double scaleHeight(double u)
Returns the height of scale in pixels at the specified location u in the scale space. Although the scale for u is only defined in the range [0..1], this value can generaly return even values outside this range, although this is not guaranteed.

Returns:
Height of scale in pixels.

getLabelPosition

public java.awt.Point getLabelPosition()
Returns the point where the label should be positioned. This point represents geometric center of the text. There are no limits to the size of the text written around this position.

Returns:
Center point for label.

getSegmentCount

public int getSegmentCount()
Returns the number of segments describing this scale. Even if the value is zero, this transform may still provide space transformation functionality.

Returns:
Number of segments.

addSegment

protected void addSegment(ScaleTransform.ScaleSegment segment)
Adds segment to this transform.

Parameters:
segment - to add.

getSegment

public ScaleTransform.ScaleSegment getSegment(int i)
Returns scale segment at specified index.

Parameters:
i - Index of segment.
Returns:
Scale segment.

setLabelPosition

protected void setLabelPosition(int x,
                                int y)
Sets position of value label. The position is center point of label.

Parameters:
x - coordinate of label center.
y - coordinate of label center.

measureTick

public abstract int measureTick(java.awt.Graphics g,
                                double x,
                                java.lang.String text)
Measues the width of tick label.

Parameters:
g - Graphic context.
x - Relative position of tick.
text - Tick label.
Returns:
Width of label in pixels.


Copyright © 2010. All Rights Reserved.