Class SvgGraphics

  • All Implemented Interfaces:
    IGraphics

    public class SvgGraphics
    extends Object
    implements IGraphics
    Implementation of IGraphics that generates SVG markup.
    • Constructor Summary

      Constructors 
      Constructor Description
      SvgGraphics()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears all drawing operations.
      void drawCircle​(double x, double y, double radius)
      Draws the outline of a circle.
      void drawLine​(double x1, double y1, double x2, double y2)
      Draws a line from point (x1,y1) to point (x2,y2).
      void drawPolygon​(List<Point> points)
      Draws the outline of a polygon defined by a list of points.
      void drawRectangle​(double x, double y, double width, double height)
      Draws the outline of a rectangle.
      void drawText​(String text, double x, double y)
      Draws text at the specified position.
      void fillCircle​(double x, double y, double radius)
      Fills a circle with the current fill color.
      void fillPolygon​(List<Point> points)
      Fills a polygon defined by a list of points with the current fill color.
      void fillRectangle​(double x, double y, double width, double height)
      Fills a rectangle with the current fill color.
      void setFillColor​(Color color)
      Sets the color used for filling shapes.
      void setFont​(String fontFamily, double fontSize)
      Sets the font used for drawing text.
      void setStrokeColor​(Color color)
      Sets the color used for drawing outlines.
      void setStrokeWidth​(double width)
      Sets the width of the stroke used for drawing outlines.
      String toSvg()
      Generates the SVG representation of all drawing operations.
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SvgGraphics

        public SvgGraphics()
    • Method Detail

      • drawLine

        public void drawLine​(double x1,
                             double y1,
                             double x2,
                             double y2)
        Draws a line from point (x1,y1) to point (x2,y2).
        Specified by:
        drawLine in interface IGraphics
        Parameters:
        x1 - The x coordinate of the first point.
        y1 - The y coordinate of the first point.
        x2 - The x coordinate of the second point.
        y2 - The y coordinate of the second point.
      • drawRectangle

        public void drawRectangle​(double x,
                                  double y,
                                  double width,
                                  double height)
        Draws the outline of a rectangle.
        Specified by:
        drawRectangle in interface IGraphics
        Parameters:
        x - The x coordinate of the upper-left corner of the rectangle.
        y - The y coordinate of the upper-left corner of the rectangle.
        width - The width of the rectangle.
        height - The height of the rectangle.
      • fillRectangle

        public void fillRectangle​(double x,
                                  double y,
                                  double width,
                                  double height)
        Fills a rectangle with the current fill color.
        Specified by:
        fillRectangle in interface IGraphics
        Parameters:
        x - The x coordinate of the upper-left corner of the rectangle.
        y - The y coordinate of the upper-left corner of the rectangle.
        width - The width of the rectangle.
        height - The height of the rectangle.
      • drawCircle

        public void drawCircle​(double x,
                               double y,
                               double radius)
        Draws the outline of a circle.
        Specified by:
        drawCircle in interface IGraphics
        Parameters:
        x - The x coordinate of the center of the circle.
        y - The y coordinate of the center of the circle.
        radius - The radius of the circle.
      • fillCircle

        public void fillCircle​(double x,
                               double y,
                               double radius)
        Fills a circle with the current fill color.
        Specified by:
        fillCircle in interface IGraphics
        Parameters:
        x - The x coordinate of the center of the circle.
        y - The y coordinate of the center of the circle.
        radius - The radius of the circle.
      • drawPolygon

        public void drawPolygon​(List<Point> points)
        Draws the outline of a polygon defined by a list of points.
        Specified by:
        drawPolygon in interface IGraphics
        Parameters:
        points - List of points defining the polygon.
      • fillPolygon

        public void fillPolygon​(List<Point> points)
        Fills a polygon defined by a list of points with the current fill color.
        Specified by:
        fillPolygon in interface IGraphics
        Parameters:
        points - List of points defining the polygon.
      • drawText

        public void drawText​(String text,
                             double x,
                             double y)
        Draws text at the specified position.
        Specified by:
        drawText in interface IGraphics
        Parameters:
        text - The text to draw.
        x - The x coordinate where to draw the text.
        y - The y coordinate where to draw the text.
      • setStrokeColor

        public void setStrokeColor​(Color color)
        Sets the color used for drawing outlines.
        Specified by:
        setStrokeColor in interface IGraphics
        Parameters:
        color - The color to use for drawing outlines.
      • setFillColor

        public void setFillColor​(Color color)
        Sets the color used for filling shapes.
        Specified by:
        setFillColor in interface IGraphics
        Parameters:
        color - The color to use for filling shapes.
      • setStrokeWidth

        public void setStrokeWidth​(double width)
        Sets the width of the stroke used for drawing outlines.
        Specified by:
        setStrokeWidth in interface IGraphics
        Parameters:
        width - The width of the stroke.
      • setFont

        public void setFont​(String fontFamily,
                            double fontSize)
        Sets the font used for drawing text.
        Specified by:
        setFont in interface IGraphics
        Parameters:
        fontFamily - The font family name.
        fontSize - The font size.
      • toSvg

        public String toSvg()
        Generates the SVG representation of all drawing operations.
        Specified by:
        toSvg in interface IGraphics
        Returns:
        A string containing the SVG representation.
      • clear

        public void clear()
        Clears all drawing operations.
        Specified by:
        clear in interface IGraphics