org.jfree.report.elementfactory
Class StaticShapeElementFactory

java.lang.Object
  extended byorg.jfree.report.elementfactory.ElementFactory
      extended byorg.jfree.report.elementfactory.ShapeElementFactory
          extended byorg.jfree.report.elementfactory.StaticShapeElementFactory

public class StaticShapeElementFactory
extends ShapeElementFactory

A factory to produce static shape elements. The shapes must not contain negative coordinates and should start at (0,0). The factory does not scale shapes which have a negative width or height. This behaviour was valid for JFreeReport versions up to version 0.8.3 and is highly dangerous.

The shape is considered immutable.

The static utility methods provided in that class try to map negative values of lines and rectangles in the createLineShapeElement and createRectangleElement to preserve the old behaviour.

The static method createShapeElement(String, Color, Stroke, Shape, boolean, boolean) extracts the bounds from the given shape and performs an tranlate transform to map the shape to the coordinate (0,0).

Author:
Thomas Morgner

Constructor Summary
StaticShapeElementFactory()
          Default Constructor.
 
Method Summary
 Element createElement()
          Generates a new shape element.
static ShapeElement createLineShapeElement(java.lang.String name, java.awt.Color paint, java.awt.Stroke stroke, java.awt.geom.Line2D shape)
          Creates a new LineShapeElement.
static ShapeElement createRectangleShapeElement(java.lang.String name, java.awt.Color paint, java.awt.Stroke stroke, java.awt.geom.Rectangle2D shape, boolean shouldDraw, boolean shouldFill)
          Creates a new RectangleShapeElement.
static ShapeElement createShapeElement(java.lang.String name, java.awt.Color paint, java.awt.Stroke stroke, java.awt.Shape shape, boolean shouldDraw, boolean shouldFill)
          Creates a new LineShapeElement.
static ShapeElement createShapeElement(java.lang.String name, java.awt.geom.Rectangle2D bounds, java.awt.Color paint, java.awt.Stroke stroke, java.awt.Shape shape, boolean shouldDraw, boolean shouldFill, boolean shouldScale)
          Creates a new ShapeElement.
static ShapeElement createShapeElement(java.lang.String name, java.awt.geom.Rectangle2D bounds, java.awt.Color paint, java.awt.Stroke stroke, java.awt.Shape shape, boolean shouldDraw, boolean shouldFill, boolean shouldScale, boolean keepAspectRatio)
          Creates a new ShapeElement.
 java.awt.Shape getShape()
          Returns the shape object used as content of the new elements.
 void setShape(java.awt.Shape shape)
          Defines the shape object used as content of the new elements.
 
Methods inherited from class org.jfree.report.elementfactory.ShapeElementFactory
applyStyle, getColor, getKeepAspectRatio, getScale, getShouldDraw, getShouldFill, getStroke, setColor, setKeepAspectRatio, setScale, setShouldDraw, setShouldFill, setStroke
 
Methods inherited from class org.jfree.report.elementfactory.ElementFactory
applyElementName, getAbsolutePosition, getDynamicHeight, getMaximumSize, getMinimumSize, getName, getPreferredSize, setAbsolutePosition, setDynamicHeight, setMaximumSize, setMinimumSize, setName, setPreferredSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticShapeElementFactory

public StaticShapeElementFactory()
Default Constructor.

Method Detail

getShape

public java.awt.Shape getShape()
Returns the shape object used as content of the new elements.

Returns:
the shape content.

setShape

public void setShape(java.awt.Shape shape)
Defines the shape object used as content of the new elements.

Parameters:
shape - the shape content.

createElement

public Element createElement()
Generates a new shape element.

Specified by:
createElement in class ElementFactory
Returns:
the generated element.
See Also:
ElementFactory.createElement()

createLineShapeElement

public static ShapeElement createLineShapeElement(java.lang.String name,
                                                  java.awt.Color paint,
                                                  java.awt.Stroke stroke,
                                                  java.awt.geom.Line2D shape)
Creates a new LineShapeElement. The line must not contain negative coordinates, or an IllegalArgumentException will be thrown. If you want to define scaling lines, you will have use one of the createShape methods.

Parameters:
name - the name of the new element
paint - the line color of this element
stroke - the stroke of this shape. For pdf use, restrict to BasicStokes.
shape - the Line2D shape
Returns:
a report element for drawing a line.
Throws:
java.lang.NullPointerException - if bounds or shape are null
java.lang.IllegalArgumentException - if the given alignment is invalid

createShapeElement

public static ShapeElement createShapeElement(java.lang.String name,
                                              java.awt.Color paint,
                                              java.awt.Stroke stroke,
                                              java.awt.Shape shape,
                                              boolean shouldDraw,
                                              boolean shouldFill)
Creates a new LineShapeElement. This methods extracts the bounds from the shape and correct the shape to start from point (0,0) by using an AffineTransform. Use one of the createShape methods, that allow you to supply separate bounds and shapes, if you want to have full control over the creation process.

Parameters:
name - the name of the new element.
paint - the line color of this element.
stroke - the stroke of this shape. For pdf use, restrict to BasicStrokes.
shape - the shape.
shouldDraw - draw the shape?
shouldFill - fill the shape?
Returns:
a report element for drawing a line.
Throws:
java.lang.NullPointerException - if bounds or shape are null
java.lang.IllegalArgumentException - if the given alignment is invalid

createShapeElement

public static ShapeElement createShapeElement(java.lang.String name,
                                              java.awt.geom.Rectangle2D bounds,
                                              java.awt.Color paint,
                                              java.awt.Stroke stroke,
                                              java.awt.Shape shape,
                                              boolean shouldDraw,
                                              boolean shouldFill,
                                              boolean shouldScale)
Creates a new ShapeElement.

Parameters:
name - the name of the new element.
bounds - the bounds.
paint - the line color of this element.
stroke - the stroke of this shape. For pdf use, restrict to BasicStrokes.
shape - the shape.
shouldDraw - draw the shape?
shouldFill - fill the shape?
shouldScale - scale the shape?
Returns:
a report element for drawing a line.
Throws:
java.lang.NullPointerException - if bounds or shape are null
java.lang.IllegalArgumentException - if the given alignment is invalid

createShapeElement

public static ShapeElement createShapeElement(java.lang.String name,
                                              java.awt.geom.Rectangle2D bounds,
                                              java.awt.Color paint,
                                              java.awt.Stroke stroke,
                                              java.awt.Shape shape,
                                              boolean shouldDraw,
                                              boolean shouldFill,
                                              boolean shouldScale,
                                              boolean keepAspectRatio)
Creates a new ShapeElement.

Parameters:
name - the name of the new element.
bounds - the bounds.
paint - the line color of this element.
stroke - the stroke of this shape. For pdf use, restrict to BasicStrokes.
shape - the shape.
shouldDraw - draw the shape?
shouldFill - fill the shape?
shouldScale - scale the shape?
keepAspectRatio - preserve the aspect ratio?
Returns:
a report element for drawing a line.
Throws:
java.lang.NullPointerException - if bounds or shape are null
java.lang.IllegalArgumentException - if the given alignment is invalid

createRectangleShapeElement

public static ShapeElement createRectangleShapeElement(java.lang.String name,
                                                       java.awt.Color paint,
                                                       java.awt.Stroke stroke,
                                                       java.awt.geom.Rectangle2D shape,
                                                       boolean shouldDraw,
                                                       boolean shouldFill)
Creates a new RectangleShapeElement.

Parameters:
name - the name of the new element
paint - the line color of this element
stroke - the stroke of this shape. For pdf use, restrict to BasicStokes.
shape - the Rectangle2D shape
shouldDraw - a flag controlling whether or not the shape outline is drawn.
shouldFill - a flag controlling whether or not the shape interior is filled.
Returns:
a report element for drawing a rectangle.
Throws:
java.lang.NullPointerException - if bounds or shape are null
java.lang.IllegalArgumentException - if the given alignment is invalid