Class ShapeTransform
- java.lang.Object
-
- org.pentaho.reporting.engine.classic.core.util.ShapeTransform
-
public final class ShapeTransform extends Object
Utility class, which resizes or translates a Shape. The class contains special handlers for Rectangles and Lines.- Author:
- Thomas Morgner
-
-
Field Summary
Fields Modifier and Type Field Description static int
ABOVE
Flag for point lying "above" clipping area.static int
BELOW
Flag for point lying "below" clipping area.static int
H_CENTER
Flag for point lying between horizontal bounds of area.static int
INSIDE
Mask for points which are inside.static int
LEFT
Flag for point lying left of clipping area.static int
OUTSIDE
Mask for points which are outside.static int
RIGHT
Flag for point lying right of clipping area.static int
V_CENTER
Flag for point lying between vertical bounds of clipping area.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Point2D[]
getClipped(double x1, double y1, double x2, double y2, double xmin, double xmax, double ymin, double ymax)
Calculate the clipping points of a line with a rectangle.static Shape
performCliping(Shape s, Rectangle2D bounds)
Clips the given shape to the given bounds.static Shape
resizeRect(RectangularShape rectangularShape, double width, double height)
Resizes a rectangle.static Shape
resizeShape(Shape s, float width, float height)
Resizes a shape, so that the shape has the given width and height, but the origin of the shape does not change.static Shape
transformShape(Shape s, boolean scale, boolean keepAR, double width, double height)
Translates the given shape.static Shape
transformShape(Shape s, boolean scale, boolean keepAR, Dimension2D dim)
Translates the given shape.static Shape
translateShape(Shape s, double x, double y)
Translates a se.
-
-
-
Field Detail
-
LEFT
public static final int LEFT
Flag for point lying left of clipping area.- See Also:
- Constant Field Values
-
H_CENTER
public static final int H_CENTER
Flag for point lying between horizontal bounds of area.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
Flag for point lying right of clipping area.- See Also:
- Constant Field Values
-
BELOW
public static final int BELOW
Flag for point lying "below" clipping area.- See Also:
- Constant Field Values
-
V_CENTER
public static final int V_CENTER
Flag for point lying between vertical bounds of clipping area.- See Also:
- Constant Field Values
-
ABOVE
public static final int ABOVE
Flag for point lying "above" clipping area.- See Also:
- Constant Field Values
-
INSIDE
public static final int INSIDE
Mask for points which are inside.- See Also:
- Constant Field Values
-
OUTSIDE
public static final int OUTSIDE
Mask for points which are outside.- See Also:
- Constant Field Values
-
-
Method Detail
-
resizeShape
public static Shape resizeShape(Shape s, float width, float height)
Resizes a shape, so that the shape has the given width and height, but the origin of the shape does not change. Unlike the AffineTransform, this method tries to preserve the Shape's Type.- Parameters:
s
- the shapewidth
- the new widthheight
- the new height- Returns:
- the resized shape.
-
resizeRect
public static Shape resizeRect(RectangularShape rectangularShape, double width, double height)
Resizes a rectangle. This works for real rectangles and produces funny results for RoundRects etc ..- Parameters:
rectangularShape
- the rectanglewidth
- the new width of the rectangleheight
- the new height of the rectangle.- Returns:
- the resized rectangle.
-
transformShape
public static Shape transformShape(Shape s, boolean scale, boolean keepAR, double width, double height)
Translates the given shape. The shape is translated to the origin supplied inpoint
. If scaling is requested, the shape will also be scaled using an AffineTransform.- Parameters:
s
- the shape that should be transformedscale
- true, if the shape should be scaled, false otherwisekeepAR
- true, if the scaled shape should keep the aspect ratiowidth
- the target width.height
- the target height.- Returns:
- the transformed shape
-
transformShape
public static Shape transformShape(Shape s, boolean scale, boolean keepAR, Dimension2D dim)
Translates the given shape. The shape is translated to the origin supplied inpoint
. If scaling is requested, the shape will also be scaled using an AffineTransform.- Parameters:
s
- the shape that should be transformedscale
- true, if the shape should be scaled, false otherwisekeepAR
- true, if the scaled shape should keep the aspect ratiodim
- the target dimension.- Returns:
- the transformed shape
-
performCliping
public static Shape performCliping(Shape s, Rectangle2D bounds)
Clips the given shape to the given bounds. If the shape is a Line2D, manual clipping is performed, as the built in Area does not handle lines.- Parameters:
s
- the shape to be clippedbounds
- the bounds to which the shape should be clipped- Returns:
- the clipped shape.
-
translateShape
public static Shape translateShape(Shape s, double x, double y)
Translates a se. Special care is taken to preserve the shape's original class, if the shape is a rectangle or a line.- Parameters:
s
- the shapex
- the x coordinate where the shape is translated toy
- the y coordinate where the shape is translated to- Returns:
- the translated shape
-
getClipped
public static Point2D[] getClipped(double x1, double y1, double x2, double y2, double xmin, double xmax, double ymin, double ymax)
Calculate the clipping points of a line with a rectangle.- Parameters:
x1
- starting x of liney1
- starting y of linex2
- ending x of liney2
- ending y of linexmin
- lower left x of rectanglexmax
- upper right x of rectangleymin
- lower left y of rectangleymax
- upper right y of rectangle- Returns:
null
(does not clip) or array of two points
-
-