edu.umd.cs.piccolox.util
Class PFixedWidthStroke

java.lang.Object
  extended by edu.umd.cs.piccolox.util.PSemanticStroke
      extended by edu.umd.cs.piccolox.util.PFixedWidthStroke
All Implemented Interfaces:
Stroke, Serializable

public class PFixedWidthStroke
extends PSemanticStroke
implements Serializable

PFixedWidthStroke is the same as BasicStroke except that PFixedWidthStroke has a fixed width on the screen so that even when the canvas view is zooming its width stays the same in canvas coordinates.

PSemanticStroke.createStrokedShape(Shape) checks if the scale has changed since the last usage and if that's the case calls newStroke(float) to get a new Stroke instance to delegate to.

CAUTION! this implementation falls short for large scaling factors - the effective miterlimit might drop below 1.0 which isn't permitted by BasicStroke and therefore limited to a minimal 1.0 by this implementation. A more sophisticated implementation might use the approach mentioned at http://code.google.com/p/piccolo2d/issues/detail?id=49

CAUTION! after extreme scaling this implementation seems to change to internal state of the base stroke. Try PathExample with extreme zoom in and zoom back to the original scale. The pickable circles disappear. Strange!

Version:
1.0
Author:
Jesse Grosjean
See Also:
PPath, BasicStroke, Serialized Form

Field Summary
 
Fields inherited from class edu.umd.cs.piccolox.util.PSemanticStroke
stroke, THRESHOLD
 
Constructor Summary
PFixedWidthStroke()
          Constructs a simple PFixedWidthStroke with the default stroke.
PFixedWidthStroke(float width)
          Constructs a simple PFixedWidthStroke with the width provided.
PFixedWidthStroke(float width, int cap, int join)
          Constructs a PFixedWidthStroke with the stroke properties provided.
PFixedWidthStroke(float width, int cap, int join, float miterlimit)
          Constructs a PFixedWidthStroke with the stroke properties provided.
PFixedWidthStroke(float width, int cap, int join, float miterlimit, float[] dash, float dashPhase)
          Constructs a PFixedWidthStroke with the stroke properties provided.
 
Method Summary
 Object clone()
          Throws an exception since PFixedWidthStrokes are not serializable.
 float[] getDashArray()
          Returns the array representing the lengths of the dash segments.
 float getDashPhase()
          Returns the current dash phase.
 int getEndCap()
          Returns the end cap style.
 int getLineJoin()
          Returns the line join style.
 float getLineWidth()
          Returns the line width.
 float getMiterLimit()
          Returns the miter limit of this node.
protected  Stroke newStroke(float activeScale)
          Returns a stroke equivalent to this one, but scaled by the scale provided.
protected  Object readResolve()
          Is it really necessary to implement Serializable?
 
Methods inherited from class edu.umd.cs.piccolox.util.PSemanticStroke
createStrokedShape, equals, getActiveScale, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PFixedWidthStroke

public PFixedWidthStroke()
Constructs a simple PFixedWidthStroke with the default stroke.


PFixedWidthStroke

public PFixedWidthStroke(float width)
Constructs a simple PFixedWidthStroke with the width provided.

Parameters:
width - desired width of the stroke

PFixedWidthStroke

public PFixedWidthStroke(float width,
                         int cap,
                         int join)
Constructs a PFixedWidthStroke with the stroke properties provided.

Parameters:
width - width of stroke
cap - cap to use in stroke
join - join to use in stroke

PFixedWidthStroke

public PFixedWidthStroke(float width,
                         int cap,
                         int join,
                         float miterlimit)
Constructs a PFixedWidthStroke with the stroke properties provided.

Parameters:
width - width of stroke
cap - cap to use in stroke
join - join to use in stroke
miterlimit - miter limit of stroke

PFixedWidthStroke

public PFixedWidthStroke(float width,
                         int cap,
                         int join,
                         float miterlimit,
                         float[] dash,
                         float dashPhase)
Constructs a PFixedWidthStroke with the stroke properties provided.

Parameters:
width - width of stroke
cap - cap to use in stroke
join - join to use in stroke
miterlimit - miter limit of stroke
dash - array of dash lengths
dashPhase - phase to use when rendering dashes
Method Detail

clone

public Object clone()
Throws an exception since PFixedWidthStrokes are not serializable.

Overrides:
clone in class Object
Returns:
never returns anything

getDashArray

public float[] getDashArray()
Returns the array representing the lengths of the dash segments. Alternate entries in the array represent the user space lengths of the opaque and transparent segments of the dashes. As the pen moves along the outline of the Shape to be stroked, the user space distance that the pen travels is accumulated. The distance value is used to index into the dash array. The pen is opaque when its current cumulative distance maps to an even element of the dash array and transparent otherwise.

Returns:
the dash array

getDashPhase

public float getDashPhase()
Returns the current dash phase. The dash phase is a distance specified in user coordinates that represents an offset into the dashing pattern. In other words, the dash phase defines the point in the dashing pattern that will correspond to the beginning of the stroke.

Returns:
the dash phase as a float value.

getEndCap

public int getEndCap()
Returns the end cap style.

Returns:
the end cap style of this BasicStroke as one of the static int values that define possible end cap styles.

getLineJoin

public int getLineJoin()
Returns the line join style.

Returns:
the line join style of the PFixedWidthStroke as one of the static int values that define possible line join styles.

getLineWidth

public float getLineWidth()
Returns the line width. Line width is represented in user space, which is the default-coordinate space used by Java 2D. See the Graphics2D class comments for more information on the user space coordinate system.

Returns:
the line width of this BasicStroke.

getMiterLimit

public float getMiterLimit()
Returns the miter limit of this node.

Returns:
the limit of miter joins of the PFixedWidthStroke

newStroke

protected Stroke newStroke(float activeScale)
Returns a stroke equivalent to this one, but scaled by the scale provided.

Specified by:
newStroke in class PSemanticStroke
Parameters:
activeScale - scale to apply to the new stoke
Returns:
scaled stroke

readResolve

protected Object readResolve()
                      throws ObjectStreamException
Is it really necessary to implement Serializable?

Returns:
the resolved stroke
Throws:
ObjectStreamException - doesn't actually throw this at all, why's this here?


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.