com.tensegrity.graphics
Class StrokeFormat

java.lang.Object
  extended bycom.tensegrity.graphics.StrokeFormat
All Implemented Interfaces:
Format

public final class StrokeFormat
extends java.lang.Object
implements Format

The StrokeFormat class represents a format for lines. This format consists of the following attributes:

The style attribute defines the pattern the line is drawn with. The different styles StrokeFormat provides are as follows:

The weight attribute defines the thickness the line is drawn with. It can be freely chosen and is given in device units. The weight is used for each of the different styles the StrokeFormat provides.

The color attribute defines the color the line is drawn with. The color is represented by an int that defines the values for the red, green and blue components as illustrated by the following hexadecimal pattern:
0x00rrggbb
where rr stands for the red component, gg stands for the green component and bb stands for the blue component of the color.

The custom pattern attribute defines the pattern of the stroke by setting the length of the segments that should be drawn or skipped.

Since the StrokeFormat is an object that is frequently used within the graphics framework and all frameworks that use the graphics framework StrokeFormats are subject of pooling. The pooling of the StrokeFormat instances is being done by the FormatPool. To get more informations about this class take a look at the documentation about the FormatPool.

In order to pool a StrokeFormat it has to be immutable because maybe many objects have a reference on the same StrokeFormat and modifying the StrokeFormat will affect all these objects.

For the pooling also an unique expression is needed so that a StrokeFormat can be surely identified. The unique expression is called the canonical description. This canonical description is made up of the attributes a StrokeFormat consists of and it can be gained by Format.getCanonicalDescription().

An instance of class StrokeFormat can only be created by using the FormatPool.parseStrokeFormat(String) method to ensure a correct pooling behavior. You can obtain the canonical description by calling the on of the static methods called getCanonicalDescription().

A StrokeFormat is usually applied to a Primitive by calling the Primitive.setStroke(StrokeFormat) method.

Version:
$Id: StrokeFormat.java,v 1.43 2005/05/30 13:05:56 AndreasEbbert Exp $
Author:
M. Kegel

Field Summary
protected static java.lang.String CANONIC_DESCRIPTION_DELIMITER
          constant needed as delimitier for the canonical description
static StrokeFormat DEFAULT_STROKE_FORMAT
          constant for a default stroke format
static StrokeFormat NULL_STROKE_FORMAT
          constant for an invisible stroke format
protected static java.lang.String PATTERN_DESCRIPTION_DELIMITER
          constant needed as delimitier for the canonical description
static int STYLE_CONTINUOUS
          constant that tells about a style StrokeFormat provides
static int STYLE_CUSTOM
          constant that tells about a style StrokeFormat provides
static int STYLE_DASH
          constant that tells about a style StrokeFormat provides
static int STYLE_DASHDOT
          constant that tells about a style StrokeFormat provides
static int STYLE_DASHDOTDOT
          constant that tells about a style StrokeFormat provides
static int STYLE_DOT
          constant that tells about a style StrokeFormat provides
static int STYLE_INVISIBLE
          constant that tells about a style StrokeFormat provides
static int STYLE_MAX
          constant that indicates the maximum number of predefined styles
protected static java.lang.String TOKEN_COLOR
          constant that tells about a token of the canonical description
protected static java.lang.String TOKEN_PATTERN
          constant that tells about a token of the canonical description
protected static java.lang.String TOKEN_STYLE
          constant that tells about a token of the canonical description
protected static java.lang.String TOKEN_WEIGHT
          constant that tells about a token of the canonical description
static int WEIGHT_HAIRLINE
          constant that tells about a weight StrokeFormat provides
 
Method Summary
static double[] createPattern(int style, int weight, double[] customPattern)
          Creates a pattern representing the given style.
 boolean equals(java.lang.Object o)
           
 java.lang.String getCanonicalDescription()
          Returns the canonical description of a StrokeFormat.
static java.lang.String getCanonicalDescription(int style, int weight, int color)
          Returns the canonical description of a StrokeFormat.
static java.lang.String getCanonicalDescription(int style, int weight, int color, double[] pattern)
          Returns the canonical description of a StrokeFormat.
static java.lang.String getCanonicalDescription(java.lang.String style, java.lang.String weight, java.lang.String color, java.lang.String pattern)
          Returns the canonical description of a StrokeFormat.
 int getColor()
          Returns the color that is used to draw a line.
 double[] getCustomPattern()
          Returns the pattern as a double array.
 java.lang.String getCustomPatternString()
          Returns the string representation of the pattern of this instance.
static double[] getDefaultPattern()
          Returns the default pattern as a double array.
 java.lang.Object[] getFormatData()
          Returns an array filled with the attributes of the StrokeFormat.
 double[] getPattern()
          Returns the pattern that should be used for drawing.
 int getStyle()
          Returns the style of the StrokeFormat.
 int getWeight()
          Returns the weight of the StrokeFormat.
 int hashCode()
           
 boolean isVisible()
          Returns a boolean that indicates whether is format defines a visible line or not.
static java.lang.String patternToString(double[] pattern)
          Converts a given double array of segment lengths to the string representation of a pattern.
static double[] stringToPattern(java.lang.String tokenPattern)
          Converts a given string representation of a pattern to the double array of segment lengths.
 java.lang.String toString()
          Returns a String that represent the StrokeFormat and all of the attributes of it.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STYLE_INVISIBLE

public static final int STYLE_INVISIBLE
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_CONTINUOUS

public static final int STYLE_CONTINUOUS
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_DASH

public static final int STYLE_DASH
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_DASHDOT

public static final int STYLE_DASHDOT
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_DASHDOTDOT

public static final int STYLE_DASHDOTDOT
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_DOT

public static final int STYLE_DOT
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_CUSTOM

public static final int STYLE_CUSTOM
constant that tells about a style StrokeFormat provides

See Also:
Constant Field Values

STYLE_MAX

public static final int STYLE_MAX
constant that indicates the maximum number of predefined styles

See Also:
Constant Field Values

WEIGHT_HAIRLINE

public static final int WEIGHT_HAIRLINE
constant that tells about a weight StrokeFormat provides

See Also:
Constant Field Values

CANONIC_DESCRIPTION_DELIMITER

protected static final java.lang.String CANONIC_DESCRIPTION_DELIMITER
constant needed as delimitier for the canonical description

See Also:
Constant Field Values

PATTERN_DESCRIPTION_DELIMITER

protected static final java.lang.String PATTERN_DESCRIPTION_DELIMITER
constant needed as delimitier for the canonical description

See Also:
Constant Field Values

TOKEN_STYLE

protected static final java.lang.String TOKEN_STYLE
constant that tells about a token of the canonical description

See Also:
Constant Field Values

TOKEN_WEIGHT

protected static final java.lang.String TOKEN_WEIGHT
constant that tells about a token of the canonical description

See Also:
Constant Field Values

TOKEN_COLOR

protected static final java.lang.String TOKEN_COLOR
constant that tells about a token of the canonical description

See Also:
Constant Field Values

TOKEN_PATTERN

protected static final java.lang.String TOKEN_PATTERN
constant that tells about a token of the canonical description

See Also:
Constant Field Values

DEFAULT_STROKE_FORMAT

public static final StrokeFormat DEFAULT_STROKE_FORMAT
constant for a default stroke format


NULL_STROKE_FORMAT

public static final StrokeFormat NULL_STROKE_FORMAT
constant for an invisible stroke format

Method Detail

getStyle

public int getStyle()
Returns the style of the StrokeFormat. The possible styles are given by the style constants defined in this class.

Returns:
the style of the StrokeFormat

getCustomPattern

public double[] getCustomPattern()
Returns the pattern as a double array. Modifying the array will not effect the stroke format.

Returns:
the pattern as a double array containing the segment lengths

getPattern

public double[] getPattern()
Returns the pattern that should be used for drawing. It returns predefined patterns for all styles except STYLE_CUSTOM, in this case the custom pattern is returned.

Returns:
the pattern that should be used for drawing or null if no pattern should be used (styles continuous and invisible)

getCustomPatternString

public java.lang.String getCustomPatternString()
Returns the string representation of the pattern of this instance.

Returns:
the string representation of the pattern of this instance.

getWeight

public int getWeight()
Returns the weight of the StrokeFormat. The returned value is either WEIGHT_HAIRLINE that defines a thickness of one pixel or an int value greater than zero that defines the tickness of the line in device units.

Returns:
a constant or a positive int value greater than zero that defines the thickness of the line

getColor

public int getColor()
Returns the color that is used to draw a line. The color is represented by an int that defines the values for the red, green and blue components as illustrated by the following hexadecimal pattern:
0x00rrggbb
where rr stands for the red component, gg stands for the green component and bb stands for the blue component of the color.

Returns:
the color used for drawing a line.

isVisible

public boolean isVisible()
Returns a boolean that indicates whether is format defines a visible line or not.

Returns:
boolean flag that indicates if a drawn line will be visible

getFormatData

public java.lang.Object[] getFormatData()
Returns an array filled with the attributes of the StrokeFormat. The indices of the attributes are given by constants defined in this class. This array is used by Renderers and Devices. To get more information about this objects take a look at the documentation of Renderer and Device

Returns:
int[] the array with the attributes if the StrokeFormat

getCanonicalDescription

public java.lang.String getCanonicalDescription()
Returns the canonical description of a StrokeFormat. For instance this description is used for the pooling of StrokeFormats. It can also be used to compare two instances of a StrokeFormat.

Specified by:
getCanonicalDescription in interface Format
Returns:
the canonical representation of this StrokeFormat instance.

toString

public java.lang.String toString()
Returns a String that represent the StrokeFormat and all of the attributes of it. For instance this representation can be used for tracing purposes and such.

Specified by:
toString in interface Format
Returns:
the textual representation of the StrokeFormat.

hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object o)

getCanonicalDescription

public static final java.lang.String getCanonicalDescription(int style,
                                                             int weight,
                                                             int color)
Returns the canonical description of a StrokeFormat. For instance this description is used for the pooling of StrokeFormats. It can also be used to compare two instances of a StrokeFormat.

Parameters:
style - the style of a StrokeFormat
weight - the weight of a StrokeFormat
color - the color of a StrokeFormat
Returns:
the canonical description of a StrokeFormat.

getCanonicalDescription

public static final java.lang.String getCanonicalDescription(int style,
                                                             int weight,
                                                             int color,
                                                             double[] pattern)
Returns the canonical description of a StrokeFormat. For instance this description is used for the pooling of StrokeFormats. It can also be used to compare two instances of a StrokeFormat.

Parameters:
style - the style of a StrokeFormat
weight - the weight of a StrokeFormat
color - the color of a StrokeFormat
pattern - the pattern to use for custom style
Returns:
the canonical description of a StrokeFormat.

getCanonicalDescription

public static final java.lang.String getCanonicalDescription(java.lang.String style,
                                                             java.lang.String weight,
                                                             java.lang.String color,
                                                             java.lang.String pattern)
Returns the canonical description of a StrokeFormat. For instance this description is used for the pooling of StrokeFormats. It can also be used to compare two instances of a StrokeFormat.

Parameters:
style - the style of a StrokeFormat
weight - the weight of a StrokeFormat
color - the color of a StrokeFormat
pattern - the pattern to use, use patternToString() to obtain this string representation
Returns:
the canonical description of a StrokeFormat

stringToPattern

public static double[] stringToPattern(java.lang.String tokenPattern)
Converts a given string representation of a pattern to the double array of segment lengths.

Parameters:
tokenPattern - The string representation of a pattern
Returns:
The double array with segment lengths

patternToString

public static java.lang.String patternToString(double[] pattern)
Converts a given double array of segment lengths to the string representation of a pattern.

Parameters:
pattern - The double array with segment lengths
Returns:
The string representation of a pattern

getDefaultPattern

public static final double[] getDefaultPattern()
Returns the default pattern as a double array.

Returns:
the default pattern as a double array containing the segment lengths

createPattern

public static final double[] createPattern(int style,
                                           int weight,
                                           double[] customPattern)
Creates a pattern representing the given style. For the style STYLE_CUSTOM, the given customPattern is returned.

Parameters:
style - the style of the stroke
weight - the weight of the stroke
customPattern - the pattern to use for custom style
Returns:
a pattern representing the given style


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.