cox.jmatt.java.MathTools.markup.svg
Class TransformPen

java.lang.Object
  extended by cox.jmatt.java.MathTools.markup.svg.TransformPen

public class TransformPen
extends java.lang.Object

This pen provides an easy way to create a sequence of transformations for an SVG tag 'transform=' attribute. The operations work exactly per that standard. All transformations are applied IN THE ORDER THEY ARE SET, so set with care!

All transform methods return a reference to this instance to allow method chaining. This, along with reset() and copyOf() allows easy re-use of TransformPens.


Constructor Summary
TransformPen()
          The only constructor required.
 
Method Summary
 TransformPen copyOf()
          Return a copy of this TransformPen exactly as it is at this moment.
 boolean isEmpty()
          Check to see if any transformations are present.
 TransformPen reset()
          Clear all transforms.
 TransformPen rotate(double pTheta)
          Add a rotation about the origin: 'rotate(pTheta)'.
 TransformPen rotate(double pTheta, double pCX, double pCY)
          Add a rotation about a center point other than the origin: 'rotate(pTheta, pCX, pCY)'.
 TransformPen scale(double pScale)
          Add a uniform scaling transform: 'scale(pScale)'.
 TransformPen scale(double pScaleX, double pScaleY)
          Add a non-uniform scaling transform: 'scale(pScaleX, pScaleY)'.
 TransformPen skewX(double pTheta)
          Apply a skew transform in the X coordinate.
 TransformPen skewY(double pTheta)
          Skew all Y-coordinates.
 java.lang.String toString(boolean pComplete)
          Print and format the tag as an SVG 'transform=' attribute.
 TransformPen translate(double pDeltaX, double pDeltaY)
          Apply a translation: 'translate(pDeltaX, pDeltaY)'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformPen

public TransformPen()
The only constructor required.

Method Detail

toString

public java.lang.String toString(boolean pComplete)
Print and format the tag as an SVG 'transform=' attribute. NOTE: All information is retained; transformations can be added after this method is called. Either the complete attribute or just the data can be returned. Complete prepends 'transform=' and encloses the data in quotes.

Parameters:
pComplete - true to include the attrubute name and quotes, false for just the data.

copyOf

public TransformPen copyOf()
Return a copy of this TransformPen exactly as it is at this moment. Changing the original later will not affect the copy or vise versa.


isEmpty

public boolean isEmpty()
Check to see if any transformations are present. If so, this method returns false.


reset

public TransformPen reset()
Clear all transforms. Returns a reference to itself to allow method chaining.


scale

public TransformPen scale(double pScale)
Add a uniform scaling transform: 'scale(pScale)'.

Parameters:
pScale - The scale factor. This is applied to both the X and Y coordinates uniformly.

scale

public TransformPen scale(double pScaleX,
                          double pScaleY)
Add a non-uniform scaling transform: 'scale(pScaleX, pScaleY)'.

Parameters:
pScaleX - The X-coordinate scale factor.
pScaleY - The Y scaling factor.

rotate

public TransformPen rotate(double pTheta)
Add a rotation about the origin: 'rotate(pTheta)'. NOTE: Positive angles increase DOWNWARD from the X-axis!!

Parameters:
pTheta - The angle of rotation. The center is (0, 0).

rotate

public TransformPen rotate(double pTheta,
                           double pCX,
                           double pCY)
Add a rotation about a center point other than the origin: 'rotate(pTheta, pCX, pCY)'.

Parameters:
pTheta - The angle of rotation to apply.
pCX - The X-coordinate of the center of rotation.
pCY - The Y-coordinate of the center of rotation.

translate

public TransformPen translate(double pDeltaX,
                              double pDeltaY)
Apply a translation: 'translate(pDeltaX, pDeltaY)'.

Parameters:
pDeltaX - The X-axis translation.
pDeltaY - The translation in the Y direction.

skewX

public TransformPen skewX(double pTheta)
Apply a skew transform in the X coordinate.

Parameters:
pTheta - The angle by which all X-coordinates are to be skewed.

skewY

public TransformPen skewY(double pTheta)
Skew all Y-coordinates.

Parameters:
pTheta - The angle by which all X-coordinates are to be skewed.