Class Graphics


  • public class Graphics
    extends java.lang.Object
    Platform independent painting canvas. The Graphics has an offset and a scaling factor, managing the calls to the applications GraphicContext-methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      Graphics​(GraphicContext context, double xfactor, double yfactor)
      Creates a new Graphics without offset.
      Graphics​(GraphicContext context, double xfactor, double yfactor, int xOffset, int yOffset)
      Creates a new Graphics.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Graphics create​(int x, int y, double xFactor, double yFactor)
      Creates a new Graphics with the given offset and scaling factors.
      void drawImageCentered​(java.lang.String image, int x, int y)
      Draws the image centered.
      void drawImageCentered​(java.lang.String image, int x, int y, double factor)
      Draws the image centered and scaled.
      void drawLine​(int x1, int y1, int x2, int y2)
      Draws a line.
      void drawOval​(int x, int y, int width, int height)
      Draws an oval.
      void drawRect​(int x, int y, int width, int height)
      Draws a rect.
      void drawString​(java.lang.String str, int x, int y, Font f)
      Draws a string.
      void fillOval​(int x, int y, int width, int height)
      Draws a filled oval.
      void fillRect​(int x, int y, int width, int height)
      Draws a filled rect.
      Rectangle getStringBounds​(java.lang.String ct, Font currentFont)
      Returns the bounding rectangle of the given string in the given font.
      protected Font scaleFont​(Font f)
      Returns a scaled variant of the font.
      void setColor​(int c)
      Sets the drawing color.
      • Methods inherited from class java.lang.Object

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

      • Graphics

        public Graphics​(GraphicContext context,
                        double xfactor,
                        double yfactor)
        Creates a new Graphics without offset.
        Parameters:
        context - The GraphicContext.
        xfactor - x scaling factor.
        yfactor - y scaling factor.
      • Graphics

        public Graphics​(GraphicContext context,
                        double xfactor,
                        double yfactor,
                        int xOffset,
                        int yOffset)
        Creates a new Graphics.
        Parameters:
        context - The GraphicContext.
        xfactor - x scaling factor.
        yfactor - y scaling factor.
        xOffset - x offset.
        yOffset - y offset.
    • Method Detail

      • drawImageCentered

        public void drawImageCentered​(java.lang.String image,
                                      int x,
                                      int y)
        Draws the image centered.
        Parameters:
        image - The image.
        x - The x coordinate.
        y - The y coordinate.
      • drawImageCentered

        public void drawImageCentered​(java.lang.String image,
                                      int x,
                                      int y,
                                      double factor)
        Draws the image centered and scaled.
        Parameters:
        image - The image.
        x - The x coordinate.
        y - The y coordinate.
        factor - The scaling factor.
      • setColor

        public void setColor​(int c)
        Sets the drawing color.
        Parameters:
        c - The new color.
      • drawOval

        public void drawOval​(int x,
                             int y,
                             int width,
                             int height)
        Draws an oval.
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        width - The width.
        height - The height.
      • fillOval

        public void fillOval​(int x,
                             int y,
                             int width,
                             int height)
        Draws a filled oval.
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        width - The width.
        height - The height.
      • drawLine

        public void drawLine​(int x1,
                             int y1,
                             int x2,
                             int y2)
        Draws a line.
        Parameters:
        x1 - The 1.x coordinate.
        y1 - The 1.y coordinate.
        x2 - The 2.x coordinate.
        y2 - The 2.y coordinate.
      • drawRect

        public void drawRect​(int x,
                             int y,
                             int width,
                             int height)
        Draws a rect.
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        width - The width.
        height - The height.
      • fillRect

        public void fillRect​(int x,
                             int y,
                             int width,
                             int height)
        Draws a filled rect.
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        width - The width.
        height - The height.
      • drawString

        public void drawString​(java.lang.String str,
                               int x,
                               int y,
                               Font f)
        Draws a string.
        Parameters:
        str - The String.
        x - The x coordinate.
        y - The y coordinate.
        f - The font.
      • getStringBounds

        public Rectangle getStringBounds​(java.lang.String ct,
                                         Font currentFont)
        Returns the bounding rectangle of the given string in the given font.
        Parameters:
        ct - The String.
        currentFont - The Font.
        Returns:
        The String bounds.
      • scaleFont

        protected Font scaleFont​(Font f)
        Returns a scaled variant of the font.
        Parameters:
        f - The font to scale.
        Returns:
        The scaled font according to this Graphics scaling factors.
      • create

        public Graphics create​(int x,
                               int y,
                               double xFactor,
                               double yFactor)
        Creates a new Graphics with the given offset and scaling factors.
        Parameters:
        x - The X-offset.
        y - The Y-offset.
        xFactor - The x-scalingfactor.
        yFactor - The y-scalingfactor.
        Returns:
        The Graphics.