public class mxGraphicsCanvas2D extends java.lang.Object implements mxICanvas2D
BufferedImage image = mxUtils.createBufferedImage(width, height, background);
Graphics2D g2 = image.createGraphics();
mxUtils.setAntiAlias(g2, true, true);
XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
reader.setContentHandler(new mxSaxOutputHandler(new mxGraphicsCanvas2D(g2)));
reader.parse(new InputSource(new StringReader(xml)));
Modifier and Type | Class and Description |
---|---|
protected class |
mxGraphicsCanvas2D.CanvasState |
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoAntiAlias
Specifies if anti aliasing should be disabled for rectangles
and orthogonal paths.
|
protected java.awt.Font |
currentFont
Holds the current font.
|
protected java.awt.geom.GeneralPath |
currentPath
Holds the current path.
|
protected boolean |
currentPathIsOrthogonal
Holds the current state for crisp rendering.
|
protected java.awt.Color |
currentShadowColor
Holds the current parsed shadow color.
|
protected java.lang.String |
currentShadowValue
Holds the current value for the shadow color.
|
protected java.awt.Stroke |
currentStroke
Holds the current stroke.
|
protected java.awt.Graphics2D |
graphics
Reference to the graphics instance for painting.
|
static int |
IMAGE_SCALING
Specifies the image scaling quality.
|
protected java.awt.geom.Point2D |
lastPoint
Holds the last point of a moveTo or lineTo operation to determine if the
current path is orthogonal.
|
protected java.util.Stack<mxGraphicsCanvas2D.CanvasState> |
stack
Stack of states for save/restore.
|
protected mxGraphicsCanvas2D.CanvasState |
state
Represents the current state of the canvas.
|
Constructor and Description |
---|
mxGraphicsCanvas2D(java.awt.Graphics2D g)
Constructs a new graphics export canvas.
|
Modifier and Type | Method and Description |
---|---|
void |
arcTo(double rx,
double ry,
double xAxisRotation,
boolean largeArc,
boolean sweep,
double x,
double y) |
void |
begin()
Begins a new path.
|
void |
clip()
Uses the current path for clipping.
|
protected mxGraphicsCanvas2D.CanvasState |
cloneState(mxGraphicsCanvas2D.CanvasState state)
Returns a clone of thec given state.
|
void |
close()
Closes the current path.
|
protected java.awt.Font |
createFont(java.lang.String family,
int style,
int size)
Hook for subclassers to implement font caching.
|
protected java.awt.Graphics2D |
createImageGraphics(double x,
double y,
double w,
double h,
boolean flipH,
boolean flipV)
Creates a graphic instance for rendering an image.
|
protected java.awt.Graphics2D |
createTextGraphics(double x,
double y,
double w,
double h,
boolean vertical)
Returns a new graphics instance with the correct color and font for
text rendering.
|
void |
curveTo(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Draws a bezier curve to the given point.
|
protected void |
drawImage(java.awt.Graphics2D graphics,
java.awt.Image image,
int x,
int y) |
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.
|
java.awt.Graphics2D |
getGraphics()
Returns the graphics instance.
|
protected double |
getHorizontalTextPosition(double x,
double y,
double w,
double h,
java.lang.String align,
java.lang.String valign,
boolean vertical,
java.awt.FontMetrics fm,
java.lang.String[] lines)
This implementation returns x.
|
protected java.awt.Rectangle |
getImageBounds(java.awt.Image img,
double x,
double y,
double w,
double h,
boolean aspect) |
protected java.awt.Dimension |
getImageSize(java.awt.Image image)
Returns the size for the given image.
|
protected double |
getVerticalTextPosition(double x,
double y,
double w,
double h,
java.lang.String align,
java.lang.String valign,
boolean vertical,
java.awt.FontMetrics fm,
java.lang.String[] lines) |
void |
image(double x,
double y,
double w,
double h,
java.lang.String src,
boolean aspect,
boolean flipH,
boolean flipV)
Draws the given image.
|
boolean |
isAutoAntiAlias()
Returns true if automatic anti aliasing is enabled.
|
void |
lineTo(double x,
double y)
Draws a line to the given path.
|
protected java.awt.Image |
loadImage(java.lang.String src)
Hook for image caching.
|
void |
moveTo(double x,
double y)
Moves to the given path.
|
protected java.awt.Color |
parseColor(java.lang.String hex)
Helper method that uses
mxUtils.parseColor(String) . |
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 last canvas state.
|
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)
Implements a rounded rectangle using a path.
|
void |
save()
Saves the current canvas state.
|
void |
scale(double value)
Uniformaly scales the canvas by the given amount.
|
protected java.awt.Image |
scaleImage(java.awt.Image img,
int w,
int h)
Uses
IMAGE_SCALING to scale the given image. |
void |
setAlpha(double value)
Default value 1.
|
void |
setAutoAntiAlias(boolean value)
Disabled or enabled automatic anti aliasing.
|
void |
setDashed(boolean value)
Sets the dashed state.
|
void |
setDashPattern(java.lang.String value)
Sets the dash pattern.
|
void |
setFillColor(java.lang.String value)
Default value
mxConstants.NONE . |
void |
setFontColor(java.lang.String value)
Default value "#000000".
|
void |
setFontFamily(java.lang.String value)
Default value
mxConstants.DEFAULT_FONTFAMILY . |
void |
setFontSize(double value)
Default value
mxConstants.DEFAULT_FONTSIZE . |
void |
setFontStyle(int value)
Default value 0.
|
void |
setGlassGradient(double x,
double y,
double w,
double h)
Prepares the canvas to draw a glass gradient.
|
void |
setGradient(java.lang.String color1,
java.lang.String color2,
double x,
double y,
double w,
double h,
java.lang.String direction)
Prepares the canvas to draw a gradient.
|
void |
setGraphics(java.awt.Graphics2D value)
Sets the graphics instance.
|
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 |
setStrokeColor(java.lang.String value)
Caches color conversion as it is expensive.
|
void |
setStrokeWidth(double value)
Sets the stroke width.
|
void |
shadow(java.lang.String value)
Paints the current path as a shadow.
|
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 vertical)
Draws the given text.
|
void |
translate(double dx,
double dy)
Translates the canvas by the given amount.
|
protected void |
updateFont() |
protected void |
updateStroke() |
public static int IMAGE_SCALING
scaleImage(Image, int, int)
protected java.awt.Graphics2D graphics
protected boolean autoAntiAlias
protected transient mxGraphicsCanvas2D.CanvasState state
protected transient java.util.Stack<mxGraphicsCanvas2D.CanvasState> stack
protected transient java.awt.geom.GeneralPath currentPath
protected transient boolean currentPathIsOrthogonal
protected transient java.awt.geom.Point2D lastPoint
protected transient java.awt.Stroke currentStroke
protected transient java.awt.Font currentFont
protected transient java.lang.String currentShadowValue
protected transient java.awt.Color currentShadowColor
public mxGraphicsCanvas2D(java.awt.Graphics2D g)
public void setGraphics(java.awt.Graphics2D value)
public java.awt.Graphics2D getGraphics()
public boolean isAutoAntiAlias()
public void setAutoAntiAlias(boolean value)
public void save()
save
in interface mxICanvas2D
public void restore()
restore
in interface mxICanvas2D
protected mxGraphicsCanvas2D.CanvasState cloneState(mxGraphicsCanvas2D.CanvasState state)
public void scale(double value)
mxICanvas2D
scale
in interface mxICanvas2D
value
- The new scale value.public void translate(double dx, double dy)
mxICanvas2D
translate
in interface mxICanvas2D
dx
- X-coordinate of the translation.dy
- Y-coordinate of the translation.public void rotate(double theta, boolean flipH, boolean flipV, double cx, double cy)
mxICanvas2D
rotate
in interface mxICanvas2D
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.public void setStrokeWidth(double value)
mxICanvas2D
setStrokeWidth
in interface mxICanvas2D
value
- Width of the stroke. The value should be multiplied by the
current scale.public void setStrokeColor(java.lang.String value)
setStrokeColor
in interface mxICanvas2D
value
- Hex representation of the color or mxConstants.NONE
.public void setDashed(boolean value)
mxICanvas2D
setDashed
in interface mxICanvas2D
value
- Boolean representing the dashed state.public void setDashPattern(java.lang.String value)
mxICanvas2D
setDashPattern
in interface mxICanvas2D
value
- Space separated list of floats representing the dash
pattern. The value should be multiplied by the current scale.public void setLineCap(java.lang.String value)
mxICanvas2D
setLineCap
in interface mxICanvas2D
value
- "flat", "square" or "round".public void setLineJoin(java.lang.String value)
mxICanvas2D
setLineJoin
in interface mxICanvas2D
value
- "miter", "round" or "bevel".public void setMiterLimit(double value)
mxICanvas2D
setMiterLimit
in interface mxICanvas2D
public void setFontSize(double value)
mxICanvas2D
mxConstants.DEFAULT_FONTSIZE
.setFontSize
in interface mxICanvas2D
public void setFontColor(java.lang.String value)
mxICanvas2D
setFontColor
in interface mxICanvas2D
value
- Hex representation of the color or mxConstants.NONE
.public void setFontFamily(java.lang.String value)
mxICanvas2D
mxConstants.DEFAULT_FONTFAMILY
.setFontFamily
in interface mxICanvas2D
public void setFontStyle(int value)
mxICanvas2D
mxConstants.STYLE_FONTSTYLE
.setFontStyle
in interface mxICanvas2D
public void setAlpha(double value)
mxICanvas2D
setAlpha
in interface mxICanvas2D
public void setFillColor(java.lang.String value)
mxICanvas2D
mxConstants.NONE
.setFillColor
in interface mxICanvas2D
value
- Hex representation of the color or mxConstants.NONE
.public void setGradient(java.lang.String color1, java.lang.String color2, double x, double y, double w, double h, java.lang.String direction)
mxICanvas2D
setGradient
in interface mxICanvas2D
direction
- Direction may be null. Use default value
mxConstants.DIRECTION_SOUTH
.protected java.awt.Color parseColor(java.lang.String hex)
mxUtils.parseColor(String)
. Subclassers
can override this to implement caching for frequently used colors.public void setGlassGradient(double x, double y, double w, double h)
mxICanvas2D
setGlassGradient
in interface mxICanvas2D
public void rect(double x, double y, double w, double h)
mxICanvas2D
rect
in interface mxICanvas2D
public void roundrect(double x, double y, double w, double h, double dx, double dy)
roundrect
in interface mxICanvas2D
public void ellipse(double x, double y, double w, double h)
mxICanvas2D
ellipse
in interface mxICanvas2D
public void image(double x, double y, double w, double h, java.lang.String src, boolean aspect, boolean flipH, boolean flipV)
mxICanvas2D
image
in interface mxICanvas2D
protected void drawImage(java.awt.Graphics2D graphics, java.awt.Image image, int x, int y)
protected java.awt.Image loadImage(java.lang.String src)
protected final java.awt.Rectangle getImageBounds(java.awt.Image img, double x, double y, double w, double h, boolean aspect)
protected java.awt.Dimension getImageSize(java.awt.Image image)
protected java.awt.Image scaleImage(java.awt.Image img, int w, int h)
IMAGE_SCALING
to scale the given image.protected final java.awt.Graphics2D createImageGraphics(double x, double y, double w, double h, boolean flipH, boolean flipV)
public void text(double x, double y, double w, double h, java.lang.String str, java.lang.String align, java.lang.String valign, boolean vertical)
text
in interface mxICanvas2D
protected final java.awt.Graphics2D createTextGraphics(double x, double y, double w, double h, boolean vertical)
protected double getVerticalTextPosition(double x, double y, double w, double h, java.lang.String align, java.lang.String valign, boolean vertical, java.awt.FontMetrics fm, java.lang.String[] lines)
protected double getHorizontalTextPosition(double x, double y, double w, double h, java.lang.String align, java.lang.String valign, boolean vertical, java.awt.FontMetrics fm, java.lang.String[] lines)
public void begin()
mxICanvas2D
begin
in interface mxICanvas2D
public void moveTo(double x, double y)
mxICanvas2D
moveTo
in interface mxICanvas2D
public void lineTo(double x, double y)
mxICanvas2D
lineTo
in interface mxICanvas2D
public void quadTo(double x1, double y1, double x2, double y2)
mxICanvas2D
quadTo
in interface mxICanvas2D
public void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
mxICanvas2D
curveTo
in interface mxICanvas2D
public void arcTo(double rx, double ry, double xAxisRotation, boolean largeArc, boolean sweep, double x, double y)
public void close()
close
in interface mxICanvas2D
public void stroke()
mxICanvas2D
stroke
in interface mxICanvas2D
public void fill()
mxICanvas2D
fill
in interface mxICanvas2D
public void fillAndStroke()
mxICanvas2D
fillAndStroke
in interface mxICanvas2D
public void shadow(java.lang.String value)
mxICanvas2D
shadow
in interface mxICanvas2D
public void clip()
mxICanvas2D
clip
in interface mxICanvas2D
protected void updateFont()
protected java.awt.Font createFont(java.lang.String family, int style, int size)
protected void updateStroke()
Copyright (c) 2010 Gaudenz Alder. All rights reserved.