1 /* 2 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt; 27 28 import java.awt.RenderingHints.Key; 29 import java.awt.geom.AffineTransform; 30 import java.awt.image.ImageObserver; 31 import java.awt.image.BufferedImageOp; 32 import java.awt.image.BufferedImage; 33 import java.awt.image.RenderedImage; 34 import java.awt.image.renderable.RenderableImage; 35 import java.awt.font.GlyphVector; 36 import java.awt.font.FontRenderContext; 37 import java.awt.font.TextAttribute; 38 import java.text.AttributedCharacterIterator; 39 import java.util.Map; 40 41 /** 42 * This {@code Graphics2D} class extends the 43 * {@link Graphics} class to provide more sophisticated 44 * control over geometry, coordinate transformations, color management, 45 * and text layout. This is the fundamental class for rendering 46 * 2-dimensional shapes, text and images on the Java(tm) platform. 47 * 48 * <h2>Coordinate Spaces</h2> 49 * All coordinates passed to a {@code Graphics2D} object are specified 50 * in a device-independent coordinate system called User Space, which is 51 * used by applications. The {@code Graphics2D} object contains 52 * an {@link AffineTransform} object as part of its rendering state 53 * that defines how to convert coordinates from user space to 54 * device-dependent coordinates in Device Space. 55 * <p> 56 * Coordinates in device space usually refer to individual device pixels 57 * and are aligned on the infinitely thin gaps between these pixels. 58 * Some {@code Graphics2D} objects can be used to capture rendering 59 * operations for storage into a graphics metafile for playback on a 60 * concrete device of unknown physical resolution at a later time. Since 61 * the resolution might not be known when the rendering operations are 62 * captured, the {@code Graphics2D Transform} is set up 63 * to transform user coordinates to a virtual device space that 64 * approximates the expected resolution of the target device. Further 65 * transformations might need to be applied at playback time if the 66 * estimate is incorrect. 67 * <p> 68 * Some of the operations performed by the rendering attribute objects 69 * occur in the device space, but all {@code Graphics2D} methods take 70 * user space coordinates. 71 * <p> 72 * Every {@code Graphics2D} object is associated with a target that 73 * defines where rendering takes place. A 74 * {@link GraphicsConfiguration} object defines the characteristics 75 * of the rendering target, such as pixel format and resolution. 76 * The same rendering target is used throughout the life of a 77 * {@code Graphics2D} object. 78 * <p> 79 * When creating a {@code Graphics2D} object, the 80 * {@code GraphicsConfiguration} 81 * specifies the <a id="deftransform">default transform</a> for 82 * the target of the {@code Graphics2D} (a 83 * {@link Component} or {@link Image}). This default transform maps the 84 * user space coordinate system to screen and printer device coordinates 85 * such that the origin maps to the upper left hand corner of the 86 * target region of the device with increasing X coordinates extending 87 * to the right and increasing Y coordinates extending downward. 88 * The scaling of the default transform is set to identity for those devices 89 * that are close to 72 dpi, such as screen devices. 90 * The scaling of the default transform is set to approximately 72 user 91 * space coordinates per square inch for high resolution devices, such as 92 * printers. For image buffers, the default transform is the 93 * {@code Identity} transform. 94 * 95 * <h2>Rendering Process</h2> 96 * The Rendering Process can be broken down into four phases that are 97 * controlled by the {@code Graphics2D} rendering attributes. 98 * The renderer can optimize many of these steps, either by caching the 99 * results for future calls, by collapsing multiple virtual steps into 100 * a single operation, or by recognizing various attributes as common 101 * simple cases that can be eliminated by modifying other parts of the 102 * operation. 103 * <p> 104 * The steps in the rendering process are: 105 * <ol> 106 * <li> 107 * Determine what to render. 108 * <li> 109 * Constrain the rendering operation to the current {@code Clip}. 110 * The {@code Clip} is specified by a {@link Shape} in user 111 * space and is controlled by the program using the various clip 112 * manipulation methods of {@code Graphics} and 113 * {@code Graphics2D}. This <i>user clip</i> 114 * is transformed into device space by the current 115 * {@code Transform} and combined with the 116 * <i>device clip</i>, which is defined by the visibility of windows and 117 * device extents. The combination of the user clip and device clip 118 * defines the <i>composite clip</i>, which determines the final clipping 119 * region. The user clip is not modified by the rendering 120 * system to reflect the resulting composite clip. 121 * <li> 122 * Determine what colors to render. 123 * <li> 124 * Apply the colors to the destination drawing surface using the current 125 * {@link Composite} attribute in the {@code Graphics2D} context. 126 * </ol> 127 * <br> 128 * The three types of rendering operations, along with details of each 129 * of their particular rendering processes are: 130 * <ol> 131 * <li> 132 * <b><a id="rendershape">{@code Shape} operations</a></b> 133 * <ol> 134 * <li> 135 * If the operation is a {@code draw(Shape)} operation, then 136 * the {@link Stroke#createStrokedShape(Shape) createStrokedShape} 137 * method on the current {@link Stroke} attribute in the 138 * {@code Graphics2D} context is used to construct a new 139 * {@code Shape} object that contains the outline of the specified 140 * {@code Shape}. 141 * <li> 142 * The {@code Shape} is transformed from user space to device space 143 * using the current {@code Transform} 144 * in the {@code Graphics2D} context. 145 * <li> 146 * The outline of the {@code Shape} is extracted using the 147 * {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of 148 * {@code Shape}, which returns a 149 * {@link java.awt.geom.PathIterator PathIterator} 150 * object that iterates along the boundary of the {@code Shape}. 151 * <li> 152 * If the {@code Graphics2D} object cannot handle the curved segments 153 * that the {@code PathIterator} object returns then it can call the 154 * alternate 155 * {@link Shape#getPathIterator(AffineTransform, double) getPathIterator} 156 * method of {@code Shape}, which flattens the {@code Shape}. 157 * <li> 158 * The current {@link Paint} in the {@code Graphics2D} context 159 * is queried for a {@link PaintContext}, which specifies the 160 * colors to render in device space. 161 * </ol> 162 * <li> 163 * <b><a id=rendertext>Text operations</a></b> 164 * <ol> 165 * <li> 166 * The following steps are used to determine the set of glyphs required 167 * to render the indicated {@code String}: 168 * <ol> 169 * <li> 170 * If the argument is a {@code String}, then the current 171 * {@code Font} in the {@code Graphics2D} context is asked to 172 * convert the Unicode characters in the {@code String} into a set of 173 * glyphs for presentation with whatever basic layout and shaping 174 * algorithms the font implements. 175 * <li> 176 * If the argument is an 177 * {@link AttributedCharacterIterator}, 178 * the iterator is asked to convert itself to a 179 * {@link java.awt.font.TextLayout TextLayout} 180 * using its embedded font attributes. The {@code TextLayout} 181 * implements more sophisticated glyph layout algorithms that 182 * perform Unicode bi-directional layout adjustments automatically 183 * for multiple fonts of differing writing directions. 184 * <li> 185 * If the argument is a 186 * {@link GlyphVector}, then the 187 * {@code GlyphVector} object already contains the appropriate 188 * font-specific glyph codes with explicit coordinates for the position of 189 * each glyph. 190 * </ol> 191 * <li> 192 * The current {@code Font} is queried to obtain outlines for the 193 * indicated glyphs. These outlines are treated as shapes in user space 194 * relative to the position of each glyph that was determined in step 1. 195 * <li> 196 * The character outlines are filled as indicated above 197 * under <a href="#rendershape">{@code Shape} operations</a>. 198 * <li> 199 * The current {@code Paint} is queried for a 200 * {@code PaintContext}, which specifies 201 * the colors to render in device space. 202 * </ol> 203 * <li> 204 * <b><a id= renderingimage>{@code Image} Operations</a></b> 205 * <ol> 206 * <li> 207 * The region of interest is defined by the bounding box of the source 208 * {@code Image}. 209 * This bounding box is specified in Image Space, which is the 210 * {@code Image} object's local coordinate system. 211 * <li> 212 * If an {@code AffineTransform} is passed to 213 * {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)}, 214 * the {@code AffineTransform} is used to transform the bounding 215 * box from image space to user space. If no {@code AffineTransform} 216 * is supplied, the bounding box is treated as if it is already in user space. 217 * <li> 218 * The bounding box of the source {@code Image} is transformed from user 219 * space into device space using the current {@code Transform}. 220 * Note that the result of transforming the bounding box does not 221 * necessarily result in a rectangular region in device space. 222 * <li> 223 * The {@code Image} object determines what colors to render, 224 * sampled according to the source to destination 225 * coordinate mapping specified by the current {@code Transform} and the 226 * optional image transform. 227 * </ol> 228 * </ol> 229 * 230 * <h2>Default Rendering Attributes</h2> 231 * The default values for the {@code Graphics2D} rendering attributes are: 232 * <dl> 233 * <dt><i>{@code Paint}</i> 234 * <dd>The color of the {@code Component}. 235 * <dt><i>{@code Font}</i> 236 * <dd>The {@code Font} of the {@code Component}. 237 * <dt><i>{@code Stroke}</i> 238 * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins 239 * and square end caps. 240 * <dt><i>{@code Transform}</i> 241 * <dd>The 242 * {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform} 243 * for the {@code GraphicsConfiguration} of the {@code Component}. 244 * <dt><i>{@code Composite}</i> 245 * <dd>The {@link AlphaComposite#SRC_OVER} rule. 246 * <dt><i>{@code Clip}</i> 247 * <dd>No rendering {@code Clip}, the output is clipped to the 248 * {@code Component}. 249 * </dl> 250 * 251 * <h2>Rendering Compatibility Issues</h2> 252 * The JDK(tm) 1.1 rendering model is based on a pixelization model 253 * that specifies that coordinates 254 * are infinitely thin, lying between the pixels. Drawing operations are 255 * performed using a one-pixel wide pen that fills the 256 * pixel below and to the right of the anchor point on the path. 257 * The JDK 1.1 rendering model is consistent with the 258 * capabilities of most of the existing class of platform 259 * renderers that need to resolve integer coordinates to a 260 * discrete pen that must fall completely on a specified number of pixels. 261 * <p> 262 * The Java 2D(tm) (Java(tm) 2 platform) API supports antialiasing renderers. 263 * A pen with a width of one pixel does not need to fall 264 * completely on pixel N as opposed to pixel N+1. The pen can fall 265 * partially on both pixels. It is not necessary to choose a bias 266 * direction for a wide pen since the blending that occurs along the 267 * pen traversal edges makes the sub-pixel position of the pen 268 * visible to the user. On the other hand, when antialiasing is 269 * turned off by setting the 270 * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint key 271 * to the 272 * {@link RenderingHints#VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_OFF} 273 * hint value, the renderer might need 274 * to apply a bias to determine which pixel to modify when the pen 275 * is straddling a pixel boundary, such as when it is drawn 276 * along an integer coordinate in device space. While the capabilities 277 * of an antialiasing renderer make it no longer necessary for the 278 * rendering model to specify a bias for the pen, it is desirable for the 279 * antialiasing and non-antialiasing renderers to perform similarly for 280 * the common cases of drawing one-pixel wide horizontal and vertical 281 * lines on the screen. To ensure that turning on antialiasing by 282 * setting the 283 * {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint 284 * key to 285 * {@link RenderingHints#VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_ON} 286 * does not cause such lines to suddenly become twice as wide and half 287 * as opaque, it is desirable to have the model specify a path for such 288 * lines so that they completely cover a particular set of pixels to help 289 * increase their crispness. 290 * <p> 291 * Java 2D API maintains compatibility with JDK 1.1 rendering 292 * behavior, such that legacy operations and existing renderer 293 * behavior is unchanged under Java 2D API. Legacy 294 * methods that map onto general {@code draw} and 295 * {@code fill} methods are defined, which clearly indicates 296 * how {@code Graphics2D} extends {@code Graphics} based 297 * on settings of {@code Stroke} and {@code Transform} 298 * attributes and rendering hints. The definition 299 * performs identically under default attribute settings. 300 * For example, the default {@code Stroke} is a 301 * {@code BasicStroke} with a width of 1 and no dashing and the 302 * default Transform for screen drawing is an Identity transform. 303 * <p> 304 * The following two rules provide predictable rendering behavior whether 305 * aliasing or antialiasing is being used. 306 * <ul> 307 * <li> Device coordinates are defined to be between device pixels which 308 * avoids any inconsistent results between aliased and antialiased 309 * rendering. If coordinates were defined to be at a pixel's center, some 310 * of the pixels covered by a shape, such as a rectangle, would only be 311 * half covered. 312 * With aliased rendering, the half covered pixels would either be 313 * rendered inside the shape or outside the shape. With anti-aliased 314 * rendering, the pixels on the entire edge of the shape would be half 315 * covered. On the other hand, since coordinates are defined to be 316 * between pixels, a shape like a rectangle would have no half covered 317 * pixels, whether or not it is rendered using antialiasing. 318 * <li> Lines and paths stroked using the {@code BasicStroke} 319 * object may be "normalized" to provide consistent rendering of the 320 * outlines when positioned at various points on the drawable and 321 * whether drawn with aliased or antialiased rendering. This 322 * normalization process is controlled by the 323 * {@link RenderingHints#KEY_STROKE_CONTROL KEY_STROKE_CONTROL} hint. 324 * The exact normalization algorithm is not specified, but the goals 325 * of this normalization are to ensure that lines are rendered with 326 * consistent visual appearance regardless of how they fall on the 327 * pixel grid and to promote more solid horizontal and vertical 328 * lines in antialiased mode so that they resemble their non-antialiased 329 * counterparts more closely. A typical normalization step might 330 * promote antialiased line endpoints to pixel centers to reduce the 331 * amount of blending or adjust the subpixel positioning of 332 * non-antialiased lines so that the floating point line widths 333 * round to even or odd pixel counts with equal likelihood. This 334 * process can move endpoints by up to half a pixel (usually towards 335 * positive infinity along both axes) to promote these consistent 336 * results. 337 * </ul> 338 * <p> 339 * The following definitions of general legacy methods 340 * perform identically to previously specified behavior under default 341 * attribute settings: 342 * <ul> 343 * <li> 344 * For {@code fill} operations, including {@code fillRect}, 345 * {@code fillRoundRect}, {@code fillOval}, 346 * {@code fillArc}, {@code fillPolygon}, and 347 * {@code clearRect}, {@link #fill(Shape) fill} can now be called 348 * with the desired {@code Shape}. For example, when filling a 349 * rectangle: 350 * <pre> 351 * fill(new Rectangle(x, y, w, h)); 352 * </pre> 353 * is called. 354 * 355 * <li> 356 * Similarly, for draw operations, including {@code drawLine}, 357 * {@code drawRect}, {@code drawRoundRect}, 358 * {@code drawOval}, {@code drawArc}, {@code drawPolyline}, 359 * and {@code drawPolygon}, {@link #draw(Shape) draw} can now be 360 * called with the desired {@code Shape}. For example, when drawing a 361 * rectangle: 362 * <pre> 363 * draw(new Rectangle(x, y, w, h)); 364 * </pre> 365 * is called. 366 * 367 * <li> 368 * The {@code draw3DRect} and {@code fill3DRect} methods were 369 * implemented in terms of the {@code drawLine} and 370 * {@code fillRect} methods in the {@code Graphics} class which 371 * would predicate their behavior upon the current {@code Stroke} 372 * and {@code Paint} objects in a {@code Graphics2D} context. 373 * This class overrides those implementations with versions that use 374 * the current {@code Color} exclusively, overriding the current 375 * {@code Paint} and which uses {@code fillRect} to describe 376 * the exact same behavior as the preexisting methods regardless of the 377 * setting of the current {@code Stroke}. 378 * </ul> 379 * The {@code Graphics} class defines only the {@code setColor} 380 * method to control the color to be painted. Since the Java 2D API extends 381 * the {@code Color} object to implement the new {@code Paint} 382 * interface, the existing 383 * {@code setColor} method is now a convenience method for setting the 384 * current {@code Paint} attribute to a {@code Color} object. 385 * {@code setColor(c)} is equivalent to {@code setPaint(c)}. 386 * <p> 387 * The {@code Graphics} class defines two methods for controlling 388 * how colors are applied to the destination. 389 * <ol> 390 * <li> 391 * The {@code setPaintMode} method is implemented as a convenience 392 * method to set the default {@code Composite}, equivalent to 393 * {@code setComposite(new AlphaComposite.SrcOver)}. 394 * <li> 395 * The {@code setXORMode(Color xorcolor)} method is implemented 396 * as a convenience method to set a special {@code Composite} object that 397 * ignores the {@code Alpha} components of source colors and sets the 398 * destination color to the value: 399 * <pre> 400 * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel); 401 * </pre> 402 * </ol> 403 * 404 * @author Jim Graham 405 * @see java.awt.RenderingHints 406 */ 407 public abstract class Graphics2D extends Graphics { 408 409 /** 410 * Constructs a new {@code Graphics2D} object. Since 411 * {@code Graphics2D} is an abstract class, and since it must be 412 * customized by subclasses for different output devices, 413 * {@code Graphics2D} objects cannot be created directly. 414 * Instead, {@code Graphics2D} objects must be obtained from another 415 * {@code Graphics2D} object, created by a 416 * {@code Component}, or obtained from images such as 417 * {@link BufferedImage} objects. 418 * @see java.awt.Component#getGraphics 419 * @see java.awt.Graphics#create 420 */ Graphics2D()421 protected Graphics2D() { 422 } 423 424 /** 425 * Draws a 3-D highlighted outline of the specified rectangle. 426 * The edges of the rectangle are highlighted so that they 427 * appear to be beveled and lit from the upper left corner. 428 * <p> 429 * The colors used for the highlighting effect are determined 430 * based on the current color. 431 * The resulting rectangle covers an area that is 432 * <code>width + 1</code> pixels wide 433 * by <code>height + 1</code> pixels tall. This method 434 * uses the current {@code Color} exclusively and ignores 435 * the current {@code Paint}. 436 * @param x the x coordinate of the rectangle to be drawn. 437 * @param y the y coordinate of the rectangle to be drawn. 438 * @param width the width of the rectangle to be drawn. 439 * @param height the height of the rectangle to be drawn. 440 * @param raised a boolean that determines whether the rectangle 441 * appears to be raised above the surface 442 * or sunk into the surface. 443 * @see java.awt.Graphics#fill3DRect 444 */ draw3DRect(int x, int y, int width, int height, boolean raised)445 public void draw3DRect(int x, int y, int width, int height, 446 boolean raised) { 447 Paint p = getPaint(); 448 Color c = getColor(); 449 Color brighter = c.brighter(); 450 Color darker = c.darker(); 451 452 setColor(raised ? brighter : darker); 453 //drawLine(x, y, x, y + height); 454 fillRect(x, y, 1, height + 1); 455 //drawLine(x + 1, y, x + width - 1, y); 456 fillRect(x + 1, y, width - 1, 1); 457 setColor(raised ? darker : brighter); 458 //drawLine(x + 1, y + height, x + width, y + height); 459 fillRect(x + 1, y + height, width, 1); 460 //drawLine(x + width, y, x + width, y + height - 1); 461 fillRect(x + width, y, 1, height); 462 setPaint(p); 463 } 464 465 /** 466 * Paints a 3-D highlighted rectangle filled with the current color. 467 * The edges of the rectangle are highlighted so that it appears 468 * as if the edges were beveled and lit from the upper left corner. 469 * The colors used for the highlighting effect and for filling are 470 * determined from the current {@code Color}. This method uses 471 * the current {@code Color} exclusively and ignores the current 472 * {@code Paint}. 473 * @param x the x coordinate of the rectangle to be filled. 474 * @param y the y coordinate of the rectangle to be filled. 475 * @param width the width of the rectangle to be filled. 476 * @param height the height of the rectangle to be filled. 477 * @param raised a boolean value that determines whether the 478 * rectangle appears to be raised above the surface 479 * or etched into the surface. 480 * @see java.awt.Graphics#draw3DRect 481 */ fill3DRect(int x, int y, int width, int height, boolean raised)482 public void fill3DRect(int x, int y, int width, int height, 483 boolean raised) { 484 Paint p = getPaint(); 485 Color c = getColor(); 486 Color brighter = c.brighter(); 487 Color darker = c.darker(); 488 489 if (!raised) { 490 setColor(darker); 491 } else if (p != c) { 492 setColor(c); 493 } 494 fillRect(x+1, y+1, width-2, height-2); 495 setColor(raised ? brighter : darker); 496 //drawLine(x, y, x, y + height - 1); 497 fillRect(x, y, 1, height); 498 //drawLine(x + 1, y, x + width - 2, y); 499 fillRect(x + 1, y, width - 2, 1); 500 setColor(raised ? darker : brighter); 501 //drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1); 502 fillRect(x + 1, y + height - 1, width - 1, 1); 503 //drawLine(x + width - 1, y, x + width - 1, y + height - 2); 504 fillRect(x + width - 1, y, 1, height - 1); 505 setPaint(p); 506 } 507 508 /** 509 * Strokes the outline of a {@code Shape} using the settings of the 510 * current {@code Graphics2D} context. The rendering attributes 511 * applied include the {@code Clip}, {@code Transform}, 512 * {@code Paint}, {@code Composite} and 513 * {@code Stroke} attributes. 514 * @param s the {@code Shape} to be rendered 515 * @see #setStroke 516 * @see #setPaint 517 * @see java.awt.Graphics#setColor 518 * @see #transform 519 * @see #setTransform 520 * @see #clip 521 * @see #setClip 522 * @see #setComposite 523 */ draw(Shape s)524 public abstract void draw(Shape s); 525 526 /** 527 * Renders an image, applying a transform from image space into user space 528 * before drawing. 529 * The transformation from user space into device space is done with 530 * the current {@code Transform} in the {@code Graphics2D}. 531 * The specified transformation is applied to the image before the 532 * transform attribute in the {@code Graphics2D} context is applied. 533 * The rendering attributes applied include the {@code Clip}, 534 * {@code Transform}, and {@code Composite} attributes. 535 * Note that no rendering is done if the specified transform is 536 * noninvertible. 537 * @param img the specified image to be rendered. 538 * This method does nothing if {@code img} is null. 539 * @param xform the transformation from image space into user space 540 * @param obs the {@link ImageObserver} 541 * to be notified as more of the {@code Image} 542 * is converted 543 * @return {@code true} if the {@code Image} is 544 * fully loaded and completely rendered, or if it's null; 545 * {@code false} if the {@code Image} is still being loaded. 546 * @see #transform 547 * @see #setTransform 548 * @see #setComposite 549 * @see #clip 550 * @see #setClip 551 */ drawImage(Image img, AffineTransform xform, ImageObserver obs)552 public abstract boolean drawImage(Image img, 553 AffineTransform xform, 554 ImageObserver obs); 555 556 /** 557 * Renders a {@code BufferedImage} that is 558 * filtered with a 559 * {@link BufferedImageOp}. 560 * The rendering attributes applied include the {@code Clip}, 561 * {@code Transform} 562 * and {@code Composite} attributes. This is equivalent to: 563 * <pre> 564 * img1 = op.filter(img, null); 565 * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null); 566 * </pre> 567 * @param op the filter to be applied to the image before rendering 568 * @param img the specified {@code BufferedImage} to be rendered. 569 * This method does nothing if {@code img} is null. 570 * @param x the x coordinate of the location in user space where 571 * the upper left corner of the image is rendered 572 * @param y the y coordinate of the location in user space where 573 * the upper left corner of the image is rendered 574 * 575 * @see #transform 576 * @see #setTransform 577 * @see #setComposite 578 * @see #clip 579 * @see #setClip 580 */ drawImage(BufferedImage img, BufferedImageOp op, int x, int y)581 public abstract void drawImage(BufferedImage img, 582 BufferedImageOp op, 583 int x, 584 int y); 585 586 /** 587 * Renders a {@link RenderedImage}, 588 * applying a transform from image 589 * space into user space before drawing. 590 * The transformation from user space into device space is done with 591 * the current {@code Transform} in the {@code Graphics2D}. 592 * The specified transformation is applied to the image before the 593 * transform attribute in the {@code Graphics2D} context is applied. 594 * The rendering attributes applied include the {@code Clip}, 595 * {@code Transform}, and {@code Composite} attributes. Note 596 * that no rendering is done if the specified transform is 597 * noninvertible. 598 * @param img the image to be rendered. This method does 599 * nothing if {@code img} is null. 600 * @param xform the transformation from image space into user space 601 * @see #transform 602 * @see #setTransform 603 * @see #setComposite 604 * @see #clip 605 * @see #setClip 606 */ drawRenderedImage(RenderedImage img, AffineTransform xform)607 public abstract void drawRenderedImage(RenderedImage img, 608 AffineTransform xform); 609 610 /** 611 * Renders a 612 * {@link RenderableImage}, 613 * applying a transform from image space into user space before drawing. 614 * The transformation from user space into device space is done with 615 * the current {@code Transform} in the {@code Graphics2D}. 616 * The specified transformation is applied to the image before the 617 * transform attribute in the {@code Graphics2D} context is applied. 618 * The rendering attributes applied include the {@code Clip}, 619 * {@code Transform}, and {@code Composite} attributes. Note 620 * that no rendering is done if the specified transform is 621 * noninvertible. 622 *<p> 623 * Rendering hints set on the {@code Graphics2D} object might 624 * be used in rendering the {@code RenderableImage}. 625 * If explicit control is required over specific hints recognized by a 626 * specific {@code RenderableImage}, or if knowledge of which hints 627 * are used is required, then a {@code RenderedImage} should be 628 * obtained directly from the {@code RenderableImage} 629 * and rendered using 630 *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}. 631 * @param img the image to be rendered. This method does 632 * nothing if {@code img} is null. 633 * @param xform the transformation from image space into user space 634 * @see #transform 635 * @see #setTransform 636 * @see #setComposite 637 * @see #clip 638 * @see #setClip 639 * @see #drawRenderedImage 640 */ drawRenderableImage(RenderableImage img, AffineTransform xform)641 public abstract void drawRenderableImage(RenderableImage img, 642 AffineTransform xform); 643 644 /** 645 * Renders the text of the specified {@code String}, using the 646 * current text attribute state in the {@code Graphics2D} context. 647 * The baseline of the 648 * first character is at position (<i>x</i>, <i>y</i>) in 649 * the User Space. 650 * The rendering attributes applied include the {@code Clip}, 651 * {@code Transform}, {@code Paint}, {@code Font} and 652 * {@code Composite} attributes. For characters in script 653 * systems such as Hebrew and Arabic, the glyphs can be rendered from 654 * right to left, in which case the coordinate supplied is the 655 * location of the leftmost character on the baseline. 656 * @param str the string to be rendered 657 * @param x the x coordinate of the location where the 658 * {@code String} should be rendered 659 * @param y the y coordinate of the location where the 660 * {@code String} should be rendered 661 * @throws NullPointerException if {@code str} is 662 * {@code null} 663 * @see java.awt.Graphics#drawBytes 664 * @see java.awt.Graphics#drawChars 665 * @since 1.0 666 */ drawString(String str, int x, int y)667 public abstract void drawString(String str, int x, int y); 668 669 /** 670 * Renders the text specified by the specified {@code String}, 671 * using the current text attribute state in the {@code Graphics2D} context. 672 * The baseline of the first character is at position 673 * (<i>x</i>, <i>y</i>) in the User Space. 674 * The rendering attributes applied include the {@code Clip}, 675 * {@code Transform}, {@code Paint}, {@code Font} and 676 * {@code Composite} attributes. For characters in script systems 677 * such as Hebrew and Arabic, the glyphs can be rendered from right to 678 * left, in which case the coordinate supplied is the location of the 679 * leftmost character on the baseline. 680 * @param str the {@code String} to be rendered 681 * @param x the x coordinate of the location where the 682 * {@code String} should be rendered 683 * @param y the y coordinate of the location where the 684 * {@code String} should be rendered 685 * @throws NullPointerException if {@code str} is 686 * {@code null} 687 * @see #setPaint 688 * @see java.awt.Graphics#setColor 689 * @see java.awt.Graphics#setFont 690 * @see #setTransform 691 * @see #setComposite 692 * @see #setClip 693 */ drawString(String str, float x, float y)694 public abstract void drawString(String str, float x, float y); 695 696 /** 697 * Renders the text of the specified iterator applying its attributes 698 * in accordance with the specification of the {@link TextAttribute} class. 699 * <p> 700 * The baseline of the first character is at position 701 * (<i>x</i>, <i>y</i>) in User Space. 702 * For characters in script systems such as Hebrew and Arabic, 703 * the glyphs can be rendered from right to left, in which case the 704 * coordinate supplied is the location of the leftmost character 705 * on the baseline. 706 * @param iterator the iterator whose text is to be rendered 707 * @param x the x coordinate where the iterator's text is to be 708 * rendered 709 * @param y the y coordinate where the iterator's text is to be 710 * rendered 711 * @throws NullPointerException if {@code iterator} is 712 * {@code null} 713 * @see #setPaint 714 * @see java.awt.Graphics#setColor 715 * @see #setTransform 716 * @see #setComposite 717 * @see #setClip 718 */ drawString(AttributedCharacterIterator iterator, int x, int y)719 public abstract void drawString(AttributedCharacterIterator iterator, 720 int x, int y); 721 722 /** 723 * Renders the text of the specified iterator applying its attributes 724 * in accordance with the specification of the {@link TextAttribute} class. 725 * <p> 726 * The baseline of the first character is at position 727 * (<i>x</i>, <i>y</i>) in User Space. 728 * For characters in script systems such as Hebrew and Arabic, 729 * the glyphs can be rendered from right to left, in which case the 730 * coordinate supplied is the location of the leftmost character 731 * on the baseline. 732 * @param iterator the iterator whose text is to be rendered 733 * @param x the x coordinate where the iterator's text is to be 734 * rendered 735 * @param y the y coordinate where the iterator's text is to be 736 * rendered 737 * @throws NullPointerException if {@code iterator} is 738 * {@code null} 739 * @see #setPaint 740 * @see java.awt.Graphics#setColor 741 * @see #setTransform 742 * @see #setComposite 743 * @see #setClip 744 */ drawString(AttributedCharacterIterator iterator, float x, float y)745 public abstract void drawString(AttributedCharacterIterator iterator, 746 float x, float y); 747 748 /** 749 * Renders the text of the specified 750 * {@link GlyphVector} using 751 * the {@code Graphics2D} context's rendering attributes. 752 * The rendering attributes applied include the {@code Clip}, 753 * {@code Transform}, {@code Paint}, and 754 * {@code Composite} attributes. The {@code GlyphVector} 755 * specifies individual glyphs from a {@link Font}. 756 * The {@code GlyphVector} can also contain the glyph positions. 757 * This is the fastest way to render a set of characters to the 758 * screen. 759 * @param g the {@code GlyphVector} to be rendered 760 * @param x the x position in User Space where the glyphs should 761 * be rendered 762 * @param y the y position in User Space where the glyphs should 763 * be rendered 764 * @throws NullPointerException if {@code g} is {@code null}. 765 * 766 * @see java.awt.Font#createGlyphVector 767 * @see java.awt.font.GlyphVector 768 * @see #setPaint 769 * @see java.awt.Graphics#setColor 770 * @see #setTransform 771 * @see #setComposite 772 * @see #setClip 773 */ drawGlyphVector(GlyphVector g, float x, float y)774 public abstract void drawGlyphVector(GlyphVector g, float x, float y); 775 776 /** 777 * Fills the interior of a {@code Shape} using the settings of the 778 * {@code Graphics2D} context. The rendering attributes applied 779 * include the {@code Clip}, {@code Transform}, 780 * {@code Paint}, and {@code Composite}. 781 * @param s the {@code Shape} to be filled 782 * @see #setPaint 783 * @see java.awt.Graphics#setColor 784 * @see #transform 785 * @see #setTransform 786 * @see #setComposite 787 * @see #clip 788 * @see #setClip 789 */ fill(Shape s)790 public abstract void fill(Shape s); 791 792 /** 793 * Checks whether or not the specified {@code Shape} intersects 794 * the specified {@link Rectangle}, which is in device 795 * space. If {@code onStroke} is false, this method checks 796 * whether or not the interior of the specified {@code Shape} 797 * intersects the specified {@code Rectangle}. If 798 * {@code onStroke} is {@code true}, this method checks 799 * whether or not the {@code Stroke} of the specified 800 * {@code Shape} outline intersects the specified 801 * {@code Rectangle}. 802 * The rendering attributes taken into account include the 803 * {@code Clip}, {@code Transform}, and {@code Stroke} 804 * attributes. 805 * @param rect the area in device space to check for a hit 806 * @param s the {@code Shape} to check for a hit 807 * @param onStroke flag used to choose between testing the 808 * stroked or the filled shape. If the flag is {@code true}, the 809 * {@code Stroke} outline is tested. If the flag is 810 * {@code false}, the filled {@code Shape} is tested. 811 * @return {@code true} if there is a hit; {@code false} 812 * otherwise. 813 * @see #setStroke 814 * @see #fill 815 * @see #draw 816 * @see #transform 817 * @see #setTransform 818 * @see #clip 819 * @see #setClip 820 */ hit(Rectangle rect, Shape s, boolean onStroke)821 public abstract boolean hit(Rectangle rect, 822 Shape s, 823 boolean onStroke); 824 825 /** 826 * Returns the device configuration associated with this 827 * {@code Graphics2D}. 828 * @return the device configuration of this {@code Graphics2D}. 829 */ getDeviceConfiguration()830 public abstract GraphicsConfiguration getDeviceConfiguration(); 831 832 /** 833 * Sets the {@code Composite} for the {@code Graphics2D} context. 834 * The {@code Composite} is used in all drawing methods such as 835 * {@code drawImage}, {@code drawString}, {@code draw}, 836 * and {@code fill}. It specifies how new pixels are to be combined 837 * with the existing pixels on the graphics device during the rendering 838 * process. 839 * <p>If this {@code Graphics2D} context is drawing to a 840 * {@code Component} on the display screen and the 841 * {@code Composite} is a custom object rather than an 842 * instance of the {@code AlphaComposite} class, and if 843 * there is a security manager, its {@code checkPermission} 844 * method is called with an {@code AWTPermission("readDisplayPixels")} 845 * permission. 846 * @throws SecurityException 847 * if a custom {@code Composite} object is being 848 * used to render to the screen and a security manager 849 * is set and its {@code checkPermission} method 850 * does not allow the operation. 851 * @param comp the {@code Composite} object to be used for rendering 852 * @see java.awt.Graphics#setXORMode 853 * @see java.awt.Graphics#setPaintMode 854 * @see #getComposite 855 * @see AlphaComposite 856 * @see SecurityManager#checkPermission 857 * @see java.awt.AWTPermission 858 */ setComposite(Composite comp)859 public abstract void setComposite(Composite comp); 860 861 /** 862 * Sets the {@code Paint} attribute for the 863 * {@code Graphics2D} context. Calling this method 864 * with a {@code null Paint} object does 865 * not have any effect on the current {@code Paint} attribute 866 * of this {@code Graphics2D}. 867 * @param paint the {@code Paint} object to be used to generate 868 * color during the rendering process, or {@code null} 869 * @see java.awt.Graphics#setColor 870 * @see #getPaint 871 * @see GradientPaint 872 * @see TexturePaint 873 */ setPaint( Paint paint )874 public abstract void setPaint( Paint paint ); 875 876 /** 877 * Sets the {@code Stroke} for the {@code Graphics2D} context. 878 * @param s the {@code Stroke} object to be used to stroke a 879 * {@code Shape} during the rendering process 880 * @see BasicStroke 881 * @see #getStroke 882 */ setStroke(Stroke s)883 public abstract void setStroke(Stroke s); 884 885 /** 886 * Sets the value of a single preference for the rendering algorithms. 887 * Hint categories include controls for rendering quality and overall 888 * time/quality trade-off in the rendering process. Refer to the 889 * {@code RenderingHints} class for definitions of some common 890 * keys and values. 891 * @param hintKey the key of the hint to be set. 892 * @param hintValue the value indicating preferences for the specified 893 * hint category. 894 * @see #getRenderingHint(RenderingHints.Key) 895 * @see RenderingHints 896 */ setRenderingHint(Key hintKey, Object hintValue)897 public abstract void setRenderingHint(Key hintKey, Object hintValue); 898 899 /** 900 * Returns the value of a single preference for the rendering algorithms. 901 * Hint categories include controls for rendering quality and overall 902 * time/quality trade-off in the rendering process. Refer to the 903 * {@code RenderingHints} class for definitions of some common 904 * keys and values. 905 * @param hintKey the key corresponding to the hint to get. 906 * @return an object representing the value for the specified hint key. 907 * Some of the keys and their associated values are defined in the 908 * {@code RenderingHints} class. 909 * @see RenderingHints 910 * @see #setRenderingHint(RenderingHints.Key, Object) 911 */ getRenderingHint(Key hintKey)912 public abstract Object getRenderingHint(Key hintKey); 913 914 /** 915 * Replaces the values of all preferences for the rendering 916 * algorithms with the specified {@code hints}. 917 * The existing values for all rendering hints are discarded and 918 * the new set of known hints and values are initialized from the 919 * specified {@link Map} object. 920 * Hint categories include controls for rendering quality and 921 * overall time/quality trade-off in the rendering process. 922 * Refer to the {@code RenderingHints} class for definitions of 923 * some common keys and values. 924 * @param hints the rendering hints to be set 925 * @see #getRenderingHints 926 * @see RenderingHints 927 */ setRenderingHints(Map<?,?> hints)928 public abstract void setRenderingHints(Map<?,?> hints); 929 930 /** 931 * Sets the values of an arbitrary number of preferences for the 932 * rendering algorithms. 933 * Only values for the rendering hints that are present in the 934 * specified {@code Map} object are modified. 935 * All other preferences not present in the specified 936 * object are left unmodified. 937 * Hint categories include controls for rendering quality and 938 * overall time/quality trade-off in the rendering process. 939 * Refer to the {@code RenderingHints} class for definitions of 940 * some common keys and values. 941 * @param hints the rendering hints to be set 942 * @see RenderingHints 943 */ addRenderingHints(Map<?,?> hints)944 public abstract void addRenderingHints(Map<?,?> hints); 945 946 /** 947 * Gets the preferences for the rendering algorithms. Hint categories 948 * include controls for rendering quality and overall time/quality 949 * trade-off in the rendering process. 950 * Returns all of the hint key/value pairs that were ever specified in 951 * one operation. Refer to the 952 * {@code RenderingHints} class for definitions of some common 953 * keys and values. 954 * @return a reference to an instance of {@code RenderingHints} 955 * that contains the current preferences. 956 * @see RenderingHints 957 * @see #setRenderingHints(Map) 958 */ getRenderingHints()959 public abstract RenderingHints getRenderingHints(); 960 961 /** 962 * Translates the origin of the {@code Graphics2D} context to the 963 * point (<i>x</i>, <i>y</i>) in the current coordinate system. 964 * Modifies the {@code Graphics2D} context so that its new origin 965 * corresponds to the point (<i>x</i>, <i>y</i>) in the 966 * {@code Graphics2D} context's former coordinate system. All 967 * coordinates used in subsequent rendering operations on this graphics 968 * context are relative to this new origin. 969 * @param x the specified x coordinate 970 * @param y the specified y coordinate 971 * @since 1.0 972 */ translate(int x, int y)973 public abstract void translate(int x, int y); 974 975 /** 976 * Concatenates the current 977 * {@code Graphics2D Transform} 978 * with a translation transform. 979 * Subsequent rendering is translated by the specified 980 * distance relative to the previous position. 981 * This is equivalent to calling transform(T), where T is an 982 * {@code AffineTransform} represented by the following matrix: 983 * <pre> 984 * [ 1 0 tx ] 985 * [ 0 1 ty ] 986 * [ 0 0 1 ] 987 * </pre> 988 * @param tx the distance to translate along the x-axis 989 * @param ty the distance to translate along the y-axis 990 */ translate(double tx, double ty)991 public abstract void translate(double tx, double ty); 992 993 /** 994 * Concatenates the current {@code Graphics2D} 995 * {@code Transform} with a rotation transform. 996 * Subsequent rendering is rotated by the specified radians relative 997 * to the previous origin. 998 * This is equivalent to calling {@code transform(R)}, where R is an 999 * {@code AffineTransform} represented by the following matrix: 1000 * <pre> 1001 * [ cos(theta) -sin(theta) 0 ] 1002 * [ sin(theta) cos(theta) 0 ] 1003 * [ 0 0 1 ] 1004 * </pre> 1005 * Rotating with a positive angle theta rotates points on the positive 1006 * x axis toward the positive y axis. 1007 * @param theta the angle of rotation in radians 1008 */ rotate(double theta)1009 public abstract void rotate(double theta); 1010 1011 /** 1012 * Concatenates the current {@code Graphics2D} 1013 * {@code Transform} with a translated rotation 1014 * transform. Subsequent rendering is transformed by a transform 1015 * which is constructed by translating to the specified location, 1016 * rotating by the specified radians, and translating back by the same 1017 * amount as the original translation. This is equivalent to the 1018 * following sequence of calls: 1019 * <pre> 1020 * translate(x, y); 1021 * rotate(theta); 1022 * translate(-x, -y); 1023 * </pre> 1024 * Rotating with a positive angle theta rotates points on the positive 1025 * x axis toward the positive y axis. 1026 * @param theta the angle of rotation in radians 1027 * @param x the x coordinate of the origin of the rotation 1028 * @param y the y coordinate of the origin of the rotation 1029 */ rotate(double theta, double x, double y)1030 public abstract void rotate(double theta, double x, double y); 1031 1032 /** 1033 * Concatenates the current {@code Graphics2D} 1034 * {@code Transform} with a scaling transformation 1035 * Subsequent rendering is resized according to the specified scaling 1036 * factors relative to the previous scaling. 1037 * This is equivalent to calling {@code transform(S)}, where S is an 1038 * {@code AffineTransform} represented by the following matrix: 1039 * <pre> 1040 * [ sx 0 0 ] 1041 * [ 0 sy 0 ] 1042 * [ 0 0 1 ] 1043 * </pre> 1044 * @param sx the amount by which X coordinates in subsequent 1045 * rendering operations are multiplied relative to previous 1046 * rendering operations. 1047 * @param sy the amount by which Y coordinates in subsequent 1048 * rendering operations are multiplied relative to previous 1049 * rendering operations. 1050 */ scale(double sx, double sy)1051 public abstract void scale(double sx, double sy); 1052 1053 /** 1054 * Concatenates the current {@code Graphics2D} 1055 * {@code Transform} with a shearing transform. 1056 * Subsequent renderings are sheared by the specified 1057 * multiplier relative to the previous position. 1058 * This is equivalent to calling {@code transform(SH)}, where SH 1059 * is an {@code AffineTransform} represented by the following 1060 * matrix: 1061 * <pre> 1062 * [ 1 shx 0 ] 1063 * [ shy 1 0 ] 1064 * [ 0 0 1 ] 1065 * </pre> 1066 * @param shx the multiplier by which coordinates are shifted in 1067 * the positive X axis direction as a function of their Y coordinate 1068 * @param shy the multiplier by which coordinates are shifted in 1069 * the positive Y axis direction as a function of their X coordinate 1070 */ shear(double shx, double shy)1071 public abstract void shear(double shx, double shy); 1072 1073 /** 1074 * Composes an {@code AffineTransform} object with the 1075 * {@code Transform} in this {@code Graphics2D} according 1076 * to the rule last-specified-first-applied. If the current 1077 * {@code Transform} is Cx, the result of composition 1078 * with Tx is a new {@code Transform} Cx'. Cx' becomes the 1079 * current {@code Transform} for this {@code Graphics2D}. 1080 * Transforming a point p by the updated {@code Transform} Cx' is 1081 * equivalent to first transforming p by Tx and then transforming 1082 * the result by the original {@code Transform} Cx. In other 1083 * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary, 1084 * so further modifications to Tx do not affect rendering. 1085 * @param Tx the {@code AffineTransform} object to be composed with 1086 * the current {@code Transform} 1087 * @see #setTransform 1088 * @see AffineTransform 1089 */ transform(AffineTransform Tx)1090 public abstract void transform(AffineTransform Tx); 1091 1092 /** 1093 * Overwrites the Transform in the {@code Graphics2D} context. 1094 * WARNING: This method should <b>never</b> be used to apply a new 1095 * coordinate transform on top of an existing transform because the 1096 * {@code Graphics2D} might already have a transform that is 1097 * needed for other purposes, such as rendering Swing 1098 * components or applying a scaling transformation to adjust for the 1099 * resolution of a printer. 1100 * <p>To add a coordinate transform, use the 1101 * {@code transform}, {@code rotate}, {@code scale}, 1102 * or {@code shear} methods. The {@code setTransform} 1103 * method is intended only for restoring the original 1104 * {@code Graphics2D} transform after rendering, as shown in this 1105 * example: 1106 * <pre> 1107 * // Get the current transform 1108 * AffineTransform saveAT = g2.getTransform(); 1109 * // Perform transformation 1110 * g2d.transform(...); 1111 * // Render 1112 * g2d.draw(...); 1113 * // Restore original transform 1114 * g2d.setTransform(saveAT); 1115 * </pre> 1116 * 1117 * @param Tx the {@code AffineTransform} that was retrieved 1118 * from the {@code getTransform} method 1119 * @see #transform 1120 * @see #getTransform 1121 * @see AffineTransform 1122 */ setTransform(AffineTransform Tx)1123 public abstract void setTransform(AffineTransform Tx); 1124 1125 /** 1126 * Returns a copy of the current {@code Transform} in the 1127 * {@code Graphics2D} context. 1128 * @return the current {@code AffineTransform} in the 1129 * {@code Graphics2D} context. 1130 * @see #transform 1131 * @see #setTransform 1132 */ getTransform()1133 public abstract AffineTransform getTransform(); 1134 1135 /** 1136 * Returns the current {@code Paint} of the 1137 * {@code Graphics2D} context. 1138 * @return the current {@code Graphics2D Paint}, 1139 * which defines a color or pattern. 1140 * @see #setPaint 1141 * @see java.awt.Graphics#setColor 1142 */ getPaint()1143 public abstract Paint getPaint(); 1144 1145 /** 1146 * Returns the current {@code Composite} in the 1147 * {@code Graphics2D} context. 1148 * @return the current {@code Graphics2D Composite}, 1149 * which defines a compositing style. 1150 * @see #setComposite 1151 */ getComposite()1152 public abstract Composite getComposite(); 1153 1154 /** 1155 * Sets the background color for the {@code Graphics2D} context. 1156 * The background color is used for clearing a region. 1157 * When a {@code Graphics2D} is constructed for a 1158 * {@code Component}, the background color is 1159 * inherited from the {@code Component}. Setting the background color 1160 * in the {@code Graphics2D} context only affects the subsequent 1161 * {@code clearRect} calls and not the background color of the 1162 * {@code Component}. To change the background 1163 * of the {@code Component}, use appropriate methods of 1164 * the {@code Component}. 1165 * @param color the background color that is used in 1166 * subsequent calls to {@code clearRect} 1167 * @see #getBackground 1168 * @see java.awt.Graphics#clearRect 1169 */ setBackground(Color color)1170 public abstract void setBackground(Color color); 1171 1172 /** 1173 * Returns the background color used for clearing a region. 1174 * @return the current {@code Graphics2D Color}, 1175 * which defines the background color. 1176 * @see #setBackground 1177 */ getBackground()1178 public abstract Color getBackground(); 1179 1180 /** 1181 * Returns the current {@code Stroke} in the 1182 * {@code Graphics2D} context. 1183 * @return the current {@code Graphics2D Stroke}, 1184 * which defines the line style. 1185 * @see #setStroke 1186 */ getStroke()1187 public abstract Stroke getStroke(); 1188 1189 /** 1190 * Intersects the current {@code Clip} with the interior of the 1191 * specified {@code Shape} and sets the {@code Clip} to the 1192 * resulting intersection. The specified {@code Shape} is 1193 * transformed with the current {@code Graphics2D} 1194 * {@code Transform} before being intersected with the current 1195 * {@code Clip}. This method is used to make the current 1196 * {@code Clip} smaller. 1197 * To make the {@code Clip} larger, use {@code setClip}. 1198 * The <i>user clip</i> modified by this method is independent of the 1199 * clipping associated with device bounds and visibility. If no clip has 1200 * previously been set, or if the clip has been cleared using 1201 * {@link Graphics#setClip(Shape) setClip} with a {@code null} 1202 * argument, the specified {@code Shape} becomes the new 1203 * user clip. 1204 * @param s the {@code Shape} to be intersected with the current 1205 * {@code Clip}. If {@code s} is {@code null}, 1206 * this method clears the current {@code Clip}. 1207 */ clip(Shape s)1208 public abstract void clip(Shape s); 1209 1210 /** 1211 * Get the rendering context of the {@code Font} within this 1212 * {@code Graphics2D} context. 1213 * The {@link FontRenderContext} 1214 * encapsulates application hints such as anti-aliasing and 1215 * fractional metrics, as well as target device specific information 1216 * such as dots-per-inch. This information should be provided by the 1217 * application when using objects that perform typographical 1218 * formatting, such as {@code Font} and 1219 * {@code TextLayout}. This information should also be provided 1220 * by applications that perform their own layout and need accurate 1221 * measurements of various characteristics of glyphs such as advance 1222 * and line height when various rendering hints have been applied to 1223 * the text rendering. 1224 * 1225 * @return a reference to an instance of FontRenderContext. 1226 * @see java.awt.font.FontRenderContext 1227 * @see java.awt.Font#createGlyphVector 1228 * @see java.awt.font.TextLayout 1229 * @since 1.2 1230 */ 1231 getFontRenderContext()1232 public abstract FontRenderContext getFontRenderContext(); 1233 1234 } 1235