org.geotools.axis
Class Axis2D

java.lang.Object
  extended byjava.awt.geom.Line2D
      extended byorg.geotools.axis.Axis2D
All Implemented Interfaces:
java.lang.Cloneable, org.opengis.util.Cloneable, java.io.Serializable, java.awt.Shape

public class Axis2D
extends java.awt.geom.Line2D
implements org.opengis.util.Cloneable, java.io.Serializable

An axis as a graduated line. objets are really Line2D objects with a Graduation. Because axis are Line2D, they can be located anywhere in a widget with any orientation. Lines are drawn from starting point (x1,y1) to end point (x2,y2), using a graduation from minimal value Graduation.getMinimum() to maximal value Graduation.getMaximum(). Note the line's coordinates (x1,y1) and (x2,y2) are completly independant of graduation minimal and maximal values. Line's coordinates should be expressed in some units convenient for rendering, as pixels or point (1/72 of inch). On the opposite, graduation can have any arbitrary units, which is given by Graduation.getUnit(). The static method createAffineTransform(org.geotools.axis.Axis2D, org.geotools.axis.Axis2D) can be used for mapping logical coordinates to pixels coordinates for an arbitrary pair of objects, which doesn't need to be perpendicular.

Since:
2.0
Version:
$Id: Axis2D.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
DefaultCoordinateSystemAxis, AxisDirection, Graduation, Serialized Form

Nested Class Summary
 class Axis2D.TickIterator
          Iterates along the graduation ticks and provides access to the graduation values.
 
Nested classes inherited from class java.awt.geom.Line2D
java.awt.geom.Line2D.Double, java.awt.geom.Line2D.Float
 
Constructor Summary
Axis2D()
          Constructs an axis with a default NumberGraduation.
Axis2D(Graduation graduation)
          Constructs an axis with the specified graduation.
 
Method Summary
static java.awt.geom.AffineTransform createAffineTransform(Axis2D xAxis, Axis2D yAxis)
          Creates an affine transform mapping logical to pixels coordinates for a pair of axis.
 java.awt.geom.Rectangle2D getBounds2D()
          Returns a bounding box for this axis.
 Graduation getGraduation()
          Returns the axis's graduation.
 double getLength()
          Returns the axis length.
 java.awt.geom.Point2D getP1()
          Returns the (x,y) coordinates of the start point.
 java.awt.geom.Point2D getP2()
          Returns the (x,y) coordinates of the end point.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform)
          Returns an iterator object that iterates along the boundary and provides access to the geometry of the shape outline.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform, double flatness)
          Returns an iterator object that iterates along the boundary and provides access to the geometry of the shape outline.
 java.lang.Object getRenderingHint(java.awt.RenderingHints.Key key)
          Returns the value of a single preference for the rendering algorithms.
 double getX1()
          Returns the x coordinate of the start point.
 double getX2()
          Returns the x coordinate of the end point.
 double getY1()
          Returns the y coordinate of the start point.
 double getY2()
          Returns the y coordinate of the end point.
 boolean isLabelClockwise()
          Returns if the axis would have to rotate clockwise in order to overlaps its graduation.
 void paint(java.awt.Graphics2D graphics)
          Draw this axis in the specified graphics context.
 void setLabelClockwise(boolean c)
          Sets the label's locations relative to this axis.
 void setLine(double x1, double y1, double x2, double y2)
          Sets the location of the endpoints of this to the specified coordinates.
 void setRenderingHint(java.awt.RenderingHints.Key key, java.lang.Object value)
          Sets the value of a single preference for the rendering algorithms.
 DefaultCoordinateSystemAxis toCoordinateSystemAxis()
          Returns this axis name and direction.
 java.lang.String toString()
          Returns a string representation of this axis.
 
Methods inherited from class java.awt.geom.Line2D
clone, contains, contains, contains, contains, getBounds, intersects, intersects, intersectsLine, intersectsLine, linesIntersect, ptLineDist, ptLineDist, ptLineDist, ptLineDistSq, ptLineDistSq, ptLineDistSq, ptSegDist, ptSegDist, ptSegDist, ptSegDistSq, ptSegDistSq, ptSegDistSq, relativeCCW, relativeCCW, relativeCCW, setLine, setLine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opengis.util.Cloneable
clone
 

Constructor Detail

Axis2D

public Axis2D()
Constructs an axis with a default NumberGraduation.


Axis2D

public Axis2D(Graduation graduation)
Constructs an axis with the specified graduation.

Method Detail

getGraduation

public Graduation getGraduation()
Returns the axis's graduation.


getX1

public double getX1()
Returns the x coordinate of the start point. By convention, this coordinate should be in pixels or points (1/72 of inch) for proper positionning of ticks and labels.

See Also:
getY1(), getX2(), setLine(double, double, double, double)

getX2

public double getX2()
Returns the x coordinate of the end point. By convention, this coordinate should be in pixels or points (1/72 of inch) for proper positionning of ticks and labels.

See Also:
getY2(), getX1(), setLine(double, double, double, double)

getY1

public double getY1()
Returns the y coordinate of the start point. By convention, this coordinate should be in pixels or points (1/72 of inch) for proper positionning of ticks and labels.

See Also:
getX1(), getY2(), setLine(double, double, double, double)

getY2

public double getY2()
Returns the y coordinate of the end point. By convention, this coordinate should be in pixels or points (1/72 of inch) for proper positionning of ticks and labels.

See Also:
getX2(), getY1(), setLine(double, double, double, double)

getP1

public java.awt.geom.Point2D getP1()
Returns the (x,y) coordinates of the start point. By convention, those coordinates should be in pixels or points (1/72 of inch) for proper positionning of ticks and labels.


getP2

public java.awt.geom.Point2D getP2()
Returns the (x,y) coordinates of the end point. By convention, those coordinates should be in pixels or points (1/72 of inch) for proper positionning of ticks and labels.


getLength

public double getLength()
Returns the axis length. This is the distance between starting point (@link #getP1 P1}) and end point (P2). This length is usually measured in pixels or points (1/72 of inch).


getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Returns a bounding box for this axis. The bounding box includes the axis's line (P1) to (P2), the axis's ticks and all labels.

Specified by:
getBounds2D in interface java.awt.Shape
See Also:
getX1(), getY1(), getX2(), getY2()

setLine

public void setLine(double x1,
                    double y1,
                    double x2,
                    double y2)
             throws java.lang.IllegalArgumentException
Sets the location of the endpoints of this to the specified coordinates. Coordinates should be in pixels (for screen rendering) or points (for paper rendering). Using points units make it easy to render labels with a raisonable font size, no matter the screen resolution or the axis graduation.

Parameters:
x1 - Coordinate x of starting point.
y1 - Coordinate y of starting point
x2 - Coordinate x of end point.
y2 - Coordinate y of end point.
Throws:
java.lang.IllegalArgumentException - If a coordinate is or infinite.
See Also:
getX1(), getY1(), getX2(), getY2()

isLabelClockwise

public boolean isLabelClockwise()
Returns if the axis would have to rotate clockwise in order to overlaps its graduation.


setLabelClockwise

public void setLabelClockwise(boolean c)
Sets the label's locations relative to this axis. Value means that the axis would have to rotate clockwise in order to overlaps its graduation. Value means that the axis would have to rotate counter-clockwise in order to overlaps its graduation.


getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform)
Returns an iterator object that iterates along the boundary and provides access to the geometry of the shape outline. The shape includes the axis line, graduation and labels. If an optional AffineTransform is specified, the coordinates returned in the iteration are transformed accordingly.

Specified by:
getPathIterator in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform,
                                                  double flatness)
Returns an iterator object that iterates along the boundary and provides access to the geometry of the shape outline. The shape includes the axis line, graduation and labels. If an optional AffineTransform is specified, the coordinates returned in the iteration are transformed accordingly.

Specified by:
getPathIterator in interface java.awt.Shape

paint

public void paint(java.awt.Graphics2D graphics)
Draw this axis in the specified graphics context. This method is equivalents to . However, this method may be slightly faster and produce better quality output.

Parameters:
graphics - The graphics context to use for drawing.

getRenderingHint

public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key key)
Returns the value of a single preference for the rendering algorithms. Hint categories include controls for label fonts and colors. Some of the keys and their associated values are defined in the Graduation interface.

Parameters:
key - The key corresponding to the hint to get.
Returns:
An object representing the value for the specified hint key, or if no value is associated to the specified key.
See Also:
Graduation.TICK_LABEL_FONT, Graduation.AXIS_TITLE_FONT

setRenderingHint

public void setRenderingHint(java.awt.RenderingHints.Key key,
                             java.lang.Object value)
Sets the value of a single preference for the rendering algorithms. Hint categories include controls for label fonts and colors. Some of the keys and their associated values are defined in the Graduation interface.

Parameters:
key - The key of the hint to be set.
value - The value indicating preferences for the specified hint category. A value removes any hint for the specified key.
See Also:
Graduation.TICK_LABEL_FONT, Graduation.AXIS_TITLE_FONT

toString

public java.lang.String toString()
Returns a string representation of this axis.


toCoordinateSystemAxis

public DefaultCoordinateSystemAxis toCoordinateSystemAxis()
Returns this axis name and direction. Information include a name (usually the graduation title) and an direction. The direction is usually up or down for vertical axis, right or left for horizontal axis, or other otherwise.


createAffineTransform

public static java.awt.geom.AffineTransform createAffineTransform(Axis2D xAxis,
                                                                  Axis2D yAxis)
Creates an affine transform mapping logical to pixels coordinates for a pair of axis. The affine transform will maps coordinates in the following way:

Parameters:
xAxis - The x axis. This axis doesn't have to be horizontal; it can have any orientation, including vertical.
yAxis - The y axis. This axis doesn't have to be vertical; it can have any orientation, including horizontal.
Returns:
An affine transform mapping logical to pixels coordinates.


Copyright © GeoTools. All Rights Reserved.