0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017:
0018: /* $Id: AbstractGraphics2D.java 496556 2007-01-16 00:59:48Z cam $ */
0019:
0020: package org.apache.xmlgraphics.java2d;
0021:
0022: import java.awt.AlphaComposite;
0023: import java.awt.Color;
0024: import java.awt.Composite;
0025: import java.awt.Font;
0026: import java.awt.Graphics2D;
0027: import java.awt.Image;
0028: import java.awt.Paint;
0029: import java.awt.Polygon;
0030: import java.awt.Rectangle;
0031: import java.awt.RenderingHints;
0032: import java.awt.Shape;
0033: import java.awt.Stroke;
0034: import java.awt.font.FontRenderContext;
0035: import java.awt.font.GlyphVector;
0036: import java.awt.font.TextLayout;
0037: import java.awt.geom.AffineTransform;
0038: import java.awt.geom.Arc2D;
0039: import java.awt.geom.Ellipse2D;
0040: import java.awt.geom.GeneralPath;
0041: import java.awt.geom.Line2D;
0042: import java.awt.geom.NoninvertibleTransformException;
0043: import java.awt.geom.RoundRectangle2D;
0044: import java.awt.image.BufferedImage;
0045: import java.awt.image.BufferedImageOp;
0046: import java.awt.image.ImageObserver;
0047: import java.text.AttributedCharacterIterator;
0048: import java.util.Map;
0049:
0050: /**
0051: * This extension of the <tt>java.awt.Graphics2D</tt> abstract class
0052: * is still abstract, but it implements a lot of the <tt>Graphics2D</tt>
0053: * method in a way that concrete implementations can reuse.
0054: *
0055: * This class uses a <tt>GraphicContext</tt> to store the state of
0056: * its various attributes that control the rendering, such as the
0057: * current <tt>Font</tt>, <tt>Paint</tt> or clip.
0058: *
0059: * Concrete implementations can focus on implementing the rendering
0060: * methods, such as <tt>drawShape</tt>. As a convenience, rendering
0061: * methods that can be expressed with other rendering methods (e.g.,
0062: * <tt>drawRect</tt> can be expressed as <tt>draw(new Rectangle(..))</tt>),
0063: * are implemented by <tt>AbstractGraphics2D</tt>
0064: *
0065: * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
0066: * @version $Id: AbstractGraphics2D.java 496556 2007-01-16 00:59:48Z cam $
0067: * @see org.apache.xmlgraphics.java2d.GraphicContext
0068: */
0069: public abstract class AbstractGraphics2D extends Graphics2D implements
0070: Cloneable {
0071: /**
0072: * Current state of the Graphic Context. The GraphicsContext
0073: * class manages the state of this <tt>Graphics2D</tt> graphic context
0074: * attributes.
0075: */
0076: protected GraphicContext gc;
0077:
0078: /**
0079: * Text handling strategy.
0080: */
0081: protected boolean textAsShapes = false;
0082:
0083: /**
0084: * Protection agains infinite recursion
0085: */
0086: protected boolean inPossibleRecursion = false;
0087:
0088: /**
0089: * @param textAsShapes if true, all text is turned into shapes in the
0090: * convertion. No text is output.
0091: *
0092: */
0093: public AbstractGraphics2D(boolean textAsShapes) {
0094: this .textAsShapes = textAsShapes;
0095: }
0096:
0097: /**
0098: * Creates a new AbstractGraphics2D from an existing instance.
0099: * @param g the AbstractGraphics2D whose properties should be copied
0100: */
0101: public AbstractGraphics2D(AbstractGraphics2D g) {
0102: this .gc = (GraphicContext) g.gc.clone();
0103: this .gc.validateTransformStack();
0104: this .textAsShapes = g.textAsShapes;
0105: }
0106:
0107: /**
0108: * Translates the origin of the graphics context to the point
0109: * (<i>x</i>, <i>y</i>) in the current coordinate system.
0110: * Modifies this graphics context so that its new origin corresponds
0111: * to the point (<i>x</i>, <i>y</i>) in this graphics context's
0112: * original coordinate system. All coordinates used in subsequent
0113: * rendering operations on this graphics context will be relative
0114: * to this new origin.
0115: * @param x the <i>x</i> coordinate.
0116: * @param y the <i>y</i> coordinate.
0117: */
0118: public void translate(int x, int y) {
0119: gc.translate(x, y);
0120: }
0121:
0122: /**
0123: * Gets this graphics context's current color.
0124: * @return this graphics context's current color.
0125: * @see java.awt.Color
0126: * @see java.awt.Graphics#setColor
0127: */
0128: public Color getColor() {
0129: return gc.getColor();
0130: }
0131:
0132: /**
0133: * Sets this graphics context's current color to the specified
0134: * color. All subsequent graphics operations using this graphics
0135: * context use this specified color.
0136: * @param c the new rendering color.
0137: * @see java.awt.Color
0138: * @see java.awt.Graphics#getColor
0139: */
0140: public void setColor(Color c) {
0141: gc.setColor(c);
0142: }
0143:
0144: /**
0145: * Sets the paint mode of this graphics context to overwrite the
0146: * destination with this graphics context's current color.
0147: * This sets the logical pixel operation function to the paint or
0148: * overwrite mode. All subsequent rendering operations will
0149: * overwrite the destination with the current color.
0150: */
0151: public void setPaintMode() {
0152: gc.setComposite(AlphaComposite.SrcOver);
0153: }
0154:
0155: /**
0156: * Gets the current font.
0157: * @return this graphics context's current font.
0158: * @see java.awt.Font
0159: * @see java.awt.Graphics#setFont
0160: */
0161: public Font getFont() {
0162: return gc.getFont();
0163: }
0164:
0165: /**
0166: * Sets this graphics context's font to the specified font.
0167: * All subsequent text operations using this graphics context
0168: * use this font.
0169: * @param font the font.
0170: * @see java.awt.Graphics#getFont
0171: */
0172: public void setFont(Font font) {
0173: gc.setFont(font);
0174: }
0175:
0176: /**
0177: * Returns the bounding rectangle of the current clipping area.
0178: * This method refers to the user clip, which is independent of the
0179: * clipping associated with device bounds and window visibility.
0180: * If no clip has previously been set, or if the clip has been
0181: * cleared using <code>setClip(null)</code>, this method returns
0182: * <code>null</code>.
0183: * The coordinates in the rectangle are relative to the coordinate
0184: * system origin of this graphics context.
0185: * @return the bounding rectangle of the current clipping area,
0186: * or <code>null</code> if no clip is set.
0187: * @see java.awt.Graphics#getClip
0188: * @see java.awt.Graphics#clipRect
0189: * @see java.awt.Graphics#setClip(int, int, int, int)
0190: * @see java.awt.Graphics#setClip(Shape)
0191: * @since JDK1.1
0192: */
0193: public Rectangle getClipBounds() {
0194: return gc.getClipBounds();
0195: }
0196:
0197: /**
0198: * Intersects the current clip with the specified rectangle.
0199: * The resulting clipping area is the intersection of the current
0200: * clipping area and the specified rectangle. If there is no
0201: * current clipping area, either because the clip has never been
0202: * set, or the clip has been cleared using <code>setClip(null)</code>,
0203: * the specified rectangle becomes the new clip.
0204: * This method sets the user clip, which is independent of the
0205: * clipping associated with device bounds and window visibility.
0206: * This method can only be used to make the current clip smaller.
0207: * To set the current clip larger, use any of the setClip methods.
0208: * Rendering operations have no effect outside of the clipping area.
0209: * @param x the x coordinate of the rectangle to intersect the clip with
0210: * @param y the y coordinate of the rectangle to intersect the clip with
0211: * @param width the width of the rectangle to intersect the clip with
0212: * @param height the height of the rectangle to intersect the clip with
0213: * @see #setClip(int, int, int, int)
0214: * @see #setClip(Shape)
0215: */
0216: public void clipRect(int x, int y, int width, int height) {
0217: gc.clipRect(x, y, width, height);
0218: }
0219:
0220: /**
0221: * Sets the current clip to the rectangle specified by the given
0222: * coordinates. This method sets the user clip, which is
0223: * independent of the clipping associated with device bounds
0224: * and window visibility.
0225: * Rendering operations have no effect outside of the clipping area.
0226: * @param x the <i>x</i> coordinate of the new clip rectangle.
0227: * @param y the <i>y</i> coordinate of the new clip rectangle.
0228: * @param width the width of the new clip rectangle.
0229: * @param height the height of the new clip rectangle.
0230: * @see java.awt.Graphics#clipRect
0231: * @see java.awt.Graphics#setClip(Shape)
0232: * @since JDK1.1
0233: */
0234: public void setClip(int x, int y, int width, int height) {
0235: gc.setClip(x, y, width, height);
0236: }
0237:
0238: /**
0239: * Gets the current clipping area.
0240: * This method returns the user clip, which is independent of the
0241: * clipping associated with device bounds and window visibility.
0242: * If no clip has previously been set, or if the clip has been
0243: * cleared using <code>setClip(null)</code>, this method returns
0244: * <code>null</code>.
0245: * @return a <code>Shape</code> object representing the
0246: * current clipping area, or <code>null</code> if
0247: * no clip is set.
0248: * @see java.awt.Graphics#getClipBounds()
0249: * @see java.awt.Graphics#clipRect(int, int, int, int)
0250: * @see java.awt.Graphics#setClip(int, int, int, int)
0251: * @see java.awt.Graphics#setClip(Shape)
0252: * @since JDK1.1
0253: */
0254: public Shape getClip() {
0255: return gc.getClip();
0256: }
0257:
0258: /**
0259: * Sets the current clipping area to an arbitrary clip shape.
0260: * Not all objects that implement the <code>Shape</code>
0261: * interface can be used to set the clip. The only
0262: * <code>Shape</code> objects that are guaranteed to be
0263: * supported are <code>Shape</code> objects that are
0264: * obtained via the <code>getClip</code> method and via
0265: * <code>Rectangle</code> objects. This method sets the
0266: * user clip, which is independent of the clipping associated
0267: * with device bounds and window visibility.
0268: * @param clip the <code>Shape</code> to use to set the clip
0269: * @see java.awt.Graphics#getClip()
0270: * @see java.awt.Graphics#clipRect
0271: * @see java.awt.Graphics#setClip(int, int, int, int)
0272: * @since JDK1.1
0273: */
0274: public void setClip(Shape clip) {
0275: gc.setClip(clip);
0276: }
0277:
0278: /**
0279: * Draws a line, using the current color, between the points
0280: * <code>(x1, y1)</code> and <code>(x2, y2)</code>
0281: * in this graphics context's coordinate system.
0282: * @param x1 the first point's <i>x</i> coordinate.
0283: * @param y1 the first point's <i>y</i> coordinate.
0284: * @param x2 the second point's <i>x</i> coordinate.
0285: * @param y2 the second point's <i>y</i> coordinate.
0286: */
0287: public void drawLine(int x1, int y1, int x2, int y2) {
0288: Line2D line = new Line2D.Float(x1, y1, x2, y2);
0289: draw(line);
0290: }
0291:
0292: /**
0293: * Fills the specified rectangle.
0294: * The left and right edges of the rectangle are at
0295: * <code>x</code> and <code>x + width - 1</code>.
0296: * The top and bottom edges are at
0297: * <code>y</code> and <code>y + height - 1</code>.
0298: * The resulting rectangle covers an area
0299: * <code>width</code> pixels wide by
0300: * <code>height</code> pixels tall.
0301: * The rectangle is filled using the graphics context's current color.
0302: * @param x the <i>x</i> coordinate
0303: * of the rectangle to be filled.
0304: * @param y the <i>y</i> coordinate
0305: * of the rectangle to be filled.
0306: * @param width the width of the rectangle to be filled.
0307: * @param height the height of the rectangle to be filled.
0308: * @see java.awt.Graphics#clearRect
0309: * @see java.awt.Graphics#drawRect
0310: */
0311: public void fillRect(int x, int y, int width, int height) {
0312: Rectangle rect = new Rectangle(x, y, width, height);
0313: fill(rect);
0314: }
0315:
0316: public void drawRect(int x, int y, int width, int height) {
0317: Rectangle rect = new Rectangle(x, y, width, height);
0318: draw(rect);
0319: }
0320:
0321: /**
0322: * Clears the specified rectangle by filling it with the background
0323: * color of the current drawing surface. This operation does not
0324: * use the current paint mode.
0325: * <p>
0326: * Beginning with Java 1.1, the background color
0327: * of offscreen images may be system dependent. Applications should
0328: * use <code>setColor</code> followed by <code>fillRect</code> to
0329: * ensure that an offscreen image is cleared to a specific color.
0330: * @param x the <i>x</i> coordinate of the rectangle to clear.
0331: * @param y the <i>y</i> coordinate of the rectangle to clear.
0332: * @param width the width of the rectangle to clear.
0333: * @param height the height of the rectangle to clear.
0334: * @see java.awt.Graphics#fillRect(int, int, int, int)
0335: * @see java.awt.Graphics#drawRect
0336: * @see java.awt.Graphics#setColor(java.awt.Color)
0337: * @see java.awt.Graphics#setPaintMode
0338: * @see java.awt.Graphics#setXORMode(java.awt.Color)
0339: */
0340: public void clearRect(int x, int y, int width, int height) {
0341: Paint paint = gc.getPaint();
0342: gc.setColor(gc.getBackground());
0343: fillRect(x, y, width, height);
0344: gc.setPaint(paint);
0345: }
0346:
0347: /**
0348: * Draws an outlined round-cornered rectangle using this graphics
0349: * context's current color. The left and right edges of the rectangle
0350: * are at <code>x</code> and <code>x + width</code>,
0351: * respectively. The top and bottom edges of the rectangle are at
0352: * <code>y</code> and <code>y + height</code>.
0353: * @param x the <i>x</i> coordinate of the rectangle to be drawn.
0354: * @param y the <i>y</i> coordinate of the rectangle to be drawn.
0355: * @param width the width of the rectangle to be drawn.
0356: * @param height the height of the rectangle to be drawn.
0357: * @param arcWidth the horizontal diameter of the arc
0358: * at the four corners.
0359: * @param arcHeight the vertical diameter of the arc
0360: * at the four corners.
0361: * @see java.awt.Graphics#fillRoundRect
0362: */
0363: public void drawRoundRect(int x, int y, int width, int height,
0364: int arcWidth, int arcHeight) {
0365: RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, width,
0366: height, arcWidth, arcHeight);
0367: draw(rect);
0368: }
0369:
0370: /**
0371: * Fills the specified rounded corner rectangle with the current color.
0372: * The left and right edges of the rectangle
0373: * are at <code>x</code> and <code>x + width - 1</code>,
0374: * respectively. The top and bottom edges of the rectangle are at
0375: * <code>y</code> and <code>y + height - 1</code>.
0376: * @param x the <i>x</i> coordinate of the rectangle to be filled.
0377: * @param y the <i>y</i> coordinate of the rectangle to be filled.
0378: * @param width the width of the rectangle to be filled.
0379: * @param height the height of the rectangle to be filled.
0380: * @param arcWidth the horizontal diameter
0381: * of the arc at the four corners.
0382: * @param arcHeight the vertical diameter
0383: * of the arc at the four corners.
0384: * @see java.awt.Graphics#drawRoundRect
0385: */
0386: public void fillRoundRect(int x, int y, int width, int height,
0387: int arcWidth, int arcHeight) {
0388: RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, width,
0389: height, arcWidth, arcHeight);
0390: fill(rect);
0391: }
0392:
0393: /**
0394: * Draws the outline of an oval.
0395: * The result is a circle or ellipse that fits within the
0396: * rectangle specified by the <code>x</code>, <code>y</code>,
0397: * <code>width</code>, and <code>height</code> arguments.
0398: * <p>
0399: * The oval covers an area that is
0400: * <code>width + 1</code> pixels wide
0401: * and <code>height + 1</code> pixels tall.
0402: * @param x the <i>x</i> coordinate of the upper left
0403: * corner of the oval to be drawn.
0404: * @param y the <i>y</i> coordinate of the upper left
0405: * corner of the oval to be drawn.
0406: * @param width the width of the oval to be drawn.
0407: * @param height the height of the oval to be drawn.
0408: * @see java.awt.Graphics#fillOval
0409: */
0410: public void drawOval(int x, int y, int width, int height) {
0411: Ellipse2D oval = new Ellipse2D.Float(x, y, width, height);
0412: draw(oval);
0413: }
0414:
0415: /**
0416: * Fills an oval bounded by the specified rectangle with the
0417: * current color.
0418: * @param x the <i>x</i> coordinate of the upper left corner
0419: * of the oval to be filled.
0420: * @param y the <i>y</i> coordinate of the upper left corner
0421: * of the oval to be filled.
0422: * @param width the width of the oval to be filled.
0423: * @param height the height of the oval to be filled.
0424: * @see java.awt.Graphics#drawOval
0425: */
0426: public void fillOval(int x, int y, int width, int height) {
0427: Ellipse2D oval = new Ellipse2D.Float(x, y, width, height);
0428: fill(oval);
0429: }
0430:
0431: /**
0432: * Draws the outline of a circular or elliptical arc
0433: * covering the specified rectangle.
0434: * <p>
0435: * The resulting arc begins at <code>startAngle</code> and extends
0436: * for <code>arcAngle</code> degrees, using the current color.
0437: * Angles are interpreted such that 0 degrees
0438: * is at the 3 o'clock position.
0439: * A positive value indicates a counter-clockwise rotation
0440: * while a negative value indicates a clockwise rotation.
0441: * <p>
0442: * The center of the arc is the center of the rectangle whose origin
0443: * is (<i>x</i>, <i>y</i>) and whose size is specified by the
0444: * <code>width</code> and <code>height</code> arguments.
0445: * <p>
0446: * The resulting arc covers an area
0447: * <code>width + 1</code> pixels wide
0448: * by <code>height + 1</code> pixels tall.
0449: * <p>
0450: * The angles are specified relative to the non-square extents of
0451: * the bounding rectangle such that 45 degrees always falls on the
0452: * line from the center of the ellipse to the upper right corner of
0453: * the bounding rectangle. As a result, if the bounding rectangle is
0454: * noticeably longer in one axis than the other, the angles to the
0455: * start and end of the arc segment will be skewed farther along the
0456: * longer axis of the bounds.
0457: * @param x the <i>x</i> coordinate of the
0458: * upper-left corner of the arc to be drawn.
0459: * @param y the <i>y</i> coordinate of the
0460: * upper-left corner of the arc to be drawn.
0461: * @param width the width of the arc to be drawn.
0462: * @param height the height of the arc to be drawn.
0463: * @param startAngle the beginning angle.
0464: * @param arcAngle the angular extent of the arc,
0465: * relative to the start angle.
0466: * @see java.awt.Graphics#fillArc
0467: */
0468: public void drawArc(int x, int y, int width, int height,
0469: int startAngle, int arcAngle) {
0470: Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle,
0471: arcAngle, Arc2D.OPEN);
0472: draw(arc);
0473: }
0474:
0475: /**
0476: * Fills a circular or elliptical arc covering the specified rectangle.
0477: * <p>
0478: * The resulting arc begins at <code>startAngle</code> and extends
0479: * for <code>arcAngle</code> degrees.
0480: * Angles are interpreted such that 0 degrees
0481: * is at the 3 o'clock position.
0482: * A positive value indicates a counter-clockwise rotation
0483: * while a negative value indicates a clockwise rotation.
0484: * <p>
0485: * The center of the arc is the center of the rectangle whose origin
0486: * is (<i>x</i>, <i>y</i>) and whose size is specified by the
0487: * <code>width</code> and <code>height</code> arguments.
0488: * <p>
0489: * The resulting arc covers an area
0490: * <code>width + 1</code> pixels wide
0491: * by <code>height + 1</code> pixels tall.
0492: * <p>
0493: * The angles are specified relative to the non-square extents of
0494: * the bounding rectangle such that 45 degrees always falls on the
0495: * line from the center of the ellipse to the upper right corner of
0496: * the bounding rectangle. As a result, if the bounding rectangle is
0497: * noticeably longer in one axis than the other, the angles to the
0498: * start and end of the arc segment will be skewed farther along the
0499: * longer axis of the bounds.
0500: * @param x the <i>x</i> coordinate of the
0501: * upper-left corner of the arc to be filled.
0502: * @param y the <i>y</i> coordinate of the
0503: * upper-left corner of the arc to be filled.
0504: * @param width the width of the arc to be filled.
0505: * @param height the height of the arc to be filled.
0506: * @param startAngle the beginning angle.
0507: * @param arcAngle the angular extent of the arc,
0508: * relative to the start angle.
0509: * @see java.awt.Graphics#drawArc
0510: */
0511: public void fillArc(int x, int y, int width, int height,
0512: int startAngle, int arcAngle) {
0513: Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle,
0514: arcAngle, Arc2D.PIE);
0515: fill(arc);
0516: }
0517:
0518: /**
0519: * Draws a sequence of connected lines defined by
0520: * arrays of <i>x</i> and <i>y</i> coordinates.
0521: * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
0522: * The figure is not closed if the first point
0523: * differs from the last point.
0524: * @param xPoints an array of <i>x</i> points
0525: * @param yPoints an array of <i>y</i> points
0526: * @param nPoints the total number of points
0527: * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0528: * @since JDK1.1
0529: */
0530: public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
0531: if (nPoints > 0) {
0532: GeneralPath path = new GeneralPath();
0533: path.moveTo(xPoints[0], yPoints[0]);
0534: for (int i = 1; i < nPoints; i++)
0535: path.lineTo(xPoints[i], yPoints[i]);
0536:
0537: draw(path);
0538: }
0539: }
0540:
0541: /**
0542: * Draws a closed polygon defined by
0543: * arrays of <i>x</i> and <i>y</i> coordinates.
0544: * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.
0545: * <p>
0546: * This method draws the polygon defined by <code>nPoint</code> line
0547: * segments, where the first <code>nPoint - 1</code>
0548: * line segments are line segments from
0549: * <code>(xPoints[i - 1], yPoints[i - 1])</code>
0550: * to <code>(xPoints[i], yPoints[i])</code>, for
0551: * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
0552: * The figure is automatically closed by drawing a line connecting
0553: * the final point to the first point, if those points are different.
0554: * @param xPoints a an array of <code>x</code> coordinates.
0555: * @param yPoints a an array of <code>y</code> coordinates.
0556: * @param nPoints a the total number of points.
0557: * @see java.awt.Graphics#fillPolygon(int[],int[],int)
0558: * @see java.awt.Graphics#drawPolyline
0559: */
0560: public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
0561: Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
0562: draw(polygon);
0563: }
0564:
0565: /**
0566: * Fills a closed polygon defined by
0567: * arrays of <i>x</i> and <i>y</i> coordinates.
0568: * <p>
0569: * This method draws the polygon defined by <code>nPoint</code> line
0570: * segments, where the first <code>nPoint - 1</code>
0571: * line segments are line segments from
0572: * <code>(xPoints[i - 1], yPoints[i - 1])</code>
0573: * to <code>(xPoints[i], yPoints[i])</code>, for
0574: * 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
0575: * The figure is automatically closed by drawing a line connecting
0576: * the final point to the first point, if those points are different.
0577: * <p>
0578: * The area inside the polygon is defined using an
0579: * even-odd fill rule, also known as the alternating rule.
0580: * @param xPoints a an array of <code>x</code> coordinates.
0581: * @param yPoints a an array of <code>y</code> coordinates.
0582: * @param nPoints a the total number of points.
0583: * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0584: */
0585: public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
0586: Polygon polygon = new Polygon(xPoints, yPoints, nPoints);
0587: fill(polygon);
0588: }
0589:
0590: /**
0591: * Draws the text given by the specified string, using this
0592: * graphics context's current font and color. The baseline of the
0593: * first character is at position (<i>x</i>, <i>y</i>) in this
0594: * graphics context's coordinate system.
0595: * @param str the string to be drawn.
0596: * @param x the <i>x</i> coordinate.
0597: * @param y the <i>y</i> coordinate.
0598: * @see java.awt.Graphics#drawBytes
0599: * @see java.awt.Graphics#drawChars
0600: */
0601: public void drawString(String str, int x, int y) {
0602: drawString(str, (float) x, (float) y);
0603: }
0604:
0605: /**
0606: * Generic implementation for drawing attributed strings using TextLayout.
0607: *
0608: * @param iterator the iterator whose text is to be rendered
0609: * @param x the x coordinate where the iterator's text is to be rendered
0610: * @param y the y coordinate where the iterator's text is to be rendered
0611: * @see java.awt.Graphics2D#drawString (java.text.AttributedCharacterIterator,
0612: * float, float)
0613: */
0614: public void drawString(AttributedCharacterIterator iterator,
0615: float x, float y) {
0616: if (inPossibleRecursion) {
0617: System.err
0618: .println("Called itself: drawString(AttributedCharacterIterator)");
0619: } else {
0620: inPossibleRecursion = true;
0621: TextLayout layout = new TextLayout(iterator,
0622: getFontRenderContext());
0623: layout.draw(this , x, y);
0624: inPossibleRecursion = false;
0625: }
0626: }
0627:
0628: /**
0629: * Draws the text given by the specified iterator, using this
0630: * graphics context's current color. The iterator has to specify a font
0631: * for each character. The baseline of the
0632: * first character is at position (<i>x</i>, <i>y</i>) in this
0633: * graphics context's coordinate system.
0634: * @param iterator the iterator whose text is to be drawn
0635: * @param x the <i>x</i> coordinate.
0636: * @param y the <i>y</i> coordinate.
0637: * @see java.awt.Graphics#drawBytes
0638: * @see java.awt.Graphics#drawChars
0639: */
0640: public void drawString(AttributedCharacterIterator iterator, int x,
0641: int y) {
0642: drawString(iterator, (float) x, (float) y);
0643: }
0644:
0645: /**
0646: * Draws as much of the specified image as is currently available.
0647: * The image is drawn with its top-left corner at
0648: * (<i>x</i>, <i>y</i>) in this graphics context's coordinate
0649: * space. Transparent pixels are drawn in the specified
0650: * background color.
0651: * <p>
0652: * This operation is equivalent to filling a rectangle of the
0653: * width and height of the specified image with the given color and then
0654: * drawing the image on top of it, but possibly more efficient.
0655: * <p>
0656: * This method returns immediately in all cases, even if the
0657: * complete image has not yet been loaded, and it has not been dithered
0658: * and converted for the current output device.
0659: * <p>
0660: * If the image has not yet been completely loaded, then
0661: * <code>drawImage</code> returns <code>false</code>. As more of
0662: * the image becomes available, the process that draws the image notifies
0663: * the specified image observer.
0664: * @param img the specified image to be drawn.
0665: * @param x the <i>x</i> coordinate.
0666: * @param y the <i>y</i> coordinate.
0667: * @param bgcolor the background color to paint under the
0668: * non-opaque portions of the image.
0669: * @param observer object to be notified as more of
0670: * the image is converted.
0671: * @see java.awt.Image
0672: * @see java.awt.image.ImageObserver
0673: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0674: */
0675: public boolean drawImage(Image img, int x, int y, Color bgcolor,
0676: ImageObserver observer) {
0677: return drawImage(img, x, y, img.getWidth(null), img
0678: .getHeight(null), bgcolor, observer);
0679: }
0680:
0681: /**
0682: * Draws as much of the specified image as has already been scaled
0683: * to fit inside the specified rectangle.
0684: * <p>
0685: * The image is drawn inside the specified rectangle of this
0686: * graphics context's coordinate space, and is scaled if
0687: * necessary. Transparent pixels are drawn in the specified
0688: * background color.
0689: * This operation is equivalent to filling a rectangle of the
0690: * width and height of the specified image with the given color and then
0691: * drawing the image on top of it, but possibly more efficient.
0692: * <p>
0693: * This method returns immediately in all cases, even if the
0694: * entire image has not yet been scaled, dithered, and converted
0695: * for the current output device.
0696: * If the current output representation is not yet complete then
0697: * <code>drawImage</code> returns <code>false</code>. As more of
0698: * the image becomes available, the process that draws the image notifies
0699: * the specified image observer.
0700: * <p>
0701: * A scaled version of an image will not necessarily be
0702: * available immediately just because an unscaled version of the
0703: * image has been constructed for this output device. Each size of
0704: * the image may be cached separately and generated from the original
0705: * data in a separate image production sequence.
0706: * @param img the specified image to be drawn.
0707: * @param x the <i>x</i> coordinate.
0708: * @param y the <i>y</i> coordinate.
0709: * @param width the width of the rectangle.
0710: * @param height the height of the rectangle.
0711: * @param bgcolor the background color to paint under the
0712: * non-opaque portions of the image.
0713: * @param observer object to be notified as more of
0714: * the image is converted.
0715: * @see java.awt.Image
0716: * @see java.awt.image.ImageObserver
0717: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0718: */
0719: public boolean drawImage(Image img, int x, int y, int width,
0720: int height, Color bgcolor, ImageObserver observer) {
0721: Paint paint = gc.getPaint();
0722: gc.setPaint(bgcolor);
0723: fillRect(x, y, width, height);
0724: gc.setPaint(paint);
0725: drawImage(img, x, y, width, height, observer);
0726:
0727: return true;
0728: }
0729:
0730: /**
0731: * Draws as much of the specified area of the specified image as is
0732: * currently available, scaling it on the fly to fit inside the
0733: * specified area of the destination drawable surface. Transparent pixels
0734: * do not affect whatever pixels are already there.
0735: * <p>
0736: * This method returns immediately in all cases, even if the
0737: * image area to be drawn has not yet been scaled, dithered, and converted
0738: * for the current output device.
0739: * If the current output representation is not yet complete then
0740: * <code>drawImage</code> returns <code>false</code>. As more of
0741: * the image becomes available, the process that draws the image notifies
0742: * the specified image observer.
0743: * <p>
0744: * This method always uses the unscaled version of the image
0745: * to render the scaled rectangle and performs the required
0746: * scaling on the fly. It does not use a cached, scaled version
0747: * of the image for this operation. Scaling of the image from source
0748: * to destination is performed such that the first coordinate
0749: * of the source rectangle is mapped to the first coordinate of
0750: * the destination rectangle, and the second source coordinate is
0751: * mapped to the second destination coordinate. The subimage is
0752: * scaled and flipped as needed to preserve those mappings.
0753: * @param img the specified image to be drawn
0754: * @param dx1 the <i>x</i> coordinate of the first corner of the
0755: * destination rectangle.
0756: * @param dy1 the <i>y</i> coordinate of the first corner of the
0757: * destination rectangle.
0758: * @param dx2 the <i>x</i> coordinate of the second corner of the
0759: * destination rectangle.
0760: * @param dy2 the <i>y</i> coordinate of the second corner of the
0761: * destination rectangle.
0762: * @param sx1 the <i>x</i> coordinate of the first corner of the
0763: * source rectangle.
0764: * @param sy1 the <i>y</i> coordinate of the first corner of the
0765: * source rectangle.
0766: * @param sx2 the <i>x</i> coordinate of the second corner of the
0767: * source rectangle.
0768: * @param sy2 the <i>y</i> coordinate of the second corner of the
0769: * source rectangle.
0770: * @param observer object to be notified as more of the image is
0771: * scaled and converted.
0772: * @see java.awt.Image
0773: * @see java.awt.image.ImageObserver
0774: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0775: * @since JDK1.1
0776: */
0777: public boolean drawImage(Image img, int dx1, int dy1, int dx2,
0778: int dy2, int sx1, int sy1, int sx2, int sy2,
0779: ImageObserver observer) {
0780: BufferedImage src = new BufferedImage(img.getWidth(null), img
0781: .getHeight(null), BufferedImage.TYPE_INT_ARGB);
0782: Graphics2D g = src.createGraphics();
0783: g.drawImage(img, 0, 0, null);
0784: g.dispose();
0785:
0786: src = src.getSubimage(sx1, sy1, sx2 - sx1, sy2 - sy1);
0787:
0788: return drawImage(src, dx1, dy1, dx2 - dx1, dy2 - dy1, observer);
0789: }
0790:
0791: /**
0792: * Draws as much of the specified area of the specified image as is
0793: * currently available, scaling it on the fly to fit inside the
0794: * specified area of the destination drawable surface.
0795: * <p>
0796: * Transparent pixels are drawn in the specified background color.
0797: * This operation is equivalent to filling a rectangle of the
0798: * width and height of the specified image with the given color and then
0799: * drawing the image on top of it, but possibly more efficient.
0800: * <p>
0801: * This method returns immediately in all cases, even if the
0802: * image area to be drawn has not yet been scaled, dithered, and converted
0803: * for the current output device.
0804: * If the current output representation is not yet complete then
0805: * <code>drawImage</code> returns <code>false</code>. As more of
0806: * the image becomes available, the process that draws the image notifies
0807: * the specified image observer.
0808: * <p>
0809: * This method always uses the unscaled version of the image
0810: * to render the scaled rectangle and performs the required
0811: * scaling on the fly. It does not use a cached, scaled version
0812: * of the image for this operation. Scaling of the image from source
0813: * to destination is performed such that the first coordinate
0814: * of the source rectangle is mapped to the first coordinate of
0815: * the destination rectangle, and the second source coordinate is
0816: * mapped to the second destination coordinate. The subimage is
0817: * scaled and flipped as needed to preserve those mappings.
0818: * @param img the specified image to be drawn
0819: * @param dx1 the <i>x</i> coordinate of the first corner of the
0820: * destination rectangle.
0821: * @param dy1 the <i>y</i> coordinate of the first corner of the
0822: * destination rectangle.
0823: * @param dx2 the <i>x</i> coordinate of the second corner of the
0824: * destination rectangle.
0825: * @param dy2 the <i>y</i> coordinate of the second corner of the
0826: * destination rectangle.
0827: * @param sx1 the <i>x</i> coordinate of the first corner of the
0828: * source rectangle.
0829: * @param sy1 the <i>y</i> coordinate of the first corner of the
0830: * source rectangle.
0831: * @param sx2 the <i>x</i> coordinate of the second corner of the
0832: * source rectangle.
0833: * @param sy2 the <i>y</i> coordinate of the second corner of the
0834: * source rectangle.
0835: * @param bgcolor the background color to paint under the
0836: * non-opaque portions of the image.
0837: * @param observer object to be notified as more of the image is
0838: * scaled and converted.
0839: * @see java.awt.Image
0840: * @see java.awt.image.ImageObserver
0841: * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0842: * @since JDK1.1
0843: */
0844: public boolean drawImage(Image img, int dx1, int dy1, int dx2,
0845: int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
0846: ImageObserver observer) {
0847: Paint paint = gc.getPaint();
0848: gc.setPaint(bgcolor);
0849: fillRect(dx1, dy1, dx2 - dx1, dy2 - dy1);
0850: gc.setPaint(paint);
0851: return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
0852: observer);
0853: }
0854:
0855: /**
0856: * Renders an image, applying a transform from image space into user space
0857: * before drawing.
0858: * The transformation from user space into device space is done with
0859: * the current <code>Transform</code> in the <code>Graphics2D</code>.
0860: * The specified transformation is applied to the image before the
0861: * transform attribute in the <code>Graphics2D</code> context is applied.
0862: * The rendering attributes applied include the <code>Clip</code>,
0863: * <code>Transform</code>, and <code>Composite</code> attributes.
0864: * Note that no rendering is done if the specified transform is
0865: * noninvertible.
0866: * @param img the <code>Image</code> to be rendered
0867: * @param xform the transformation from image space into user space
0868: * @param obs the {@link ImageObserver}
0869: * to be notified as more of the <code>Image</code>
0870: * is converted
0871: * @return <code>true</code> if the <code>Image</code> is
0872: * fully loaded and completely rendered;
0873: * <code>false</code> if the <code>Image</code> is still being loaded.
0874: * @see #transform
0875: * @see #setTransform
0876: * @see #setComposite
0877: * @see #clip
0878: * @see #setClip(Shape)
0879: */
0880: public boolean drawImage(Image img, AffineTransform xform,
0881: ImageObserver obs) {
0882: boolean retVal = true;
0883:
0884: if (xform.getDeterminant() != 0) {
0885: AffineTransform inverseTransform = null;
0886: try {
0887: inverseTransform = xform.createInverse();
0888: } catch (NoninvertibleTransformException e) {
0889: // Should never happen since we checked the
0890: // matrix determinant
0891: throw new Error();
0892: }
0893:
0894: gc.transform(xform);
0895: retVal = drawImage(img, 0, 0, null);
0896: gc.transform(inverseTransform);
0897: } else {
0898: AffineTransform savTransform = new AffineTransform(gc
0899: .getTransform());
0900: gc.transform(xform);
0901: retVal = drawImage(img, 0, 0, null);
0902: gc.setTransform(savTransform);
0903: }
0904:
0905: return retVal;
0906:
0907: }
0908:
0909: /**
0910: * Renders a <code>BufferedImage</code> that is
0911: * filtered with a
0912: * {@link BufferedImageOp}.
0913: * The rendering attributes applied include the <code>Clip</code>,
0914: * <code>Transform</code>
0915: * and <code>Composite</code> attributes. This is equivalent to:
0916: * <pre>
0917: * img1 = op.filter(img, null);
0918: * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
0919: * </pre>
0920: * @param img the <code>BufferedImage</code> to be rendered
0921: * @param op the filter to be applied to the image before rendering
0922: * @param x the x coordinate in user space where the image is rendered
0923: * @param y the y coordinate in user space where the image is rendered
0924: * @see #transform
0925: * @see #setTransform
0926: * @see #setComposite
0927: * @see #clip
0928: * @see #setClip(Shape)
0929: */
0930: public void drawImage(BufferedImage img, BufferedImageOp op, int x,
0931: int y) {
0932: img = op.filter(img, null);
0933: drawImage(img, x, y, null);
0934: }
0935:
0936: /**
0937: * Renders the text of the specified
0938: * {@link GlyphVector} using
0939: * the <code>Graphics2D</code> context's rendering attributes.
0940: * The rendering attributes applied include the <code>Clip</code>,
0941: * <code>Transform</code>, <code>Paint</code>, and
0942: * <code>Composite</code> attributes. The <code>GlyphVector</code>
0943: * specifies individual glyphs from a {@link Font}.
0944: * The <code>GlyphVector</code> can also contain the glyph positions.
0945: * This is the fastest way to render a set of characters to the
0946: * screen.
0947: *
0948: * @param g the <code>GlyphVector</code> to be rendered
0949: * @param x the x position in user space where the glyphs should be
0950: * rendered
0951: * @param y the y position in user space where the glyphs should be
0952: * rendered
0953: *
0954: * @see java.awt.Font#createGlyphVector(FontRenderContext, char[])
0955: * @see java.awt.font.GlyphVector
0956: * @see #setPaint
0957: * @see java.awt.Graphics#setColor
0958: * @see #setTransform
0959: * @see #setComposite
0960: * @see #setClip(Shape)
0961: */
0962: public void drawGlyphVector(GlyphVector g, float x, float y) {
0963: Shape glyphOutline = g.getOutline(x, y);
0964: fill(glyphOutline);
0965: }
0966:
0967: /**
0968: * Checks whether or not the specified <code>Shape</code> intersects
0969: * the specified {@link Rectangle}, which is in device
0970: * space. If <code>onStroke</code> is false, this method checks
0971: * whether or not the interior of the specified <code>Shape</code>
0972: * intersects the specified <code>Rectangle</code>. If
0973: * <code>onStroke</code> is <code>true</code>, this method checks
0974: * whether or not the <code>Stroke</code> of the specified
0975: * <code>Shape</code> outline intersects the specified
0976: * <code>Rectangle</code>.
0977: * The rendering attributes taken into account include the
0978: * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
0979: * attributes.
0980: * @param rect the area in device space to check for a hit
0981: * @param s the <code>Shape</code> to check for a hit
0982: * @param onStroke flag used to choose between testing the
0983: * stroked or the filled shape. If the flag is <code>true</code>, the
0984: * <code>Stroke</code> oultine is tested. If the flag is
0985: * <code>false</code>, the filled <code>Shape</code> is tested.
0986: * @return <code>true</code> if there is a hit; <code>false</code>
0987: * otherwise.
0988: * @see #setStroke
0989: * @see #fill(Shape)
0990: * @see #draw(Shape)
0991: * @see #transform
0992: * @see #setTransform
0993: * @see #clip
0994: * @see #setClip(Shape)
0995: */
0996: public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
0997: if (onStroke) {
0998: s = gc.getStroke().createStrokedShape(s);
0999: }
1000:
1001: s = gc.getTransform().createTransformedShape(s);
1002:
1003: return s.intersects(rect);
1004: }
1005:
1006: /**
1007: * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
1008: * The <code>Composite</code> is used in all drawing methods such as
1009: * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
1010: * and <code>fill</code>. It specifies how new pixels are to be combined
1011: * with the existing pixels on the graphics device during the rendering
1012: * process.
1013: * <p>If this <code>Graphics2D</code> context is drawing to a
1014: * <code>Component</code> on the display screen and the
1015: * <code>Composite</code> is a custom object rather than an
1016: * instance of the <code>AlphaComposite</code> class, and if
1017: * there is a security manager, its <code>checkPermission</code>
1018: * method is called with an <code>AWTPermission("readDisplayPixels")</code>
1019: * permission.
1020: * @param comp the <code>Composite</code> object to be used for rendering
1021: * @throws SecurityException
1022: * if a custom <code>Composite</code> object is being
1023: * used to render to the screen and a security manager
1024: * is set and its <code>checkPermission</code> method
1025: * does not allow the operation.
1026: * @see java.awt.Graphics#setXORMode
1027: * @see java.awt.Graphics#setPaintMode
1028: * @see java.awt.AlphaComposite
1029: */
1030: public void setComposite(Composite comp) {
1031: gc.setComposite(comp);
1032: }
1033:
1034: /**
1035: * Sets the <code>Paint</code> attribute for the
1036: * <code>Graphics2D</code> context. Calling this method
1037: * with a <code>null</code> <code>Paint</code> object does
1038: * not have any effect on the current <code>Paint</code> attribute
1039: * of this <code>Graphics2D</code>.
1040: * @param paint the <code>Paint</code> object to be used to generate
1041: * color during the rendering process, or <code>null</code>
1042: * @see java.awt.Graphics#setColor
1043: */
1044: public void setPaint(Paint paint) {
1045: gc.setPaint(paint);
1046: }
1047:
1048: /**
1049: * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
1050: * @param s the <code>Stroke</code> object to be used to stroke a
1051: * <code>Shape</code> during the rendering process
1052: */
1053: public void setStroke(Stroke s) {
1054: gc.setStroke(s);
1055: }
1056:
1057: /**
1058: * Sets the value of a single preference for the rendering algorithms.
1059: * Hint categories include controls for rendering quality and overall
1060: * time/quality trade-off in the rendering process. Refer to the
1061: * <code>RenderingHints</code> class for definitions of some common
1062: * keys and values.
1063: * @param hintKey the key of the hint to be set.
1064: * @param hintValue the value indicating preferences for the specified
1065: * hint category.
1066: * @see RenderingHints
1067: */
1068: public void setRenderingHint(RenderingHints.Key hintKey,
1069: Object hintValue) {
1070: gc.setRenderingHint(hintKey, hintValue);
1071: }
1072:
1073: /**
1074: * Returns the value of a single preference for the rendering algorithms.
1075: * Hint categories include controls for rendering quality and overall
1076: * time/quality trade-off in the rendering process. Refer to the
1077: * <code>RenderingHints</code> class for definitions of some common
1078: * keys and values.
1079: * @param hintKey the key corresponding to the hint to get.
1080: * @return an object representing the value for the specified hint key.
1081: * Some of the keys and their associated values are defined in the
1082: * <code>RenderingHints</code> class.
1083: * @see RenderingHints
1084: */
1085: public Object getRenderingHint(RenderingHints.Key hintKey) {
1086: return gc.getRenderingHint(hintKey);
1087: }
1088:
1089: /**
1090: * Replaces the values of all preferences for the rendering
1091: * algorithms with the specified <code>hints</code>.
1092: * The existing values for all rendering hints are discarded and
1093: * the new set of known hints and values are initialized from the
1094: * specified {@link Map} object.
1095: * Hint categories include controls for rendering quality and
1096: * overall time/quality trade-off in the rendering process.
1097: * Refer to the <code>RenderingHints</code> class for definitions of
1098: * some common keys and values.
1099: * @param hints the rendering hints to be set
1100: * @see RenderingHints
1101: */
1102: public void setRenderingHints(Map hints) {
1103: gc.setRenderingHints(hints);
1104: }
1105:
1106: /**
1107: * Sets the values of an arbitrary number of preferences for the
1108: * rendering algorithms.
1109: * Only values for the rendering hints that are present in the
1110: * specified <code>Map</code> object are modified.
1111: * All other preferences not present in the specified
1112: * object are left unmodified.
1113: * Hint categories include controls for rendering quality and
1114: * overall time/quality trade-off in the rendering process.
1115: * Refer to the <code>RenderingHints</code> class for definitions of
1116: * some common keys and values.
1117: * @param hints the rendering hints to be set
1118: * @see RenderingHints
1119: */
1120: public void addRenderingHints(Map hints) {
1121: gc.addRenderingHints(hints);
1122: }
1123:
1124: /**
1125: * Gets the preferences for the rendering algorithms. Hint categories
1126: * include controls for rendering quality and overall time/quality
1127: * trade-off in the rendering process.
1128: * Returns all of the hint key/value pairs that were ever specified in
1129: * one operation. Refer to the
1130: * <code>RenderingHints</code> class for definitions of some common
1131: * keys and values.
1132: * @return a reference to an instance of <code>RenderingHints</code>
1133: * that contains the current preferences.
1134: * @see RenderingHints
1135: */
1136: public RenderingHints getRenderingHints() {
1137: return gc.getRenderingHints();
1138: }
1139:
1140: /**
1141: * Concatenates the current
1142: * <code>Graphics2D</code> <code>Transform</code>
1143: * with a translation transform.
1144: * Subsequent rendering is translated by the specified
1145: * distance relative to the previous position.
1146: * This is equivalent to calling transform(T), where T is an
1147: * <code>AffineTransform</code> represented by the following matrix:
1148: * <pre>
1149: * [ 1 0 tx ]
1150: * [ 0 1 ty ]
1151: * [ 0 0 1 ]
1152: * </pre>
1153: * @param tx the distance to translate along the x-axis
1154: * @param ty the distance to translate along the y-axis
1155: */
1156: public void translate(double tx, double ty) {
1157: gc.translate(tx, ty);
1158: }
1159:
1160: /**
1161: * Concatenates the current <code>Graphics2D</code>
1162: * <code>Transform</code> with a rotation transform.
1163: * Subsequent rendering is rotated by the specified radians relative
1164: * to the previous origin.
1165: * This is equivalent to calling <code>transform(R)</code>, where R is an
1166: * <code>AffineTransform</code> represented by the following matrix:
1167: * <pre>
1168: * [ cos(theta) -sin(theta) 0 ]
1169: * [ sin(theta) cos(theta) 0 ]
1170: * [ 0 0 1 ]
1171: * </pre>
1172: * Rotating with a positive angle theta rotates points on the positive
1173: * x axis toward the positive y axis.
1174: * @param theta the angle of rotation in radians
1175: */
1176: public void rotate(double theta) {
1177: gc.rotate(theta);
1178: }
1179:
1180: /**
1181: * Concatenates the current <code>Graphics2D</code>
1182: * <code>Transform</code> with a translated rotation
1183: * transform. Subsequent rendering is transformed by a transform
1184: * which is constructed by translating to the specified location,
1185: * rotating by the specified radians, and translating back by the same
1186: * amount as the original translation. This is equivalent to the
1187: * following sequence of calls:
1188: * <pre>
1189: * translate(x, y);
1190: * rotate(theta);
1191: * translate(-x, -y);
1192: * </pre>
1193: * Rotating with a positive angle theta rotates points on the positive
1194: * x axis toward the positive y axis.
1195: * @param theta the angle of rotation in radians
1196: * @param x the x coordinate of the origin of the rotation
1197: * @param y the y coordinate of the origin of the rotation
1198: */
1199: public void rotate(double theta, double x, double y) {
1200: gc.rotate(theta, x, y);
1201: }
1202:
1203: /**
1204: * Concatenates the current <code>Graphics2D</code>
1205: * <code>Transform</code> with a scaling transformation
1206: * Subsequent rendering is resized according to the specified scaling
1207: * factors relative to the previous scaling.
1208: * This is equivalent to calling <code>transform(S)</code>, where S is an
1209: * <code>AffineTransform</code> represented by the following matrix:
1210: * <pre>
1211: * [ sx 0 0 ]
1212: * [ 0 sy 0 ]
1213: * [ 0 0 1 ]
1214: * </pre>
1215: * @param sx the amount by which X coordinates in subsequent
1216: * rendering operations are multiplied relative to previous
1217: * rendering operations.
1218: * @param sy the amount by which Y coordinates in subsequent
1219: * rendering operations are multiplied relative to previous
1220: * rendering operations.
1221: */
1222: public void scale(double sx, double sy) {
1223: gc.scale(sx, sy);
1224: }
1225:
1226: /**
1227: * Concatenates the current <code>Graphics2D</code>
1228: * <code>Transform</code> with a shearing transform.
1229: * Subsequent renderings are sheared by the specified
1230: * multiplier relative to the previous position.
1231: * This is equivalent to calling <code>transform(SH)</code>, where SH
1232: * is an <code>AffineTransform</code> represented by the following
1233: * matrix:
1234: * <pre>
1235: * [ 1 shx 0 ]
1236: * [ shy 1 0 ]
1237: * [ 0 0 1 ]
1238: * </pre>
1239: * @param shx the multiplier by which coordinates are shifted in
1240: * the positive X axis direction as a function of their Y coordinate
1241: * @param shy the multiplier by which coordinates are shifted in
1242: * the positive Y axis direction as a function of their X coordinate
1243: */
1244: public void shear(double shx, double shy) {
1245: gc.shear(shx, shy);
1246: }
1247:
1248: /**
1249: * Composes an <code>AffineTransform</code> object with the
1250: * <code>Transform</code> in this <code>Graphics2D</code> according
1251: * to the rule last-specified-first-applied. If the current
1252: * <code>Transform</code> is Cx, the result of composition
1253: * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
1254: * current <code>Transform</code> for this <code>Graphics2D</code>.
1255: * Transforming a point p by the updated <code>Transform</code> Cx' is
1256: * equivalent to first transforming p by Tx and then transforming
1257: * the result by the original <code>Transform</code> Cx. In other
1258: * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
1259: * so further modifications to Tx do not affect rendering.
1260: * @param Tx the <code>AffineTransform</code> object to be composed with
1261: * the current <code>Transform</code>
1262: * @see #setTransform
1263: * @see AffineTransform
1264: */
1265: public void transform(AffineTransform Tx) {
1266: gc.transform(Tx);
1267: }
1268:
1269: /**
1270: * Sets the <code>Transform</code> in the <code>Graphics2D</code>
1271: * context.
1272: * @param Tx the <code>AffineTransform</code> object to be used in the
1273: * rendering process
1274: * @see #transform
1275: * @see AffineTransform
1276: */
1277: public void setTransform(AffineTransform Tx) {
1278: gc.setTransform(Tx);
1279: }
1280:
1281: /**
1282: * Returns a copy of the current <code>Transform</code> in the
1283: * <code>Graphics2D</code> context.
1284: * @return the current <code>AffineTransform</code> in the
1285: * <code>Graphics2D</code> context.
1286: * @see #transform
1287: * @see #setTransform
1288: */
1289: public AffineTransform getTransform() {
1290: return gc.getTransform();
1291: }
1292:
1293: /**
1294: * Returns the current <code>Paint</code> of the
1295: * <code>Graphics2D</code> context.
1296: * @return the current <code>Graphics2D</code> <code>Paint</code>,
1297: * which defines a color or pattern.
1298: * @see #setPaint
1299: * @see java.awt.Graphics#setColor
1300: */
1301: public Paint getPaint() {
1302: return gc.getPaint();
1303: }
1304:
1305: /**
1306: * Returns the current <code>Composite</code> in the
1307: * <code>Graphics2D</code> context.
1308: * @return the current <code>Graphics2D</code> <code>Composite</code>,
1309: * which defines a compositing style.
1310: * @see #setComposite
1311: */
1312: public Composite getComposite() {
1313: return gc.getComposite();
1314: }
1315:
1316: /**
1317: * Sets the background color for the <code>Graphics2D</code> context.
1318: * The background color is used for clearing a region.
1319: * When a <code>Graphics2D</code> is constructed for a
1320: * <code>Component</code>, the background color is
1321: * inherited from the <code>Component</code>. Setting the background color
1322: * in the <code>Graphics2D</code> context only affects the subsequent
1323: * <code>clearRect</code> calls and not the background color of the
1324: * <code>Component</code>. To change the background
1325: * of the <code>Component</code>, use appropriate methods of
1326: * the <code>Component</code>.
1327: * @param color the background color that isused in
1328: * subsequent calls to <code>clearRect</code>
1329: * @see #getBackground
1330: * @see java.awt.Graphics#clearRect
1331: */
1332: public void setBackground(Color color) {
1333: gc.setBackground(color);
1334: }
1335:
1336: /**
1337: * Returns the background color used for clearing a region.
1338: * @return the current <code>Graphics2D</code> <code>Color</code>,
1339: * which defines the background color.
1340: * @see #setBackground
1341: */
1342: public Color getBackground() {
1343: return gc.getBackground();
1344: }
1345:
1346: /**
1347: * Returns the current <code>Stroke</code> in the
1348: * <code>Graphics2D</code> context.
1349: * @return the current <code>Graphics2D</code> <code>Stroke</code>,
1350: * which defines the line style.
1351: * @see #setStroke
1352: */
1353: public Stroke getStroke() {
1354: return gc.getStroke();
1355: }
1356:
1357: /**
1358: * Intersects the current <code>Clip</code> with the interior of the
1359: * specified <code>Shape</code> and sets the <code>Clip</code> to the
1360: * resulting intersection. The specified <code>Shape</code> is
1361: * transformed with the current <code>Graphics2D</code>
1362: * <code>Transform</code> before being intersected with the current
1363: * <code>Clip</code>. This method is used to make the current
1364: * <code>Clip</code> smaller.
1365: * To make the <code>Clip</code> larger, use <code>setClip</code>.
1366: * The <i>user clip</i> modified by this method is independent of the
1367: * clipping associated with device bounds and visibility. If no clip has
1368: * previously been set, or if the clip has been cleared using
1369: * {@link java.awt.Graphics#setClip(Shape) setClip} with a
1370: * <code>null</code> argument, the specified <code>Shape</code> becomes
1371: * the new user clip.
1372: * @param s the <code>Shape</code> to be intersected with the current
1373: * <code>Clip</code>. If <code>s</code> is <code>null</code>,
1374: * this method clears the current <code>Clip</code>.
1375: */
1376: public void clip(Shape s) {
1377: gc.clip(s);
1378: }
1379:
1380: /**
1381: * Get the rendering context of the <code>Font</code> within this
1382: * <code>Graphics2D</code> context.
1383: * The {@link FontRenderContext}
1384: * encapsulates application hints such as anti-aliasing and
1385: * fractional metrics, as well as target device specific information
1386: * such as dots-per-inch. This information should be provided by the
1387: * application when using objects that perform typographical
1388: * formatting, such as <code>Font</code> and
1389: * <code>TextLayout</code>. This information should also be provided
1390: * by applications that perform their own layout and need accurate
1391: * measurements of various characteristics of glyphs such as advance
1392: * and line height when various rendering hints have been applied to
1393: * the text rendering.
1394: *
1395: * @return a reference to an instance of FontRenderContext.
1396: * @see java.awt.font.FontRenderContext
1397: * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
1398: * @see java.awt.font.TextLayout
1399: * @since JDK1.2
1400: */
1401: public FontRenderContext getFontRenderContext() {
1402: return gc.getFontRenderContext();
1403: }
1404:
1405: /**
1406: * @return the {@link GraphicContext} of this <code>Graphics2D</code>.
1407: */
1408: public GraphicContext getGraphicContext() {
1409: return gc;
1410: }
1411: }
|