Class HTMLGraphics2D
- java.lang.Object
 - 
- java.awt.Graphics
 - 
- java.awt.Graphics2D
 - 
- nl.tudelft.simulation.dsol.web.animation.HTMLGraphics2D
 
 
 
 
- 
public class HTMLGraphics2D extends Graphics2D
HTMLGraphics.java.
Copyright (c) 2003-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information www.simulation.tudelft.nl. The source code and binary code of this software is proprietary information of Delft University of Technology.- Author:
 - Alexander Verbraeck
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description (package private) AffineTransformaffineTransformthe current affine transform.(package private) Colorbackgroundthe current color of the background for drawing.(package private) Canvascanvasthe drawing canvas.(package private) Colorcolorthe current drawing color.(package private) StringBuffercommandsthe commands to send over the channel to the HTML5 code.(package private) CompositecompositeTODO: the current composite.(package private) Fontfontthe current font.(package private) FontMetricsfontMetricsthe cached current font properties.(package private) Paintpaintthe current paint.(package private) RenderingHintsrenderingHintsTODO: the current rendering hints.(package private) Strokestrokethe current stroke. 
- 
Constructor Summary
Constructors Constructor Description HTMLGraphics2D() 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAffineTransform()add AffineTransform to the command.protected voidaddColor(Color c)add Color to the command.protected voidaddDraw(String drawCommand, Object... params)Add a draw command.protected voidaddFontData()add font data to the command, font-name, font-size, bold/italic/plain.voidaddRenderingHints(Map<?,?> hints)protected voidaddTransformDraw(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 voidaddTransformFill(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 voidaddTransformPathDouble(Path2D.Double path, boolean fill)Add a path2D to the command.protected voidaddTransformPathFloat(Path2D.Float path, boolean fill)Add a path2D to the command.protected voidaddTransformText(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.voidclearCommand()Clear the commands and put the start tag in.voidclearRect(int x, int y, int width, int height)voidclip(Shape s)voidclipRect(int x, int y, int width, int height)StringcloseAndGetCommands()Close the commands and put the end tag in.voidcopyArea(int x, int y, int width, int height, int dx, int dy)Graphicscreate()voiddispose()voiddraw(Shape shape)voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle)protected voiddrawFillShape(Shape shape, boolean fill)Draw or fill a shape.voiddrawGlyphVector(GlyphVector g, float x, float y)voiddrawImage(BufferedImage img, BufferedImageOp op, int x, int y)booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)booleandrawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)booleandrawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)booleandrawImage(Image img, int x, int y, int width, int height, ImageObserver observer)booleandrawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)booleandrawImage(Image img, int x, int y, ImageObserver observer)booleandrawImage(Image img, AffineTransform xform, ImageObserver obs)voiddrawLine(int x1, int y1, int x2, int y2)voiddrawOval(int x, int y, int width, int height)voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints)voiddrawRenderableImage(RenderableImage img, AffineTransform xform)voiddrawRenderedImage(RenderedImage img, AffineTransform xform)voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)voiddrawString(String str, float x, float y)voiddrawString(String str, int x, int y)voiddrawString(AttributedCharacterIterator iterator, float x, float y)voiddrawString(AttributedCharacterIterator iterator, int x, int y)voidfill(Shape shape)voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle)voidfillOval(int x, int y, int width, int height)voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)voidfillRect(int x, int y, int width, int height)voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)ColorgetBackground()ShapegetClip()RectanglegetClipBounds()ColorgetColor()CompositegetComposite()GraphicsConfigurationgetDeviceConfiguration()FontgetFont()FontMetricsgetFontMetrics(Font f)FontRenderContextgetFontRenderContext()PaintgetPaint()ObjectgetRenderingHint(RenderingHints.Key hintKey)RenderingHintsgetRenderingHints()StrokegetStroke()AffineTransformgetTransform()booleanhit(Rectangle rect, Shape s, boolean onStroke)voidrotate(double theta)voidrotate(double theta, double x, double y)voidscale(double sx, double sy)voidsetBackground(Color color)voidsetClip(int x, int y, int width, int height)voidsetClip(Shape clip)voidsetColor(Color c)voidsetComposite(Composite comp)voidsetFont(Font font)voidsetPaint(Paint paint)voidsetPaintMode()voidsetRenderingHint(RenderingHints.Key hintKey, Object hintValue)voidsetRenderingHints(Map<?,?> hints)voidsetStroke(Stroke s)voidsetTransform(AffineTransform Tx)voidsetXORMode(Color c1)voidshear(double shx, double shy)voidtransform(AffineTransform Tx)voidtranslate(double tx, double ty)voidtranslate(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 Detail
- 
background
Color background
the current color of the background for drawing. 
- 
color
Color color
the current drawing color. 
- 
font
Font font
the current font. 
- 
canvas
Canvas canvas
the drawing canvas. 
- 
fontMetrics
FontMetrics fontMetrics
the cached current font properties. 
- 
paint
Paint paint
the current paint. 
- 
stroke
Stroke stroke
the current stroke. 
- 
renderingHints
RenderingHints renderingHints
TODO: the current rendering hints. 
- 
affineTransform
AffineTransform affineTransform
the current affine transform. 
- 
composite
Composite composite
TODO: the current composite. What is that? 
- 
commands
StringBuffer commands
the commands to send over the channel to the HTML5 code. 
 - 
 
- 
Method Detail
- 
clearCommand
public void clearCommand()
Clear the commands and put the start tag in. 
- 
closeAndGetCommands
public String closeAndGetCommands()
Close the commands and put the end tag in.- Returns:
 - the current set of commands
 
 
- 
addDraw
protected void addDraw(String drawCommand, Object... params)
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
protected void addColor(Color c)
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
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...- Parameters:
 fillCommand- String; the tag to useparams- Object...; the params to send
 
- 
addTransformDraw
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...- Parameters:
 drawCommand- String; the tag to useparams- Object...; the params
 
- 
addTransformPathFloat
protected void addTransformPathFloat(Path2D.Float path, boolean fill)
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
protected void addTransformPathDouble(Path2D.Double path, boolean fill)
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
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.- Parameters:
 drawCommand- String; the tag to useparams- Object...; the params
 
- 
draw
public void draw(Shape shape)
- Specified by:
 drawin classGraphics2D
 
- 
drawFillShape
protected void drawFillShape(Shape shape, boolean fill)
Draw or fill a shape.- Parameters:
 shape- Shape; the shapefill- boolean; filled or not
 
- 
drawImage
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
- Specified by:
 drawImagein classGraphics2D
 
- 
drawImage
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
- Specified by:
 drawImagein classGraphics2D
 
- 
drawRenderedImage
public void drawRenderedImage(RenderedImage img, AffineTransform xform)
- Specified by:
 drawRenderedImagein classGraphics2D
 
- 
drawRenderableImage
public void drawRenderableImage(RenderableImage img, AffineTransform xform)
- Specified by:
 drawRenderableImagein classGraphics2D
 
- 
drawString
public void drawString(String str, int x, int y)
- Specified by:
 drawStringin classGraphics2D
 
- 
drawString
public void drawString(String str, float x, float y)
- Specified by:
 drawStringin classGraphics2D
 
- 
drawString
public void drawString(AttributedCharacterIterator iterator, int x, int y)
- Specified by:
 drawStringin classGraphics2D
 
- 
drawString
public void drawString(AttributedCharacterIterator iterator, float x, float y)
- Specified by:
 drawStringin classGraphics2D
 
- 
drawGlyphVector
public void drawGlyphVector(GlyphVector g, float x, float y)
- Specified by:
 drawGlyphVectorin classGraphics2D
 
- 
fill
public void fill(Shape shape)
- Specified by:
 fillin classGraphics2D
 
- 
hit
public boolean hit(Rectangle rect, Shape s, boolean onStroke)
- Specified by:
 hitin classGraphics2D
 
- 
getDeviceConfiguration
public GraphicsConfiguration getDeviceConfiguration()
- Specified by:
 getDeviceConfigurationin classGraphics2D
 
- 
setComposite
public void setComposite(Composite comp)
- Specified by:
 setCompositein classGraphics2D
 
- 
setPaint
public void setPaint(Paint paint)
- Specified by:
 setPaintin classGraphics2D
 
- 
setStroke
public void setStroke(Stroke s)
- Specified by:
 setStrokein classGraphics2D
 
- 
setRenderingHint
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
- Specified by:
 setRenderingHintin classGraphics2D
 
- 
getRenderingHint
public Object getRenderingHint(RenderingHints.Key hintKey)
- Specified by:
 getRenderingHintin classGraphics2D
 
- 
setRenderingHints
public void setRenderingHints(Map<?,?> hints)
- Specified by:
 setRenderingHintsin classGraphics2D
 
- 
addRenderingHints
public void addRenderingHints(Map<?,?> hints)
- Specified by:
 addRenderingHintsin classGraphics2D
 
- 
getRenderingHints
public RenderingHints getRenderingHints()
- Specified by:
 getRenderingHintsin classGraphics2D
 
- 
translate
public void translate(int x, int y)- Specified by:
 translatein classGraphics2D
 
- 
translate
public void translate(double tx, double ty)- Specified by:
 translatein classGraphics2D
 
- 
rotate
public void rotate(double theta)
- Specified by:
 rotatein classGraphics2D
 
- 
rotate
public void rotate(double theta, double x, double y)- Specified by:
 rotatein classGraphics2D
 
- 
scale
public void scale(double sx, double sy)- Specified by:
 scalein classGraphics2D
 
- 
shear
public void shear(double shx, double shy)- Specified by:
 shearin classGraphics2D
 
- 
transform
public void transform(AffineTransform Tx)
- Specified by:
 transformin classGraphics2D
 
- 
setTransform
public void setTransform(AffineTransform Tx)
- Specified by:
 setTransformin classGraphics2D
 
- 
getTransform
public AffineTransform getTransform()
- Specified by:
 getTransformin classGraphics2D
 
- 
getPaint
public Paint getPaint()
- Specified by:
 getPaintin classGraphics2D
 
- 
getComposite
public Composite getComposite()
- Specified by:
 getCompositein classGraphics2D
 
- 
setBackground
public void setBackground(Color color)
- Specified by:
 setBackgroundin classGraphics2D
 
- 
getBackground
public Color getBackground()
- Specified by:
 getBackgroundin classGraphics2D
 
- 
getStroke
public Stroke getStroke()
- Specified by:
 getStrokein classGraphics2D
 
- 
clip
public void clip(Shape s)
- Specified by:
 clipin classGraphics2D
 
- 
getFontRenderContext
public FontRenderContext getFontRenderContext()
- Specified by:
 getFontRenderContextin classGraphics2D
 
- 
setPaintMode
public void setPaintMode()
- Specified by:
 setPaintModein classGraphics
 
- 
setXORMode
public void setXORMode(Color c1)
- Specified by:
 setXORModein classGraphics
 
- 
getFontMetrics
public FontMetrics getFontMetrics(Font f)
- Specified by:
 getFontMetricsin classGraphics
 
- 
getClipBounds
public Rectangle getClipBounds()
- Specified by:
 getClipBoundsin 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) 
- 
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:
 drawRoundRectin classGraphics
 
- 
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)- Specified by:
 fillRoundRectin 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:
 drawPolylinein classGraphics
 
- 
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
 drawPolygonin classGraphics
 
- 
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
 fillPolygonin classGraphics
 
- 
drawImage
public boolean drawImage(Image img, int x, int y, ImageObserver observer)
 
- 
drawImage
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
 
- 
drawImage
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
 
- 
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)
 
 - 
 
 -