Class Painter
public class Painter
extends java.lang.Object
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.
-
Field Details
-
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
Set the background color of painting.- Returns:
- The background color of painting
-
setBackground
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
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 drawny
- The y coordinate of the upper left corner of the oval to be drawnwidth
- The width of the oval to be drawnheight
- The height of the oval to be drawncolor
- The color of the oval to be drawn
-
fillEllipse
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 filledy
- The y coordinate of the upper left corner of the oval to be filledwidth
- The width of the oval to be filledheight
- The height of the oval to be filledcolor
- The color of the oval to be filled
-
drawRectangle
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 drawny
- The y coordinate of the rectangle to be drawnwidth
- The width of the rectangle to be drawnheight
- The height of the rectangle to be drawncolor
- The color of the rectangle to be drawn
-
fillRectangle
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 filledy
- The y coordinate of the rectangle to be filledwidth
- The width of the rectangle to be filledheight
- The height of the rectangle to be filledcolor
- The color of the rectangle to be filled
-
drawPolygon
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, wherenPoint == min(x.length, y.length)
and where the firstnPoint - 1
line segments are line segments from(x[i - 1], y[i - 1])
to(x[i], y[i])
for1 ≤ 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 coordinatesy
- An array of y coordinatescolor
- The color of the polygon to be drawn
-
fillPolygon
Fills a closed polygon defined by arrays of x and y coordinates.This method draws the polygon defined by
nPoint
line segments, wherenPoint == min(x.length, y.length)
and where the firstnPoint - 1
line segments are line segments from(x[i - 1], y[i - 1])
to(x[i], y[i])
, for1 ≤ 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 coordinatesy
- An array of y coordinatescolor
- The color of the polygon to be drawn
-
drawLine
Draws a line, using the specified color, between the points(x1, y1)
and(x2, y2)
.- Parameters:
x1
- The first point's x coordinatey1
- The first point's y coordinatex2
- The second point's x coordinatey2
- The second point's x coordinatecolor
- The color of the line to be drawn
-
drawText
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 drawnx
- The x coordinatey
- The y coordinatecolor
- 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 currentTransform
in theGraphics2D
. The specified transformation is applied to the image before the transform attribute in theGraphics2D
context is applied. The rendering attributes applied include theClip
,Transform
, andComposite
attributes. Note that no rendering is done if the specified transform is noninvertible.- Parameters:
x
- The x coordinate of the upper left cornery
- The y coordinate of the upper left cornerimage
- The drawn imageat
- The transformation from image space into user space
-