org.geotools.axis
Class Axis2D.TickIterator

Object
  extended by Axis2D.TickIterator
All Implemented Interfaces:
TickIterator
Enclosing class:
Axis2D

public class Axis2D.TickIterator
extends Object
implements TickIterator

Iterates along the graduation ticks and provides access to the graduation values. Each Axis2D.TickIterator object traverses the graduation of the unclosing Axis2D object independently from any other TickIterator objects in use at the same time. If a change occurs in the underlying Axis2D object during the iteration, then refresh() must be invoked in order to reset the iterator as if a new instance was created. Except for refresh() method, using the iterator after a change in the underlying Axis2D may thrown a ConcurrentModificationException.

Since:
2.0
Author:
Martin Desruisseaux (PMO, IRD)

Constructor Summary
Axis2D.TickIterator(FontRenderContext fontContext)
          Construct an iterator.
 
Method Summary
 String currentLabel()
          Returns the label for current tick.
 Rectangle2D currentLabelBounds()
          Returns a bounding vector for the current tick label.
 GlyphVector currentLabelGlyphs()
          Returns the label for current tick as a glyphs vector.
 double currentPosition()
          Returns the position where to draw the current tick.
 Point2D currentPosition(Point2D dest)
          Returns the coordinates of the intersection point between current tick and the underlying axis.
 Line2D currentTick(Line2D dest)
          Returns the coordinates of the current tick.
 double currentValue()
          Returns the value for current tick.
 Locale getLocale()
          Returns the locale used for formatting tick labels.
 boolean hasNext()
          Tests if the iterator has more ticks.
 boolean isMajorTick()
          Tests if the current tick is a major one.
 void next()
          Moves the iterator to the next minor or major tick.
 void nextMajor()
          Moves the iterator to the next major tick.
 void refresh()
          Reset the iterator on its first tick.
 void rewind()
          Reset the iterator on its first tick.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Axis2D.TickIterator

public Axis2D.TickIterator(FontRenderContext fontContext)
Construct an iterator.

Parameters:
fontContext - Information needed to correctly measure text, or null if unknow. This object is usually given by Graphics2D.getFontRenderContext().
Method Detail

hasNext

public boolean hasNext()
Tests if the iterator has more ticks.

Specified by:
hasNext in interface TickIterator

isMajorTick

public boolean isMajorTick()
Tests if the current tick is a major one.

Specified by:
isMajorTick in interface TickIterator
Returns:
true if current tick is a major tick, or false if it is a minor tick.

currentPosition

public double currentPosition()
Returns the position where to draw the current tick. The position is scaled from the graduation's minimum to maximum. This is usually the same number than currentValue(). The mean exception is for logarithmic graduation, in which the tick position is not proportional to the tick value.

Specified by:
currentPosition in interface TickIterator

currentValue

public double currentValue()
Returns the value for current tick. The current tick may be major or minor.

Specified by:
currentValue in interface TickIterator

currentPosition

public Point2D currentPosition(Point2D dest)
Returns the coordinates of the intersection point between current tick and the underlying axis. Units are the same than axis start point (x1,y1) and end point (x2,y2). This is usually pixels.

Parameters:
dest - A destination point that stores the intersection coordinates, or null to create a new Point2D object.
Returns:
dest, or a new Point2D object if dest was null.

currentTick

public Line2D currentTick(Line2D dest)
Returns the coordinates of the current tick. Units are the same than axis start point (x1,y1) and end point (x2,y2). This is usually pixels.

Parameters:
dest - A destination line that stores the current tick coordinates, or null to create a new Line2D object.
Returns:
dest, or a new Line2D object if dest was null.

currentLabel

public String currentLabel()
Returns the label for current tick. This method is usually invoked only for major ticks, but may be invoked for minor ticks as well. This method returns null if it can't produces a label for current tick.

Specified by:
currentLabel in interface TickIterator

currentLabelGlyphs

public GlyphVector currentLabelGlyphs()
Returns the label for current tick as a glyphs vector. This method is used together with currentLabelBounds() for labels rendering. Do not change the returned GlyphVector, since the glyphs vector is not cloned for performance raisons. This method returns null if it can't produces a glyph vector for current tick.


currentLabelBounds

public Rectangle2D currentLabelBounds()
Returns a bounding vector for the current tick label. Units are the same than axis start point (x1,y1) and end point (x2,y2). This is usually pixels. This method can be used as in the example below:
 Axis2D.TickIterator iterator = axis.new TickIterator(null};
 while (iterator.hasNext()) {
     GlyphVector glyphs = iterator.currentLabelGlyphs();
     Rectangle2D bounds = iterator.currentLabelBounds();
     graphics.drawGlyphVector(glyphs, (float)bounds.getMinX(), (float)bounds.getMaxY());
     iterator.next();
 }
 
This method returns null if it can't compute bounding box for current tick.


next

public void next()
Moves the iterator to the next minor or major tick.

Specified by:
next in interface TickIterator

nextMajor

public void nextMajor()
Moves the iterator to the next major tick. This move ignore any minor ticks between current position and the next major tick.

Specified by:
nextMajor in interface TickIterator

rewind

public void rewind()
Reset the iterator on its first tick. All other properties are left unchanged.

Specified by:
rewind in interface TickIterator

refresh

public void refresh()
Reset the iterator on its first tick. If some axis properies have changed (e.g. minimum and/or maximum values), then the new settings are taken in account. This refresh() method help to reduce garbage-collection by constructing an Axis2D.TickIterator object only once and reuse it for each axis's rendering.


getLocale

public Locale getLocale()
Returns the locale used for formatting tick labels.

Specified by:
getLocale in interface TickIterator


Copyright © 1996-2009 Geotools. All Rights Reserved.