Path: blob/master/src/java.desktop/share/classes/sun/print/ProxyGraphics.java
41153 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.print;2627import java.awt.Color;28import java.awt.Font;29import java.awt.FontMetrics;30import java.awt.Graphics;31import java.awt.Image;32import java.awt.Polygon;33import java.awt.Rectangle;34import java.awt.Shape;3536import java.awt.image.ImageObserver;3738import java.text.AttributedCharacterIterator;3940/**41* Implements the Graphics API but does all42* rendering through a second Graphics instance.43* The primary use of this class is to provide44* a Graphics instance without the 2D API to45* an application, but to implement the rendering46* with a Graphics2D instance.47*/48public class ProxyGraphics extends Graphics {4950/**51* The Graphics instance that performs the52* drawing for this Graphics.53*/54private Graphics g;5556public ProxyGraphics(Graphics graphics) {57g = graphics;58}5960Graphics getGraphics() {61return g;62}6364/**65* Creates a new {@code Graphics} object that is66* a copy of this {@code Graphics} object.67* @return a new graphics context that is a copy of68* this graphics context.69*/70public Graphics create() {71return new ProxyGraphics(g.create());72}7374/**75* Creates a new {@code Graphics} object based on this76* {@code Graphics} object, but with a new translation and clip area.77* The new {@code Graphics} object has its origin78* translated to the specified point (<i>x</i>, <i>y</i>).79* Its clip area is determined by the intersection of the original80* clip area with the specified rectangle. The arguments are all81* interpreted in the coordinate system of the original82* {@code Graphics} object. The new graphics context is83* identical to the original, except in two respects:84* <p>85* <ul>86* <li>87* The new graphics context is translated by (<i>x</i>, <i>y</i>).88* That is to say, the point ({@code 0}, {@code 0}) in the89* new graphics context is the same as (<i>x</i>, <i>y</i>) in90* the original graphics context.91* <li>92* The new graphics context has an additional clipping rectangle, in93* addition to whatever (translated) clipping rectangle it inherited94* from the original graphics context. The origin of the new clipping95* rectangle is at ({@code 0}, {@code 0}), and its size96* is specified by the {@code width} and {@code height}97* arguments.98* </ul>99* <p>100* @param x the <i>x</i> coordinate.101* @param y the <i>y</i> coordinate.102* @param width the width of the clipping rectangle.103* @param height the height of the clipping rectangle.104* @return a new graphics context.105* @see java.awt.Graphics#translate106* @see java.awt.Graphics#clipRect107*/108public Graphics create(int x, int y, int width, int height) {109return new ProxyGraphics(g.create(x, y, width, height));110}111112/**113* Translates the origin of the graphics context to the point114* (<i>x</i>, <i>y</i>) in the current coordinate system.115* Modifies this graphics context so that its new origin corresponds116* to the point (<i>x</i>, <i>y</i>) in this graphics context's117* original coordinate system. All coordinates used in subsequent118* rendering operations on this graphics context will be relative119* to this new origin.120* @param x the <i>x</i> coordinate.121* @param y the <i>y</i> coordinate.122*/123public void translate(int x, int y) {124g.translate(x, y);125}126127/**128* Gets this graphics context's current color.129* @return this graphics context's current color.130* @see java.awt.Color131* @see java.awt.Graphics#setColor132*/133public Color getColor() {134return g.getColor();135}136137/**138* Sets this graphics context's current color to the specified139* color. All subsequent graphics operations using this graphics140* context use this specified color.141* @param c the new rendering color.142* @see java.awt.Color143* @see java.awt.Graphics#getColor144*/145public void setColor(Color c) {146g.setColor(c);147}148149/**150* Sets the paint mode of this graphics context to overwrite the151* destination with this graphics context's current color.152* This sets the logical pixel operation function to the paint or153* overwrite mode. All subsequent rendering operations will154* overwrite the destination with the current color.155*/156public void setPaintMode() {157g.setPaintMode();158}159160/**161* Sets the paint mode of this graphics context to alternate between162* this graphics context's current color and the new specified color.163* This specifies that logical pixel operations are performed in the164* XOR mode, which alternates pixels between the current color and165* a specified XOR color.166* <p>167* When drawing operations are performed, pixels which are the168* current color are changed to the specified color, and vice versa.169* <p>170* Pixels that are of colors other than those two colors are changed171* in an unpredictable but reversible manner; if the same figure is172* drawn twice, then all pixels are restored to their original values.173* @param c1 the XOR alternation color174*/175public void setXORMode(Color c1) {176g.setXORMode(c1);177}178179/**180* Gets the current font.181* @return this graphics context's current font.182* @see java.awt.Font183* @see java.awt.Graphics#setFont184*/185public Font getFont() {186return g.getFont();187}188189/**190* Sets this graphics context's font to the specified font.191* All subsequent text operations using this graphics context192* use this font.193* @param font the font.194* @see java.awt.Graphics#getFont195* @see java.awt.Graphics#drawString(java.lang.String, int, int)196* @see java.awt.Graphics#drawBytes(byte[], int, int, int, int)197* @see java.awt.Graphics#drawChars(char[], int, int, int, int)198*/199public void setFont(Font font) {200g.setFont(font);201}202203/**204* Gets the font metrics of the current font.205* @return the font metrics of this graphics206* context's current font.207* @see java.awt.Graphics#getFont208* @see java.awt.FontMetrics209* @see java.awt.Graphics#getFontMetrics(Font)210*/211public FontMetrics getFontMetrics() {212return g.getFontMetrics();213}214215/**216* Gets the font metrics for the specified font.217* @return the font metrics for the specified font.218* @param f the specified font219* @see java.awt.Graphics#getFont220* @see java.awt.FontMetrics221* @see java.awt.Graphics#getFontMetrics()222*/223public FontMetrics getFontMetrics(Font f) {224return g.getFontMetrics(f);225}226227228/**229* Returns the bounding rectangle of the current clipping area.230* This method refers to the user clip, which is independent of the231* clipping associated with device bounds and window visibility.232* If no clip has previously been set, or if the clip has been233* cleared using {@code setClip(null)}, this method returns234* {@code null}.235* The coordinates in the rectangle are relative to the coordinate236* system origin of this graphics context.237* @return the bounding rectangle of the current clipping area,238* or {@code null} if no clip is set.239* @see java.awt.Graphics#getClip240* @see java.awt.Graphics#clipRect241* @see java.awt.Graphics#setClip(int, int, int, int)242* @see java.awt.Graphics#setClip(Shape)243* @since 1.1244*/245public Rectangle getClipBounds() {246return g.getClipBounds();247}248249/**250* Intersects the current clip with the specified rectangle.251* The resulting clipping area is the intersection of the current252* clipping area and the specified rectangle. If there is no253* current clipping area, either because the clip has never been254* set, or the clip has been cleared using {@code setClip(null)},255* the specified rectangle becomes the new clip.256* This method sets the user clip, which is independent of the257* clipping associated with device bounds and window visibility.258* This method can only be used to make the current clip smaller.259* To set the current clip larger, use any of the setClip methods.260* Rendering operations have no effect outside of the clipping area.261* @param x the x coordinate of the rectangle to intersect the clip with262* @param y the y coordinate of the rectangle to intersect the clip with263* @param width the width of the rectangle to intersect the clip with264* @param height the height of the rectangle to intersect the clip with265* @see #setClip(int, int, int, int)266* @see #setClip(Shape)267*/268public void clipRect(int x, int y, int width, int height) {269g.clipRect(x, y, width, height);270}271272/**273* Sets the current clip to the rectangle specified by the given274* coordinates. This method sets the user clip, which is275* independent of the clipping associated with device bounds276* and window visibility.277* Rendering operations have no effect outside of the clipping area.278* @param x the <i>x</i> coordinate of the new clip rectangle.279* @param y the <i>y</i> coordinate of the new clip rectangle.280* @param width the width of the new clip rectangle.281* @param height the height of the new clip rectangle.282* @see java.awt.Graphics#clipRect283* @see java.awt.Graphics#setClip(Shape)284* @since 1.1285*/286public void setClip(int x, int y, int width, int height) {287g.setClip(x, y, width, height);288}289290/**291* Gets the current clipping area.292* This method returns the user clip, which is independent of the293* clipping associated with device bounds and window visibility.294* If no clip has previously been set, or if the clip has been295* cleared using {@code setClip(null)}, this method returns296* {@code null}.297* @return a {@code Shape} object representing the298* current clipping area, or {@code null} if299* no clip is set.300* @see java.awt.Graphics#getClipBounds301* @see java.awt.Graphics#clipRect302* @see java.awt.Graphics#setClip(int, int, int, int)303* @see java.awt.Graphics#setClip(Shape)304* @since 1.1305*/306public Shape getClip() {307return g.getClip();308}309310/**311* Sets the current clipping area to an arbitrary clip shape.312* Not all objects that implement the {@code Shape}313* interface can be used to set the clip. The only314* {@code Shape} objects that are guaranteed to be315* supported are {@code Shape} objects that are316* obtained via the {@code getClip} method and via317* {@code Rectangle} objects. This method sets the318* user clip, which is independent of the clipping associated319* with device bounds and window visibility.320* @param clip the {@code Shape} to use to set the clip321* @see java.awt.Graphics#getClip()322* @see java.awt.Graphics#clipRect323* @see java.awt.Graphics#setClip(int, int, int, int)324* @since 1.1325*/326public void setClip(Shape clip) {327g.setClip(clip);328}329330/**331* Copies an area of the component by a distance specified by332* {@code dx} and {@code dy}. From the point specified333* by {@code x} and {@code y}, this method334* copies downwards and to the right. To copy an area of the335* component to the left or upwards, specify a negative value for336* {@code dx} or {@code dy}.337* If a portion of the source rectangle lies outside the bounds338* of the component, or is obscured by another window or component,339* {@code copyArea} will be unable to copy the associated340* pixels. The area that is omitted can be refreshed by calling341* the component's {@code paint} method.342* @param x the <i>x</i> coordinate of the source rectangle.343* @param y the <i>y</i> coordinate of the source rectangle.344* @param width the width of the source rectangle.345* @param height the height of the source rectangle.346* @param dx the horizontal distance to copy the pixels.347* @param dy the vertical distance to copy the pixels.348*/349public void copyArea(int x, int y, int width, int height,350int dx, int dy) {351g.copyArea(x, y, width, height, dx, dy);352}353354/**355* Draws a line, using the current color, between the points356* <code>(x1, y1)</code> and <code>(x2, y2)</code>357* in this graphics context's coordinate system.358* @param x1 the first point's <i>x</i> coordinate.359* @param y1 the first point's <i>y</i> coordinate.360* @param x2 the second point's <i>x</i> coordinate.361* @param y2 the second point's <i>y</i> coordinate.362*/363public void drawLine(int x1, int y1, int x2, int y2) {364g.drawLine(x1, y1, x2, y2);365}366367/**368* Fills the specified rectangle.369* The left and right edges of the rectangle are at370* {@code x} and <code>x + width - 1</code>.371* The top and bottom edges are at372* {@code y} and <code>y + height - 1</code>.373* The resulting rectangle covers an area374* {@code width} pixels wide by375* {@code height} pixels tall.376* The rectangle is filled using the graphics context's current color.377* @param x the <i>x</i> coordinate378* of the rectangle to be filled.379* @param y the <i>y</i> coordinate380* of the rectangle to be filled.381* @param width the width of the rectangle to be filled.382* @param height the height of the rectangle to be filled.383* @see java.awt.Graphics#clearRect384* @see java.awt.Graphics#drawRect385*/386public void fillRect(int x, int y, int width, int height) {387g.fillRect(x, y, width, height);388}389390/**391* Draws the outline of the specified rectangle.392* The left and right edges of the rectangle are at393* {@code x} and <code>x + width</code>.394* The top and bottom edges are at395* {@code y} and <code>y + height</code>.396* The rectangle is drawn using the graphics context's current color.397* @param x the <i>x</i> coordinate398* of the rectangle to be drawn.399* @param y the <i>y</i> coordinate400* of the rectangle to be drawn.401* @param width the width of the rectangle to be drawn.402* @param height the height of the rectangle to be drawn.403* @see java.awt.Graphics#fillRect404* @see java.awt.Graphics#clearRect405*/406public void drawRect(int x, int y, int width, int height) {407g.drawRect(x, y, width, height);408}409410/**411* Clears the specified rectangle by filling it with the background412* color of the current drawing surface. This operation does not413* use the current paint mode.414* <p>415* Beginning with Java 1.1, the background color416* of offscreen images may be system dependent. Applications should417* use {@code setColor} followed by {@code fillRect} to418* ensure that an offscreen image is cleared to a specific color.419* @param x the <i>x</i> coordinate of the rectangle to clear.420* @param y the <i>y</i> coordinate of the rectangle to clear.421* @param width the width of the rectangle to clear.422* @param height the height of the rectangle to clear.423* @see java.awt.Graphics#fillRect(int, int, int, int)424* @see java.awt.Graphics#drawRect425* @see java.awt.Graphics#setColor(java.awt.Color)426* @see java.awt.Graphics#setPaintMode427* @see java.awt.Graphics#setXORMode(java.awt.Color)428*/429public void clearRect(int x, int y, int width, int height) {430g.clearRect(x, y, width, height);431}432433/**434* Draws an outlined round-cornered rectangle using this graphics435* context's current color. The left and right edges of the rectangle436* are at {@code x} and <code>x + width</code>,437* respectively. The top and bottom edges of the rectangle are at438* {@code y} and <code>y + height</code>.439* @param x the <i>x</i> coordinate of the rectangle to be drawn.440* @param y the <i>y</i> coordinate of the rectangle to be drawn.441* @param width the width of the rectangle to be drawn.442* @param height the height of the rectangle to be drawn.443* @param arcWidth the horizontal diameter of the arc444* at the four corners.445* @param arcHeight the vertical diameter of the arc446* at the four corners.447* @see java.awt.Graphics#fillRoundRect448*/449public void drawRoundRect(int x, int y, int width, int height,450int arcWidth, int arcHeight) {451g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);452}453454/**455* Fills the specified rounded corner rectangle with the current color.456* The left and right edges of the rectangle457* are at {@code x} and <code>x + width - 1</code>,458* respectively. The top and bottom edges of the rectangle are at459* {@code y} and <code>y + height - 1</code>.460* @param x the <i>x</i> coordinate of the rectangle to be filled.461* @param y the <i>y</i> coordinate of the rectangle to be filled.462* @param width the width of the rectangle to be filled.463* @param height the height of the rectangle to be filled.464* @param arcWidth the horizontal diameter465* of the arc at the four corners.466* @param arcHeight the vertical diameter467* of the arc at the four corners.468* @see java.awt.Graphics#drawRoundRect469*/470public void fillRoundRect(int x, int y, int width, int height,471int arcWidth, int arcHeight) {472g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);473}474475/**476* Draws a 3-D highlighted outline of the specified rectangle.477* The edges of the rectangle are highlighted so that they478* appear to be beveled and lit from the upper left corner.479* <p>480* The colors used for the highlighting effect are determined481* based on the current color.482* The resulting rectangle covers an area that is483* <code>width + 1</code> pixels wide484* by <code>height + 1</code> pixels tall.485* @param x the <i>x</i> coordinate of the rectangle to be drawn.486* @param y the <i>y</i> coordinate of the rectangle to be drawn.487* @param width the width of the rectangle to be drawn.488* @param height the height of the rectangle to be drawn.489* @param raised a boolean that determines whether the rectangle490* appears to be raised above the surface491* or sunk into the surface.492* @see java.awt.Graphics#fill3DRect493*/494public void draw3DRect(int x, int y, int width, int height,495boolean raised) {496g.draw3DRect(x, y, width, height, raised);497}498499/**500* Paints a 3-D highlighted rectangle filled with the current color.501* The edges of the rectangle will be highlighted so that it appears502* as if the edges were beveled and lit from the upper left corner.503* The colors used for the highlighting effect will be determined from504* the current color.505* @param x the <i>x</i> coordinate of the rectangle to be filled.506* @param y the <i>y</i> coordinate of the rectangle to be filled.507* @param width the width of the rectangle to be filled.508* @param height the height of the rectangle to be filled.509* @param raised a boolean value that determines whether the510* rectangle appears to be raised above the surface511* or etched into the surface.512* @see java.awt.Graphics#draw3DRect513*/514public void fill3DRect(int x, int y, int width, int height,515boolean raised) {516g.fill3DRect(x, y, width, height, raised);517}518519/**520* Draws the outline of an oval.521* The result is a circle or ellipse that fits within the522* rectangle specified by the {@code x}, {@code y},523* {@code width}, and {@code height} arguments.524* <p>525* The oval covers an area that is526* <code>width + 1</code> pixels wide527* and <code>height + 1</code> pixels tall.528* @param x the <i>x</i> coordinate of the upper left529* corner of the oval to be drawn.530* @param y the <i>y</i> coordinate of the upper left531* corner of the oval to be drawn.532* @param width the width of the oval to be drawn.533* @param height the height of the oval to be drawn.534* @see java.awt.Graphics#fillOval535*/536public void drawOval(int x, int y, int width, int height) {537g.drawOval(x, y, width, height);538}539540/**541* Fills an oval bounded by the specified rectangle with the542* current color.543* @param x the <i>x</i> coordinate of the upper left corner544* of the oval to be filled.545* @param y the <i>y</i> coordinate of the upper left corner546* of the oval to be filled.547* @param width the width of the oval to be filled.548* @param height the height of the oval to be filled.549* @see java.awt.Graphics#drawOval550*/551public void fillOval(int x, int y, int width, int height) {552g.fillOval(x, y, width, height);553}554555/**556* Draws the outline of a circular or elliptical arc557* covering the specified rectangle.558* <p>559* The resulting arc begins at {@code startAngle} and extends560* for {@code arcAngle} degrees, using the current color.561* Angles are interpreted such that 0 degrees562* is at the 3 o'clock position.563* A positive value indicates a counter-clockwise rotation564* while a negative value indicates a clockwise rotation.565* <p>566* The center of the arc is the center of the rectangle whose origin567* is (<i>x</i>, <i>y</i>) and whose size is specified by the568* {@code width} and {@code height} arguments.569* <p>570* The resulting arc covers an area571* <code>width + 1</code> pixels wide572* by <code>height + 1</code> pixels tall.573* <p>574* The angles are specified relative to the non-square extents of575* the bounding rectangle such that 45 degrees always falls on the576* line from the center of the ellipse to the upper right corner of577* the bounding rectangle. As a result, if the bounding rectangle is578* noticeably longer in one axis than the other, the angles to the579* start and end of the arc segment will be skewed farther along the580* longer axis of the bounds.581* @param x the <i>x</i> coordinate of the582* upper-left corner of the arc to be drawn.583* @param y the <i>y</i> coordinate of the584* upper-left corner of the arc to be drawn.585* @param width the width of the arc to be drawn.586* @param height the height of the arc to be drawn.587* @param startAngle the beginning angle.588* @param arcAngle the angular extent of the arc,589* relative to the start angle.590* @see java.awt.Graphics#fillArc591*/592public void drawArc(int x, int y, int width, int height,593int startAngle, int arcAngle) {594g.drawArc(x, y, width, height, startAngle, arcAngle);595}596597/**598* Fills a circular or elliptical arc covering the specified rectangle.599* <p>600* The resulting arc begins at {@code startAngle} and extends601* for {@code arcAngle} degrees.602* Angles are interpreted such that 0 degrees603* is at the 3 o'clock position.604* A positive value indicates a counter-clockwise rotation605* while a negative value indicates a clockwise rotation.606* <p>607* The center of the arc is the center of the rectangle whose origin608* is (<i>x</i>, <i>y</i>) and whose size is specified by the609* {@code width} and {@code height} arguments.610* <p>611* The resulting arc covers an area612* <code>width + 1</code> pixels wide613* by <code>height + 1</code> pixels tall.614* <p>615* The angles are specified relative to the non-square extents of616* the bounding rectangle such that 45 degrees always falls on the617* line from the center of the ellipse to the upper right corner of618* the bounding rectangle. As a result, if the bounding rectangle is619* noticeably longer in one axis than the other, the angles to the620* start and end of the arc segment will be skewed farther along the621* longer axis of the bounds.622* @param x the <i>x</i> coordinate of the623* upper-left corner of the arc to be filled.624* @param y the <i>y</i> coordinate of the625* upper-left corner of the arc to be filled.626* @param width the width of the arc to be filled.627* @param height the height of the arc to be filled.628* @param startAngle the beginning angle.629* @param arcAngle the angular extent of the arc,630* relative to the start angle.631* @see java.awt.Graphics#drawArc632*/633public void fillArc(int x, int y, int width, int height,634int startAngle, int arcAngle) {635636g.fillArc(x, y, width, height, startAngle, arcAngle);637}638639/**640* Draws a sequence of connected lines defined by641* arrays of <i>x</i> and <i>y</i> coordinates.642* Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.643* The figure is not closed if the first point644* differs from the last point.645* @param xPoints an array of <i>x</i> points646* @param yPoints an array of <i>y</i> points647* @param nPoints the total number of points648* @see java.awt.Graphics#drawPolygon(int[], int[], int)649* @since 1.1650*/651public void drawPolyline(int[] xPoints, int[] yPoints,652int nPoints) {653g.drawPolyline(xPoints, yPoints, nPoints);654}655656/**657* Draws a closed polygon defined by658* arrays of <i>x</i> and <i>y</i> coordinates.659* Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point.660* <p>661* This method draws the polygon defined by {@code nPoint} line662* segments, where the first <code>nPoint - 1</code>663* line segments are line segments from664* <code>(xPoints[i - 1], yPoints[i - 1])</code>665* to <code>(xPoints[i], yPoints[i])</code>, for666* 1 ≤ <i>i</i> ≤ {@code nPoints}.667* The figure is automatically closed by drawing a line connecting668* the final point to the first point, if those points are different.669* @param xPoints a an array of {@code x} coordinates.670* @param yPoints a an array of {@code y} coordinates.671* @param nPoints a the total number of points.672* @see java.awt.Graphics#fillPolygon673* @see java.awt.Graphics#drawPolyline674*/675public void drawPolygon(int[] xPoints, int[] yPoints,676int nPoints) {677g.drawPolygon(xPoints, yPoints, nPoints);678}679680/**681* Draws the outline of a polygon defined by the specified682* {@code Polygon} object.683* @param p the polygon to draw.684* @see java.awt.Graphics#fillPolygon685* @see java.awt.Graphics#drawPolyline686*/687public void drawPolygon(Polygon p) {688g.drawPolygon(p);689}690691/**692* Fills a closed polygon defined by693* arrays of <i>x</i> and <i>y</i> coordinates.694* <p>695* This method draws the polygon defined by {@code nPoint} line696* segments, where the first <code>nPoint - 1</code>697* line segments are line segments from698* <code>(xPoints[i - 1], yPoints[i - 1])</code>699* to <code>(xPoints[i], yPoints[i])</code>, for700* 1 ≤ <i>i</i> ≤ {@code nPoints}.701* The figure is automatically closed by drawing a line connecting702* the final point to the first point, if those points are different.703* <p>704* The area inside the polygon is defined using an705* even-odd fill rule, also known as the alternating rule.706* @param xPoints a an array of {@code x} coordinates.707* @param yPoints a an array of {@code y} coordinates.708* @param nPoints a the total number of points.709* @see java.awt.Graphics#drawPolygon(int[], int[], int)710*/711public void fillPolygon(int[] xPoints, int[] yPoints,712int nPoints) {713g.fillPolygon(xPoints, yPoints, nPoints);714}715716/**717* Fills the polygon defined by the specified Polygon object with718* the graphics context's current color.719* <p>720* The area inside the polygon is defined using an721* even-odd fill rule, also known as the alternating rule.722* @param p the polygon to fill.723* @see java.awt.Graphics#drawPolygon(int[], int[], int)724*/725public void fillPolygon(Polygon p) {726g.fillPolygon(p);727}728729/**730* Draws the text given by the specified string, using this731* graphics context's current font and color. The baseline of the732* leftmost character is at position (<i>x</i>, <i>y</i>) in this733* graphics context's coordinate system.734* @param str the string to be drawn.735* @param x the <i>x</i> coordinate.736* @param y the <i>y</i> coordinate.737* @see java.awt.Graphics#drawBytes738* @see java.awt.Graphics#drawChars739*/740public void drawString(String str, int x, int y) {741g.drawString(str, x, y);742}743744/**745* Draws the text given by the specified iterator, using this746* graphics context's current color. The iterator has to specify a font747* for each character. The baseline of the748* leftmost character is at position (<i>x</i>, <i>y</i>) in this749* graphics context's coordinate system.750* @param iterator the iterator whose text is to be drawn751* @param x the <i>x</i> coordinate.752* @param y the <i>y</i> coordinate.753* @see java.awt.Graphics#drawBytes754* @see java.awt.Graphics#drawChars755*/756public void drawString(AttributedCharacterIterator iterator,757int x, int y) {758g.drawString(iterator, x, y);759}760761/**762* Draws the text given by the specified character array, using this763* graphics context's current font and color. The baseline of the764* first character is at position (<i>x</i>, <i>y</i>) in this765* graphics context's coordinate system.766* @param data the array of characters to be drawn767* @param offset the start offset in the data768* @param length the number of characters to be drawn769* @param x the <i>x</i> coordinate of the baseline of the text770* @param y the <i>y</i> coordinate of the baseline of the text771* @see java.awt.Graphics#drawBytes772* @see java.awt.Graphics#drawString773*/774public void drawChars(char[] data, int offset, int length, int x, int y) {775g.drawChars(data, offset, length, x, y);776}777778/**779* Draws the text given by the specified byte array, using this780* graphics context's current font and color. The baseline of the781* first character is at position (<i>x</i>, <i>y</i>) in this782* graphics context's coordinate system.783* @param data the data to be drawn784* @param offset the start offset in the data785* @param length the number of bytes that are drawn786* @param x the <i>x</i> coordinate of the baseline of the text787* @param y the <i>y</i> coordinate of the baseline of the text788* @see java.awt.Graphics#drawChars789* @see java.awt.Graphics#drawString790*/791public void drawBytes(byte[] data, int offset, int length, int x, int y) {792g.drawBytes(data, offset, length, x, y);793}794795/**796* Draws as much of the specified image as is currently available.797* The image is drawn with its top-left corner at798* (<i>x</i>, <i>y</i>) in this graphics context's coordinate799* space. Transparent pixels in the image do not affect whatever800* pixels are already there.801* <p>802* This method returns immediately in all cases, even if the803* complete image has not yet been loaded, and it has not been dithered804* and converted for the current output device.805* <p>806* If the image has not yet been completely loaded, then807* {@code drawImage} returns {@code false}. As more of808* the image becomes available, the process that draws the image notifies809* the specified image observer.810* @param img the specified image to be drawn.811* @param x the <i>x</i> coordinate.812* @param y the <i>y</i> coordinate.813* @param observer object to be notified as more of814* the image is converted.815* @see java.awt.Image816* @see java.awt.image.ImageObserver817* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)818*/819public boolean drawImage(Image img, int x, int y,820ImageObserver observer) {821return g.drawImage(img, x, y, observer);822}823824/**825* Draws as much of the specified image as has already been scaled826* to fit inside the specified rectangle.827* <p>828* The image is drawn inside the specified rectangle of this829* graphics context's coordinate space, and is scaled if830* necessary. Transparent pixels do not affect whatever pixels831* are already there.832* <p>833* This method returns immediately in all cases, even if the834* entire image has not yet been scaled, dithered, and converted835* for the current output device.836* If the current output representation is not yet complete, then837* {@code drawImage} returns {@code false}. As more of838* the image becomes available, the process that draws the image notifies839* the image observer by calling its {@code imageUpdate} method.840* <p>841* A scaled version of an image will not necessarily be842* available immediately just because an unscaled version of the843* image has been constructed for this output device. Each size of844* the image may be cached separately and generated from the original845* data in a separate image production sequence.846* @param img the specified image to be drawn.847* @param x the <i>x</i> coordinate.848* @param y the <i>y</i> coordinate.849* @param width the width of the rectangle.850* @param height the height of the rectangle.851* @param observer object to be notified as more of852* the image is converted.853* @see java.awt.Image854* @see java.awt.image.ImageObserver855* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)856*/857public boolean drawImage(Image img, int x, int y,858int width, int height,859ImageObserver observer) {860return g.drawImage(img, x, y, width, height, observer);861}862863/**864* Draws as much of the specified image as is currently available.865* The image is drawn with its top-left corner at866* (<i>x</i>, <i>y</i>) in this graphics context's coordinate867* space. Transparent pixels are drawn in the specified868* background color.869* <p>870* This operation is equivalent to filling a rectangle of the871* width and height of the specified image with the given color and then872* drawing the image on top of it, but possibly more efficient.873* <p>874* This method returns immediately in all cases, even if the875* complete image has not yet been loaded, and it has not been dithered876* and converted for the current output device.877* <p>878* If the image has not yet been completely loaded, then879* {@code drawImage} returns {@code false}. As more of880* the image becomes available, the process that draws the image notifies881* the specified image observer.882* @param img the specified image to be drawn.883* @param x the <i>x</i> coordinate.884* @param y the <i>y</i> coordinate.885* @param bgcolor the background color to paint under the886* non-opaque portions of the image.887* @param observer object to be notified as more of888* the image is converted.889* @see java.awt.Image890* @see java.awt.image.ImageObserver891* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)892*/893public boolean drawImage(Image img, int x, int y,894Color bgcolor,895ImageObserver observer) {896return g.drawImage(img, x, y, bgcolor, observer);897}898899/**900* Draws as much of the specified image as has already been scaled901* to fit inside the specified rectangle.902* <p>903* The image is drawn inside the specified rectangle of this904* graphics context's coordinate space, and is scaled if905* necessary. Transparent pixels are drawn in the specified906* background color.907* This operation is equivalent to filling a rectangle of the908* width and height of the specified image with the given color and then909* drawing the image on top of it, but possibly more efficient.910* <p>911* This method returns immediately in all cases, even if the912* entire image has not yet been scaled, dithered, and converted913* for the current output device.914* If the current output representation is not yet complete then915* {@code drawImage} returns {@code false}. As more of916* the image becomes available, the process that draws the image notifies917* the specified image observer.918* <p>919* A scaled version of an image will not necessarily be920* available immediately just because an unscaled version of the921* image has been constructed for this output device. Each size of922* the image may be cached separately and generated from the original923* data in a separate image production sequence.924* @param img the specified image to be drawn.925* @param x the <i>x</i> coordinate.926* @param y the <i>y</i> coordinate.927* @param width the width of the rectangle.928* @param height the height of the rectangle.929* @param bgcolor the background color to paint under the930* non-opaque portions of the image.931* @param observer object to be notified as more of932* the image is converted.933* @see java.awt.Image934* @see java.awt.image.ImageObserver935* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)936*/937public boolean drawImage(Image img, int x, int y,938int width, int height,939Color bgcolor,940ImageObserver observer) {941942return g.drawImage(img, x, y, width, height, bgcolor, observer);943}944945/**946* Draws as much of the specified area of the specified image as is947* currently available, scaling it on the fly to fit inside the948* specified area of the destination drawable surface. Transparent pixels949* do not affect whatever pixels are already there.950* <p>951* This method returns immediately in all cases, even if the952* image area to be drawn has not yet been scaled, dithered, and converted953* for the current output device.954* If the current output representation is not yet complete then955* {@code drawImage} returns {@code false}. As more of956* the image becomes available, the process that draws the image notifies957* the specified image observer.958* <p>959* This method always uses the unscaled version of the image960* to render the scaled rectangle and performs the required961* scaling on the fly. It does not use a cached, scaled version962* of the image for this operation. Scaling of the image from source963* to destination is performed such that the first coordinate964* of the source rectangle is mapped to the first coordinate of965* the destination rectangle, and the second source coordinate is966* mapped to the second destination coordinate. The subimage is967* scaled and flipped as needed to preserve those mappings.968* @param img the specified image to be drawn969* @param dx1 the <i>x</i> coordinate of the first corner of the970* destination rectangle.971* @param dy1 the <i>y</i> coordinate of the first corner of the972* destination rectangle.973* @param dx2 the <i>x</i> coordinate of the second corner of the974* destination rectangle.975* @param dy2 the <i>y</i> coordinate of the second corner of the976* destination rectangle.977* @param sx1 the <i>x</i> coordinate of the first corner of the978* source rectangle.979* @param sy1 the <i>y</i> coordinate of the first corner of the980* source rectangle.981* @param sx2 the <i>x</i> coordinate of the second corner of the982* source rectangle.983* @param sy2 the <i>y</i> coordinate of the second corner of the984* source rectangle.985* @param observer object to be notified as more of the image is986* scaled and converted.987* @see java.awt.Image988* @see java.awt.image.ImageObserver989* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)990* @since 1.1991*/992public boolean drawImage(Image img,993int dx1, int dy1, int dx2, int dy2,994int sx1, int sy1, int sx2, int sy2,995ImageObserver observer) {996997return g.drawImage(img, dx1, dy1, dx2, dy2,998sx1, sy1, sx2, sy2,999observer);1000}10011002/**1003* Draws as much of the specified area of the specified image as is1004* currently available, scaling it on the fly to fit inside the1005* specified area of the destination drawable surface.1006* <p>1007* Transparent pixels are drawn in the specified background color.1008* This operation is equivalent to filling a rectangle of the1009* width and height of the specified image with the given color and then1010* drawing the image on top of it, but possibly more efficient.1011* <p>1012* This method returns immediately in all cases, even if the1013* image area to be drawn has not yet been scaled, dithered, and converted1014* for the current output device.1015* If the current output representation is not yet complete then1016* {@code drawImage} returns {@code false}. As more of1017* the image becomes available, the process that draws the image notifies1018* the specified image observer.1019* <p>1020* This method always uses the unscaled version of the image1021* to render the scaled rectangle and performs the required1022* scaling on the fly. It does not use a cached, scaled version1023* of the image for this operation. Scaling of the image from source1024* to destination is performed such that the first coordinate1025* of the source rectangle is mapped to the first coordinate of1026* the destination rectangle, and the second source coordinate is1027* mapped to the second destination coordinate. The subimage is1028* scaled and flipped as needed to preserve those mappings.1029* @param img the specified image to be drawn1030* @param dx1 the <i>x</i> coordinate of the first corner of the1031* destination rectangle.1032* @param dy1 the <i>y</i> coordinate of the first corner of the1033* destination rectangle.1034* @param dx2 the <i>x</i> coordinate of the second corner of the1035* destination rectangle.1036* @param dy2 the <i>y</i> coordinate of the second corner of the1037* destination rectangle.1038* @param sx1 the <i>x</i> coordinate of the first corner of the1039* source rectangle.1040* @param sy1 the <i>y</i> coordinate of the first corner of the1041* source rectangle.1042* @param sx2 the <i>x</i> coordinate of the second corner of the1043* source rectangle.1044* @param sy2 the <i>y</i> coordinate of the second corner of the1045* source rectangle.1046* @param bgcolor the background color to paint under the1047* non-opaque portions of the image.1048* @param observer object to be notified as more of the image is1049* scaled and converted.1050* @see java.awt.Image1051* @see java.awt.image.ImageObserver1052* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)1053* @since 1.11054*/1055public boolean drawImage(Image img,1056int dx1, int dy1, int dx2, int dy2,1057int sx1, int sy1, int sx2, int sy2,1058Color bgcolor,1059ImageObserver observer) {10601061return g.drawImage(img, dx1, dy1, dx2, dy2,1062sx1, sy1, sx2, sy2,1063bgcolor,1064observer);1065}10661067/**1068* Disposes of this graphics context and releases1069* any system resources that it is using.1070* A {@code Graphics} object cannot be used after1071* {@code dispose} has been called.1072* <p>1073* When a Java program runs, a large number of {@code Graphics}1074* objects can be created within a short time frame.1075* Although the finalization process of the garbage collector1076* also disposes of the same system resources, it is preferable1077* to manually free the associated resources by calling this1078* method rather than to rely on a finalization process which1079* may not run to completion for a long period of time.1080* <p>1081* Graphics objects which are provided as arguments to the1082* {@code paint} and {@code update} methods1083* of components are automatically released by the system when1084* those methods return. For efficiency, programmers should1085* call {@code dispose} when finished using1086* a {@code Graphics} object only if it was created1087* directly from a component or another {@code Graphics} object.1088* @see java.awt.Graphics#finalize1089* @see java.awt.Component#paint1090* @see java.awt.Component#update1091* @see java.awt.Component#getGraphics1092* @see java.awt.Graphics#create1093*/1094public void dispose() {1095g.dispose();1096}10971098/**1099* Empty finalizer as no clean up needed here.1100*/1101@SuppressWarnings("deprecation")1102public void finalize() {1103}11041105/**1106* Returns a {@code String} object representing this1107* {@code Graphics} object's value.1108* @return a string representation of this graphics context.1109*/1110public String toString() {1111return getClass().getName() + "[font=" + getFont() + ",color=" + getColor() + "]";1112}11131114/**1115* @deprecated As of JDK version 1.1,1116* replaced by {@code getClipBounds()}.1117*/1118@Deprecated1119public Rectangle getClipRect() {1120return g.getClipRect();1121}11221123/**1124* Returns true if the specified rectangular area intersects1125* the bounding rectangle of the current clipping area.1126* The coordinates in the rectangle are relative to the coordinate1127* system origin of this graphics context.1128*1129* @param x the x coordinate of the rectangle to test against the clip1130* @param y the y coordinate of the rectangle to test against the clip1131* @param width the width of the rectangle to test against the clip1132* @param height the height of the rectangle to test against the clip1133*/1134public boolean hitClip(int x, int y, int width, int height) {1135return g.hitClip(x, y, width, height);1136}11371138/**1139* Returns the bounding rectangle of the current clipping area.1140* The coordinates in the rectangle are relative to the coordinate1141* system origin of this graphics context. This method differs1142* from {@link #getClipBounds() getClipBounds} in that an existing1143* rectangle is used instead of allocating a new one.1144* This method refers to the user clip, which is independent of the1145* clipping associated with device bounds and window visibility.1146* If no clip has previously been set, or if the clip has been1147* cleared using {@code setClip(null)}, this method returns the1148* specified {@code Rectangle}.1149* @param r the rectangle where the current clipping area is1150* copied to. Any current values in this rectangle are1151* overwritten.1152* @return the bounding rectangle of the current clipping area.1153*/1154public Rectangle getClipBounds(Rectangle r) {1155return g.getClipBounds(r);1156}1157}115811591160