Class DXFGraphics
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- com.jsevy.jdxf.DXFGraphics
-
public class DXFGraphics extends java.awt.Graphics2D
The DXFGraphics class is the main class of the DXFGraphics library. It extends the standard Java Graphics and Graphics2D classes, reimplementing their methods to generate DXF objects which can then generate DXF output for use with CAD programs. A DXFGraphics object is always associated with a DXFDocument instance, and is obtained from the DXFDocument through a call to the getGraphics() method. The typical workflow is as follows:// Create a DXF document and get its associated DXFGraphics instance DXFDocument dxfDocument = new DXFDocument("Example"); DXFGraphics dxfGraphics = dxfDocument.getGraphics(); // Do drawing commands as on any other Graphics. If you have a paint(Graphics) method, // you can just use it with the DXFGraphics instance since it's a subclass of Graphics. graphics.setColor(Color.RED); graphics.setStroke(new BasicStroke(3)); graphics.drawLine(0, 0, 1000, 500); graphics.drawRect(1000, 500, 150, 150); graphics.drawRoundRect(20, 200, 130, 100, 20, 10); // Get the DXF output as a string - it's just text - and save in a file for use with a CAD package String stringOutput = dxfDocument.toDXFString(); String filePath = "path/to/file.dxf"; FileWriter fileWriter = new FileWriter(filePath); fileWriter.write(dxfText); fileWriter.flush(); fileWriter.close();
- Author:
- jsevy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DXFGraphics.BlockLayerMode
-
Constructor Summary
Constructors Constructor Description DXFGraphics(DXFDocument dxfDocument)
Constructs a new DXFGraphics object.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addRenderingHints(java.util.Map<?,?> arg0)
Does nothing...void
clear(java.awt.Shape shape)
Clear the specified shape by filling with the current background color.void
clearRect(double x, double y, double width, double height)
Clears the specified rectangle by filling it with the background color.void
clearRect(int x, int y, int width, int height)
Clears the specified rectangle by filling it with the background color.void
clip(java.awt.Shape arg0)
Does nothing as clipping not supported.void
clipRect(int x, int y, int width, int height)
Does nothing, as clipping not supportedvoid
copyArea(int x, int y, int width, int height, int dx, int dy)
Throws UnsupportedOperationException, as copyArea not supported.DXFGraphics
create()
Creates a new DXFGraphics object that is a copy of this DXFGraphics object.DXFGraphics
create(int x, int y, int width, int height)
Creates a new DXFGraphics object based on this DXFGraphics object, but with a new translation.void
dispose()
Disposes of this graphics context and releases any system resources that it is using.void
draw(java.awt.Shape shape)
Draw the specified shape.void
draw3DRect(int x, int y, int width, int height, boolean raised)
Draws a 3-D highlighted outline of the specified rectangle.void
drawArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.void
drawArc(int x, int y, int width, int height, int startAngle, int sweepAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.void
drawBytes(byte[] data, int offset, int length, int x, int y)
Draws the text given by the specified byte array, using this graphics context's current font and color.void
drawChars(char[] data, int offset, int length, int x, int y)
Draws the text given by the specified character array, using this graphics context's current font and color.void
drawGlyphVector(java.awt.font.GlyphVector arg0, float arg1, float arg2)
Throws UnsupportedOperationException as glyph drawing not supported.void
drawImage(java.awt.image.BufferedImage arg0, java.awt.image.BufferedImageOp arg1, int arg2, int arg3)
Throws UnsupportedOperationException as image drawing not supported.boolean
drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.boolean
drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.boolean
drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.boolean
drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.boolean
drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.boolean
drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.boolean
drawImage(java.awt.Image arg0, java.awt.geom.AffineTransform arg1, java.awt.image.ImageObserver arg2)
Throws UnsupportedOperationException as image drawing not supported.void
drawLine(double x1, double y1, double x2, double y2)
Draws a line, using the current color, between the points(x1, y1)
and(x2, y2)
in this graphics context's coordinate system.void
drawLine(int x1, int y1, int x2, int y2)
Draws a line, using the current color, between the points(x1, y1)
and(x2, y2)
in this graphics context's coordinate system.void
drawOval(double x, double y, double width, double height)
Draws the outline of an oval.void
drawOval(int x, int y, int width, int height)
Draws the outline of an oval.void
drawPoint(double x, double y)
Draws a point, using the current color, at location(x, y)
in this graphics context's coordinate system.void
drawPoint(int x, int y)
Draws a point, using the current color, at location(x, y)
in this graphics context's coordinate system.void
drawPolygon(double[] xPoints, double[] yPoints, int nPoints)
Draws a closed polygon defined by arrays of x and y coordinates.void
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
Draws a closed polygon defined by arrays of x and y coordinates.void
drawPolygon(java.awt.Polygon p)
Draws the outline of a polygon defined by the specifiedPolygon
object.void
drawPolyline(double[] xPoints, double[] yPoints, int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates.void
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates.void
drawRect(double x, double y, double width, double height)
Draws the outline of the specified rectangle.void
drawRect(int x, int y, int width, int height)
Draws the outline of the specified rectangle.void
drawRenderableImage(java.awt.image.renderable.RenderableImage arg0, java.awt.geom.AffineTransform arg1)
Throws UnsupportedOperationException as image drawing not supported.void
drawRenderedImage(java.awt.image.RenderedImage arg0, java.awt.geom.AffineTransform arg1)
Throws UnsupportedOperationException as image drawing not supported.void
drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color.void
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color.void
drawSpline(int degree, double[] controlPoints, double[] knots)
An extension method that supports the drawing of a B-spline with an arbitrary knot sequence.void
drawSpline(int degree, double[] controlPoints, int[] multiplicities, boolean throughEndpoints)
An extension method that supports the drawing of a B-spline.void
drawString(java.lang.String string, double x, double y)
Draws the text given by the specified string, using this graphics context's current font and color.void
drawString(java.lang.String str, float x, float y)
void
drawString(java.lang.String str, int x, int y)
Draws the text given by the specified string, using this graphics context's current font and color.void
drawString(java.text.AttributedCharacterIterator charIterator, float x, float y)
void
drawString(java.text.AttributedCharacterIterator charIterator, int x, int y)
Renders the text of the specified iterator, but ignoring text attributes.void
fill(java.awt.Shape shape)
Fill the specified shape with the current foreground color.void
fill3DRect(int x, int y, int width, int height, boolean raised)
Paints a 3-D highlighted rectangle filled with the current color.void
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Fills a circular or elliptical arc wedge covering the specified rectangle.void
fillOval(double x, double y, double width, double height)
Fills an oval bounded by the specified rectangle with the current color.void
fillOval(int x, int y, int width, int height)
Fills an oval bounded by the specified rectangle with the current color.void
fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
Fills a closed polygon defined by arrays of x and y coordinates.void
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
Fills a closed polygon defined by arrays of x and y coordinates.void
fillPolygon(java.awt.Polygon p)
Fills the polygon defined by the specified Polygon object with the graphics context's current color.void
fillRect(double x, double y, double width, double height)
Fills the specified rectangle.void
fillRect(int x, int y, int width, int height)
Fills the specified rectangle.void
fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
Fills the specified rounded corner rectangle with the current color.void
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Fills the specified rounded corner rectangle with the current color.void
finalize()
Disposes of this graphics context once it is no longer referenced.java.awt.Color
getBackground()
Return the current background color.java.awt.Shape
getClip()
Returns null, as clipping not supportedjava.awt.Rectangle
getClipBounds()
Returns null, as clipping not supported.java.awt.Rectangle
getClipBounds(java.awt.Rectangle r)
Returns r, as clipping not supported.java.awt.Rectangle
getClipRect()
Deprecated.java.awt.Color
getColor()
Gets this graphic's foreground color.java.awt.Composite
getComposite()
Returns null; Composite not supported.java.awt.GraphicsConfiguration
getDeviceConfiguration()
Returns null; GraphicsConfiguration not supported.java.awt.Font
getFont()
Gets the current font.java.awt.FontMetrics
getFontMetrics()
Gets the font metrics of the current font.java.awt.FontMetrics
getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font.java.awt.font.FontRenderContext
getFontRenderContext()
Returns null; Font render context needed for Font sizing; use from current graphics environment.java.awt.Paint
getPaint()
Just return the current foreground color object.java.lang.Object
getRenderingHint(java.awt.RenderingHints.Key arg0)
Return null; rendering hints not supported.java.awt.RenderingHints
getRenderingHints()
Return null; rendering hints not supported.java.awt.Stroke
getStroke()
Return our current pen stroke.java.awt.geom.AffineTransform
getTransform()
Return a copy of the current graphics transformation being applied to drawing and text operations.boolean
hit(java.awt.Rectangle arg0, java.awt.Shape arg1, boolean arg2)
Not supported; return false.boolean
hitClip(int x, int y, int width, int height)
Returns true as clipping not supported.void
rotate(double radians)
Apply the specified rotation to the current graphics transformation.void
rotate(double radians, double x, double y)
Apply the specified rotation to the current graphics transformation, but first translating by (x,y) and after translating back by (-x, -y).void
scale(double sx, double sy)
Apply the specified scaling to the current graphics transformation.void
setBackground(java.awt.Color color)
Set the background color used in clear operations to the specified colorvoid
setClip(int x, int y, int width, int height)
Does nothing, as clipping not supportedvoid
setClip(java.awt.Shape clip)
Does nothing, as clipping not supportedvoid
setColor(java.awt.Color color)
Sets this graphics foreground color to the specified color.void
setComposite(java.awt.Composite arg0)
Do nothing - composite not supported.void
setFont(java.awt.Font font)
Sets this graphics context's font to the specified font.void
setPaint(java.awt.Paint paint)
Use to set foreground color if instance of Color, otherwise do nothing.void
setPaintMode()
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color.void
setRenderingHint(java.awt.RenderingHints.Key arg0, java.lang.Object arg1)
Do nothing; rendering hints not supported.void
setRenderingHints(java.util.Map<?,?> arg0)
Do nothing; rendering hints not supported.void
setStroke(java.awt.Stroke stroke)
Set stroke if instance of BasicStroke, otherwise throw UnsupportedOperationException.void
setTransform(java.awt.geom.AffineTransform newTransform)
Set current graphics transformation to that supplied.void
setXORMode(java.awt.Color xorColor)
Currently does nothing, as only PAINT_MODE is supportedvoid
shear(double sx, double sy)
Apply the specified shearing to the current graphics transformation.java.lang.String
toString()
Returns aString
object representing thisGraphics
object's value.void
transform(java.awt.geom.AffineTransform transform)
Concatenate the supplied transformation to the current graphics transformation.void
translate(double x, double y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system.void
translate(int x, int y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system.
-
-
-
Constructor Detail
-
DXFGraphics
public DXFGraphics(DXFDocument dxfDocument)
Constructs a new DXFGraphics object. Since a DXFGraphics object is always associated with a DXFDocument instance, applications should not call this constructor directly, but rather use the getGraphics() method of a DXFDocument.- Parameters:
dxfDocument
- The associated DXFDocument instance
-
-
Method Detail
-
create
public DXFGraphics create()
Creates a new DXFGraphics object that is a copy of this DXFGraphics object. Since a DXFGraphics object is always associated with a DXFDocument instance, applications should not call this constructor directly, but rather use the getGraphics() method of a DXFDocument.- Specified by:
create
in classjava.awt.Graphics
- Returns:
- a new DXFGraphics context that is a copy of this graphics context.
-
create
public DXFGraphics create(int x, int y, int width, int height)
Creates a new DXFGraphics object based on this DXFGraphics object, but with a new translation. Since a DXFGraphics object is always associated with a DXFDocument instance, applications should not call this constructor directly, but rather use the getGraphics() method of a DXFDocument.- Overrides:
create
in classjava.awt.Graphics
-
getColor
public java.awt.Color getColor()
Gets this graphic's foreground color.- Specified by:
getColor
in classjava.awt.Graphics
- Returns:
- the foreground color
-
setColor
public void setColor(java.awt.Color color)
Sets this graphics foreground color to the specified color. All subsequent graphics operations using this graphics objects use this new color.- Specified by:
setColor
in classjava.awt.Graphics
- Parameters:
color
- the new rendering color.
-
setPaintMode
public void setPaintMode()
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color. Note that this is the only mode supported by DXFGraphics.- Specified by:
setPaintMode
in classjava.awt.Graphics
-
setXORMode
public void setXORMode(java.awt.Color xorColor)
Currently does nothing, as only PAINT_MODE is supported- Specified by:
setXORMode
in classjava.awt.Graphics
-
getFont
public java.awt.Font getFont()
Gets the current font.- Specified by:
getFont
in classjava.awt.Graphics
- Returns:
- this graphic's current font.
-
setFont
public void setFont(java.awt.Font font)
Sets this graphics context's font to the specified font. All subsequent text operations using this graphics context use this font. A null argument is silently ignored.- Specified by:
setFont
in classjava.awt.Graphics
- Parameters:
font
- the new font.
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics()
Gets the font metrics of the current font.- Overrides:
getFontMetrics
in classjava.awt.Graphics
- Returns:
- the font metrics of this graphics context's current font.
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
Gets the font metrics for the specified font.- Specified by:
getFontMetrics
in classjava.awt.Graphics
- Parameters:
f
- the specified font- Returns:
- the font metrics for the specified font.
-
getClipBounds
public java.awt.Rectangle getClipBounds()
Returns null, as clipping not supported.- Specified by:
getClipBounds
in classjava.awt.Graphics
- Returns:
- null
-
clipRect
public void clipRect(int x, int y, int width, int height)
Does nothing, as clipping not supported- Specified by:
clipRect
in classjava.awt.Graphics
-
setClip
public void setClip(int x, int y, int width, int height)
Does nothing, as clipping not supported- Specified by:
setClip
in classjava.awt.Graphics
-
getClip
public java.awt.Shape getClip()
Returns null, as clipping not supported- Specified by:
getClip
in classjava.awt.Graphics
- Returns:
- null
-
setClip
public void setClip(java.awt.Shape clip)
Does nothing, as clipping not supported- Specified by:
setClip
in classjava.awt.Graphics
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy)
Throws UnsupportedOperationException, as copyArea not supported.- Specified by:
copyArea
in classjava.awt.Graphics
-
drawPoint
public void drawPoint(int x, int y)
Draws a point, using the current color, at location(x, y)
in this graphics context's coordinate system.- Parameters:
x
- the point's x coordinate.y
- the point's y coordinate.
-
drawPoint
public void drawPoint(double x, double y)
Draws a point, using the current color, at location(x, y)
in this graphics context's coordinate system.- Parameters:
x
- the point's x coordinate.y
- the point's y coordinate.
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2)
Draws a line, using the current color, between the points(x1, y1)
and(x2, y2)
in this graphics context's coordinate system.- Specified by:
drawLine
in classjava.awt.Graphics
- 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 y coordinate.
-
drawLine
public void drawLine(double x1, double y1, double x2, double y2)
Draws a line, using the current color, between the points(x1, y1)
and(x2, y2)
in this graphics context's coordinate system.- 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 y coordinate.
-
fillRect
public void fillRect(int x, int y, int width, int height)
Fills the specified rectangle. The left and right edges of the rectangle are atx
andx + width - 1
. The top and bottom edges are aty
andy + height - 1
. The rectangle is filled using the graphics context's current color.- Specified by:
fillRect
in classjava.awt.Graphics
- 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.
-
fillRect
public void fillRect(double x, double y, double width, double height)
Fills the specified rectangle. The left and right edges of the rectangle are atx
andx + width - 1
. The top and bottom edges are aty
andy + height - 1
. The rectangle is filled using the graphics context's current color.- 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.
-
drawRect
public void drawRect(int x, int y, int width, int height)
Draws the outline of the specified rectangle. The left and right edges of the rectangle are atx
andx + width
. The top and bottom edges are aty
andy + height
. The rectangle is drawn using the graphics context's current color.- Overrides:
drawRect
in classjava.awt.Graphics
- 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.
-
drawRect
public void drawRect(double x, double y, double width, double height)
Draws the outline of the specified rectangle. The left and right edges of the rectangle are atx
andx + width
. The top and bottom edges are aty
andy + height
. The rectangle is drawn using the graphics context's current 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.
-
clearRect
public void clearRect(int x, int y, int width, int height)
Clears the specified rectangle by filling it with the background color.- Specified by:
clearRect
in classjava.awt.Graphics
- Parameters:
x
- the x coordinate of the rectangle to clear.y
- the y coordinate of the rectangle to clear.width
- the width of the rectangle to clear.height
- the height of the rectangle to clear.
-
clearRect
public void clearRect(double x, double y, double width, double height)
Clears the specified rectangle by filling it with the background color.- Parameters:
x
- the x coordinate of the rectangle to clear.y
- the y coordinate of the rectangle to clear.width
- the width of the rectangle to clear.height
- the height of the rectangle to clear.
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color. The left and right edges of the rectangle are atx
andx + width
, respectively. The top and bottom edges of the rectangle are aty
andy + height
.- Specified by:
drawRoundRect
in classjava.awt.Graphics
- 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.arcWidth
- the horizontal diameter of the arc at the four corners.arcHeight
- the vertical diameter of the arc at the four corners.
-
drawRoundRect
public void drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color. The left and right edges of the rectangle are atx
andx + width
, respectively. The top and bottom edges of the rectangle are aty
andy + height
.- 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.arcWidth
- the horizontal diameter of the arc at the four corners.arcHeight
- the vertical diameter of the arc at the four corners.
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are atx
andx + width - 1
, respectively. The top and bottom edges of the rectangle are aty
andy + height - 1
.- Specified by:
fillRoundRect
in classjava.awt.Graphics
- 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.arcWidth
- the horizontal diameter of the arc at the four corners.arcHeight
- the vertical diameter of the arc at the four corners.
-
fillRoundRect
public void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are atx
andx + width - 1
, respectively. The top and bottom edges of the rectangle are aty
andy + height - 1
.- 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.arcWidth
- the horizontal diameter of the arc at the four corners.arcHeight
- the vertical diameter of the arc at the four corners.
-
draw3DRect
public void draw3DRect(int x, int y, int width, int height, boolean raised)
Draws a 3-D highlighted outline of the specified rectangle. The edges of the rectangle are highlighted so that they appear to be beveled and lit from the upper left corner.The colors used for the highlighting effect are determined based on the current color. The resulting rectangle covers an area that is
width + 1
pixels wide byheight + 1
pixels tall.- Overrides:
draw3DRect
in classjava.awt.Graphics2D
- 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.raised
- a boolean that determines whether the rectangle appears to be raised above the surface or sunk into the surface.
-
fill3DRect
public void fill3DRect(int x, int y, int width, int height, boolean raised)
Paints a 3-D highlighted rectangle filled with the current color. The edges of the rectangle will be highlighted so that it appears as if the edges were beveled and lit from the upper left corner. The colors used for the highlighting effect will be determined from the current color.- Overrides:
fill3DRect
in classjava.awt.Graphics2D
- 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.raised
- a boolean value that determines whether the rectangle appears to be raised above the surface or etched into the surface.- See Also:
Graphics.draw3DRect(int, int, int, int, boolean)
-
drawOval
public void drawOval(int x, int y, int width, int height)
Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by thex
,y
,width
, andheight
arguments.- Specified by:
drawOval
in classjava.awt.Graphics
- 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.
-
drawOval
public void drawOval(double x, double y, double width, double height)
Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by thex
,y
,width
, andheight
arguments.- 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.
-
fillOval
public void fillOval(int x, int y, int width, int height)
Fills an oval bounded by the specified rectangle with the current color.- Specified by:
fillOval
in classjava.awt.Graphics
- 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.
-
fillOval
public void fillOval(double x, double y, double width, double height)
Fills an oval bounded by the specified rectangle with the current 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.
-
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int sweepAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.The resulting arc begins at
startAngle
and extends forarcAngle
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
andheight
arguments.The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
- Specified by:
drawArc
in classjava.awt.Graphics
- Parameters:
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, in degreessweepAngle
- the angular extent of the arc, in degrees, relative to the start angle.
-
drawArc
public void drawArc(double x, double y, double width, double height, double startAngle, double sweepAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle.The resulting arc begins at
startAngle
and extends forarcAngle
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
andheight
arguments.The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
- Parameters:
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, in degreessweepAngle
- the angular extent of the arc, in degrees, relative to the start angle.
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Fills a circular or elliptical arc wedge covering the specified rectangle.The resulting arc begins at
startAngle
and extends forarcAngle
degrees. 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
andheight
arguments.The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
- Specified by:
fillArc
in classjava.awt.Graphics
- Parameters:
x
- the x coordinate of the upper-left corner of the arc to be filled.y
- the y coordinate of the upper-left corner of the arc to be filled.width
- the width of the arc to be filled.height
- the height of the arc to be filled.startAngle
- the beginning angle.arcAngle
- the angular extent of the arc, relative to the start angle.
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point. The figure is not closed if the first point differs from the last point.- Specified by:
drawPolyline
in classjava.awt.Graphics
- Parameters:
xPoints
- an array of x pointsyPoints
- an array of y pointsnPoints
- the total number of points
-
drawPolyline
public void drawPolyline(double[] xPoints, double[] yPoints, int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point. The figure is not closed if the first point differs from the last point.- Parameters:
xPoints
- an array of x pointsyPoints
- an array of y pointsnPoints
- the total number of points
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
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 the firstnPoint - 1
line segments are line segments from(xPoints[i - 1], yPoints[i - 1])
to(xPoints[i], yPoints[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.- Specified by:
drawPolygon
in classjava.awt.Graphics
- Parameters:
xPoints
- a an array ofx
coordinates.yPoints
- a an array ofy
coordinates.nPoints
- a the total number of points.
-
drawPolygon
public void drawPolygon(double[] xPoints, double[] yPoints, int nPoints)
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 the firstnPoint - 1
line segments are line segments from(xPoints[i - 1], yPoints[i - 1])
to(xPoints[i], yPoints[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:
xPoints
- a an array ofx
coordinates.yPoints
- a an array ofy
coordinates.nPoints
- a the total number of points.
-
drawPolygon
public void drawPolygon(java.awt.Polygon p)
Draws the outline of a polygon defined by the specifiedPolygon
object.- Overrides:
drawPolygon
in classjava.awt.Graphics
- Parameters:
p
- the polygon to draw.
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
Fills a closed polygon defined by arrays of x and y coordinates.This method fills the polygon defined by
nPoint
line segments, where the firstnPoint - 1
line segments are line segments from(xPoints[i - 1], yPoints[i - 1])
to(xPoints[i], yPoints[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.- Specified by:
fillPolygon
in classjava.awt.Graphics
- Parameters:
xPoints
- a an array ofx
coordinates.yPoints
- a an array ofy
coordinates.nPoints
- a the total number of points.
-
fillPolygon
public void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
Fills a closed polygon defined by arrays of x and y coordinates.This method fills the polygon defined by
nPoint
line segments, where the firstnPoint - 1
line segments are line segments from(xPoints[i - 1], yPoints[i - 1])
to(xPoints[i], yPoints[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:
xPoints
- a an array ofx
coordinates.yPoints
- a an array ofy
coordinates.nPoints
- a the total number of points.
-
fillPolygon
public void fillPolygon(java.awt.Polygon p)
Fills the polygon defined by the specified Polygon object with the graphics context's current color.- Overrides:
fillPolygon
in classjava.awt.Graphics
- Parameters:
p
- the polygon to fill.
-
drawSpline
public void drawSpline(int degree, double[] controlPoints, int[] multiplicities, boolean throughEndpoints)
An extension method that supports the drawing of a B-spline. For the common case of a spline that passes through the first and last control points, set the multiplicity of these equal to the spline degree plus 1.- Parameters:
degree
- The degree of the spline; must be greater than 0controlPoints
- The control points that define the shape of the spline, {x1, y1, x2, y2, ..., xn, yn}.multiplicities
- The multiplicities for the control points; the number of multiplicity values must equal the number of control points (i.e., the array size must be half that of the controlPoints array)throughEndpoints
- If true, the spline will be forced to pass through the endpoints by setting the end control point multiplicities to degree + 1
-
drawSpline
public void drawSpline(int degree, double[] controlPoints, double[] knots)
An extension method that supports the drawing of a B-spline with an arbitrary knot sequence. This is included specifically to cover the case of the quadratic and cubic curve segments generated by PathIterator, which are specified as Bezier curves, or B-splines with knots {0,0,0,0,1,1,1,1} (for the cubic). This will handle other knot sequences if needed; however, note the constraint on the number of knots vs the number of control points. Also, the multiplicities of the control points are all set to 1.- Parameters:
degree
- The degree of the spline; must be greater than 0controlPoints
- The control points that define the shape of the spline, {x1, y1, x2, y2, ..., xn, yn}.knots
- The knots for the control points; the number of knot values must equal the number of control points plus the degree plus 1. Setting the first degree + 1 knots equal and the last degree + 1 knots equal will make the spline pass through the endpoints
-
drawString
public void drawString(java.lang.String str, int x, int y)
Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system.- Specified by:
drawString
in classjava.awt.Graphics2D
- Parameters:
str
- the string to be drawn.x
- the x coordinate.y
- the y coordinate.- Throws:
java.lang.NullPointerException
- ifstr
isnull
.
-
drawString
public void drawString(java.text.AttributedCharacterIterator charIterator, int x, int y)
Renders the text of the specified iterator, but ignoring text attributes.The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system.
- Specified by:
drawString
in classjava.awt.Graphics2D
- Parameters:
charIterator
- the iterator whose text is to be drawnx
- the x coordinate.y
- the y coordinate.- Throws:
java.lang.NullPointerException
- ifiterator
isnull
.
-
drawChars
public void drawChars(char[] data, int offset, int length, int x, int y)
Draws the text given by the specified character array, using this graphics context's current font and color. The baseline of the first character is at position (x, y) in this graphics context's coordinate system.- Overrides:
drawChars
in classjava.awt.Graphics
- Parameters:
data
- the array of characters to be drawnoffset
- the start offset in the datalength
- the number of characters to be drawnx
- the x coordinate of the baseline of the texty
- the y coordinate of the baseline of the text- Throws:
java.lang.NullPointerException
- ifdata
isnull
.java.lang.IndexOutOfBoundsException
- ifoffset
orlength
is less than zero, oroffset+length
is greater than the length of thedata
array.- See Also:
Graphics.drawBytes(byte[], int, int, int, int)
,Graphics.drawString(java.lang.String, int, int)
-
drawBytes
public void drawBytes(byte[] data, int offset, int length, int x, int y)
Draws the text given by the specified byte array, using this graphics context's current font and color. The baseline of the first character is at position (x, y) in this graphics context's coordinate system.Use of this method is not recommended as each byte is interpreted as a Unicode code point in the range 0 to 255, and so can only be used to draw Latin characters in that range.
- Overrides:
drawBytes
in classjava.awt.Graphics
- Parameters:
data
- the data to be drawnoffset
- the start offset in the datalength
- the number of bytes that are drawnx
- the x coordinate of the baseline of the texty
- the y coordinate of the baseline of the text- Throws:
java.lang.NullPointerException
- ifdata
isnull
.java.lang.IndexOutOfBoundsException
- ifoffset
orlength
is less than zero, oroffset+length
is greater than the length of thedata
array.
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.- Specified by:
drawImage
in classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)
Throws UnsupportedOperationException, as drawImage not supported.- Specified by:
drawImage
in classjava.awt.Graphics
-
dispose
public void dispose()
Disposes of this graphics context and releases any system resources that it is using. Does nothing here.- Specified by:
dispose
in classjava.awt.Graphics
-
finalize
public void finalize()
Disposes of this graphics context once it is no longer referenced.- Overrides:
finalize
in classjava.awt.Graphics
- See Also:
dispose()
-
toString
public java.lang.String toString()
Returns aString
object representing thisGraphics
object's value.- Overrides:
toString
in classjava.awt.Graphics
- Returns:
- a string representation of this graphics context.
-
getClipRect
@Deprecated public java.awt.Rectangle getClipRect()
Deprecated.Returns null as clipping not supported.- Overrides:
getClipRect
in classjava.awt.Graphics
- Returns:
- null
-
hitClip
public boolean hitClip(int x, int y, int width, int height)
Returns true as clipping not supported.- Overrides:
hitClip
in classjava.awt.Graphics
- Returns:
- true.
-
getClipBounds
public java.awt.Rectangle getClipBounds(java.awt.Rectangle r)
Returns r, as clipping not supported.- Overrides:
getClipBounds
in classjava.awt.Graphics
- Parameters:
r
- the rectangle where the current clipping area is copied to. Any current values in this rectangle are overwritten.- Returns:
- r.
-
addRenderingHints
public void addRenderingHints(java.util.Map<?,?> arg0)
Does nothing...- Specified by:
addRenderingHints
in classjava.awt.Graphics2D
-
clip
public void clip(java.awt.Shape arg0)
Does nothing as clipping not supported.- Specified by:
clip
in classjava.awt.Graphics2D
-
draw
public void draw(java.awt.Shape shape)
Draw the specified shape.- Specified by:
draw
in classjava.awt.Graphics2D
- Parameters:
shape
- shape to be drawn
-
drawGlyphVector
public void drawGlyphVector(java.awt.font.GlyphVector arg0, float arg1, float arg2)
Throws UnsupportedOperationException as glyph drawing not supported.- Specified by:
drawGlyphVector
in classjava.awt.Graphics2D
-
drawImage
public boolean drawImage(java.awt.Image arg0, java.awt.geom.AffineTransform arg1, java.awt.image.ImageObserver arg2)
Throws UnsupportedOperationException as image drawing not supported.- Specified by:
drawImage
in classjava.awt.Graphics2D
-
drawImage
public void drawImage(java.awt.image.BufferedImage arg0, java.awt.image.BufferedImageOp arg1, int arg2, int arg3)
Throws UnsupportedOperationException as image drawing not supported.- Specified by:
drawImage
in classjava.awt.Graphics2D
-
drawRenderableImage
public void drawRenderableImage(java.awt.image.renderable.RenderableImage arg0, java.awt.geom.AffineTransform arg1)
Throws UnsupportedOperationException as image drawing not supported.- Specified by:
drawRenderableImage
in classjava.awt.Graphics2D
-
drawRenderedImage
public void drawRenderedImage(java.awt.image.RenderedImage arg0, java.awt.geom.AffineTransform arg1)
Throws UnsupportedOperationException as image drawing not supported.- Specified by:
drawRenderedImage
in classjava.awt.Graphics2D
-
drawString
public void drawString(java.lang.String str, float x, float y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
drawString
public void drawString(java.lang.String string, double x, double y)
Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system.- Parameters:
string
- the string to be drawn.x
- the x coordinate.y
- the y coordinate.- Throws:
java.lang.NullPointerException
- ifstr
isnull
.
-
drawString
public void drawString(java.text.AttributedCharacterIterator charIterator, float x, float y)
- Specified by:
drawString
in classjava.awt.Graphics2D
-
clear
public void clear(java.awt.Shape shape)
Clear the specified shape by filling with the current background color.- Parameters:
shape
- shape to be cleared
-
fill
public void fill(java.awt.Shape shape)
Fill the specified shape with the current foreground color.- Specified by:
fill
in classjava.awt.Graphics2D
- Parameters:
shape
- shape to be filled
-
getBackground
public java.awt.Color getBackground()
Return the current background color.- Specified by:
getBackground
in classjava.awt.Graphics2D
- Returns:
- current background color
-
getComposite
public java.awt.Composite getComposite()
Returns null; Composite not supported.- Specified by:
getComposite
in classjava.awt.Graphics2D
-
getDeviceConfiguration
public java.awt.GraphicsConfiguration getDeviceConfiguration()
Returns null; GraphicsConfiguration not supported.- Specified by:
getDeviceConfiguration
in classjava.awt.Graphics2D
-
getFontRenderContext
public java.awt.font.FontRenderContext getFontRenderContext()
Returns null; Font render context needed for Font sizing; use from current graphics environment.- Specified by:
getFontRenderContext
in classjava.awt.Graphics2D
-
getPaint
public java.awt.Paint getPaint()
Just return the current foreground color object.- Specified by:
getPaint
in classjava.awt.Graphics2D
- Returns:
- current foreground color
-
getRenderingHint
public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key arg0)
Return null; rendering hints not supported.- Specified by:
getRenderingHint
in classjava.awt.Graphics2D
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
Return null; rendering hints not supported.- Specified by:
getRenderingHints
in classjava.awt.Graphics2D
-
getStroke
public java.awt.Stroke getStroke()
Return our current pen stroke.- Specified by:
getStroke
in classjava.awt.Graphics2D
- Returns:
- current pen stroke
-
getTransform
public java.awt.geom.AffineTransform getTransform()
Return a copy of the current graphics transformation being applied to drawing and text operations.- Specified by:
getTransform
in classjava.awt.Graphics2D
- Returns:
- copy of current graphics transform
-
hit
public boolean hit(java.awt.Rectangle arg0, java.awt.Shape arg1, boolean arg2)
Not supported; return false.- Specified by:
hit
in classjava.awt.Graphics2D
-
rotate
public void rotate(double radians)
Apply the specified rotation to the current graphics transformation. Subsequent graphics operations will have the new combined transformation applied.- Specified by:
rotate
in classjava.awt.Graphics2D
- Parameters:
radians
- rotation in radians
-
rotate
public void rotate(double radians, double x, double y)
Apply the specified rotation to the current graphics transformation, but first translating by (x,y) and after translating back by (-x, -y). Subsequent graphics operations will have the new combined transformation applied.- Specified by:
rotate
in classjava.awt.Graphics2D
- Parameters:
radians
- rotation in radiansx
- x coordinate of pre- and post-translationy
- y coordinate of pre- and post-translation
-
scale
public void scale(double sx, double sy)
Apply the specified scaling to the current graphics transformation. Subsequent graphics operations will have the new combined transformation applied.- Specified by:
scale
in classjava.awt.Graphics2D
- Parameters:
sx
- amount to scale x coordinatessy
- amount to scale y coordinates
-
setBackground
public void setBackground(java.awt.Color color)
Set the background color used in clear operations to the specified color- Specified by:
setBackground
in classjava.awt.Graphics2D
- Parameters:
color
- color to use for background
-
setComposite
public void setComposite(java.awt.Composite arg0)
Do nothing - composite not supported.- Specified by:
setComposite
in classjava.awt.Graphics2D
-
setPaint
public void setPaint(java.awt.Paint paint)
Use to set foreground color if instance of Color, otherwise do nothing.- Specified by:
setPaint
in classjava.awt.Graphics2D
- Parameters:
paint
- paint object; only used if it's an instance of Color
-
setRenderingHint
public void setRenderingHint(java.awt.RenderingHints.Key arg0, java.lang.Object arg1)
Do nothing; rendering hints not supported.- Specified by:
setRenderingHint
in classjava.awt.Graphics2D
-
setRenderingHints
public void setRenderingHints(java.util.Map<?,?> arg0)
Do nothing; rendering hints not supported.- Specified by:
setRenderingHints
in classjava.awt.Graphics2D
-
setStroke
public void setStroke(java.awt.Stroke stroke)
Set stroke if instance of BasicStroke, otherwise throw UnsupportedOperationException.- Specified by:
setStroke
in classjava.awt.Graphics2D
- Parameters:
stroke
- stroke to use (must be BasicStroke)
-
setTransform
public void setTransform(java.awt.geom.AffineTransform newTransform)
Set current graphics transformation to that supplied.- Specified by:
setTransform
in classjava.awt.Graphics2D
- Parameters:
newTransform
- new graphics transformation to be used.
-
shear
public void shear(double sx, double sy)
Apply the specified shearing to the current graphics transformation. Subsequent graphics operations will have the new combined transformation applied.- Specified by:
shear
in classjava.awt.Graphics2D
- Parameters:
sx
- amount to shear x coordinatessy
- amount to shear y coordinates
-
transform
public void transform(java.awt.geom.AffineTransform transform)
Concatenate the supplied transformation to the current graphics transformation. Subsequent graphics operations will have the new combined transformation applied.- Specified by:
transform
in classjava.awt.Graphics2D
-
translate
public void translate(int x, int y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. Modifies this graphics context so that its new origin corresponds to the point (x, y) in this graphics context's original coordinate system. All coordinates used in subsequent rendering operations on this graphics context will be relative to this new origin.- Specified by:
translate
in classjava.awt.Graphics2D
- Parameters:
x
- the x coordinate.y
- the y coordinate.
-
translate
public void translate(double x, double y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. Modifies this graphics context so that its new origin corresponds to the point (x, y) in this graphics context's original coordinate system. All coordinates used in subsequent rendering operations on this graphics context will be relative to this new origin.- Specified by:
translate
in classjava.awt.Graphics2D
- Parameters:
x
- the x coordinate.y
- the y coordinate.
-
-