Class Painter

java.lang.Object
eu.pedu.lib20s.canvasmanager.Painter

public class Painter
extends java.lang.Object
Instances of class Painter mediates the posibility to paint the shapes on the canvas to the instances managed by a CanvasManager. The main task of the class si to facilitate komunication of the graphics shapes with the graphics context – instances of the class java.awt.Graphics2D. The class Painter is constructed as an adapter for these instances.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  Painter.ImageObserver
    Instance třídy ImageObserver slouží k předání informací o tom, že požadovaný obrázek je již načten.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static Painter.ImageObserver IMG_OBSERVER
    Images observer that knows that the observed images will not change, because they are loaded at the beginning.
  • Method Summary

    Modifier and Type Method Description
    void drawEllipse​(int x, int y, int width, int height, NamedColor color)
    Draws the outline of an oval.
    void drawLine​(int x1, int y1, int x2, int y2, NamedColor color)
    Draws a line, using the specified color, between the points (x1, y1) and (x2, y2).
    void drawPicture​(int x, int y, java.awt.Image image, java.awt.geom.AffineTransform at)
    Renders an image, applying a transform from image space into user space before drawing.
    void drawPolygon​(int[] x, int[] y, NamedColor color)
    Draws a closed polygon defined by arrays of x and y coordinates.
    void drawRectangle​(int x, int y, int width, int height, NamedColor color)
    Draws the outline of the specified rectangle.
    void drawText​(java.lang.String text, int x, int y, NamedColor color)
    Draws the text given by the specified string, using the current font and the specified color.
    void fillEllipse​(int x, int y, int width, int height, NamedColor color)
    Fills an oval bounded by the specified rectangle with the specified color.
    void fillPolygon​(int[] x, int[] y, NamedColor color)
    Fills a closed polygon defined by arrays of x and y coordinates.
    void fillRectangle​(int x, int y, int width, int height, NamedColor color)
    Fills the specified rectangle.
    NamedColor getBackground()
    Set the background color of painting.
    java.awt.Font getFont()
    Returns the currently used font.
    java.awt.Graphics2D getGraphics()
    Returns the wraped graphics context.
    void setBackground​(NamedColor color)
    Set the background color of painting.
    void setFont​(java.awt.Font font)
    Sets the specified font as the current.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • IMG_OBSERVER

      public static final Painter.ImageObserver IMG_OBSERVER
      Images observer that knows that the observed images will not change, because they are loaded at the beginning.
  • Method Details

    • getFont

      public java.awt.Font getFont()
      Returns the currently used font.
      Returns:
      The current font
    • setFont

      public void setFont​(java.awt.Font font)
      Sets the specified font as the current. All subsequent text operations use this font. A null argument is silently ignored.
      Parameters:
      font - The set font
    • getBackground

      public NamedColor getBackground()
      Set the background color of painting.
      Returns:
      The background color of painting
    • setBackground

      public void setBackground​(NamedColor color)
      Set the background color of painting.
      Parameters:
      color - The set background color
    • getGraphics

      public java.awt.Graphics2D getGraphics()
      Returns the wraped graphics context.
      Returns:
      The current font
    • drawEllipse

      public void drawEllipse​(int x, int y, int width, int height, NamedColor color)
      Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments.

      The oval covers an area that is width + 1 pixels wide and height + 1 pixels tall.

      Parameters:
      x - The x coordinate of the upper left corner of the oval to be drawn
      y - The y coordinate of the upper left corner of the oval to be drawn
      width - The width of the oval to be drawn
      height - The height of the oval to be drawn
      color - The color of the oval to be drawn
    • fillEllipse

      public void fillEllipse​(int x, int y, int width, int height, NamedColor color)
      Fills an oval bounded by the specified rectangle with the specified color.
      Parameters:
      x - The x coordinate of the upper left corner of the oval to be filled
      y - The y coordinate of the upper left corner of the oval to be filled
      width - The width of the oval to be filled
      height - The height of the oval to be filled
      color - The color of the oval to be filled
    • drawRectangle

      public void drawRectangle​(int x, int y, int width, int height, NamedColor color)
      Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the specified color.
      Parameters:
      x - The x coordinate of the rectangle to be drawn
      y - The y coordinate of the rectangle to be drawn
      width - The width of the rectangle to be drawn
      height - The height of the rectangle to be drawn
      color - The color of the rectangle to be drawn
    • fillRectangle

      public void fillRectangle​(int x, int y, int width, int height, NamedColor color)
      Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall.
      Parameters:
      x - The x coordinate of the rectangle to be filled
      y - The y coordinate of the rectangle to be filled
      width - The width of the rectangle to be filled
      height - The height of the rectangle to be filled
      color - The color of the rectangle to be filled
    • drawPolygon

      public void drawPolygon​(int[] x, int[] y, NamedColor color)
      Draws a closed polygon defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point.

      This method draws the polygon defined by nPoint line segments, where nPoint == min(x.length, y.length) and where the first nPoint - 1 line segments are line segments from (x[i - 1], y[i - 1]) to (x[i], y[i]) for 1 ≤ i ≤ nPoints. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.

      Parameters:
      x - An array of x coordinates
      y - An array of y coordinates
      color - The color of the polygon to be drawn
    • fillPolygon

      public void fillPolygon​(int[] x, int[] y, NamedColor color)
      Fills a closed polygon defined by arrays of x and y coordinates.

      This method draws the polygon defined by nPoint line segments, where nPoint == min(x.length, y.length) and where the first nPoint - 1 line segments are line segments from (x[i - 1], y[i - 1]) to (x[i], y[i]), for 1 ≤ i ≤ nPoints. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.

      The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.

      Parameters:
      x - An array of x coordinates
      y - An array of y coordinates
      color - The color of the polygon to be drawn
    • drawLine

      public void drawLine​(int x1, int y1, int x2, int y2, NamedColor color)
      Draws a line, using the specified color, between the points (x1, y1) and (x2, y2).
      Parameters:
      x1 - The first point's x coordinate
      y1 - The first point's y coordinate
      x2 - The second point's x coordinate
      y2 - The second point's x coordinate
      color - The color of the line to be drawn
    • drawText

      public void drawText​(java.lang.String text, int x, int y, NamedColor color)
      Draws the text given by the specified string, using the current font and the specified color. The baseline of the leftmost character is at position (x, y).
      Parameters:
      text - The text to be drawn
      x - The x coordinate
      y - The y coordinate
      color - The color of the text to be drawn
    • drawPicture

      public void drawPicture​(int x, int y, java.awt.Image image, java.awt.geom.AffineTransform at)
      Renders an image, applying a transform from image space into user space before drawing. The transformation from user space into device space is done with the current Transform in the Graphics2D. The specified transformation is applied to the image before the transform attribute in the Graphics2D context is applied. The rendering attributes applied include the Clip, Transform, and Composite attributes. Note that no rendering is done if the specified transform is noninvertible.
      Parameters:
      x - The x coordinate of the upper left corner
      y - The y coordinate of the upper left corner
      image - The drawn image
      at - The transformation from image space into user space