Class HtmlGraphics2d
java.lang.Object
java.awt.Graphics
java.awt.Graphics2D
nl.tudelft.simulation.dsol.web.animation.HtmlGraphics2d
HTMLGraphics.java.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck
-
Field Summary
Modifier and TypeFieldDescription(package private) AffineTransform
the current affine transform.(package private) Color
the current color of the background for drawing.(package private) Canvas
the drawing canvas.(package private) Color
the current drawing color.(package private) StringBuffer
the commands to send over the channel to the HTML5 code.(package private) Composite
TODO: the current composite.(package private) Font
the current font.(package private) FontMetrics
the cached current font properties.(package private) Paint
the current paint.(package private) RenderingHints
TODO: the current rendering hints.(package private) Stroke
the current stroke. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
add AffineTransform to the command.protected void
add Color to the command.protected void
Add a draw command.protected void
add font data to the command, font-name, font-size, bold/italic/plain.void
addRenderingHints
(Map<?, ?> hints) protected void
addTransformDraw
(String drawCommand, Object... params) Add command, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), linecolor.r, linecolor.g, linecolor.b, linecolor.alpha, linecolor.transparency, line-width, params...protected void
addTransformFill
(String fillCommand, Object... params) Add fill command, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), color.r, color.g, color.b, color.alpha, color.transparency, params...protected void
addTransformPathDouble
(Path2D.Double path, boolean fill) Add a path2D to the command.protected void
addTransformPathFloat
(Path2D.Float path, boolean fill) Add a path2D to the command.protected void
addTransformText
(String drawCommand, Object... params) Add string, 0=command, 1=transform.m11(h-scale), 2=transform.m12(h-skew), 3=transform.m21(v-skew), 4=transform.m22(v-scale), 5=transform.dx(h-translate), 6=transform.dy(v-translate), 7=color.r, 8=color.g, 9=color.b, 10=color.alpha, 11=color.transparency, 12=fontname, 13=fontsize, 14=fontstyle(normal/italic/bold), 15=x, 16=y, 17=text.void
Clear the commands and put the start tag in.void
clearRect
(int x, int y, int width, int height) void
void
clipRect
(int x, int y, int width, int height) Close the commands and put the end tag in.void
copyArea
(int x, int y, int width, int height, int dx, int dy) create()
void
dispose()
void
void
drawArc
(int x, int y, int width, int height, int startAngle, int arcAngle) protected void
drawFillShape
(Shape shape, boolean fill) Draw or fill a shape.void
drawGlyphVector
(GlyphVector g, float x, float y) void
drawImage
(BufferedImage img, BufferedImageOp op, int x, int y) boolean
drawImage
(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) boolean
drawImage
(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) boolean
drawImage
(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) boolean
drawImage
(Image img, int x, int y, int width, int height, ImageObserver observer) boolean
drawImage
(Image img, int x, int y, Color bgcolor, ImageObserver observer) boolean
drawImage
(Image img, int x, int y, ImageObserver observer) boolean
drawImage
(Image img, AffineTransform xform, ImageObserver obs) void
drawLine
(int x1, int y1, int x2, int y2) void
drawOval
(int x, int y, int width, int height) void
drawPolygon
(int[] xPoints, int[] yPoints, int nPoints) void
drawPolyline
(int[] xPoints, int[] yPoints, int nPoints) void
drawRenderableImage
(RenderableImage img, AffineTransform xform) void
drawRenderedImage
(RenderedImage img, AffineTransform xform) void
drawRoundRect
(int x, int y, int width, int height, int arcWidth, int arcHeight) void
drawString
(String str, float x, float y) void
drawString
(String str, int x, int y) void
drawString
(AttributedCharacterIterator iterator, float x, float y) void
drawString
(AttributedCharacterIterator iterator, int x, int y) void
void
fillArc
(int x, int y, int width, int height, int startAngle, int arcAngle) void
fillOval
(int x, int y, int width, int height) void
fillPolygon
(int[] xPoints, int[] yPoints, int nPoints) void
fillRect
(int x, int y, int width, int height) void
fillRoundRect
(int x, int y, int width, int height, int arcWidth, int arcHeight) getClip()
getColor()
getFont()
getPaint()
getRenderingHint
(RenderingHints.Key hintKey) boolean
void
rotate
(double theta) void
rotate
(double theta, double x, double y) void
scale
(double sx, double sy) void
setBackground
(Color color) void
setClip
(int x, int y, int width, int height) void
void
void
setComposite
(Composite comp) void
void
void
void
setRenderingHint
(RenderingHints.Key hintKey, Object hintValue) void
setRenderingHints
(Map<?, ?> hints) void
void
void
setXORMode
(Color c1) void
shear
(double shx, double shy) void
void
translate
(double tx, double ty) void
translate
(int x, int y) Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
Methods inherited from class java.awt.Graphics
create, drawBytes, drawChars, drawPolygon, drawRect, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toString
-
Field Details
-
background
Color backgroundthe current color of the background for drawing. -
color
Color colorthe current drawing color. -
font
Font fontthe current font. -
canvas
Canvas canvasthe drawing canvas. -
fontMetrics
FontMetrics fontMetricsthe cached current font properties. -
paint
Paint paintthe current paint. -
stroke
Stroke strokethe current stroke. -
renderingHints
RenderingHints renderingHintsTODO: the current rendering hints. -
affineTransform
AffineTransform affineTransformthe current affine transform. -
composite
Composite compositeTODO: the current composite. What is that? -
commands
StringBuffer commandsthe commands to send over the channel to the HTML5 code.
-
-
Constructor Details
-
HtmlGraphics2d
public HtmlGraphics2d()
-
-
Method Details
-
clearCommand
public void clearCommand()Clear the commands and put the start tag in. -
closeAndGetCommands
Close the commands and put the end tag in.- Returns:
- the current set of commands
-
addDraw
Add a draw command.- Parameters:
drawCommand
- String; the tag for the draw commandparams
- Object...; the params for the draw command
-
addAffineTransform
protected void addAffineTransform()add AffineTransform to the command. -
addColor
add Color to the command.- Parameters:
c
- Color; the color
-
addFontData
protected void addFontData()add font data to the command, font-name, font-size, bold/italic/plain. -
addTransformFill
Add fill command, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), color.r, color.g, color.b, color.alpha, color.transparency, params...- Parameters:
fillCommand
- String; the tag to useparams
- Object...; the params to send
-
addTransformDraw
Add command, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), linecolor.r, linecolor.g, linecolor.b, linecolor.alpha, linecolor.transparency, line-width, params...- Parameters:
drawCommand
- String; the tag to useparams
- Object...; the params
-
addTransformPathFloat
Add a path2D to the command. In case of fill:
FILL, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), fillcolor.r, fillcolor.g, fillcolor.b, fillcolor.alpha, fillcolor.transparency, winding_rule[WIND_EVEN_ODD/WIND_NON_ZERO], COMMAND, coords, COMMAND, coords, ...
In case of draw:
DRAW, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), strokecolor.r, strokecolor.g, strokecolor.b, strokecolor.alpha, strokecolor.transparency, line_width, COMMAND, coords, COMMAND, coords, ...
where command can be one of the following:
- CLOSE, followed by no coordinates
- CUBICTO, followed by 3 coordinates (6 numbers)
- LINETO, followed by 1 coordinate (2 numbers)
- MOVETO, followed by 1 coordinate (2 numbers)
- QUADTO, followed by 2 coordinates (4 numbers)- Parameters:
path
- Path2D.Float; the path to drawfill
- boolean;
-
addTransformPathDouble
Add a path2D to the command. In case of fill:
FILL, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), fillcolor.r, fillcolor.g, fillcolor.b, fillcolor.alpha, fillcolor.transparency, winding_rule[WIND_EVEN_ODD/WIND_NON_ZERO], COMMAND, coords, COMMAND, coords, ...
In case of draw:
DRAW, transform.m11(h-scale), transform.m12(h-skew), transform.m21(v-skew), transform.m22(v-scale), transform.dx(h-translate), transform.dy(v-translate), strokecolor.r, strokecolor.g, strokecolor.b, strokecolor.alpha, strokecolor.transparency, line_width, COMMAND, coords, COMMAND, coords, ...
where command can be one of the following:
- CLOSE, followed by no coordinates
- CUBICTO, followed by 3 coordinates (6 numbers)
- LINETO, followed by 1 coordinate (2 numbers)
- MOVETO, followed by 1 coordinate (2 numbers)
- QUADTO, followed by 2 coordinates (4 numbers)- Parameters:
path
- Path2D.Double; the path to drawfill
- boolean;
-
addTransformText
Add string, 0=command, 1=transform.m11(h-scale), 2=transform.m12(h-skew), 3=transform.m21(v-skew), 4=transform.m22(v-scale), 5=transform.dx(h-translate), 6=transform.dy(v-translate), 7=color.r, 8=color.g, 9=color.b, 10=color.alpha, 11=color.transparency, 12=fontname, 13=fontsize, 14=fontstyle(normal/italic/bold), 15=x, 16=y, 17=text.- Parameters:
drawCommand
- String; the tag to useparams
- Object...; the params
-
draw
- Specified by:
draw
in classGraphics2D
-
drawFillShape
Draw or fill a shape.- Parameters:
shape
- Shape; the shapefill
- boolean; filled or not
-
drawImage
- Specified by:
drawImage
in classGraphics2D
-
drawImage
- Specified by:
drawImage
in classGraphics2D
-
drawRenderedImage
- Specified by:
drawRenderedImage
in classGraphics2D
-
drawRenderableImage
- Specified by:
drawRenderableImage
in classGraphics2D
-
drawString
- Specified by:
drawString
in classGraphics2D
-
drawString
- Specified by:
drawString
in classGraphics2D
-
drawString
- Specified by:
drawString
in classGraphics2D
-
drawString
- Specified by:
drawString
in classGraphics2D
-
drawGlyphVector
- Specified by:
drawGlyphVector
in classGraphics2D
-
fill
- Specified by:
fill
in classGraphics2D
-
hit
- Specified by:
hit
in classGraphics2D
-
getDeviceConfiguration
- Specified by:
getDeviceConfiguration
in classGraphics2D
-
setComposite
- Specified by:
setComposite
in classGraphics2D
-
setPaint
- Specified by:
setPaint
in classGraphics2D
-
setStroke
- Specified by:
setStroke
in classGraphics2D
-
setRenderingHint
- Specified by:
setRenderingHint
in classGraphics2D
-
getRenderingHint
- Specified by:
getRenderingHint
in classGraphics2D
-
setRenderingHints
- Specified by:
setRenderingHints
in classGraphics2D
-
addRenderingHints
- Specified by:
addRenderingHints
in classGraphics2D
-
getRenderingHints
- Specified by:
getRenderingHints
in classGraphics2D
-
translate
public void translate(int x, int y) - Specified by:
translate
in classGraphics2D
-
translate
public void translate(double tx, double ty) - Specified by:
translate
in classGraphics2D
-
rotate
public void rotate(double theta) - Specified by:
rotate
in classGraphics2D
-
rotate
public void rotate(double theta, double x, double y) - Specified by:
rotate
in classGraphics2D
-
scale
public void scale(double sx, double sy) - Specified by:
scale
in classGraphics2D
-
shear
public void shear(double shx, double shy) - Specified by:
shear
in classGraphics2D
-
transform
- Specified by:
transform
in classGraphics2D
-
setTransform
- Specified by:
setTransform
in classGraphics2D
-
getTransform
- Specified by:
getTransform
in classGraphics2D
-
getPaint
- Specified by:
getPaint
in classGraphics2D
-
getComposite
- Specified by:
getComposite
in classGraphics2D
-
setBackground
- Specified by:
setBackground
in classGraphics2D
-
getBackground
- Specified by:
getBackground
in classGraphics2D
-
getStroke
- Specified by:
getStroke
in classGraphics2D
-
clip
- Specified by:
clip
in classGraphics2D
-
getFontRenderContext
- Specified by:
getFontRenderContext
in classGraphics2D
-
create
-
getColor
-
setColor
-
setPaintMode
public void setPaintMode()- Specified by:
setPaintMode
in classGraphics
-
setXORMode
- Specified by:
setXORMode
in classGraphics
-
getFont
-
setFont
-
getFontMetrics
- Specified by:
getFontMetrics
in classGraphics
-
getClipBounds
- Specified by:
getClipBounds
in classGraphics
-
clipRect
public void clipRect(int x, int y, int width, int height) -
setClip
public void setClip(int x, int y, int width, int height) -
getClip
-
setClip
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy) -
drawLine
public void drawLine(int x1, int y1, int x2, int y2) -
fillRect
public void fillRect(int x, int y, int width, int height) -
clearRect
public void clearRect(int x, int y, int width, int height) -
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) - Specified by:
drawRoundRect
in classGraphics
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) - Specified by:
fillRoundRect
in classGraphics
-
drawOval
public void drawOval(int x, int y, int width, int height) -
fillOval
public void fillOval(int x, int y, int width, int height) -
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) -
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) -
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) - Specified by:
drawPolyline
in classGraphics
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) - Specified by:
drawPolygon
in classGraphics
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) - Specified by:
fillPolygon
in classGraphics
-
drawImage
-
drawImage
-
drawImage
-
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) -
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) -
drawImage
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) -
dispose
public void dispose()
-