Package ca.cgjennings.graphics.shapes
Class AbstractVectorImage
- java.lang.Object
 - 
- ca.cgjennings.graphics.shapes.AbstractVectorImage
 
 
- 
- All Implemented Interfaces:
 VectorImage
- Direct Known Subclasses:
 SubregionVectorImage,SVGVectorImage
public abstract class AbstractVectorImage extends java.lang.Object implements VectorImage
An abstract base class for creating vector images. Described algorithmically, pure vector images can be scaled to arbitrary sizes without losing definition and becoming blocky as bitmap images do.Concrete subclasses must set the protected members
tx,ty,iw, andihto appropriate values and implement therender(java.awt.Graphics2D)method.- Since:
 - 3.0
 - Author:
 - Chris Jennings 
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected doubleihHeight of the image, in an arbitrary unit chosen by the image provider.protected doubleiwWidth of the image, in an arbitrary unit chosen by the image provider.protected doubletxTranslation required to move left edge of image to x=0.protected doubletyTranslation required to move top edge of image to y=0. 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractVectorImage() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.awt.image.BufferedImagecreateRasterImage(double ppi)Creates a bitmap image from the vector image at the specified resolution, assuming that the image width and height are measured in points.java.awt.image.BufferedImagecreateRasterImage(int width, int height, boolean fitToSize)Creates a bitmap image from the vector image with the specified width and height (in pixels).doublegetHeight()Returns the height of the image in an unspecified unit.doublegetWidth()Returns the width of the image in an unspecified unit.voidpaint(java.awt.Graphics2D g, double x, double y)Paints the image at the specified location in the provided graphics context.voidpaint(java.awt.Graphics2D g, double x, double y, double width, double height, boolean fitToSize)Paints the image at the specified location and size in the user coordinates of the provided graphics context.voidpaint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D paintRectangle, boolean fitToSize)Paints the image to cover the specified rectangle in the user coordinates of the provided graphics context.protected abstract voidrender(java.awt.Graphics2D g)Renders the vector image into the specified graphics context. 
 - 
 
- 
- 
Field Detail
- 
tx
protected double tx
Translation required to move left edge of image to x=0. 
- 
ty
protected double ty
Translation required to move top edge of image to y=0. 
- 
iw
protected double iw
Width of the image, in an arbitrary unit chosen by the image provider. 
- 
ih
protected double ih
Height of the image, in an arbitrary unit chosen by the image provider. 
 - 
 
- 
Method Detail
- 
getWidth
public final double getWidth()
Returns the width of the image in an unspecified unit. Typically this reflects the "natural" size of the image in the unit used by the designer.- Specified by:
 getWidthin interfaceVectorImage- Returns:
 - the image width in image-specific units
 
 
- 
getHeight
public final double getHeight()
Returns the height of the image in an unspecified unit. Typically this reflects the "natural" size of the image in the unit used by the designer.- Specified by:
 getHeightin interfaceVectorImage- Returns:
 - the image height in image-specific units
 
 
- 
paint
public final void paint(java.awt.Graphics2D g, double x, double y)Paints the image at the specified location in the provided graphics context.- Specified by:
 paintin interfaceVectorImage- Parameters:
 g- the graphics context to render intox- the x-coordinate to render aty- the y-coordinate to render at
 
- 
paint
public final void paint(java.awt.Graphics2D g, double x, double y, double width, double height, boolean fitToSize)Paints the image at the specified location and size in the user coordinates of the provided graphics context. If thefitToSizeparameter istrue, then the aspect ratio of the vector image will be maintained. If the aspect ratio of the vector image does not match the specified width and height, then the vector image will be scaled to just fit within the specified size, and centered over the drawing area.- Specified by:
 paintin interfaceVectorImage- Parameters:
 g- the graphics context to render intox- the x-coordinate to render aty- the y-coordinate to render atwidth- the width to paint the image atheight- the height to paint the image atfitToSize- iftrue, the aspect ratio of the vector image will be maintained
 
- 
paint
public final void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D paintRectangle, boolean fitToSize)Paints the image to cover the specified rectangle in the user coordinates of the provided graphics context. If thefitToSizeparameter istrue, then the aspect ratio of the vector image will be maintained. If the aspect ratio of the vector image does not match the specified width and height, then the vector image will be scaled to just fit within the specified size, and centered over the drawing area.- Specified by:
 paintin interfaceVectorImage- Parameters:
 g- the graphics context to render intopaintRectangle- the rectangle that the image should coverfitToSize- iftrue, the aspect ratio of the vector image will be maintained
 
- 
createRasterImage
public final java.awt.image.BufferedImage createRasterImage(double ppi)
Creates a bitmap image from the vector image at the specified resolution, assuming that the image width and height are measured in points.- Specified by:
 createRasterImagein interfaceVectorImage- Parameters:
 ppi- the resolution to render the image at- Returns:
 - a new bitmap image at the requested resolution
 
 
- 
createRasterImage
public final java.awt.image.BufferedImage createRasterImage(int width, int height, boolean fitToSize)Creates a bitmap image from the vector image with the specified width and height (in pixels). If thefitToSizeparameter istrue, then the aspect ratio of the vector image will be maintained. If the aspect ratio of the vector image does not match the specified width and height, then the vector image will be scaled to just fit within the specified size, and centered over the drawing area.- Specified by:
 createRasterImagein interfaceVectorImage- Parameters:
 width- the image width, in pixelsheight- the image height, in pixelsfitToSize- iftrue, the aspect ratio of the vector image will be maintained- Returns:
 - a rendering of the vector image at the specified size
 
 
- 
render
protected abstract void render(java.awt.Graphics2D g)
Renders the vector image into the specified graphics context. The upper left corner of the image should be at (-tx, -ty) and cover an area with widthiwand heightih. Any changes to the state of the graphics context (stroke, paint, clip, etc.) must be restored before the method returns.- Parameters:
 g- the graphics context to render the image into
 
 - 
 
 -