Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

JSR 216 (Maintenance Release)

java.awt
Class BasicStroke

java.lang.Object
  extended byjava.awt.BasicStroke
All Implemented Interfaces:
Stroke

public class BasicStroke
extends Object
implements Stroke

The BasicStroke class defines a basic set of rendering attributes for the outlines of graphics primitives, which are rendered with a Graphics2D object that has its Stroke attribute set to this BasicStroke. The rendering attributes defined by BasicStroke describe the shape of the mark made by a pen drawn along the outline of a Shape and the decorations applied at the ends and joins of path segments of the Shape. These rendering attributes include:

width
The pen width, measured perpendicularly to the pen trajectory.
end caps
The decoration applied to the ends of unclosed subpaths. Lines that start and end on the same point are considered unclosed. The three different decorations are: CAP_BUTT, CAP_ROUND, and CAP_SQUARE.
line joins
The decoration applied at the intersection of two path segments. The three different decorations are: JOIN_BEVEL, JOIN_MITER, and JOIN_ROUND.
miter limit
The limit to trim a line join that has a JOIN_MITER decoration. A line join is trimmed when the ratio of miter length to stroke width is greater than the miterlimit value. The miter length is the diagonal length of the miter, which is the distance between the inside corner and the outside corner of the intersection. The smaller the angle formed by two line segments, the longer the miter length and the sharper the angle of intersection. The default miterlimit value of 10.0f causes all angles less than 11 degrees to be trimmed. Trimming miters converts the decoration of the line join to bevel.

For more information on the user space coordinate system and the rendering process, see the Graphics2D class comments.

See Also:
Graphics2D

Field Summary
static int CAP_BUTT
          Ends unclosed subpaths with no added decoration.
static int CAP_ROUND
          Ends unclosed subpaths with a round decoration that has a radius equal to half of the width of the pen.
static int CAP_SQUARE
          Ends unclosed subpaths with a square projection that extends beyond the end of the segment to a distance equal to half of the line width.
static int JOIN_BEVEL
          Joins path segments by connecting the outer corners of their wide outlines with a straight segment.
static int JOIN_MITER
          Joins path segments by extending their outside edges until they meet.
static int JOIN_ROUND
          Joins path segments by rounding off the corner at a radius of half the line width.
 
Constructor Summary
BasicStroke()
          Constructs a new BasicStroke with defaults for all attributes.
BasicStroke(float width)
          Constructs a solid BasicStroke with the specified line width and with default values for the cap and join styles.
BasicStroke(float width, int cap, int join)
          Constructs a solid BasicStroke with the specified attributes.
BasicStroke(float width, int cap, int join, float miterlimit)
          Constructs a solid BasicStroke with the specified attributes.
 
Method Summary
 boolean equals(Object obj)
          Tests if a specified object is equal to this BasicStroke by first testing if it is a BasicStroke and then comparing its width, join, cap, and miter limit attributes with those of this BasicStroke.
 int getEndCap()
          Returns the end cap style.
 int getLineJoin()
          Returns the line join style.
 float getLineWidth()
          Returns the line width.
 float getMiterLimit()
          Returns the limit of miter joins.
 int hashCode()
          Returns the hashcode for this stroke.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JOIN_MITER

public static final int JOIN_MITER
Joins path segments by extending their outside edges until they meet.

See Also:
Constant Field Values

JOIN_ROUND

public static final int JOIN_ROUND
Joins path segments by rounding off the corner at a radius of half the line width.

See Also:
Constant Field Values

JOIN_BEVEL

public static final int JOIN_BEVEL
Joins path segments by connecting the outer corners of their wide outlines with a straight segment.

See Also:
Constant Field Values

CAP_BUTT

public static final int CAP_BUTT
Ends unclosed subpaths with no added decoration.

See Also:
Constant Field Values

CAP_ROUND

public static final int CAP_ROUND
Ends unclosed subpaths with a round decoration that has a radius equal to half of the width of the pen.

See Also:
Constant Field Values

CAP_SQUARE

public static final int CAP_SQUARE
Ends unclosed subpaths with a square projection that extends beyond the end of the segment to a distance equal to half of the line width.

See Also:
Constant Field Values
Constructor Detail

BasicStroke

public BasicStroke(float width,
                   int cap,
                   int join,
                   float miterlimit)
Constructs a solid BasicStroke with the specified attributes.

Parameters:
width - the width of the BasicStroke
cap - the decoration of the ends of a BasicStroke
join - the decoration applied where path segments meet
miterlimit - the limit to trim the miter join
Throws:
IllegalArgumentException - if width is negative
IllegalArgumentException - if cap is not either CAP_BUTT, CAP_ROUND or CAP_SQUARE
IllegalArgumentException - if miterlimit is less than 1 and join is JOIN_MITER
IllegalArgumentException - if join is not either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER

BasicStroke

public BasicStroke(float width,
                   int cap,
                   int join)
Constructs a solid BasicStroke with the specified attributes. The miterlimit parameter is unnecessary in cases where the default is allowable or the line joins are not specified as JOIN_MITER.

Parameters:
width - the width of the BasicStroke
cap - the decoration of the ends of a BasicStroke
join - the decoration applied where path segments meet
Throws:
IllegalArgumentException - if width is negative
IllegalArgumentException - if cap is not either CAP_BUTT, CAP_ROUND or CAP_SQUARE
IllegalArgumentException - if join is not either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER

BasicStroke

public BasicStroke(float width)
Constructs a solid BasicStroke with the specified line width and with default values for the cap and join styles.

Parameters:
width - the width of the BasicStroke
Throws:
IllegalArgumentException - if width is negative

BasicStroke

public BasicStroke()
Constructs a new BasicStroke with defaults for all attributes. The default attributes are a solid line of width 1.0, CAP_SQUARE, JOIN_MITER, a miter limit of 10.

Method Detail

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.
See Also:
Graphics2D

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 BasicStroke as one of the static int values that define possible line join styles.

getMiterLimit

public float getMiterLimit()
Returns the limit of miter joins.

Returns:
the limit of miter joins of the BasicStroke.

hashCode

public int hashCode()
Returns the hashcode for this stroke.

Overrides:
hashCode in class Object
Returns:
a hash code for this stroke.
See Also:
Object.equals(java.lang.Object), Hashtable

equals

public boolean equals(Object obj)
Tests if a specified object is equal to this BasicStroke by first testing if it is a BasicStroke and then comparing its width, join, cap, and miter limit attributes with those of this BasicStroke.

Overrides:
equals in class Object
Parameters:
obj - the specified object to compare to this BasicStroke
Returns:
true if the width, join, cap, miter limit, dash, and dash phase are the same for both objects; false otherwise.
See Also:
Object.hashCode(), Hashtable

JSR 216 (Maintenance Release)

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 216 specification.