public class Graphics2DWrapper extends Graphics2D
The AffineTransform set on this wrapper at initialization will wrap all the transformations set on the underlying Graphics2D. For example, if you want to provide an additional scale on all graphic orders, you can do the following :
AffineTransform tr = AffineTransform.getScaleInstance(scale, scale);
Graphics2DWrapper wrapper = new Graphics2DWrapper(g2d, tr);
or:
Graphics2DWrapper wrapper = new Graphics2DWrapper(g2d, scale);
or even:
Graphics2DWrapper wrapper = new Graphics2DWrapper(g2d);
wrapper.setScale(scale);
The following properties can be set on this wrapper:
filterCharacterIterators(boolean): if set to true, the
AttributedCharacterIterators passed as parameters to the
drawString(AttributedCharacterIterator, float x, float y) or
drawString(AttributedCharacterIterator, int x, int y) methods will be transformed
as simple Strings before passing the drawString order to the underlying Graphics2D.
This is useful for Graphics2D that can't draw AttributedCharacterIterators.>/li>
inverseStringYPos(boolean): if set to true, each positioned String on the
underlying Graphics2D will be positioned at y + the ascent position of the current font.| Modifier and Type | Field and Description |
|---|---|
static int |
HARD_CLIPPING
The shapes are clipped in the transcoding result.
|
static int |
NO_CLIPPING
The shapes are not clipped in the transcoding result.
|
static int |
SOFT_CLIPPING
The shapes are clipped in the transcoding result.
|
| Constructor and Description |
|---|
Graphics2DWrapper(Graphics2D g2d)
Create a new wrapper with no additional transformation.
|
Graphics2DWrapper(Graphics2D g2d,
AffineTransform transform)
Create a new wrapper with a transformation.
|
Graphics2DWrapper(Graphics2D g2d,
float scale)
Create a new wrapper with a scale transformation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRenderingHints(Map hints) |
void |
clearRect(int x,
int y,
int width,
int height) |
void |
clip(Shape shape) |
void |
clipRect(int x,
int y,
int width,
int height) |
void |
copyArea(int x,
int y,
int width,
int height,
int dx,
int dy) |
Graphics |
create() |
void |
dispose() |
void |
draw(Shape shape) |
void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle) |
void |
drawGlyphVector(GlyphVector g,
float x,
float y) |
void |
drawImage(BufferedImage img,
BufferedImageOp op,
int x,
int y) |
boolean |
drawImage(Image img,
AffineTransform xform,
ImageObserver obs) |
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,
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 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) |
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(AttributedCharacterIterator iterator,
float x,
float y) |
void |
drawString(AttributedCharacterIterator iterator,
int x,
int y) |
void |
drawString(String s,
float x,
float y) |
void |
drawString(String str,
int x,
int y) |
void |
fill(Shape shape) |
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) |
void |
filterCharacterIterators(boolean filter)
If set to true, filter all
drawString(AttributedCharacterIterator, float, float)
and drawString(AttributedCharacterIterator, int, int) methods in order to pass
only Strings to the underlying Graphics2D. |
Color |
getBackground() |
Shape |
getClip() |
Rectangle |
getClipBounds() |
Color |
getColor() |
Composite |
getComposite() |
GraphicsConfiguration |
getDeviceConfiguration() |
Font |
getFont() |
FontMetrics |
getFontMetrics(Font f) |
FontRenderContext |
getFontRenderContext() |
Paint |
getPaint() |
Object |
getRenderingHint(RenderingHints.Key hintKey) |
RenderingHints |
getRenderingHints() |
float |
getScale() |
Stroke |
getStroke() |
AffineTransform |
getTransform() |
Graphics2D |
getWrappedGraphics2D()
Return the wrapped Graphics2D.
|
AffineTransform |
getWrappedTransform()
Return the wrapped AffineTransform used for the filtering process
|
boolean |
hit(Rectangle rect,
Shape s,
boolean onStroke) |
void |
inverseStringYPos(boolean inverse)
If set to true, add to each Y String position the ascent value of the current font.
|
boolean |
isFilteringCharacterIterators() |
boolean |
isInversingStringYPos()
Return true if Y String positions are inversed
|
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 |
setClip(Shape shape) |
void |
setClippingProperty(int clipProperty) |
void |
setColor(Color c) |
void |
setComposite(Composite comp) |
void |
setFont(Font font) |
void |
setForceStroke(Float stroke) |
void |
setPaint(Paint paint) |
void |
setPaintMode() |
void |
setRenderingHint(RenderingHints.Key hintKey,
Object hintValue) |
void |
setRenderingHints(Map hints) |
void |
setScale(float scale)
Set the current scale of the transformation.
|
void |
setStroke(Stroke s) |
void |
setTransform(AffineTransform Tx)
Transformations are filtered by this class before being sent to the wrapped Graphics2D.
|
void |
setXORMode(Color c1) |
void |
shear(double shx,
double shy) |
void |
transform(AffineTransform Tx) |
void |
translate(double tx,
double ty) |
void |
translate(int x,
int y) |
draw3DRect, fill3DRectcreate, drawBytes, drawChars, drawPolygon, drawRect, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toStringpublic static final int NO_CLIPPING
public static final int SOFT_CLIPPING
public static final int HARD_CLIPPING
public Graphics2DWrapper(Graphics2D g2d)
g2d - the wrapped Graphics2Dpublic Graphics2DWrapper(Graphics2D g2d, float scale)
g2d - the wrapped Graphics2Dscale - the scale valuepublic Graphics2DWrapper(Graphics2D g2d, AffineTransform transform)
g2d - the wrapped Graphics2Dtransform - the transformationpublic Graphics2D getWrappedGraphics2D()
public void filterCharacterIterators(boolean filter)
drawString(AttributedCharacterIterator, float, float)
and drawString(AttributedCharacterIterator, int, int) methods in order to pass
only Strings to the underlying Graphics2D.public boolean isFilteringCharacterIterators()
filterCharacterIterators(boolean)public void inverseStringYPos(boolean inverse)
inverse - true if each Y String position the ascent value of the current fontpublic boolean isInversingStringYPos()
inverseStringYPos(boolean)public AffineTransform getWrappedTransform()
public void setForceStroke(Float stroke)
public void setScale(float scale)
public float getScale()
public void addRenderingHints(Map hints)
addRenderingHints in class Graphics2Dpublic void clearRect(int x,
int y,
int width,
int height)
public void clip(Shape shape)
clip in class Graphics2Dpublic void clipRect(int x,
int y,
int width,
int height)
public void copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
public void draw(Shape shape)
draw in class Graphics2Dpublic void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
public void drawGlyphVector(GlyphVector g, float x, float y)
drawGlyphVector in class Graphics2Dpublic boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
drawImage in class Graphics2Dpublic void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
drawImage in class Graphics2Dpublic boolean drawImage(Image img, int x, int y, ImageObserver observer)
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
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)
public void drawLine(int x1,
int y1,
int x2,
int y2)
public void drawOval(int x,
int y,
int width,
int height)
public void drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
drawPolygon in class Graphicspublic void drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
drawPolyline in class Graphicspublic void drawRenderableImage(RenderableImage img, AffineTransform xform)
drawRenderableImage in class Graphics2Dpublic void drawRenderedImage(RenderedImage img, AffineTransform xform)
drawRenderedImage in class Graphics2Dpublic void drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
drawRoundRect in class Graphicspublic void drawString(String s, float x, float y)
drawString in class Graphics2Dpublic void drawString(String str, int x, int y)
drawString in class Graphics2Dpublic void drawString(AttributedCharacterIterator iterator, int x, int y)
drawString in class Graphics2Dpublic void drawString(AttributedCharacterIterator iterator, float x, float y)
drawString in class Graphics2Dpublic void fill(Shape shape)
fill in class Graphics2Dpublic void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
public void fillOval(int x,
int y,
int width,
int height)
public void fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
fillPolygon in class Graphicspublic void fillRect(int x,
int y,
int width,
int height)
public void fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
fillRoundRect in class Graphicspublic Color getBackground()
getBackground in class Graphics2Dpublic Rectangle getClipBounds()
getClipBounds in class Graphicspublic Composite getComposite()
getComposite in class Graphics2Dpublic GraphicsConfiguration getDeviceConfiguration()
getDeviceConfiguration in class Graphics2Dpublic FontMetrics getFontMetrics(Font f)
getFontMetrics in class Graphicspublic FontRenderContext getFontRenderContext()
getFontRenderContext in class Graphics2Dpublic Paint getPaint()
getPaint in class Graphics2Dpublic Object getRenderingHint(RenderingHints.Key hintKey)
getRenderingHint in class Graphics2Dpublic RenderingHints getRenderingHints()
getRenderingHints in class Graphics2Dpublic Stroke getStroke()
getStroke in class Graphics2Dpublic AffineTransform getTransform()
getTransform in class Graphics2Dpublic boolean hit(Rectangle rect, Shape s, boolean onStroke)
hit in class Graphics2Dpublic void rotate(double theta)
rotate in class Graphics2Dpublic void rotate(double theta,
double x,
double y)
rotate in class Graphics2Dpublic void scale(double sx,
double sy)
scale in class Graphics2Dpublic void setBackground(Color color)
setBackground in class Graphics2Dpublic void setClip(int x,
int y,
int width,
int height)
public void setComposite(Composite comp)
setComposite in class Graphics2Dpublic void setPaint(Paint paint)
setPaint in class Graphics2Dpublic void setPaintMode()
setPaintMode in class Graphicspublic void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
setRenderingHint in class Graphics2Dpublic void setRenderingHints(Map hints)
setRenderingHints in class Graphics2Dpublic void setStroke(Stroke s)
setStroke in class Graphics2Dpublic void setClippingProperty(int clipProperty)
public void setTransform(AffineTransform Tx)
setTransform in class Graphics2Dpublic void setXORMode(Color c1)
setXORMode in class Graphicspublic void shear(double shx,
double shy)
shear in class Graphics2Dpublic void transform(AffineTransform Tx)
transform in class Graphics2Dpublic void translate(double tx,
double ty)
translate in class Graphics2Dpublic void translate(int x,
int y)
translate in class Graphics2D