DebugGraphics.java 27.9 KB
Newer Older
Tom Tromey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/* DebugGraphics.java --
   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package javax.swing;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
45
import java.awt.Point;
Tom Tromey committed
46 47 48 49 50 51 52 53
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.image.ImageObserver;
import java.io.PrintStream;
import java.text.AttributedCharacterIterator;


/**
Tom Tromey committed
54 55 56 57 58
 * An extension of {@link Graphics} that can be used for debugging
 * custom Swing widgets. <code>DebugGraphics</code> has the ability to
 * draw slowly and can log drawing actions.
 *
 * @author Andrew Selkirk
Tom Tromey committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
 */
public class DebugGraphics extends Graphics
{
  /**
   * LOG_OPTION
   */
  public static final int LOG_OPTION = 1;

  /**
   * FLASH_OPTION
   */
  public static final int FLASH_OPTION = 2;

  /**
   * BUFFERED_OPTION
   */
  public static final int BUFFERED_OPTION = 4;

  /**
   * NONE_OPTION
   */
  public static final int NONE_OPTION = -1;

  static Color debugFlashColor = Color.RED;
  static int debugFlashCount = 10;
  static int debugFlashTime = 1000;
  static PrintStream debugLogStream = System.out;

  /**
88 89
   * Counts the created DebugGraphics objects. This is used by the
   * logging facility.
Tom Tromey committed
90
   */
91
  static int counter = 0;
Tom Tromey committed
92 93

  /**
94
   * graphics
Tom Tromey committed
95
   */
96 97
  Graphics graphics;

Tom Tromey committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  /**
   * buffer
   */
  Image buffer;

  /**
   * debugOptions
   */
  int debugOptions;

  /**
   * graphicsID
   */
  int graphicsID;

  /**
   * xOffset
   */
  int xOffset;

  /**
   * yOffset
   */
  int yOffset;

  /**
   * Creates a <code>DebugGraphics</code> object.
   */
  public DebugGraphics()
  {
128
    counter++;
Tom Tromey committed
129 130 131 132 133 134 135 136 137 138
  }

  /**
   * Creates a <code>DebugGraphics</code> object.
   *
   * @param graphics The <code>Graphics</code> object to wrap
   * @param component TODO
   */
  public DebugGraphics(Graphics graphics, JComponent component)
  {
139
    this(graphics);
Tom Tromey committed
140 141 142 143 144 145 146 147 148 149
    // FIXME: What shall we do with component ?
  }

  /**
   * Creates a <code>DebugGraphics</code> object.
   *
   * @param graphics The <code>Graphics</code> object to wrap
   */
  public DebugGraphics(Graphics graphics)
  {
150
    this();
Tom Tromey committed
151 152 153 154 155
    this.graphics = graphics;
  }

  /**
   * Sets the color to draw stuff with.
156
   *
Tom Tromey committed
157 158 159 160
   * @param color The color
   */
  public void setColor(Color color)
  {
161 162 163 164
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Setting color: " + color);

    graphics.setColor(color);
Tom Tromey committed
165 166 167 168 169 170 171 172 173 174
  }

  /**
   * Creates a overrides <code>Graphics.create</code> to create a
   * <code>DebugGraphics</code> object.
   *
   * @return a new <code>DebugGraphics</code> object.
   */
  public Graphics create()
  {
175 176 177
    DebugGraphics copy = new DebugGraphics(graphics.create());
    copy.debugOptions = debugOptions;
    return copy;
Tom Tromey committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
  }

  /**
   * Creates a overrides <code>Graphics.create</code> to create a
   * <code>DebugGraphics</code> object.
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param width the width
   * @param height the height
   *
   * @return a new <code>DebugGraphics</code> object.
   */
  public Graphics create(int x, int y, int width, int height)
  {
193 194 195 196
    DebugGraphics copy = new DebugGraphics(graphics.create(x, y, width,
                                                           height));
    copy.debugOptions = debugOptions;
    return copy;
Tom Tromey committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
  }

  /**
   * flashColor
   *
   * @return Color
   */
  public static Color flashColor()
  {
    return debugFlashColor;
  }

  /**
   * setFlashColor
   *
   * @param color the color to use for flashing
   */
  public static void setFlashColor(Color color)
  {
    debugFlashColor = color;
  }

  /**
   * flashTime
   *
   * @return The time in milliseconds
   */
  public static int flashTime()
  {
    return debugFlashTime;
  }

  /**
   * setFlashTime
   *
   * @param time The time in milliseconds
   */
  public static void setFlashTime(int time)
  {
    debugFlashTime = time;
  }

  /**
   * flashCount
   *
   * @return The number of flashes
   */
  public static int flashCount()
  {
    return debugFlashCount;
  }

  /**
   * setFlashCount
   *
   * @param count The number of flashes
   */
  public static void setFlashCount(int count)
  {
    debugFlashCount = count;
  }

  /**
   * logStream
   *
   * @return The <code>PrintStream</code> to write logging messages to
   */
  public static PrintStream logStream()
  {
    return debugLogStream;
  }

  /**
   * setLogStream
   *
   * @param stream The currently set <code>PrintStream</code>.
   */
  public static void setLogStream(PrintStream stream)
  {
    debugLogStream = stream;
  }

  /**
   * getFont
   *
   * @return The font
   */
  public Font getFont()
  {
    return graphics.getFont();
  }

  /**
   * setFont
   *
   * @param font The font to use for drawing text
   */
  public void setFont(Font font)
  {
296 297 298
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Setting font: " + font);

Tom Tromey committed
299 300 301 302 303
    graphics.setFont(font);
  }

  /**
   * Returns the color used for drawing.
304
   *
Tom Tromey committed
305 306 307 308
   * @return The color.
   */
  public Color getColor()
  {
309
    return graphics.getColor();
Tom Tromey committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
  }

  /**
   * Returns the font metrics of the current font.
   *
   * @return a <code>FontMetrics</code> object
   */
  public FontMetrics getFontMetrics()
  {
    return graphics.getFontMetrics();
  }

  /**
   * Returns the font metrics for a given font.
   *
   * @param font the font to get the metrics for
   *
   * @return a <code>FontMetrics</code> object
   */
  public FontMetrics getFontMetrics(Font font)
  {
    return graphics.getFontMetrics(font);
  }

  /**
   * translate
   *
   * @param x the x coordinate
   * @param y the y coordinate
   */
  public void translate(int x, int y)
  {
342 343 344
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Translating by: " + new Point(x, y));

Tom Tromey committed
345 346 347 348 349 350 351 352
    graphics.translate(x, y);
  }

  /**
   * setPaintMode
   */
  public void setPaintMode()
  {
353 354 355
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Setting paint mode");

Tom Tromey committed
356 357 358 359 360 361 362 363 364 365
    graphics.setPaintMode();
  }

  /**
   * setXORMode
   *
   * @param color the color
   */
  public void setXORMode(Color color)
  {
366 367 368
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Setting XOR mode: " + color);

Tom Tromey committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
    graphics.setXORMode(color);
  }

  /**
   * getClipBounds
   *
   * @return Rectangle
   */
  public Rectangle getClipBounds()
  {
    return graphics.getClipBounds();
  }

  /**
   * Intersects the current clip region with the given region.
   *
   * @param x The x-position of the region
   * @param y The y-position of the region
   * @param width The width of the region
   * @param height The height of the region
   */
  public void clipRect(int x, int y, int width, int height)
  {
392 393 394 395 396 397
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().print(prefix() + " Setting clipRect: "
                          + new Rectangle(x, y, width, height));
      }

Tom Tromey committed
398
    graphics.clipRect(x, y, width, height);
399 400 401

    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(" Netting clipRect: " + graphics.getClipBounds());
Tom Tromey committed
402 403 404 405 406 407 408 409 410 411 412 413
  }

  /**
   * Sets the clipping region.
   *
   * @param x The x-position of the region
   * @param y The y-position of the region
   * @param width The width of the region
   * @param height The height of the region
   */
  public void setClip(int x, int y, int width, int height)
  {
414 415 416 417 418 419
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Setting new clipRect: "
                            + new Rectangle(x, y, width, height));
      }

Tom Tromey committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
    graphics.setClip(x, y, width, height);
  }

  /**
   * Returns the current clipping region.
   *
   * @return Shape
   */
  public Shape getClip()
  {
    return graphics.getClip();
  }

  /**
   * Sets the current clipping region
   *
   * @param shape The clippin region
   */
  public void setClip(Shape shape)
  {
440 441 442
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Setting new clipRect: " + shape);

Tom Tromey committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456
    graphics.setClip(shape);
  }

  private void sleep(int milliseconds)
  {
    try
      {
        Thread.sleep(milliseconds);
      }
    catch (InterruptedException e)
      {
        // Ignore this.
      }
  }
457

Tom Tromey committed
458 459 460 461 462 463 464 465 466 467
  /**
   * Draws a rectangle.
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   */
  public void drawRect(int x, int y, int width, int height)
  {
468
    if ((debugOptions & LOG_OPTION) != 0)
Tom Tromey committed
469
      {
470 471 472
        logStream().println(prefix() + " Drawing rect: "
                            + new Rectangle(x, y, width, height));
      }
Tom Tromey committed
473

474 475 476 477 478 479 480 481 482 483 484 485 486
    if ((debugOptions & FLASH_OPTION) != 0)
      {
        Color color = graphics.getColor();
        for (int index = 0; index < (debugFlashCount - 1); ++index)
          {
            graphics.setColor(color);
            graphics.drawRect(x, y, width, height);
            sleep(debugFlashTime);
            graphics.setColor(debugFlashColor);
            graphics.drawRect(x, y, width, height);
            sleep(debugFlashTime);
          }
        graphics.setColor(color);
Tom Tromey committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
      }

    graphics.drawRect(x, y, width, height);
  }

  /**
   * Draws a filled rectangle.
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   */
  public void fillRect(int x, int y, int width, int height)
  {
502
    if ((debugOptions & LOG_OPTION) != 0)
Tom Tromey committed
503
      {
504 505 506
        logStream().println(prefix() + " Filling rect: "
                            + new Rectangle(x, y, width, height));
      }
Tom Tromey committed
507

508 509 510 511 512 513 514 515 516 517 518 519 520
    if ((debugOptions & FLASH_OPTION) != 0)
      {
        Color color = graphics.getColor();
        for (int index = 0; index < (debugFlashCount - 1); ++index)
          {
            graphics.setColor(color);
            graphics.fillRect(x, y, width, height);
            sleep(debugFlashTime);
            graphics.setColor(debugFlashColor);
            graphics.fillRect(x, y, width, height);
            sleep(debugFlashTime);
          }
        graphics.setColor(color);
Tom Tromey committed
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
      }

    graphics.fillRect(x, y, width, height);
  }

  /**
   * clearRect
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   */
  public void clearRect(int x, int y, int width, int height)
  {
536 537 538 539 540 541
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Clearing rect: "
                            + new Rectangle(x, y, width, height));
      }

Tom Tromey committed
542 543 544 545 546 547 548 549 550 551 552 553 554
    graphics.clearRect(x, y, width, height);
  }

  /**
   * drawRoundRect
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   * @param arcWidth TODO
   * @param arcHeight TODO
   */
555 556
  public void drawRoundRect(int x, int y, int width, int height,
                            int arcWidth, int arcHeight)
Tom Tromey committed
557
  {
558 559 560 561 562 563 564 565
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing round rect: "
                            + new Rectangle(x, y, width, height)
                            + " arcWidth: " + arcWidth
                            + " arcHeight: " + arcHeight);
      }

Tom Tromey committed
566 567 568 569 570 571 572 573 574 575 576 577 578
    graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  }

  /**
   * fillRoundRect
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   * @param arcWidth TODO
   * @param arcHeight TODO
   */
579 580
  public void fillRoundRect(int x, int y, int width, int height,
                            int arcWidth, int arcHeight)
Tom Tromey committed
581
  {
582 583 584 585 586 587 588 589
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Filling round rect: "
                            + new Rectangle(x, y, width, height)
                            + " arcWidth: " + arcWidth
                            + " arcHeight: " + arcHeight);
      }

Tom Tromey committed
590 591 592 593 594 595
    graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
  }

  /**
   * drawLine
   *
596
   * @param x1 The x-position of the start
Tom Tromey committed
597 598 599 600 601 602
   * @param y1 The y-position of the start
   * @param x2 The x-position of the end
   * @param y2 The y-position of the end
   */
  public void drawLine(int x1, int y1, int x2, int y2)
  {
603 604 605 606 607 608
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing line: from (" + x1 + ", "
                            + y1 + ") to (" + x2 + ", " + y2 + ")");
      }

Tom Tromey committed
609 610 611 612 613 614 615 616 617 618 619 620 621 622
    graphics.drawLine(x1, y1, x2, y2);
  }

  /**
   * draw3DRect
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   * @param raised TODO
   */
  public void draw3DRect(int x, int y, int width, int height, boolean raised)
  {
623 624 625 626 627 628 629
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing 3D rect: "
                            + new Rectangle(x, y, width, height)
                            + "Raised bezel: " + raised);
      }

Tom Tromey committed
630 631 632 633 634 635 636 637 638 639 640 641 642 643
    graphics.draw3DRect(x, y, width, height, raised);
  }

  /**
   * fill3DRect
   *
   * @param x The x-position of the rectangle
   * @param y The y-position of the rectangle
   * @param width The width of the rectangle
   * @param height The height of the rectangle
   * @param raised TODO
   */
  public void fill3DRect(int x, int y, int width, int height, boolean raised)
  {
644 645 646 647 648 649 650
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Filling 3D rect: "
                            + new Rectangle(x, y, width, height)
                            + "Raised bezel: " + raised);
      }

Tom Tromey committed
651 652 653 654 655 656 657 658 659 660 661 662 663
    graphics.fill3DRect(x, y, width, height, raised);
  }

  /**
   * drawOval
   *
   * @param x the x coordinate
   * @param y the y coordiante
   * @param width the width
   * @param height the height
   */
  public void drawOval(int x, int y, int width, int height)
  {
664 665 666 667 668 669
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing oval: "
                            + new Rectangle(x, y, width, height));
      }

Tom Tromey committed
670 671 672 673 674 675 676 677 678 679 680 681 682
    graphics.drawOval(x, y, width, height);
  }

  /**
   * fillOval
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param width the width
   * @param height the height
   */
  public void fillOval(int x, int y, int width, int height)
  {
683 684 685 686 687 688
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Filling oval: "
                            + new Rectangle(x, y, width, height));
      }

Tom Tromey committed
689 690 691 692 693 694 695 696 697 698 699 700 701
    graphics.fillOval(x, y, width, height);
  }

  /**
   * drawArc
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param width the width
   * @param height the height
   * @param startAngle TODO
   * @param arcAngle TODO
   */
702 703
  public void drawArc(int x, int y, int width, int height,
                      int startAngle, int arcAngle)
Tom Tromey committed
704
  {
705 706 707 708 709 710 711 712
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing arc: "
                            + new Rectangle(x, y, width, height)
                            + " startAngle: " + startAngle
                            + " arcAngle: " + arcAngle);
      }

Tom Tromey committed
713 714 715 716 717 718 719 720 721 722 723 724 725
    graphics.drawArc(x, y, width, height, startAngle, arcAngle);
  }

  /**
   * fillArc
   *
   * @param x the coordinate
   * @param y the y coordinate
   * @param width the width
   * @param height the height
   * @param startAngle TODO
   * @param arcAngle TODO
   */
726 727
  public void fillArc(int x, int y, int width, int height,
                      int startAngle, int arcAngle)
Tom Tromey committed
728
  {
729 730 731 732 733 734 735 736
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Filling arc: "
                            + new Rectangle(x, y, width, height)
                            + " startAngle: " + startAngle
                            + " arcAngle: " + arcAngle);
      }

Tom Tromey committed
737 738 739 740 741 742 743 744 745 746 747 748
    graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  }

  /**
   * drawPolyline
   *
   * @param xpoints TODO
   * @param ypoints TODO
   * @param npoints TODO
   */
  public void drawPolyline(int[] xpoints, int[] ypoints, int npoints)
  {
749 750 751 752 753 754
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing polyline: nPoints: " + npoints
                            + " X's: " + xpoints + " Y's: " + ypoints);
      }

Tom Tromey committed
755 756 757 758 759 760 761 762 763 764 765 766
    graphics.drawPolyline(xpoints, ypoints, npoints);
  }

  /**
   * drawPolygon
   *
   * @param xpoints TODO
   * @param ypoints TODO
   * @param npoints TODO
   */
  public void drawPolygon(int[] xpoints, int[] ypoints, int npoints)
  {
767 768 769 770 771 772
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing polygon: nPoints: " + npoints
                            + " X's: " + xpoints + " Y's: " + ypoints);
      }

Tom Tromey committed
773 774 775 776 777 778 779 780 781 782 783 784
    graphics.drawPolygon(xpoints, ypoints, npoints);
  }

  /**
   * fillPolygon
   *
   * @param xpoints TODO
   * @param ypoints TODO
   * @param npoints TODO
   */
  public void fillPolygon(int[] xpoints, int[] ypoints, int npoints)
  {
785 786 787 788 789 790
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing polygon: nPoints: " + npoints
                            + " X's: " + xpoints + " Y's: " + ypoints);
      }

Tom Tromey committed
791 792 793 794 795 796 797 798 799 800 801 802
    graphics.fillPolygon(xpoints, ypoints, npoints);
  }

  /**
   * drawString
   *
   * @param string the string
   * @param x the x coordinate
   * @param y the y coordinate
   */
  public void drawString(String string, int x, int y)
  {
803 804 805 806 807 808
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing string: \"" + string
                            + "\" at: " + new Point(x, y));
      }

Tom Tromey committed
809 810 811 812 813 814 815 816 817 818 819
    graphics.drawString(string, x, y);
  }

  /**
   * drawString
   *
   * @param iterator TODO
   * @param x the x coordinate
   * @param y the y coordinate
   */
  public void drawString(AttributedCharacterIterator iterator,
820
                         int x, int y)
Tom Tromey committed
821
  {
822 823 824 825 826 827
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing string: \"" + iterator
                            + "\" at: " + new Point(x, y));
      }

Tom Tromey committed
828 829 830 831 832
    graphics.drawString(iterator, x, y);
  }

  /**
   * drawBytes
833
   *
Tom Tromey committed
834 835 836 837 838 839 840
   * @param data TODO
   * @param offset TODO
   * @param length TODO
   * @param x the x coordinate
   * @param y the y coordinate
   */
  public void drawBytes(byte[] data, int offset, int length,
841
                        int x, int y)
Tom Tromey committed
842
  {
843 844 845
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Drawing bytes at: " + new Point(x, y));

Tom Tromey committed
846 847 848 849 850
    graphics.drawBytes(data, offset, length, x, y);
  }

  /**
   * drawChars
851
   *
Tom Tromey committed
852 853 854 855 856 857
   * @param data array of characters to draw
   * @param offset offset in array
   * @param length number of characters in array to draw
   * @param x x-position
   * @param y y-position
   */
858 859
  public void drawChars(char[] data, int offset, int length,
                        int x, int y)
Tom Tromey committed
860
  {
861 862 863 864
    if ((debugOptions & LOG_OPTION) != 0)
      logStream().println(prefix() + " Drawing chars at: " + new Point(x, y));

    if ((debugOptions & FLASH_OPTION) != 0)
Tom Tromey committed
865
      {
866 867 868 869 870 871 872 873 874 875
        Color color = graphics.getColor();
        for (int index = 0; index < (debugFlashCount - 1); ++index)
          {
            graphics.setColor(color);
            graphics.drawChars(data, offset, length, x, y);
            sleep(debugFlashTime);
            graphics.setColor(debugFlashColor);
            graphics.drawChars(data, offset, length, x, y);
            sleep(debugFlashTime);
          }
Tom Tromey committed
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
        graphics.setColor(color);
      }

    graphics.drawChars(data, offset, length, x, y);
  }

  /**
   * drawImage
   *
   * @param image The image to draw
   * @param x The x position
   * @param y The y position
   * @param observer The image observer
   * @return boolean
   */
  public boolean drawImage(Image image, int x, int y,
892
                           ImageObserver observer)
Tom Tromey committed
893
  {
894 895 896 897 898 899
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing image: " + image + " at: "
                          + new Point(x, y));
      }

Tom Tromey committed
900 901 902 903 904
    return graphics.drawImage(image, x, y, observer);
  }

  /**
   * drawImage
905
   *
Tom Tromey committed
906 907 908 909 910 911 912 913 914
   * @param image The image to draw
   * @param x The x position
   * @param y The y position
   * @param width The width of the area to draw the image
   * @param height The height of the area to draw the image
   * @param observer The image observer
   *
   * @return boolean
   */
915 916
  public boolean drawImage(Image image, int x, int y, int width,
                           int height, ImageObserver observer)
Tom Tromey committed
917
  {
918 919 920 921 922 923
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing image: " + image
                            + " at: " + new Rectangle(x, y, width, height));
      }

Tom Tromey committed
924 925 926 927 928
    return graphics.drawImage(image, x, y, width, height, observer);
  }

  /**
   * drawImage
929
   *
Tom Tromey committed
930 931 932 933 934 935 936 937 938
   * @param image The image to draw
   * @param x The x position
   * @param y The y position
   * @param background The color for the background in the opaque regions
   * of the image
   * @param observer The image observer
   *
   * @return boolean
   */
939 940
  public boolean drawImage(Image image, int x, int y,
                           Color background, ImageObserver observer)
Tom Tromey committed
941
  {
942 943 944 945 946 947 948
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing image: " + image
                            + " at: " + new Point(x, y)
                            + ", bgcolor: " + background);
      }

Tom Tromey committed
949 950 951 952 953
    return graphics.drawImage(image, x, y, background, observer);
  }

  /**
   * drawImage
954
   *
Tom Tromey committed
955 956 957 958 959 960 961 962 963 964 965
   * @param image The image to draw
   * @param x The x position
   * @param y The y position
   * @param width The width of the area to draw the image
   * @param height The height of the area to draw the image
   * @param background The color for the background in the opaque regions
   * of the image
   * @param observer The image observer
   *
   * @return boolean
   */
966 967
  public boolean drawImage(Image image, int x, int y, int width, int height,
                           Color background, ImageObserver observer)
Tom Tromey committed
968
  {
969 970 971 972 973 974 975
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing image: " + image
                            + " at: " + new Rectangle(x, y, width, height)
                            + ", bgcolor: " + background);
      }

Tom Tromey committed
976 977 978 979 980
    return graphics.drawImage(image, x, y, width, height, background, observer);
  }

  /**
   * drawImage
981
   *
Tom Tromey committed
982 983 984 985 986 987 988 989 990 991
   * @param image The image to draw
   * @param dx1 TODO
   * @param dy1 TODO
   * @param dx2 TODO
   * @param dy2 TODO
   * @param sx1 TODO
   * @param sy1 TODO
   * @param sx2 TODO
   * @param sy2 TODO
   * @param observer The image observer
992
   *
Tom Tromey committed
993 994 995
   * @return boolean
   */
  public boolean drawImage(Image image, int dx1, int dy1,
996 997
                           int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
                           ImageObserver observer)
Tom Tromey committed
998
  {
999 1000 1001 1002 1003 1004 1005
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing image: " + image
                         + " destination: " + new Rectangle(dx1, dy1, dx2, dy2)
                         + " source: " + new Rectangle(sx1, sy1, sx2, sy2));
      }

Tom Tromey committed
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
    return graphics.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
  }

  /**
   * drawImage
   *
   * @param image The image to draw
   * @param dx1 TODO
   * @param dy1 TODO
   * @param dx2 TODO
   * @param dy2 TODO
   * @param sx1 TODO
   * @param sy1 TODO
   * @param sx2 TODO
   * @param sy2 TODO
   * @param background The color for the background in the opaque regions
   * of the image
   * @param observer The image observer
   *
   * @return boolean
   */
  public boolean drawImage(Image image, int dx1, int dy1,
1028 1029
                           int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
                           Color background, ImageObserver observer)
Tom Tromey committed
1030
  {
1031 1032 1033 1034 1035 1036 1037 1038
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Drawing image: " + image
                         + " destination: " + new Rectangle(dx1, dy1, dx2, dy2)
                         + " source: " + new Rectangle(sx1, sy1, sx2, sy2)
                         + ", bgcolor: " + background);
      }

Tom Tromey committed
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    return graphics.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, background, observer);
  }

  /**
   * copyArea
   *
   * @param x The x position of the source area
   * @param y The y position of the source area
   * @param width The width of the area
   * @param height The height of the area
   * @param destx The x position of the destination area
   * @param desty The y posiiton of the destination area
   */
1052 1053
  public void copyArea(int x, int y, int width, int height,
                       int destx, int desty)
Tom Tromey committed
1054
  {
1055 1056 1057 1058 1059 1060 1061
    if ((debugOptions & LOG_OPTION) != 0)
      {
        logStream().println(prefix() + " Copying area from: "
                            +  new Rectangle(x, y, width, height)
                            + " to: " + new Point(destx, desty));
      }

Tom Tromey committed
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
    graphics.copyArea(x, y, width, height, destx, desty);
  }

  /**
   * Releases all system resources that this <code>Graphics</code> is using.
   */
  public void dispose()
  {
    graphics.dispose();
    graphics = null;
  }

  /**
   * isDrawingBuffer
   *
   * @return boolean
   */
  public boolean isDrawingBuffer()
  {
    return false; // TODO
  }

  /**
   * setDebugOptions
   *
   * @param options the debug options
   */
  public void setDebugOptions(int options)
  {
    debugOptions = options;
1092 1093 1094 1095 1096
    if ((debugOptions & LOG_OPTION) != 0)
      if (options == NONE_OPTION)
        logStream().println(prefix() + "Disabling debug");
      else
        logStream().println(prefix() + "Enabling debug");
Tom Tromey committed
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
  }

  /**
   * getDebugOptions
   *
   * @return the debug options
   */
  public int getDebugOptions()
  {
    return debugOptions;
  }
1108 1109 1110 1111

  /**
   * Creates and returns the prefix that should be prepended to all logging
   * messages. The prefix is made up like this:
1112
   *
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
   * <code>Graphics(<counter>-1)</code> where counter is an integer number
   * saying how many DebugGraphics objects have been created so far. The second
   * number always seem to be 1 on Sun's JDK, this has to be investigated a
   * little more.
   *
   * @return the prefix that should be prepended to all logging
   *         messages
   */
  private String prefix()
  {
    return "Graphics(" + counter + "-1)";
  }
Tom Tromey committed
1125
}