Class 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, and ih to appropriate values and implement the render(java.awt.Graphics2D) method.

    Since:
    3.0
    Author:
    Chris Jennings
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double ih
      Height of the image, in an arbitrary unit chosen by the image provider.
      protected double iw
      Width of the image, in an arbitrary unit chosen by the image provider.
      protected double tx
      Translation required to move left edge of image to x=0.
      protected double ty
      Translation required to move top edge of image to y=0.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractVectorImage()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      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).
      double getHeight()
      Returns the height of the image in an unspecified unit.
      double getWidth()
      Returns the width of the image in an unspecified unit.
      void paint​(java.awt.Graphics2D g, double x, double y)
      Paints the image at the specified location in the provided graphics context.
      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.
      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.
      protected abstract void render​(java.awt.Graphics2D g)
      Renders the vector image into the specified graphics context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • Constructor Detail

      • AbstractVectorImage

        protected AbstractVectorImage()
    • 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:
        getWidth in interface VectorImage
        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:
        getHeight in interface VectorImage
        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:
        paint in interface VectorImage
        Parameters:
        g - the graphics context to render into
        x - the x-coordinate to render at
        y - 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 the fitToSize parameter is true, 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:
        paint in interface VectorImage
        Parameters:
        g - the graphics context to render into
        x - the x-coordinate to render at
        y - the y-coordinate to render at
        width - the width to paint the image at
        height - the height to paint the image at
        fitToSize - if true, 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 the fitToSize parameter is true, 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:
        paint in interface VectorImage
        Parameters:
        g - the graphics context to render into
        paintRectangle - the rectangle that the image should cover
        fitToSize - if true, 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:
        createRasterImage in interface VectorImage
        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 the fitToSize parameter is true, 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:
        createRasterImage in interface VectorImage
        Parameters:
        width - the image width, in pixels
        height - the image height, in pixels
        fitToSize - if true, 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 width iw and height ih. 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