prefuse.util
Class StrokeLib

java.lang.Object
  extended by prefuse.util.StrokeLib

public class StrokeLib
extends java.lang.Object

Library maintaining a cache of drawing strokes and other useful stroke computation routines.

Author:
jeffrey heer

Field Summary
static float[] DASHES
          Dash pattern for regular uniform dashes
static float[] DOTS
          Dash pattern for a dotted line
static float[] LONG_DASHES
          Dash pattern for longer uniform dashes
 
Constructor Summary
StrokeLib()
           
 
Method Summary
static void clearCache()
          Clear the Stroke object cache.
static int getCacheLookupCount()
          Get the number of cache lookups to the Stroke object cache.
static int getCacheMissCount()
          Get the number of cache misses to the Stroke object cache.
static java.awt.BasicStroke getDerivedStroke(java.awt.BasicStroke s, float width)
          Get a stroke with the same properties as the given stroke, but with a modified width value.
static java.awt.BasicStroke getStroke(float width)
          Get a square capped, miter joined, non-dashed stroke of the given width.
static java.awt.BasicStroke getStroke(float width, float[] dashes)
          Get a square capped, miter joined, dashed stroke with the given width and dashing attributes.
static java.awt.BasicStroke getStroke(float width, int cap, int join)
          Get a non-dashed stroke of the given width, cap, and join
static java.awt.BasicStroke getStroke(float width, int cap, int join, float miterLimit, float[] dashes, float dashPhase)
          Get a dashed stroke of the given width, cap, join, miter limit, and dashing attributes.
protected static int getStrokeKey(float width, int cap, int join, float miterLimit, float[] dashes, float dashPhase)
          Compute a hash-key for stroke storage and lookup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOTS

public static final float[] DOTS
Dash pattern for a dotted line


DASHES

public static final float[] DASHES
Dash pattern for regular uniform dashes


LONG_DASHES

public static final float[] LONG_DASHES
Dash pattern for longer uniform dashes

Constructor Detail

StrokeLib

public StrokeLib()
Method Detail

getStroke

public static java.awt.BasicStroke getStroke(float width)
Get a square capped, miter joined, non-dashed stroke of the given width.

Parameters:
width - the requested stroke width
Returns:
the stroke

getStroke

public static java.awt.BasicStroke getStroke(float width,
                                             float[] dashes)
Get a square capped, miter joined, dashed stroke with the given width and dashing attributes.

Parameters:
width - the requested stroke width
dashes - an array describing the alternation pattern of a dashed line. For example [5f, 3f] will create dashes of length 5 with spaces of length 3 between them. A null value indicates no dashing.
Returns:
the stroke
See Also:
BasicStroke

getStroke

public static java.awt.BasicStroke getStroke(float width,
                                             int cap,
                                             int join)
Get a non-dashed stroke of the given width, cap, and join

Parameters:
width - the requested stroke width
cap - the requested cap type, one of BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, or BasicStroke.CAP_SQUARE
join - the requested join type, one of BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, or BasicStroke.JOIN_ROUND
Returns:
the stroke

getStroke

public static java.awt.BasicStroke getStroke(float width,
                                             int cap,
                                             int join,
                                             float miterLimit,
                                             float[] dashes,
                                             float dashPhase)
Get a dashed stroke of the given width, cap, join, miter limit, and dashing attributes.

Parameters:
width - the requested stroke width
cap - the requested cap type, one of BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND, or BasicStroke.CAP_SQUARE
join - the requested join type, one of BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, or BasicStroke.JOIN_ROUND
miterLimit - the miter limit at which to bevel miter joins
dashes - an array describing the alternation pattern of a dashed line. For example [5f, 3f] will create dashes of length 5 with spaces of length 3 between them. A null value indicates no dashing.
dashPhase - the phase or offset from which to begin the dash pattern
Returns:
the stroke
See Also:
BasicStroke

getStrokeKey

protected static int getStrokeKey(float width,
                                  int cap,
                                  int join,
                                  float miterLimit,
                                  float[] dashes,
                                  float dashPhase)
Compute a hash-key for stroke storage and lookup.


getDerivedStroke

public static java.awt.BasicStroke getDerivedStroke(java.awt.BasicStroke s,
                                                    float width)
Get a stroke with the same properties as the given stroke, but with a modified width value.

Parameters:
s - the stroke to base the returned stroke on
width - the desired width of the derived stroke
Returns:
the derived Stroke

getCacheMissCount

public static int getCacheMissCount()
Get the number of cache misses to the Stroke object cache.

Returns:
the number of cache misses

getCacheLookupCount

public static int getCacheLookupCount()
Get the number of cache lookups to the Stroke object cache.

Returns:
the number of cache lookups

clearCache

public static void clearCache()
Clear the Stroke object cache.



Copyright © 2007 Regents of the University of California