org.jdrawing.graphics
Class Style

java.lang.Object
  extended byorg.jdrawing.graphics.Style

public class Style
extends java.lang.Object

Encapsulates style information used to perform graphics operations.


Field Summary
static java.lang.String BACKGROUND
          Key for background attribute.
static java.lang.String CLIP
          Key for rendering clip attribute.
static java.lang.String COMPOSITE
          Key for composite attribute.
static java.lang.String FONT
          Key for font attribute.
static java.lang.String PAINT
          Key for paint attribute.
static java.lang.String RENDERING_HINTS
          Key for rendering hints attribute.
static java.lang.String STROKE
          Key for stroke attribute.
static java.lang.String TRANSFORM
          Key for transform attribute.
 
Constructor Summary
Style()
          Constructs a new Style with defaults for all attributes.
Style(java.util.Map attributes)
          Constructs a new Style with the specified attributes.
 
Method Summary
 java.awt.Shape createStrokedShape(java.awt.Shape shape)
          Returns an outline Shape which encloses the area that should be painted when the Shape is stroked according to the stroke attribute.
 Style deriveStyle(java.util.Map attributes)
          Creates a new Style object by replicating the current Style object and applying a new set of style attributes to it.
 boolean equals(java.lang.Object object)
          Checks whether two styles are equal.
 java.awt.Color getBackground()
          Returns the value of the background attribute of this style.
 java.awt.Shape getClip()
          Returns the value of the clip attribute of this style.
 java.awt.Composite getComposite()
          Returns the value of the composite attribute of this style.
static Style getDefaultStyle()
          Returns the shared instance of style with defaults for all attributes.
 java.awt.Font getFont()
          Returns the value of the font attribute of this style.
 java.awt.Paint getPaint()
          Returns the value of the paint attribute of this style.
 java.util.Map getRenderingHints()
          Returns the value of the renderingHints attribute of this style.
 java.awt.Rectangle getShapeBounds(java.awt.Shape shape)
          Returns bounding box of the specified shape according to transform attribute.
 java.awt.geom.Rectangle2D getShapeBounds2D(java.awt.Shape shape)
          Returns high precision bounding box of the specified shape according to transform attribute.
 java.awt.geom.Rectangle2D getStringBounds(java.lang.String string, java.awt.font.FontRenderContext context)
          Returns bounding box of the specified string according to font attribute and specified FontRenderingContext.
 java.awt.Stroke getStroke()
          Returns the value of the stroke attribute of this style.
 java.awt.geom.AffineTransform getTransform()
          Returns the value of the transform attribute of this style.
 int hashCode()
          Returns the hashcode for this style.
 boolean shapeContains(java.awt.Shape shape, java.awt.geom.Point2D point)
          Tests if the specified shape contains the given point according to transform attribute.
 boolean shapeContains(java.awt.Shape shape, java.awt.geom.Rectangle2D rectangle)
          Tests if the specified shape contains the given rectangle according to transform attribute.
 boolean shapeIntersects(java.awt.Shape shape, java.awt.geom.Rectangle2D rectangle)
          Tests if the specified shape intersects with the given rectangle according to transform attribute.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BACKGROUND

public static final java.lang.String BACKGROUND
Key for background attribute. Value of this attribute must be an instance of class Color.

See Also:
Graphics2D.setBackground(java.awt.Color), Constant Field Values

FONT

public static final java.lang.String FONT
Key for font attribute. Value of this attribute must be an instance of class Font.

See Also:
Graphics.setFont(java.awt.Font), Constant Field Values

COMPOSITE

public static final java.lang.String COMPOSITE
Key for composite attribute. Value of this attribute must be an instance of class Composite.

See Also:
Graphics2D.setComposite(java.awt.Composite), Constant Field Values

PAINT

public static final java.lang.String PAINT
Key for paint attribute. Value of this attribute must be an instance of class Paint.

See Also:
Graphics2D.setPaint(java.awt.Paint), Constant Field Values

STROKE

public static final java.lang.String STROKE
Key for stroke attribute. Value of this attribute must be an instance of class Stroke.

See Also:
Graphics2D.setStroke(java.awt.Stroke), Constant Field Values

TRANSFORM

public static final java.lang.String TRANSFORM
Key for transform attribute. Value of this attribute must be an instance of class AffineTransform.

See Also:
Graphics2D.transform(java.awt.geom.AffineTransform), Constant Field Values

RENDERING_HINTS

public static final java.lang.String RENDERING_HINTS
Key for rendering hints attribute. Value of this attribute must implement interface Map.

See Also:
Graphics2D.setRenderingHints(java.util.Map), Constant Field Values

CLIP

public static final java.lang.String CLIP
Key for rendering clip attribute. Value of this attribute must be instance of class Shape.

See Also:
Graphics.setClip(int, int, int, int), Constant Field Values
Constructor Detail

Style

public Style()
Constructs a new Style with defaults for all attributes. The default attributes are the following:


Style

public Style(java.util.Map attributes)
Constructs a new Style with the specified attributes. All unspecified attributes are assigned with default values.

Parameters:
attributes - the attributes to assign to the new Style
Method Detail

getDefaultStyle

public static Style getDefaultStyle()
Returns the shared instance of style with defaults for all attributes.

Returns:
default style

deriveStyle

public Style deriveStyle(java.util.Map attributes)
Creates a new Style object by replicating the current Style object and applying a new set of style attributes to it.

Parameters:
attributes - a map of attributes enabled for the new Style
Returns:
a new Style object

getBackground

public java.awt.Color getBackground()
Returns the value of the background attribute of this style.

Returns:
color value

getFont

public java.awt.Font getFont()
Returns the value of the font attribute of this style.

Returns:
font value

getComposite

public java.awt.Composite getComposite()
Returns the value of the composite attribute of this style.

Returns:
composite value

getPaint

public java.awt.Paint getPaint()
Returns the value of the paint attribute of this style.

Returns:
paint value

getStroke

public java.awt.Stroke getStroke()
Returns the value of the stroke attribute of this style.

Returns:
stroke value

getTransform

public java.awt.geom.AffineTransform getTransform()
Returns the value of the transform attribute of this style.

Returns:
transform value

getRenderingHints

public java.util.Map getRenderingHints()
Returns the value of the renderingHints attribute of this style.

Returns:
rendering hints value

getClip

public java.awt.Shape getClip()
Returns the value of the clip attribute of this style.

Returns:
clip value

getStringBounds

public java.awt.geom.Rectangle2D getStringBounds(java.lang.String string,
                                                 java.awt.font.FontRenderContext context)
Returns bounding box of the specified string according to font attribute and specified FontRenderingContext.

Parameters:
string - the specified String
context - the specified FontRenderingContext
Returns:
a Rectangle2D that is the bounding box of the specified String

getShapeBounds

public java.awt.Rectangle getShapeBounds(java.awt.Shape shape)
Returns bounding box of the specified shape according to transform attribute.

Parameters:
shape - the specified shape
Returns:
a Rectangle that is the bounding box of the specified shape

getShapeBounds2D

public java.awt.geom.Rectangle2D getShapeBounds2D(java.awt.Shape shape)
Returns high precision bounding box of the specified shape according to transform attribute.

Parameters:
shape - the specified shape
Returns:
a Rectangle2D that is the bounding box of the specified shape

shapeIntersects

public boolean shapeIntersects(java.awt.Shape shape,
                               java.awt.geom.Rectangle2D rectangle)
Tests if the specified shape intersects with the given rectangle according to transform attribute.

Parameters:
shape - the specified shape
rectangle - the given rectangle
Returns:
true if the specified shape intersects with the given rectangle; false otherwise

shapeContains

public boolean shapeContains(java.awt.Shape shape,
                             java.awt.geom.Rectangle2D rectangle)
Tests if the specified shape contains the given rectangle according to transform attribute.

Parameters:
shape - the specified shape
rectangle - the given rectangle
Returns:
true if the specified shape contains the given rectangle; false otherwise

shapeContains

public boolean shapeContains(java.awt.Shape shape,
                             java.awt.geom.Point2D point)
Tests if the specified shape contains the given point according to transform attribute.

Parameters:
shape - the specified shape
point - the given point
Returns:
true if the specified shape contains the given point; false otherwise

createStrokedShape

public java.awt.Shape createStrokedShape(java.awt.Shape shape)
Returns an outline Shape which encloses the area that should be painted when the Shape is stroked according to the stroke attribute.

Parameters:
shape - the specified shape
Returns:
the stroked outline Shape

equals

public boolean equals(java.lang.Object object)
Checks whether two styles are equal. The result is true if and only if the argument is not null and is a Style object that has the same attributes as this Style.

Parameters:
object - the Object to compare with this Style
Returns:
true if the objects are equal; false otherwise.

hashCode

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

Returns:
a hash code for this style.