org.geotools.axis
Class Axis2D.TickIterator

java.lang.Object
  extended byorg.geotools.axis.Axis2D.TickIterator
All Implemented Interfaces:
TickIterator
Enclosing class:
Axis2D

public class Axis2D.TickIterator
extends java.lang.Object
implements TickIterator

Iterates along the graduation ticks and provides access to the graduation values. Each 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
Version:
$Id: Axis2D.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Constructor Summary
Axis2D.TickIterator(java.awt.font.FontRenderContext fontContext)
          Construct an iterator.
 
Method Summary
 java.lang.String currentLabel()
          Returns the label for current tick.
 java.awt.geom.Rectangle2D currentLabelBounds()
          Returns a bounding vector for the current tick label.
 java.awt.font.GlyphVector currentLabelGlyphs()
          Returns the label for current tick as a glyphs vector.
 double currentPosition()
          Returns the position where to draw the current tick.
 java.awt.geom.Point2D currentPosition(java.awt.geom.Point2D dest)
          Returns the coordinates of the intersection point between current tick and the underlying axis.
 java.awt.geom.Line2D currentTick(java.awt.geom.Line2D dest)
          Returns the coordinates of the current tick.
 double currentValue()
          Returns the value for current tick.
 java.util.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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Axis2D.TickIterator

public Axis2D.TickIterator(java.awt.font.FontRenderContext fontContext)
Construct an iterator.

Parameters:
fontContext - Information needed to correctly measure text, or 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:
if current tick is a major tick, or 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 java.awt.geom.Point2D currentPosition(java.awt.geom.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 to create a new Point2D object.
Returns:
, or a new Point2D object if was null.

currentTick

public java.awt.geom.Line2D currentTick(java.awt.geom.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 to create a new Line2D object.
Returns:
, or a new Line2D object if was null.

currentLabel

public java.lang.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 if it can't produces a label for current tick.

Specified by:
currentLabel in interface TickIterator

currentLabelGlyphs

public java.awt.font.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 if it can't produces a glyph vector for current tick.


currentLabelBounds

public java.awt.geom.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 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 object only once and reuse it for each axis's rendering.


getLocale

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

Specified by:
getLocale in interface TickIterator


Copyright © GeoTools. All Rights Reserved.