org.geotools.axis
Class Axis2D

Object
  extended by Line2D
      extended by Axis2D
All Implemented Interfaces:
Shape, Serializable, Cloneable

public class Axis2D
extends Line2D
implements Cloneable, Serializable

An axis as a graduated line. Axis2D 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 Axis2D objects, which doesn't need to be perpendicular.

Since:
2.0
Author:
Martin Desruisseaux (PMO, IRD)
See Also:
DefaultCoordinateSystemAxis, AxisDirection, Graduation, Serialized Form
Module:

Nested Class Summary
 class Axis2D.TickIterator
          Iterates along the graduation ticks and provides access to the graduation values.
 
Nested classes/interfaces inherited from class Line2D
Line2D.Double, 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 AffineTransform createAffineTransform(Axis2D xAxis, Axis2D yAxis)
          Creates an affine transform mapping logical to pixels coordinates for a pair of axis.
 Rectangle2D getBounds2D()
          Returns a bounding box for this axis.
 Graduation getGraduation()
          Returns the axis's graduation.
 double getLength()
          Returns the axis length.
 Point2D getP1()
          Returns the (x,y) coordinates of the start point.
 Point2D getP2()
          Returns the (x,y) coordinates of the end point.
 PathIterator getPathIterator(AffineTransform transform)
          Returns an iterator object that iterates along the Axis2D boundary and provides access to the geometry of the shape outline.
 PathIterator getPathIterator(AffineTransform transform, double flatness)
          Returns an iterator object that iterates along the Axis2D boundary and provides access to the geometry of the shape outline.
 Object getRenderingHint(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 true if the axis would have to rotate clockwise in order to overlaps its graduation.
 void paint(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 Axis2D to the specified coordinates.
 void setRenderingHint(RenderingHints.Key key, Object value)
          Sets the value of a single preference for the rendering algorithms.
 DefaultCoordinateSystemAxis toCoordinateSystemAxis()
          Returns this axis name and direction.
 String toString()
          Returns a string representation of this axis.
 
Methods inherited from class 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 Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface 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.

Specified by:
getX1 in class Line2D
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.

Specified by:
getX2 in class Line2D
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.

Specified by:
getY1 in class Line2D
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.

Specified by:
getY2 in class Line2D
See Also:
getX2(), getY1(), setLine(double, double, double, double)

getP1

public 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.

Specified by:
getP1 in class Line2D

getP2

public 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.

Specified by:
getP2 in class Line2D

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 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 Shape
See Also:
getX1(), getY1(), getX2(), getY2()

setLine

public void setLine(double x1,
                    double y1,
                    double x2,
                    double y2)
             throws IllegalArgumentException
Sets the location of the endpoints of this Axis2D 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.

Specified by:
setLine in class Line2D
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:
IllegalArgumentException - If a coordinate is NaN or infinite.
See Also:
getX1(), getY1(), getX2(), getY2()

isLabelClockwise

public boolean isLabelClockwise()
Returns true 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 true means that the axis would have to rotate clockwise in order to overlaps its graduation. Value false means that the axis would have to rotate counter-clockwise in order to overlaps its graduation.


getPathIterator

public PathIterator getPathIterator(AffineTransform transform)
Returns an iterator object that iterates along the Axis2D 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 Shape
Overrides:
getPathIterator in class Line2D

getPathIterator

public PathIterator getPathIterator(AffineTransform transform,
                                    double flatness)
Returns an iterator object that iterates along the Axis2D 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 Shape
Overrides:
getPathIterator in class Line2D

paint

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

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

getRenderingHint

public Object getRenderingHint(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 null if no value is associated to the specified key.
See Also:
Graduation.TICK_LABEL_FONT, Graduation.AXIS_TITLE_FONT

setRenderingHint

public void setRenderingHint(RenderingHints.Key key,
                             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 null value removes any hint for the specified key.
See Also:
Graduation.TICK_LABEL_FONT, Graduation.AXIS_TITLE_FONT

toString

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

Overrides:
toString in class Object

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 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 © 1996-2009 Geotools. All Rights Reserved.