GNU Classpath (0.17) | ||
Frames | No Frames |
1: /* DebugGraphics.java -- 2: Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package javax.swing; 39: 40: import java.awt.Color; 41: import java.awt.Font; 42: import java.awt.FontMetrics; 43: import java.awt.Graphics; 44: import java.awt.Image; 45: import java.awt.Rectangle; 46: import java.awt.Shape; 47: import java.awt.image.ImageObserver; 48: import java.io.PrintStream; 49: import java.text.AttributedCharacterIterator; 50: 51: 52: /** 53: * DebugGraphics 54: * @author Andrew Selkirk 55: * @version 1.0 56: */ 57: public class DebugGraphics extends Graphics 58: { 59: /** 60: * LOG_OPTION 61: */ 62: public static final int LOG_OPTION = 1; 63: 64: /** 65: * FLASH_OPTION 66: */ 67: public static final int FLASH_OPTION = 2; 68: 69: /** 70: * BUFFERED_OPTION 71: */ 72: public static final int BUFFERED_OPTION = 4; 73: 74: /** 75: * NONE_OPTION 76: */ 77: public static final int NONE_OPTION = -1; 78: 79: static Color debugFlashColor = Color.RED; 80: static int debugFlashCount = 10; 81: static int debugFlashTime = 1000; 82: static PrintStream debugLogStream = System.out; 83: 84: /** 85: * graphics 86: */ 87: Graphics graphics; 88: 89: /** 90: * color 91: */ 92: Color color = Color.BLACK; 93: 94: /** 95: * buffer 96: */ 97: Image buffer; 98: 99: /** 100: * debugOptions 101: */ 102: int debugOptions; 103: 104: /** 105: * graphicsID 106: */ 107: int graphicsID; 108: 109: /** 110: * xOffset 111: */ 112: int xOffset; 113: 114: /** 115: * yOffset 116: */ 117: int yOffset; 118: 119: /** 120: * Creates a <code>DebugGraphics</code> object. 121: */ 122: public DebugGraphics() 123: { 124: // TODO 125: } 126: 127: /** 128: * Creates a <code>DebugGraphics</code> object. 129: * 130: * @param graphics The <code>Graphics</code> object to wrap 131: * @param component TODO 132: */ 133: public DebugGraphics(Graphics graphics, JComponent component) 134: { 135: this.graphics = graphics; 136: // FIXME: What shall we do with component ? 137: } 138: 139: /** 140: * Creates a <code>DebugGraphics</code> object. 141: * 142: * @param graphics The <code>Graphics</code> object to wrap 143: */ 144: public DebugGraphics(Graphics graphics) 145: { 146: this.graphics = graphics; 147: } 148: 149: /** 150: * Sets the color to draw stuff with. 151: * 152: * @param color The color 153: */ 154: public void setColor(Color color) 155: { 156: this.color = color; 157: } 158: 159: /** 160: * Creates a overrides <code>Graphics.create</code> to create a 161: * <code>DebugGraphics</code> object. 162: * 163: * @return a new <code>DebugGraphics</code> object. 164: */ 165: public Graphics create() 166: { 167: return new DebugGraphics(graphics.create()); 168: } 169: 170: /** 171: * Creates a overrides <code>Graphics.create</code> to create a 172: * <code>DebugGraphics</code> object. 173: * 174: * @param x the x coordinate 175: * @param y the y coordinate 176: * @param width the width 177: * @param height the height 178: * 179: * @return a new <code>DebugGraphics</code> object. 180: */ 181: public Graphics create(int x, int y, int width, int height) 182: { 183: return new DebugGraphics(graphics.create(x, y, width, height)); 184: } 185: 186: /** 187: * flashColor 188: * 189: * @return Color 190: */ 191: public static Color flashColor() 192: { 193: return debugFlashColor; 194: } 195: 196: /** 197: * setFlashColor 198: * 199: * @param color the color to use for flashing 200: */ 201: public static void setFlashColor(Color color) 202: { 203: debugFlashColor = color; 204: } 205: 206: /** 207: * flashTime 208: * 209: * @return The time in milliseconds 210: */ 211: public static int flashTime() 212: { 213: return debugFlashTime; 214: } 215: 216: /** 217: * setFlashTime 218: * 219: * @param time The time in milliseconds 220: */ 221: public static void setFlashTime(int time) 222: { 223: debugFlashTime = time; 224: } 225: 226: /** 227: * flashCount 228: * 229: * @return The number of flashes 230: */ 231: public static int flashCount() 232: { 233: return debugFlashCount; 234: } 235: 236: /** 237: * setFlashCount 238: * 239: * @param count The number of flashes 240: */ 241: public static void setFlashCount(int count) 242: { 243: debugFlashCount = count; 244: } 245: 246: /** 247: * logStream 248: * 249: * @return The <code>PrintStream</code> to write logging messages to 250: */ 251: public static PrintStream logStream() 252: { 253: return debugLogStream; 254: } 255: 256: /** 257: * setLogStream 258: * 259: * @param stream The currently set <code>PrintStream</code>. 260: */ 261: public static void setLogStream(PrintStream stream) 262: { 263: debugLogStream = stream; 264: } 265: 266: /** 267: * getFont 268: * 269: * @return The font 270: */ 271: public Font getFont() 272: { 273: return graphics.getFont(); 274: } 275: 276: /** 277: * setFont 278: * 279: * @param font The font to use for drawing text 280: */ 281: public void setFont(Font font) 282: { 283: graphics.setFont(font); 284: } 285: 286: /** 287: * Returns the color used for drawing. 288: * 289: * @return The color. 290: */ 291: public Color getColor() 292: { 293: return color; 294: } 295: 296: /** 297: * Returns the font metrics of the current font. 298: * 299: * @return a <code>FontMetrics</code> object 300: */ 301: public FontMetrics getFontMetrics() 302: { 303: return graphics.getFontMetrics(); 304: } 305: 306: /** 307: * Returns the font metrics for a given font. 308: * 309: * @param font the font to get the metrics for 310: * 311: * @return a <code>FontMetrics</code> object 312: */ 313: public FontMetrics getFontMetrics(Font font) 314: { 315: return graphics.getFontMetrics(font); 316: } 317: 318: /** 319: * translate 320: * 321: * @param x the x coordinate 322: * @param y the y coordinate 323: */ 324: public void translate(int x, int y) 325: { 326: graphics.translate(x, y); 327: } 328: 329: /** 330: * setPaintMode 331: */ 332: public void setPaintMode() 333: { 334: graphics.setPaintMode(); 335: } 336: 337: /** 338: * setXORMode 339: * 340: * @param color the color 341: */ 342: public void setXORMode(Color color) 343: { 344: graphics.setXORMode(color); 345: } 346: 347: /** 348: * getClipBounds 349: * 350: * @return Rectangle 351: */ 352: public Rectangle getClipBounds() 353: { 354: return graphics.getClipBounds(); 355: } 356: 357: /** 358: * Intersects the current clip region with the given region. 359: * 360: * @param x The x-position of the region 361: * @param y The y-position of the region 362: * @param width The width of the region 363: * @param height The height of the region 364: */ 365: public void clipRect(int x, int y, int width, int height) 366: { 367: graphics.clipRect(x, y, width, height); 368: } 369: 370: /** 371: * Sets the clipping region. 372: * 373: * @param x The x-position of the region 374: * @param y The y-position of the region 375: * @param width The width of the region 376: * @param height The height of the region 377: */ 378: public void setClip(int x, int y, int width, int height) 379: { 380: graphics.setClip(x, y, width, height); 381: } 382: 383: /** 384: * Returns the current clipping region. 385: * 386: * @return Shape 387: */ 388: public Shape getClip() 389: { 390: return graphics.getClip(); 391: } 392: 393: /** 394: * Sets the current clipping region 395: * 396: * @param shape The clippin region 397: */ 398: public void setClip(Shape shape) 399: { 400: graphics.setClip(shape); 401: } 402: 403: private void sleep(int milliseconds) 404: { 405: try 406: { 407: Thread.sleep(milliseconds); 408: } 409: catch (InterruptedException e) 410: { 411: // Ignore this. 412: } 413: } 414: 415: /** 416: * Draws a rectangle. 417: * 418: * @param x The x-position of the rectangle 419: * @param y The y-position of the rectangle 420: * @param width The width of the rectangle 421: * @param height The height of the rectangle 422: */ 423: public void drawRect(int x, int y, int width, int height) 424: { 425: for (int index = 0; index < (debugFlashCount - 1); ++index) 426: { 427: graphics.setColor(color); 428: graphics.drawRect(x, y, width, height); 429: sleep(debugFlashTime); 430: 431: graphics.setColor(debugFlashColor); 432: graphics.drawRect(x, y, width, height); 433: sleep(debugFlashTime); 434: } 435: 436: graphics.setColor(color); 437: graphics.drawRect(x, y, width, height); 438: } 439: 440: /** 441: * Draws a filled rectangle. 442: * 443: * @param x The x-position of the rectangle 444: * @param y The y-position of the rectangle 445: * @param width The width of the rectangle 446: * @param height The height of the rectangle 447: */ 448: public void fillRect(int x, int y, int width, int height) 449: { 450: for (int index = 0; index < (debugFlashCount - 1); ++index) 451: { 452: graphics.setColor(color); 453: graphics.fillRect(x, y, width, height); 454: sleep(debugFlashTime); 455: 456: graphics.setColor(debugFlashColor); 457: graphics.fillRect(x, y, width, height); 458: sleep(debugFlashTime); 459: } 460: 461: graphics.setColor(color); 462: graphics.fillRect(x, y, width, height); 463: } 464: 465: /** 466: * clearRect 467: * 468: * @param x The x-position of the rectangle 469: * @param y The y-position of the rectangle 470: * @param width The width of the rectangle 471: * @param height The height of the rectangle 472: */ 473: public void clearRect(int x, int y, int width, int height) 474: { 475: graphics.clearRect(x, y, width, height); 476: } 477: 478: /** 479: * drawRoundRect 480: * 481: * @param x The x-position of the rectangle 482: * @param y The y-position of the rectangle 483: * @param width The width of the rectangle 484: * @param height The height of the rectangle 485: * @param arcWidth TODO 486: * @param arcHeight TODO 487: */ 488: public void drawRoundRect(int x, int y, int width, int height, 489: int arcWidth, int arcHeight) 490: { 491: graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight); 492: } 493: 494: /** 495: * fillRoundRect 496: * 497: * @param x The x-position of the rectangle 498: * @param y The y-position of the rectangle 499: * @param width The width of the rectangle 500: * @param height The height of the rectangle 501: * @param arcWidth TODO 502: * @param arcHeight TODO 503: */ 504: public void fillRoundRect(int x, int y, int width, int height, 505: int arcWidth, int arcHeight) 506: { 507: graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight); 508: } 509: 510: /** 511: * drawLine 512: * 513: * @param x1 The x-position of the start 514: * @param y1 The y-position of the start 515: * @param x2 The x-position of the end 516: * @param y2 The y-position of the end 517: */ 518: public void drawLine(int x1, int y1, int x2, int y2) 519: { 520: graphics.drawLine(x1, y1, x2, y2); 521: } 522: 523: /** 524: * draw3DRect 525: * 526: * @param x The x-position of the rectangle 527: * @param y The y-position of the rectangle 528: * @param width The width of the rectangle 529: * @param height The height of the rectangle 530: * @param raised TODO 531: */ 532: public void draw3DRect(int x, int y, int width, int height, boolean raised) 533: { 534: graphics.draw3DRect(x, y, width, height, raised); 535: } 536: 537: /** 538: * fill3DRect 539: * 540: * @param x The x-position of the rectangle 541: * @param y The y-position of the rectangle 542: * @param width The width of the rectangle 543: * @param height The height of the rectangle 544: * @param raised TODO 545: */ 546: public void fill3DRect(int x, int y, int width, int height, boolean raised) 547: { 548: graphics.fill3DRect(x, y, width, height, raised); 549: } 550: 551: /** 552: * drawOval 553: * 554: * @param x the x coordinate 555: * @param y the y coordiante 556: * @param width the width 557: * @param height the height 558: */ 559: public void drawOval(int x, int y, int width, int height) 560: { 561: graphics.drawOval(x, y, width, height); 562: } 563: 564: /** 565: * fillOval 566: * 567: * @param x the x coordinate 568: * @param y the y coordinate 569: * @param width the width 570: * @param height the height 571: */ 572: public void fillOval(int x, int y, int width, int height) 573: { 574: graphics.fillOval(x, y, width, height); 575: } 576: 577: /** 578: * drawArc 579: * 580: * @param x the x coordinate 581: * @param y the y coordinate 582: * @param width the width 583: * @param height the height 584: * @param startAngle TODO 585: * @param arcAngle TODO 586: */ 587: public void drawArc(int x, int y, int width, int height, 588: int startAngle, int arcAngle) 589: { 590: graphics.drawArc(x, y, width, height, startAngle, arcAngle); 591: } 592: 593: /** 594: * fillArc 595: * 596: * @param x the coordinate 597: * @param y the y coordinate 598: * @param width the width 599: * @param height the height 600: * @param startAngle TODO 601: * @param arcAngle TODO 602: */ 603: public void fillArc(int x, int y, int width, int height, 604: int startAngle, int arcAngle) 605: { 606: graphics.fillArc(x, y, width, height, startAngle, arcAngle); 607: } 608: 609: /** 610: * drawPolyline 611: * 612: * @param xpoints TODO 613: * @param ypoints TODO 614: * @param npoints TODO 615: */ 616: public void drawPolyline(int[] xpoints, int[] ypoints, int npoints) 617: { 618: graphics.drawPolyline(xpoints, ypoints, npoints); 619: } 620: 621: /** 622: * drawPolygon 623: * 624: * @param xpoints TODO 625: * @param ypoints TODO 626: * @param npoints TODO 627: */ 628: public void drawPolygon(int[] xpoints, int[] ypoints, int npoints) 629: { 630: graphics.drawPolygon(xpoints, ypoints, npoints); 631: } 632: 633: /** 634: * fillPolygon 635: * 636: * @param xpoints TODO 637: * @param ypoints TODO 638: * @param npoints TODO 639: */ 640: public void fillPolygon(int[] xpoints, int[] ypoints, int npoints) 641: { 642: graphics.fillPolygon(xpoints, ypoints, npoints); 643: } 644: 645: /** 646: * drawString 647: * 648: * @param string the string 649: * @param x the x coordinate 650: * @param y the y coordinate 651: */ 652: public void drawString(String string, int x, int y) 653: { 654: graphics.drawString(string, x, y); 655: } 656: 657: /** 658: * drawString 659: * 660: * @param iterator TODO 661: * @param x the x coordinate 662: * @param y the y coordinate 663: */ 664: public void drawString(AttributedCharacterIterator iterator, 665: int x, int y) 666: { 667: graphics.drawString(iterator, x, y); 668: } 669: 670: /** 671: * drawBytes 672: * 673: * @param data TODO 674: * @param offset TODO 675: * @param length TODO 676: * @param x the x coordinate 677: * @param y the y coordinate 678: */ 679: public void drawBytes(byte[] data, int offset, int length, 680: int x, int y) 681: { 682: graphics.drawBytes(data, offset, length, x, y); 683: } 684: 685: /** 686: * drawChars 687: * 688: * @param data array of characters to draw 689: * @param offset offset in array 690: * @param length number of characters in array to draw 691: * @param x x-position 692: * @param y y-position 693: */ 694: public void drawChars(char[] data, int offset, int length, 695: int x, int y) 696: { 697: for (int index = 0; index < (debugFlashCount - 1); ++index) 698: { 699: graphics.setColor(color); 700: graphics.drawChars(data, offset, length, x, y); 701: sleep(debugFlashTime); 702: 703: graphics.setColor(debugFlashColor); 704: graphics.drawChars(data, offset, length, x, y); 705: sleep(debugFlashTime); 706: } 707: 708: graphics.setColor(color); 709: graphics.drawChars(data, offset, length, x, y); 710: } 711: 712: /** 713: * drawImage 714: * 715: * @param image The image to draw 716: * @param x The x position 717: * @param y The y position 718: * @param observer The image observer 719: * @return boolean 720: */ 721: public boolean drawImage(Image image, int x, int y, 722: ImageObserver observer) 723: { 724: return graphics.drawImage(image, x, y, observer); 725: } 726: 727: /** 728: * drawImage 729: * 730: * @param image The image to draw 731: * @param x The x position 732: * @param y The y position 733: * @param width The width of the area to draw the image 734: * @param height The height of the area to draw the image 735: * @param observer The image observer 736: * 737: * @return boolean 738: */ 739: public boolean drawImage(Image image, int x, int y, int width, 740: int height, ImageObserver observer) 741: { 742: return graphics.drawImage(image, x, y, width, height, observer); 743: } 744: 745: /** 746: * drawImage 747: * 748: * @param image The image to draw 749: * @param x The x position 750: * @param y The y position 751: * @param background The color for the background in the opaque regions 752: * of the image 753: * @param observer The image observer 754: * 755: * @return boolean 756: */ 757: public boolean drawImage(Image image, int x, int y, 758: Color background, ImageObserver observer) 759: { 760: return graphics.drawImage(image, x, y, background, observer); 761: } 762: 763: /** 764: * drawImage 765: * 766: * @param image The image to draw 767: * @param x The x position 768: * @param y The y position 769: * @param width The width of the area to draw the image 770: * @param height The height of the area to draw the image 771: * @param background The color for the background in the opaque regions 772: * of the image 773: * @param observer The image observer 774: * 775: * @return boolean 776: */ 777: public boolean drawImage(Image image, int x, int y, int width, int height, 778: Color background, ImageObserver observer) 779: { 780: return graphics.drawImage(image, x, y, width, height, background, observer); 781: } 782: 783: /** 784: * drawImage 785: * 786: * @param image The image to draw 787: * @param dx1 TODO 788: * @param dy1 TODO 789: * @param dx2 TODO 790: * @param dy2 TODO 791: * @param sx1 TODO 792: * @param sy1 TODO 793: * @param sx2 TODO 794: * @param sy2 TODO 795: * @param observer The image observer 796: * 797: * @return boolean 798: */ 799: public boolean drawImage(Image image, int dx1, int dy1, 800: int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, 801: ImageObserver observer) 802: { 803: return graphics.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); 804: } 805: 806: /** 807: * drawImage 808: * 809: * @param image The image to draw 810: * @param dx1 TODO 811: * @param dy1 TODO 812: * @param dx2 TODO 813: * @param dy2 TODO 814: * @param sx1 TODO 815: * @param sy1 TODO 816: * @param sx2 TODO 817: * @param sy2 TODO 818: * @param background The color for the background in the opaque regions 819: * of the image 820: * @param observer The image observer 821: * 822: * @return boolean 823: */ 824: public boolean drawImage(Image image, int dx1, int dy1, 825: int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, 826: Color background, ImageObserver observer) 827: { 828: return graphics.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, background, observer); 829: } 830: 831: /** 832: * copyArea 833: * 834: * @param x The x position of the source area 835: * @param y The y position of the source area 836: * @param width The width of the area 837: * @param height The height of the area 838: * @param destx The x position of the destination area 839: * @param desty The y posiiton of the destination area 840: */ 841: public void copyArea(int x, int y, int width, int height, 842: int destx, int desty) 843: { 844: graphics.copyArea(x, y, width, height, destx, desty); 845: } 846: 847: /** 848: * Releases all system resources that this <code>Graphics</code> is using. 849: */ 850: public void dispose() 851: { 852: graphics.dispose(); 853: graphics = null; 854: } 855: 856: /** 857: * isDrawingBuffer 858: * 859: * @return boolean 860: */ 861: public boolean isDrawingBuffer() 862: { 863: return false; // TODO 864: } 865: 866: /** 867: * setDebugOptions 868: * 869: * @param options the debug options 870: */ 871: public void setDebugOptions(int options) 872: { 873: debugOptions = options; 874: } 875: 876: /** 877: * getDebugOptions 878: * 879: * @return the debug options 880: */ 881: public int getDebugOptions() 882: { 883: return debugOptions; 884: } 885: }
GNU Classpath (0.17) |