Package com.mxgraph.canvas
Interface mxICanvas2D
-
- All Known Implementing Classes:
mxGraphicsCanvas2D
public interface mxICanvas2D
Requirements for implementing technologies: - Path rendering (move, line, quad, curve, arc) - Images, flip v/h, aspect, alpha (PNG, JPG, GIF) - Linear gradients (in all four directions) - Transparency, fill and stroke - Rotation, flip v/h - Font rendering - Dash patterns - Clipping by path (not just rectangle) - Alpha gradients (for glass effect) - Encode result as image (PNG, JPG)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
begin()
Begins a new path.void
close()
Closes the current path.void
curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
Draws a bezier curve to the given point.void
ellipse(double x, double y, double w, double h)
Next fill or stroke should draw an ellipse.void
fill()
Fills the current path.void
fillAndStroke()
Fills and paints the outline of the current path.void
image(double x, double y, double w, double h, java.lang.String src, boolean aspect, boolean flipH, boolean flipV)
Draws the given image.void
lineTo(double x, double y)
Draws a line to the given path.void
moveTo(double x, double y)
Moves to the given path.void
quadTo(double x1, double y1, double x2, double y2)
Draws a quadratic curve to the given point.void
rect(double x, double y, double w, double h)
Next fill or stroke should draw a rectangle.void
restore()
Restores the previous state of the canvas.void
rotate(double theta, boolean flipH, boolean flipV, double cx, double cy)
Rotates the canvas by the given angle around the given center.void
roundrect(double x, double y, double w, double h, double dx, double dy)
Next fill or stroke should draw a round rectangle.void
save()
Saves the current state of the canvas.void
scale(double value)
Uniformaly scales the canvas by the given amount.void
setAlpha(double value)
Default value 1.void
setDashed(boolean value)
Sets the dashed state.void
setDashed(boolean value, boolean fixDash)
Sets the dashed state.void
setDashPattern(java.lang.String value)
Sets the dash pattern.void
setFillAlpha(double value)
Default value 1.void
setFillColor(java.lang.String value)
Default valuemxConstants.NONE
.void
setFontBackgroundColor(java.lang.String value)
Default value "#000000".void
setFontBorderColor(java.lang.String value)
Default value "#000000".void
setFontColor(java.lang.String value)
Default value "#000000".void
setFontFamily(java.lang.String value)
Default valuemxConstants.DEFAULT_FONTFAMILY
.void
setFontSize(double value)
Default valuemxConstants.DEFAULT_FONTSIZE
.void
setFontStyle(int value)
Default value 0.void
setGradient(java.lang.String color1, java.lang.String color2, double x, double y, double w, double h, java.lang.String direction, double alpha1, double alpha2)
Prepares the canvas to draw a gradient.void
setLineCap(java.lang.String value)
Sets the linecap.void
setLineJoin(java.lang.String value)
Sets the linejoin.void
setMiterLimit(double value)
Sets the miterlimit.void
setShadow(boolean enabled)
Enables or disables the painting of shadows.void
setShadowAlpha(double value)
Default valuemxConstants.NONE
.void
setShadowColor(java.lang.String value)
Default valuemxConstants.NONE
.void
setShadowOffset(double dx, double dy)
Default valuemxConstants.NONE
.void
setStrokeAlpha(double value)
Default value 1.void
setStrokeColor(java.lang.String value)
Sets the stroke color.void
setStrokeWidth(double value)
Sets the stroke width.void
stroke()
Paints the outline of the current path.void
text(double x, double y, double w, double h, java.lang.String str, java.lang.String align, java.lang.String valign, boolean wrap, java.lang.String format, java.lang.String overflow, boolean clip, double rotation, java.lang.String dir)
Draws the given string.void
translate(double dx, double dy)
Translates the canvas by the given amount.
-
-
-
Method Detail
-
save
void save()
Saves the current state of the canvas.
-
restore
void restore()
Restores the previous state of the canvas.
-
scale
void scale(double value)
Uniformaly scales the canvas by the given amount.- Parameters:
value
- The new scale value.
-
translate
void translate(double dx, double dy)
Translates the canvas by the given amount.- Parameters:
dx
- X-coordinate of the translation.dy
- Y-coordinate of the translation.
-
rotate
void rotate(double theta, boolean flipH, boolean flipV, double cx, double cy)
Rotates the canvas by the given angle around the given center. This method may add rendering overhead and should be used with care.- Parameters:
theta
- Rotation angle in degrees (0 - 360).flipH
- Specifies if drawing should be flipped horizontally.flipV
- Specifies if drawing should be flipped vertically.cx
- X-coordinate of the center point.cy
- Y-coordinate of the center point.
-
setStrokeWidth
void setStrokeWidth(double value)
Sets the stroke width. This should default to 1 if unset.- Parameters:
value
- Width of the stroke. The value should be multiplied by the current scale.
-
setStrokeColor
void setStrokeColor(java.lang.String value)
Sets the stroke color. This should default tomxConstants.NONE
if unset.- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setDashed
void setDashed(boolean value)
Sets the dashed state. This should default to false if unset.- Parameters:
value
- Boolean representing the dashed state.
-
setDashed
void setDashed(boolean value, boolean fixDash)
Sets the dashed state. This should default to false if unset.- Parameters:
value
- Boolean representing the dashed state.
-
setDashPattern
void setDashPattern(java.lang.String value)
Sets the dash pattern. This should default to "3 3" if unset.- Parameters:
value
- Space separated list of floats representing the dash pattern. The value should be multiplied by the current scale.
-
setLineCap
void setLineCap(java.lang.String value)
Sets the linecap. This should default to "flat" if unset.- Parameters:
value
- "flat", "square" or "round".
-
setLineJoin
void setLineJoin(java.lang.String value)
Sets the linejoin. This should default to "miter" if unset.- Parameters:
value
- "miter", "round" or "bevel".
-
setMiterLimit
void setMiterLimit(double value)
Sets the miterlimit. This should default to 10 if unset.- Parameters:
value
-
-
setFontSize
void setFontSize(double value)
Default valuemxConstants.DEFAULT_FONTSIZE
.- Parameters:
value
-
-
setFontColor
void setFontColor(java.lang.String value)
Default value "#000000".- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setFontFamily
void setFontFamily(java.lang.String value)
Default valuemxConstants.DEFAULT_FONTFAMILY
.- Parameters:
value
-
-
setFontStyle
void setFontStyle(int value)
Default value 0. SeemxConstants.STYLE_FONTSTYLE
.- Parameters:
value
-
-
setFontBackgroundColor
void setFontBackgroundColor(java.lang.String value)
Default value "#000000".- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setFontBorderColor
void setFontBorderColor(java.lang.String value)
Default value "#000000".- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setAlpha
void setAlpha(double value)
Default value 1. This method may add rendering overhead and should be used with care.- Parameters:
value
-
-
setFillAlpha
void setFillAlpha(double value)
Default value 1. This method may add rendering overhead and should be used with care.- Parameters:
value
-
-
setStrokeAlpha
void setStrokeAlpha(double value)
Default value 1. This method may add rendering overhead and should be used with care.- Parameters:
value
-
-
setFillColor
void setFillColor(java.lang.String value)
Default valuemxConstants.NONE
.- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setGradient
void setGradient(java.lang.String color1, java.lang.String color2, double x, double y, double w, double h, java.lang.String direction, double alpha1, double alpha2)
Prepares the canvas to draw a gradient.- Parameters:
color1
-color2
-x
-y
-w
-h
-direction
- Direction may be null. Use default valuemxConstants.DIRECTION_SOUTH
.
-
setShadow
void setShadow(boolean enabled)
Enables or disables the painting of shadows.- Parameters:
enabled
- Whether the shadow should be enabled.
-
setShadowColor
void setShadowColor(java.lang.String value)
Default valuemxConstants.NONE
.- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setShadowAlpha
void setShadowAlpha(double value)
Default valuemxConstants.NONE
.- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
setShadowOffset
void setShadowOffset(double dx, double dy)
Default valuemxConstants.NONE
.- Parameters:
value
- Hex representation of the color ormxConstants.NONE
.
-
rect
void rect(double x, double y, double w, double h)
Next fill or stroke should draw a rectangle.- Parameters:
x
-y
-w
-h
-
-
roundrect
void roundrect(double x, double y, double w, double h, double dx, double dy)
Next fill or stroke should draw a round rectangle.- Parameters:
x
-y
-w
-h
-dx
-dy
-
-
ellipse
void ellipse(double x, double y, double w, double h)
Next fill or stroke should draw an ellipse.- Parameters:
x
-y
-w
-h
-
-
image
void image(double x, double y, double w, double h, java.lang.String src, boolean aspect, boolean flipH, boolean flipV)
Draws the given image.- Parameters:
x
-y
-w
-h
-src
-aspect
-flipH
-flipV
-
-
text
void text(double x, double y, double w, double h, java.lang.String str, java.lang.String align, java.lang.String valign, boolean wrap, java.lang.String format, java.lang.String overflow, boolean clip, double rotation, java.lang.String dir)
Draws the given string. Possible values for format are empty string for plain text and html for HTML markup.- Parameters:
x
-y
-w
-h
-str
-align
-valign
-wrap
-format
-overflow
-clip
-rotation
-dir
-
-
begin
void begin()
Begins a new path.
-
moveTo
void moveTo(double x, double y)
Moves to the given path.- Parameters:
x
-y
-
-
lineTo
void lineTo(double x, double y)
Draws a line to the given path.- Parameters:
x
-y
-
-
quadTo
void quadTo(double x1, double y1, double x2, double y2)
Draws a quadratic curve to the given point.- Parameters:
x1
-y1
-x2
-y2
-
-
curveTo
void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
Draws a bezier curve to the given point.- Parameters:
x1
-y1
-x2
-y2
-x3
-y3
-
-
close
void close()
Closes the current path.
-
stroke
void stroke()
Paints the outline of the current path.
-
fill
void fill()
Fills the current path.
-
fillAndStroke
void fillAndStroke()
Fills and paints the outline of the current path.
-
-