1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18 * @author Alexey A. Petrenko 19 * @version $Revision$ 20 */ 21 22package java.awt; 23 24import java.awt.image.ImageObserver; 25import java.text.AttributedCharacterIterator; 26 27/** 28 * The abstract Graphics class allows applications to draw on a screen or other 29 * rendering target. There are several properties which define rendering 30 * options: origin point, clipping area, color, font. <br> 31 * <br> 32 * The origin point specifies the beginning of the clipping area coordinate 33 * system. All coordinates used in rendering operations are computed with 34 * respect to this point. The clipping area defines the boundaries where 35 * rendering operations can be performed. Rendering operations can't modify 36 * pixels outside of the clipping area. <br> 37 * <br> 38 * The draw and fill methods allow applications to drawing shapes, text, images 39 * with specified font and color options in the specified part of the screen. 40 * 41 * @since Android 1.0 42 */ 43public abstract class Graphics { 44 45 // Constructors 46 47 /** 48 * Instantiates a new Graphics. This constructor is default for Graphics and 49 * can not be called directly. 50 */ 51 protected Graphics() { 52 } 53 54 // Public methods 55 56 /** 57 * Creates a copy of the Graphics object with a new origin and a new 58 * specified clip area. The new clip area is the rectangle defined by the 59 * origin point with coordinates X,Y and the given width and height. The 60 * coordinates of all subsequent rendering operations will be computed with 61 * respect to the new origin and can be performed only within the range of 62 * the clipping area dimensions. 63 * 64 * @param x 65 * the X coordinate of the original point. 66 * @param y 67 * the Y coordinate of the original point. 68 * @param width 69 * the width of clipping area. 70 * @param height 71 * the height of clipping area. 72 * @return the Graphics object with new origin point and clipping area. 73 */ 74 public Graphics create(int x, int y, int width, int height) { 75 Graphics res = create(); 76 res.translate(x, y); 77 res.clipRect(0, 0, width, height); 78 return res; 79 } 80 81 /** 82 * Draws the highlighted outline of a rectangle. 83 * 84 * @param x 85 * the X coordinate of the rectangle's top left corner. 86 * @param y 87 * the Y coordinate of the rectangle's top left corner. 88 * @param width 89 * the width of rectangle. 90 * @param height 91 * the height of rectangle. 92 * @param raised 93 * a boolean value that determines whether the rectangle is drawn 94 * as raised or indented. 95 */ 96 public void draw3DRect(int x, int y, int width, int height, boolean raised) { 97 // Note: lighter/darker colors should be used to draw 3d rect. 98 // The resulting rect is (width+1)x(height+1). Stroke and paint 99 // attributes of 100 // the Graphics2D should be reset to the default values. 101 // fillRect is used instead of drawLine to bypass stroke 102 // reset/set and rasterization. 103 104 Color color = getColor(); 105 Color colorUp, colorDown; 106 if (raised) { 107 colorUp = color.brighter(); 108 colorDown = color.darker(); 109 } else { 110 colorUp = color.darker(); 111 colorDown = color.brighter(); 112 } 113 114 setColor(colorUp); 115 fillRect(x, y, width, 1); 116 fillRect(x, y + 1, 1, height); 117 118 setColor(colorDown); 119 fillRect(x + width, y, 1, height); 120 fillRect(x + 1, y + height, width, 1); 121 } 122 123 /** 124 * Draws the text represented by byte array. This method uses the current 125 * font and color for rendering. 126 * 127 * @param bytes 128 * the byte array which contains the text to be drawn. 129 * @param off 130 * the offset within the byte array of the text to be drawn. 131 * @param len 132 * the number of bytes of text to draw. 133 * @param x 134 * the X coordinate where the text is to be drawn. 135 * @param y 136 * the Y coordinate where the text is to be drawn. 137 */ 138 public void drawBytes(byte[] bytes, int off, int len, int x, int y) { 139 drawString(new String(bytes, off, len), x, y); 140 } 141 142 /** 143 * Draws the text represented by character array. This method uses the 144 * current font and color for rendering. 145 * 146 * @param chars 147 * the character array. 148 * @param off 149 * the offset within the character array of the text to be drawn. 150 * @param len 151 * the number of characters which will be drawn. 152 * @param x 153 * the X coordinate where the text is to be drawn. 154 * @param y 155 * the Y coordinate where the text is to be drawn. 156 */ 157 public void drawChars(char[] chars, int off, int len, int x, int y) { 158 drawString(new String(chars, off, len), x, y); 159 } 160 161 /** 162 * Draws the outline of a polygon which is defined by Polygon object. 163 * 164 * @param p 165 * the Polygon object. 166 */ 167 public void drawPolygon(Polygon p) { 168 drawPolygon(p.xpoints, p.ypoints, p.npoints); 169 } 170 171 /** 172 * Draws the rectangle with the specified width and length and top left 173 * corner coordinates. 174 * 175 * @param x 176 * the X coordinate of the rectangle's top left corner. 177 * @param y 178 * the Y coordinate of the rectangle's top left corner. 179 * @param width 180 * the width of the rectangle. 181 * @param height 182 * the height of the rectangle. 183 */ 184 public void drawRect(int x, int y, int width, int height) { 185 int[] xpoints = { 186 x, x, x + width, x + width 187 }; 188 int[] ypoints = { 189 y, y + height, y + height, y 190 }; 191 192 drawPolygon(xpoints, ypoints, 4); 193 } 194 195 /** 196 * Fills the highlighted outline of a rectangle. 197 * 198 * @param x 199 * the X coordinate of the rectangle's top left corner. 200 * @param y 201 * the Y coordinate of the rectangle's top left corner. 202 * @param width 203 * the width of the rectangle. 204 * @param height 205 * the height of the rectangle. 206 * @param raised 207 * a boolean value that determines whether the rectangle is drawn 208 * as raised or indented. 209 */ 210 public void fill3DRect(int x, int y, int width, int height, boolean raised) { 211 // Note: lighter/darker colors should be used to draw 3d rect. 212 // The resulting rect is (width)x(height), same as fillRect. 213 // Stroke and paint attributes of the Graphics2D should be reset 214 // to the default values. fillRect is used instead of drawLine to 215 // bypass stroke reset/set and line rasterization. 216 217 Color color = getColor(); 218 Color colorUp, colorDown; 219 if (raised) { 220 colorUp = color.brighter(); 221 colorDown = color.darker(); 222 setColor(color); 223 } else { 224 colorUp = color.darker(); 225 colorDown = color.brighter(); 226 setColor(colorUp); 227 } 228 229 width--; 230 height--; 231 fillRect(x + 1, y + 1, width - 1, height - 1); 232 233 setColor(colorUp); 234 fillRect(x, y, width, 1); 235 fillRect(x, y + 1, 1, height); 236 237 setColor(colorDown); 238 fillRect(x + width, y, 1, height); 239 fillRect(x + 1, y + height, width, 1); 240 } 241 242 /** 243 * Fills the polygon with the current color. 244 * 245 * @param p 246 * the Polygon object. 247 */ 248 public void fillPolygon(Polygon p) { 249 fillPolygon(p.xpoints, p.ypoints, p.npoints); 250 } 251 252 /** 253 * Disposes of the Graphics. 254 */ 255 @Override 256 public void finalize() { 257 } 258 259 /** 260 * Gets the bounds of the current clipping area as a rectangle and copies it 261 * to an existing rectangle. 262 * 263 * @param r 264 * a Rectangle object where the current clipping area bounds are 265 * to be copied. 266 * @return the bounds of the current clipping area. 267 */ 268 public Rectangle getClipBounds(Rectangle r) { 269 Shape clip = getClip(); 270 271 if (clip != null) { 272 // TODO: Can we get shape bounds without creating Rectangle object? 273 Rectangle b = clip.getBounds(); 274 r.x = b.x; 275 r.y = b.y; 276 r.width = b.width; 277 r.height = b.height; 278 } 279 280 return r; 281 } 282 283 /** 284 * Gets the bounds of the current clipping area as a rectangle. 285 * 286 * @return a Rectangle object. 287 * @deprecated Use {@link #getClipBounds()} 288 */ 289 @Deprecated 290 public Rectangle getClipRect() { 291 return getClipBounds(); 292 } 293 294 /** 295 * Gets the font metrics of the current font. The font metrics object 296 * contains information about the rendering of a particular font. 297 * 298 * @return the font metrics of current font. 299 */ 300 public FontMetrics getFontMetrics() { 301 return getFontMetrics(getFont()); 302 } 303 304 /** 305 * Determines whether or not the specified rectangle intersects the current 306 * clipping area. 307 * 308 * @param x 309 * the X coordinate of the rectangle. 310 * @param y 311 * the Y coordinate of the rectangle. 312 * @param width 313 * the width of the rectangle. 314 * @param height 315 * the height of the rectangle. 316 * @return true, if the specified rectangle intersects the current clipping 317 * area, false otherwise. 318 */ 319 public boolean hitClip(int x, int y, int width, int height) { 320 // TODO: Create package private method Rectangle.intersects(int, int, 321 // int, int); 322 return getClipBounds().intersects(new Rectangle(x, y, width, height)); 323 } 324 325 /** 326 * Returns string which represents this Graphics object. 327 * 328 * @return the string which represents this Graphics object. 329 */ 330 @Override 331 public String toString() { 332 // TODO: Think about string representation of Graphics. 333 return "Graphics"; //$NON-NLS-1$ 334 } 335 336 // Abstract methods 337 338 /** 339 * Clears the specified rectangle. This method fills specified rectangle 340 * with background color. 341 * 342 * @param x 343 * the X coordinate of the rectangle. 344 * @param y 345 * the Y coordinate of the rectangle. 346 * @param width 347 * the width of the rectangle. 348 * @param height 349 * the height of the rectangle. 350 */ 351 public abstract void clearRect(int x, int y, int width, int height); 352 353 /** 354 * Intersects the current clipping area with a new rectangle. If the current 355 * clipping area is not defined, the rectangle becomes a new clipping area. 356 * Rendering operations are only allowed within the new the clipping area. 357 * 358 * @param x 359 * the X coordinate of the rectangle for intersection. 360 * @param y 361 * the Y coordinate of the rectangle for intersection. 362 * @param width 363 * the width of the rectangle for intersection. 364 * @param height 365 * the height of the rectangle for intersection. 366 */ 367 public abstract void clipRect(int x, int y, int width, int height); 368 369 /** 370 * Copies the rectangle area to another area specified by a distance (dx, 371 * dy) from the original rectangle's location. Positive dx and dy values 372 * give a new location defined by translation to the right and down from the 373 * original location, negative dx and dy values - to the left and up. 374 * 375 * @param sx 376 * the X coordinate of the rectangle which will be copied. 377 * @param sy 378 * the Y coordinate of the rectangle which will be copied. 379 * @param width 380 * the width of the rectangle which will be copied. 381 * @param height 382 * the height of the rectangle which will be copied. 383 * @param dx 384 * the horizontal distance from the source rectangle's location 385 * to the copy's location. 386 * @param dy 387 * the vertical distance from the source rectangle's location to 388 * the copy's location. 389 */ 390 public abstract void copyArea(int sx, int sy, int width, int height, int dx, int dy); 391 392 /** 393 * Creates a new copy of this Graphics. 394 * 395 * @return a new Graphics context which is a copy of this Graphics. 396 */ 397 public abstract Graphics create(); 398 399 /** 400 * Disposes of the Graphics. This Graphics object can not be used after 401 * calling this method. 402 */ 403 public abstract void dispose(); 404 405 /** 406 * Draws the arc covering the specified rectangle and using the current 407 * color. The rectangle is defined by the origin point (X, Y) and dimensions 408 * (width and height). The arc center is the the center of specified 409 * rectangle. The angle origin is 3 o'clock position, the positive angle is 410 * counted as a counter-clockwise rotation, the negative angle is counted as 411 * clockwise rotation. 412 * 413 * @param x 414 * the X origin coordinate of the rectangle which scales the arc. 415 * @param y 416 * the Y origin coordinate of the rectangle which scales the arc. 417 * @param width 418 * the width of the rectangle which scales the arc. 419 * @param height 420 * the height of the rectangle which scales the arc. 421 * @param sa 422 * start angle - the origin angle of arc. 423 * @param ea 424 * arc angle - the angular arc value relative to the start angle. 425 */ 426 public abstract void drawArc(int x, int y, int width, int height, int sa, int ea); 427 428 /** 429 * Draws the specified image with the defined background color. The top left 430 * corner of image will be drawn at point (x, y) in current coordinate 431 * system. The image loading process notifies the specified Image Observer. 432 * This method returns true if the image has loaded, otherwise it returns 433 * false. 434 * 435 * @param img 436 * the image which will be drawn. 437 * @param x 438 * the X coordinate of the image top left corner. 439 * @param y 440 * the Y coordinate of the image top left corner. 441 * @param bgcolor 442 * the background color. 443 * @param observer 444 * the ImageObserver object which should be notified about image 445 * loading process. 446 * @return true, if loading image is successful or image is null, false 447 * otherwise. 448 */ 449 public abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer); 450 451 /** 452 * Draws the specified image. The top left corner of image will be drawn at 453 * point (x, y) in current coordinate system. The image loading process 454 * notifies the specified Image Observer. This method returns true if the 455 * image has loaded, otherwise it returns false. 456 * 457 * @param img 458 * the image which will be drawn. 459 * @param x 460 * the X coordinate of the image top left corner. 461 * @param y 462 * the Y coordinate of the image top left corner. 463 * @param observer 464 * the ImageObserver object which should be notified about image 465 * loading process. 466 * @return true, if loading image is successful or image is null, otherwise 467 * false. 468 */ 469 public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer); 470 471 /** 472 * Scales the specified image to fit in the specified rectangle and draws it 473 * with the defined background color. The top left corner of the image will 474 * be drawn at the point (x, y) in current coordinate system. The non-opaque 475 * pixels will be drawn in the background color. The image loading process 476 * notifies the specified Image Observer. This method returns true if the 477 * image has loaded, otherwise it returns false. 478 * 479 * @param img 480 * the image which will be drawn. 481 * @param x 482 * the X coordinate of the image's top left corner. 483 * @param y 484 * the Y coordinate of the image's top left corner. 485 * @param width 486 * the width of rectangle which scales the image. 487 * @param height 488 * the height of rectangle which scales the image. 489 * @param bgcolor 490 * the background color. 491 * @param observer 492 * the ImageObserver object which should be notified about image 493 * loading process. 494 * @return true, if loading image is successful or image is null, otherwise 495 * false. 496 */ 497 public abstract boolean drawImage(Image img, int x, int y, int width, int height, 498 Color bgcolor, ImageObserver observer); 499 500 /** 501 * Scales the specified image to fit in the specified rectangle and draws 502 * it. The top left corner of the image will be drawn at the point (x, y) in 503 * current coordinate system. The image loading process notifies the 504 * specified Image Observer. This method returns true if the image has 505 * loaded, otherwise it returns false. 506 * 507 * @param img 508 * the image which will be drawn. 509 * @param x 510 * the X coordinate of the image top left corner. 511 * @param y 512 * the Y coordinate of the image top left corner. 513 * @param width 514 * the width of rectangle which scales the image. 515 * @param height 516 * the height of rectangle which scales the image. 517 * @param observer 518 * the ImageObserver object which should be notified about image 519 * loading process. 520 * @return true, if loading image is successful or image is null, otherwise 521 * false. 522 */ 523 public abstract boolean drawImage(Image img, int x, int y, int width, int height, 524 ImageObserver observer); 525 526 /** 527 * Scales the specified area of the specified image to fit in the rectangle 528 * area defined by its corners coordinates and draws the sub-image with the 529 * specified background color. The sub-image to be drawn is defined by its 530 * top left corner coordinates (sx1, sy1) and bottom right corner 531 * coordinates (sx2, sy2) computed with respect to the origin (top left 532 * corner) of the source image. The non opaque pixels will be drawn in the 533 * background color. The image loading process notifies specified Image 534 * Observer. This method returns true if the image has loaded, otherwise it 535 * returns false. 536 * 537 * @param img 538 * the image which will be drawn. 539 * @param dx1 540 * the X top left corner coordinate of the destination rectangle 541 * area. 542 * @param dy1 543 * the Y top left corner coordinate of the destination rectangle 544 * area. 545 * @param dx2 546 * the X bottom right corner coordinate of the destination 547 * rectangle area. 548 * @param dy2 549 * the Y bottom right corner coordinate of the destination 550 * rectangle area. 551 * @param sx1 552 * the X top left corner coordinate of the area to be drawn 553 * within the source image. 554 * @param sy1 555 * the Y top left corner coordinate of the area to be drawn 556 * within the source image. 557 * @param sx2 558 * the X bottom right corner coordinate of the area to be drawn 559 * within the source image. 560 * @param sy2 561 * the Y bottom right corner coordinate of the area to be drawn 562 * within the source image. 563 * @param bgcolor 564 * the background color. 565 * @param observer 566 * the ImageObserver object which should be notified about image 567 * loading process. 568 * @return true, if loading image is successful or image is null, false 569 * otherwise. 570 */ 571 public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, 572 int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer); 573 574 /** 575 * Scales the specified area of the specified image to fit in the rectangle 576 * area defined by its corners coordinates and draws the sub-image. The 577 * sub-image to be drawn is defined by its top left corner coordinates (sx1, 578 * sy1) and bottom right corner coordinates (sx2, sy2) computed with respect 579 * to the origin (top left corner) of the source image. The image loading 580 * process notifies specified Image Observer. This method returns true if 581 * the image has loaded, otherwise it returns false. 582 * 583 * @param img 584 * the image which will be drawn. 585 * @param dx1 586 * the X top left corner coordinate of the destination rectangle 587 * area. 588 * @param dy1 589 * the Y top left corner coordinate of the destination rectangle 590 * area. 591 * @param dx2 592 * the X bottom right corner coordinate of the destination 593 * rectangle area. 594 * @param dy2 595 * the Y bottom right corner coordinate of the destination 596 * rectangle area. 597 * @param sx1 598 * the X top left corner coordinate of the area to be drawn 599 * within the source image. 600 * @param sy1 601 * the Y top left corner coordinate of the area to be drawn 602 * within the source image. 603 * @param sx2 604 * the X bottom right corner coordinate of the area to be drawn 605 * within the source image. 606 * @param sy2 607 * the Y bottom right corner coordinate of the area to be drawn 608 * within the source image. 609 * @param observer 610 * the ImageObserver object which should be notified about image 611 * loading process. 612 * @return true, if loading image is successful or image is null, false 613 * otherwise. 614 */ 615 public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, 616 int sy1, int sx2, int sy2, ImageObserver observer); 617 618 /** 619 * Draws a line from the point (x1, y1) to the point (x2, y2). This method 620 * draws the line with current color which can be changed by setColor(Color 621 * c) method. 622 * 623 * @param x1 624 * the X coordinate of the first point. 625 * @param y1 626 * the Y coordinate of the first point. 627 * @param x2 628 * the X coordinate of the second point. 629 * @param y2 630 * the Y coordinate of the second point. 631 */ 632 public abstract void drawLine(int x1, int y1, int x2, int y2); 633 634 /** 635 * Draws the outline of an oval to fit in the rectangle defined by the given 636 * width, height, and top left corner. 637 * 638 * @param x 639 * the X top left corner oval coordinate. 640 * @param y 641 * the Y top left corner oval coordinate. 642 * @param width 643 * the oval width. 644 * @param height 645 * the oval height. 646 */ 647 public abstract void drawOval(int x, int y, int width, int height); 648 649 /** 650 * Draws the outline of a polygon. The polygon vertices are defined by 651 * points with xpoints[i], ypoints[i] as coordinates. The polygon edges are 652 * the lines from the points with (xpoints[i-1], ypoints[i-1]) coordinates 653 * to the points with (xpoints[i], ypoints[i]) coordinates, for 0 < i < 654 * npoints +1. 655 * 656 * @param xpoints 657 * the array of X coordinates of the polygon vertices. 658 * @param ypoints 659 * the array of Y coordinates of the polygon vertices. 660 * @param npoints 661 * the number of polygon vertices/points. 662 */ 663 public abstract void drawPolygon(int[] xpoints, int[] ypoints, int npoints); 664 665 /** 666 * Draws a set of connected lines which are defined by the x and y 667 * coordinate arrays. The polyline is closed if coordinates of the first 668 * point are the same as coordinates of the last point. 669 * 670 * @param xpoints 671 * the array of X point coordinates. 672 * @param ypoints 673 * the array of Y point coordinates. 674 * @param npoints 675 * the number of points. 676 */ 677 public abstract void drawPolyline(int[] xpoints, int[] ypoints, int npoints); 678 679 /** 680 * Draws the outline of a rectangle with round corners. 681 * 682 * @param x 683 * the X coordinate of the rectangle's top left corner. 684 * @param y 685 * the Y coordinate of the rectangle's top left corner. 686 * @param width 687 * the width of the rectangle. 688 * @param height 689 * the height of the rectangle. 690 * @param arcWidth 691 * the arc width for the corners. 692 * @param arcHeight 693 * the arc height for the corners. 694 */ 695 public abstract void drawRoundRect(int x, int y, int width, int height, int arcWidth, 696 int arcHeight); 697 698 /** 699 * Draws a text defined by an iterator. The iterator should specify the font 700 * for every character. 701 * 702 * @param iterator 703 * the iterator. 704 * @param x 705 * the X coordinate of the first character. 706 * @param y 707 * the Y coordinate of the first character. 708 */ 709 public abstract void drawString(AttributedCharacterIterator iterator, int x, int y); 710 711 /** 712 * Draws a text defined by a string. This method draws the text with current 713 * font and color. 714 * 715 * @param str 716 * the string. 717 * @param x 718 * the X coordinate of the first character. 719 * @param y 720 * the Y coordinate of the first character. 721 */ 722 public abstract void drawString(String str, int x, int y); 723 724 /** 725 * Fills the arc covering the rectangle and using the current color. The 726 * rectangle is defined by the origin point (X, Y) and dimensions (width and 727 * height). The arc center is the the center of specified rectangle. The 728 * angle origin is at the 3 o'clock position, and a positive angle gives 729 * counter-clockwise rotation, a negative angle gives clockwise rotation. 730 * 731 * @param x 732 * the X origin coordinate of the rectangle which scales the arc. 733 * @param y 734 * the Y origin coordinate of the rectangle which scales the arc. 735 * @param width 736 * the width of the rectangle which scales the arc. 737 * @param height 738 * the height of the rectangle which scales the arc. 739 * @param sa 740 * start angle - the origin angle of arc. 741 * @param ea 742 * arc angle - the angular arc value relative to the start angle. 743 */ 744 public abstract void fillArc(int x, int y, int width, int height, int sa, int ea); 745 746 /** 747 * Fills an oval with the current color where the oval is defined by the 748 * bounding rectangle with the given width, height, and top left corner. 749 * 750 * @param x 751 * the X top left corner oval coordinate. 752 * @param y 753 * the Y top left corner oval coordinate. 754 * @param width 755 * the oval width. 756 * @param height 757 * the oval height. 758 */ 759 public abstract void fillOval(int x, int y, int width, int height); 760 761 /** 762 * Fills a polygon with the current color. The polygon vertices are defined 763 * by the points with xpoints[i], ypoints[i] as coordinates. The polygon 764 * edges are the lines from the points with (xpoints[i-1], ypoints[i-1]) 765 * coordinates to the points with (xpoints[i], ypoints[i]) coordinates, for 766 * 0 < i < npoints +1. 767 * 768 * @param xpoints 769 * the array of X coordinates of the polygon vertices. 770 * @param ypoints 771 * the array of Y coordinates of the polygon vertices. 772 * @param npoints 773 * the number of polygon vertices/points. 774 */ 775 public abstract void fillPolygon(int[] xpoints, int[] ypoints, int npoints); 776 777 /** 778 * Fills a rectangle with the current color. The rectangle is defined by its 779 * width and length and top left corner coordinates. 780 * 781 * @param x 782 * the X coordinate of the rectangle's top left corner. 783 * @param y 784 * the Y coordinate of the rectangle's top left corner. 785 * @param width 786 * the width of rectangle. 787 * @param height 788 * the height of rectangle. 789 */ 790 public abstract void fillRect(int x, int y, int width, int height); 791 792 /** 793 * Fills a round cornered rectangle with the current color. 794 * 795 * @param x 796 * the X coordinate of the top left corner of the bounding 797 * rectangle. 798 * @param y 799 * the Y coordinate of the top left corner of the bounding 800 * rectangle. 801 * @param width 802 * the width of the bounding rectangle. 803 * @param height 804 * the height of the bounding rectangle. 805 * @param arcWidth 806 * the arc width at the corners. 807 * @param arcHeight 808 * the arc height at the corners. 809 */ 810 public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth, 811 int arcHeight); 812 813 /** 814 * Gets the clipping area. <br> 815 * <br> 816 * 817 * @return a Shape object of the clipping area or null if it is not set. 818 */ 819 public abstract Shape getClip(); 820 821 /** 822 * Gets the bounds of the current clipping area as a rectangle. 823 * 824 * @return a Rectangle object which represents the bounds of the current 825 * clipping area. 826 */ 827 public abstract Rectangle getClipBounds(); 828 829 /** 830 * Gets the current color of Graphics. 831 * 832 * @return the current color. 833 */ 834 public abstract Color getColor(); 835 836 /** 837 * Gets the current font of Graphics. 838 * 839 * @return the current font. 840 */ 841 public abstract Font getFont(); 842 843 /** 844 * Gets the font metrics of the specified font. The font metrics object 845 * contains information about the rendering of a particular font. 846 * 847 * @param font 848 * the specified font. 849 * @return the font metrics for the specified font. 850 */ 851 public abstract FontMetrics getFontMetrics(Font font); 852 853 /** 854 * Sets the new clipping area specified by rectangle. The new clipping area 855 * doesn't depend on the window's visibility. Rendering operations can't be 856 * performed outside new clipping area. 857 * 858 * @param x 859 * the X coordinate of the new clipping rectangle. 860 * @param y 861 * the Y coordinate of the new clipping rectangle. 862 * @param width 863 * the width of the new clipping rectangle. 864 * @param height 865 * the height of the new clipping rectangle. 866 */ 867 public abstract void setClip(int x, int y, int width, int height); 868 869 /** 870 * Sets the new clipping area to be the area specified by Shape object. The 871 * new clipping area doesn't depend on the window's visibility. Rendering 872 * operations can't be performed outside new clipping area. 873 * 874 * @param clip 875 * the Shape object which represents new clipping area. 876 */ 877 public abstract void setClip(Shape clip); 878 879 /** 880 * Sets the current Graphics color. All rendering operations with this 881 * Graphics will use this color. 882 * 883 * @param c 884 * the new color. 885 */ 886 public abstract void setColor(Color c); 887 888 /** 889 * Sets the current Graphics font. All rendering operations with this 890 * Graphics will use this font. 891 * 892 * @param font 893 * the new font. 894 */ 895 public abstract void setFont(Font font); 896 897 /** 898 * Sets the paint mode for the Graphics which overwrites all rendering 899 * operations with the current color. 900 */ 901 public abstract void setPaintMode(); 902 903 /** 904 * Sets the XOR mode for the Graphics which changes a pixel from the current 905 * color to the specified XOR color. <br> 906 * <br> 907 * 908 * @param color 909 * the new XOR mode. 910 */ 911 public abstract void setXORMode(Color color); 912 913 /** 914 * Translates the origin of Graphics current coordinate system to the point 915 * with X, Y coordinates in the current coordinate system. All rendering 916 * operation in this Graphics will be related to the new origin. 917 * 918 * @param x 919 * the X coordinate of the origin. 920 * @param y 921 * the Y coordinate of the origin. 922 */ 923 public abstract void translate(int x, int y); 924} 925