public class Graphics2DGraphicContext extends Object implements GraphicContext
GraphicContext
implementation using the Swing Graphics2D
to draw on
whatever you like.Constructor and Description |
---|
Graphics2DGraphicContext(Graphics2D graphics) |
Modifier and Type | Method and Description |
---|---|
Area |
calculateTextSize(String text)
Calculates the size of the text.
|
void |
clip(Area rect)
Restricts which area of the context can be used to drawn on.
|
Graphics2DGraphicContext |
delegate(Graphics2D newDelegate)
Sets the Graphics2D.
|
void |
drawLine(double x1,
double y1,
double x2,
double y2)
Draws a simple line between two points.
|
void |
drawPolyline(double[] x,
double[] y)
Paints the outline of a polyline.
|
void |
drawText(double x,
double y,
String text)
Paints the text on a position.
|
void |
fillArc(double x,
double y,
double width,
double height,
double startAngle,
double arcAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.
|
void |
fillOval(double x,
double y,
double width,
double height)
Paints a filled oval.
|
void |
fillPolygon(double[] x,
double[] y)
Paints a filled polygon.
|
void |
fillRectangle(double x,
double y,
double width,
double height)
Paints a filled rectangle.
|
int |
getColor()
Returns the color as ARGB int, e.g.
|
Graphics2D |
getDelegate()
Returns the Graphics2D.
|
Font |
getFont()
Returns the font as an enum with the font properties as hints for the actual font
used by the GUI.
|
void |
scale(double x,
double y)
Scales the drawing canvas with the factor.
|
void |
setColor(int color)
Sets the color as ARGB int, e.g.
|
void |
setDelegate(Graphics2D delegate)
Sets the Graphics2D.
|
void |
setFont(Font fontAsEnum)
Sets the font as an enum with the font properties as hints for the actual font used
by the GUI.
|
void |
translate(double x,
double y)
Moves the drawing canvas's origin to the new coordinates.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
drawRectangle, drawRectangle, fillRectangle, scale
public Graphics2DGraphicContext(Graphics2D graphics)
public void setColor(int color)
GraphicContext
0xFFFF0000
and blue is
0xFF0000FF
.setColor
in interface GraphicContext
color
- the colorpublic int getColor()
GraphicContext
0xFFFF0000
and blue is
0xFF0000FF
.getColor
in interface GraphicContext
public void setFont(Font fontAsEnum)
GraphicContext
setFont
in interface GraphicContext
fontAsEnum
- the fontpublic Font getFont()
GraphicContext
getFont
in interface GraphicContext
public Area calculateTextSize(String text)
GraphicContext
calculateTextSize
in interface GraphicContext
public void translate(double x, double y)
GraphicContext
translate
in interface GraphicContext
x
- translate xy
- translate ypublic void scale(double x, double y)
GraphicContext
scale
in interface GraphicContext
x
- factor xy
- factor ypublic void clip(Area rect)
GraphicContext
null
to remove the restriction again.clip
in interface GraphicContext
rect
- the clipping areapublic void drawLine(double x1, double y1, double x2, double y2)
GraphicContext
drawLine
in interface GraphicContext
x1
- - start point xy1
- - start point yx2
- - end point xy2
- - end point ypublic void fillRectangle(double x, double y, double width, double height)
GraphicContext
fillRectangle
in interface GraphicContext
x
- the rectangle's xy
- the rectangle's ywidth
- the rectangle's widthheight
- the rectangle's heightpublic void drawPolyline(double[] x, double[] y)
GraphicContext
drawPolyline
in interface GraphicContext
x
- the polygon's x coordinatesy
- the polygon's y coordinatesGraphicContext.fillPolygon(double[], double[])
public void fillPolygon(double[] x, double[] y)
GraphicContext
fillPolygon
in interface GraphicContext
x
- the polygon's x coordinatesy
- the polygon's y coordinatesGraphicContext.drawPolyline(double[], double[])
public void drawText(double x, double y, String text)
GraphicContext
drawText
in interface GraphicContext
x
- the text's xy
- the text's ypublic void fillOval(double x, double y, double width, double height)
GraphicContext
fillOval
in interface GraphicContext
x
- the oval's xy
- the oval's ywidth
- the oval's widthheight
- the oval's heightpublic void fillArc(double x, double y, double width, double height, double startAngle, double arcAngle)
GraphicContext
The resulting arc begins at startAngle
and extends for
arcAngle
degrees, using the current color. Angles are interpreted such
that 0 degrees is at the 3 o'clock position. A positive value indicates a
counter-clockwise rotation while a negative value indicates a clockwise rotation.
The center of the arc is the center of the rectangle whose origin is
(x, y) and whose size is specified by the width
and
height
arguments.
The resulting arc covers an area width + 1
pixels wide by
height + 1
pixels tall.
fillArc
in interface GraphicContext
x
- the x coordinate of the upper-left corner of the arc to be drawn.y
- the y coordinate of the upper-left corner of the arc to be drawn.width
- the width of the arc to be drawn.height
- the height of the arc to be drawn.startAngle
- the beginning angle.arcAngle
- the angular extent of the arc, relative to the start angle.public Graphics2D getDelegate()
public Graphics2DGraphicContext delegate(Graphics2D newDelegate)
newDelegate
- the Graphics2D to draw on; cannot be nullpublic void setDelegate(Graphics2D delegate)
delegate
- the Graphics2D to draw on; cannot be nullCopyright © 2020. All rights reserved.