0001 /*
0002 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
0003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004 *
0005 * This code is free software; you can redistribute it and/or modify it
0006 * under the terms of the GNU General Public License version 2 only, as
0007 * published by the Free Software Foundation. Sun designates this
0008 * particular file as subject to the "Classpath" exception as provided
0009 * by Sun in the LICENSE file that accompanied this code.
0010 *
0011 * This code is distributed in the hope that it will be useful, but WITHOUT
0012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014 * version 2 for more details (a copy is included in the LICENSE file that
0015 * accompanied this code).
0016 *
0017 * You should have received a copy of the GNU General Public License version
0018 * 2 along with this work; if not, write to the Free Software Foundation,
0019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020 *
0021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022 * CA 95054 USA or visit www.sun.com if you need additional information or
0023 * have any questions.
0024 */
0025
0026 package javax.swing;
0027
0028 import java.awt.*;
0029 import java.awt.image.*;
0030 import java.text.AttributedCharacterIterator;
0031
0032 /**
0033 * Graphics subclass supporting graphics debugging. Overrides most methods
0034 * from Graphics. DebugGraphics objects are rarely created by hand. They
0035 * are most frequently created automatically when a JComponent's
0036 * debugGraphicsOptions are changed using the setDebugGraphicsOptions()
0037 * method.
0038 * <p>
0039 * NOTE: You must turn off double buffering to use DebugGraphics:
0040 * RepaintManager repaintManager = RepaintManager.currentManager(component);
0041 * repaintManager.setDoubleBufferingEnabled(false);
0042 *
0043 * @see JComponent#setDebugGraphicsOptions
0044 * @see RepaintManager#currentManager
0045 * @see RepaintManager#setDoubleBufferingEnabled
0046 *
0047 * @version 1.33 05/05/07
0048 * @author Dave Karlton
0049 */
0050 public class DebugGraphics extends Graphics {
0051 Graphics graphics;
0052 Image buffer;
0053 int debugOptions;
0054 int graphicsID = graphicsCount++;
0055 int xOffset, yOffset;
0056 private static int graphicsCount = 0;
0057 private static ImageIcon imageLoadingIcon = new ImageIcon();
0058
0059 /** Log graphics operations. */
0060 public static final int LOG_OPTION = 1 << 0;
0061 /** Flash graphics operations. */
0062 public static final int FLASH_OPTION = 1 << 1;
0063 /** Show buffered operations in a separate <code>Frame</code>. */
0064 public static final int BUFFERED_OPTION = 1 << 2;
0065 /** Don't debug graphics operations. */
0066 public static final int NONE_OPTION = -1;
0067
0068 static {
0069 JComponent.DEBUG_GRAPHICS_LOADED = true;
0070 }
0071
0072 /**
0073 * Constructs a new debug graphics context that supports slowed
0074 * down drawing.
0075 */
0076 public DebugGraphics() {
0077 super ();
0078 buffer = null;
0079 xOffset = yOffset = 0;
0080 }
0081
0082 /**
0083 * Constructs a debug graphics context from an existing graphics
0084 * context that slows down drawing for the specified component.
0085 *
0086 * @param graphics the Graphics context to slow down
0087 * @param component the JComponent to draw slowly
0088 */
0089 public DebugGraphics(Graphics graphics, JComponent component) {
0090 this (graphics);
0091 setDebugOptions(component.shouldDebugGraphics());
0092 }
0093
0094 /**
0095 * Constructs a debug graphics context from an existing graphics
0096 * context that supports slowed down drawing.
0097 *
0098 * @param graphics the Graphics context to slow down
0099 */
0100 public DebugGraphics(Graphics graphics) {
0101 this ();
0102 this .graphics = graphics;
0103 }
0104
0105 /**
0106 * Overrides <code>Graphics.create</code> to return a DebugGraphics object.
0107 */
0108 public Graphics create() {
0109 DebugGraphics debugGraphics;
0110
0111 debugGraphics = new DebugGraphics();
0112 debugGraphics.graphics = graphics.create();
0113 debugGraphics.debugOptions = debugOptions;
0114 debugGraphics.buffer = buffer;
0115
0116 return debugGraphics;
0117 }
0118
0119 /**
0120 * Overrides <code>Graphics.create</code> to return a DebugGraphics object.
0121 */
0122 public Graphics create(int x, int y, int width, int height) {
0123 DebugGraphics debugGraphics;
0124
0125 debugGraphics = new DebugGraphics();
0126 debugGraphics.graphics = graphics.create(x, y, width, height);
0127 debugGraphics.debugOptions = debugOptions;
0128 debugGraphics.buffer = buffer;
0129 debugGraphics.xOffset = xOffset + x;
0130 debugGraphics.yOffset = yOffset + y;
0131
0132 return debugGraphics;
0133 }
0134
0135 //------------------------------------------------
0136 // NEW METHODS
0137 //------------------------------------------------
0138
0139 /**
0140 * Sets the Color used to flash drawing operations.
0141 */
0142 public static void setFlashColor(Color flashColor) {
0143 info().flashColor = flashColor;
0144 }
0145
0146 /**
0147 * Returns the Color used to flash drawing operations.
0148 * @see #setFlashColor
0149 */
0150 public static Color flashColor() {
0151 return info().flashColor;
0152 }
0153
0154 /**
0155 * Sets the time delay of drawing operation flashing.
0156 */
0157 public static void setFlashTime(int flashTime) {
0158 info().flashTime = flashTime;
0159 }
0160
0161 /**
0162 * Returns the time delay of drawing operation flashing.
0163 * @see #setFlashTime
0164 */
0165 public static int flashTime() {
0166 return info().flashTime;
0167 }
0168
0169 /**
0170 * Sets the number of times that drawing operations will flash.
0171 */
0172 public static void setFlashCount(int flashCount) {
0173 info().flashCount = flashCount;
0174 }
0175
0176 /** Returns the number of times that drawing operations will flash.
0177 * @see #setFlashCount
0178 */
0179 public static int flashCount() {
0180 return info().flashCount;
0181 }
0182
0183 /** Sets the stream to which the DebugGraphics logs drawing operations.
0184 */
0185 public static void setLogStream(java.io.PrintStream stream) {
0186 info().stream = stream;
0187 }
0188
0189 /** Returns the stream to which the DebugGraphics logs drawing operations.
0190 * @see #setLogStream
0191 */
0192 public static java.io.PrintStream logStream() {
0193 return info().stream;
0194 }
0195
0196 /** Sets the Font used for text drawing operations.
0197 */
0198 public void setFont(Font aFont) {
0199 if (debugLog()) {
0200 info().log(toShortString() + " Setting font: " + aFont);
0201 }
0202 graphics.setFont(aFont);
0203 }
0204
0205 /** Returns the Font used for text drawing operations.
0206 * @see #setFont
0207 */
0208 public Font getFont() {
0209 return graphics.getFont();
0210 }
0211
0212 /** Sets the color to be used for drawing and filling lines and shapes.
0213 */
0214 public void setColor(Color aColor) {
0215 if (debugLog()) {
0216 info().log(toShortString() + " Setting color: " + aColor);
0217 }
0218 graphics.setColor(aColor);
0219 }
0220
0221 /** Returns the Color used for text drawing operations.
0222 * @see #setColor
0223 */
0224 public Color getColor() {
0225 return graphics.getColor();
0226 }
0227
0228 //-----------------------------------------------
0229 // OVERRIDDEN METHODS
0230 //------------------------------------------------
0231
0232 /**
0233 * Overrides <code>Graphics.getFontMetrics</code>.
0234 */
0235 public FontMetrics getFontMetrics() {
0236 return graphics.getFontMetrics();
0237 }
0238
0239 /**
0240 * Overrides <code>Graphics.getFontMetrics</code>.
0241 */
0242 public FontMetrics getFontMetrics(Font f) {
0243 return graphics.getFontMetrics(f);
0244 }
0245
0246 /**
0247 * Overrides <code>Graphics.translate</code>.
0248 */
0249 public void translate(int x, int y) {
0250 if (debugLog()) {
0251 info().log(
0252 toShortString() + " Translating by: "
0253 + new Point(x, y));
0254 }
0255 xOffset += x;
0256 yOffset += y;
0257 graphics.translate(x, y);
0258 }
0259
0260 /**
0261 * Overrides <code>Graphics.setPaintMode</code>.
0262 */
0263 public void setPaintMode() {
0264 if (debugLog()) {
0265 info().log(toShortString() + " Setting paint mode");
0266 }
0267 graphics.setPaintMode();
0268 }
0269
0270 /**
0271 * Overrides <code>Graphics.setXORMode</code>.
0272 */
0273 public void setXORMode(Color aColor) {
0274 if (debugLog()) {
0275 info()
0276 .log(
0277 toShortString() + " Setting XOR mode: "
0278 + aColor);
0279 }
0280 graphics.setXORMode(aColor);
0281 }
0282
0283 /**
0284 * Overrides <code>Graphics.getClipBounds</code>.
0285 */
0286 public Rectangle getClipBounds() {
0287 return graphics.getClipBounds();
0288 }
0289
0290 /**
0291 * Overrides <code>Graphics.clipRect</code>.
0292 */
0293 public void clipRect(int x, int y, int width, int height) {
0294 graphics.clipRect(x, y, width, height);
0295 if (debugLog()) {
0296 info().log(
0297 toShortString() + " Setting clipRect: "
0298 + (new Rectangle(x, y, width, height))
0299 + " New clipRect: " + graphics.getClip());
0300 }
0301 }
0302
0303 /**
0304 * Overrides <code>Graphics.setClip</code>.
0305 */
0306 public void setClip(int x, int y, int width, int height) {
0307 graphics.setClip(x, y, width, height);
0308 if (debugLog()) {
0309 info().log(
0310 toShortString() + " Setting new clipRect: "
0311 + graphics.getClip());
0312 }
0313 }
0314
0315 /**
0316 * Overrides <code>Graphics.getClip</code>.
0317 */
0318 public Shape getClip() {
0319 return graphics.getClip();
0320 }
0321
0322 /**
0323 * Overrides <code>Graphics.setClip</code>.
0324 */
0325 public void setClip(Shape clip) {
0326 graphics.setClip(clip);
0327 if (debugLog()) {
0328 info().log(
0329 toShortString() + " Setting new clipRect: "
0330 + graphics.getClip());
0331 }
0332 }
0333
0334 /**
0335 * Overrides <code>Graphics.drawRect</code>.
0336 */
0337 public void drawRect(int x, int y, int width, int height) {
0338 DebugGraphicsInfo info = info();
0339
0340 if (debugLog()) {
0341 info().log(
0342 toShortString() + " Drawing rect: "
0343 + new Rectangle(x, y, width, height));
0344 }
0345
0346 if (isDrawingBuffer()) {
0347 if (debugBuffered()) {
0348 Graphics debugGraphics = debugGraphics();
0349
0350 debugGraphics.drawRect(x, y, width, height);
0351 debugGraphics.dispose();
0352 }
0353 } else if (debugFlash()) {
0354 Color oldColor = getColor();
0355 int i, count = (info.flashCount * 2) - 1;
0356
0357 for (i = 0; i < count; i++) {
0358 graphics.setColor((i % 2) == 0 ? info.flashColor
0359 : oldColor);
0360 graphics.drawRect(x, y, width, height);
0361 Toolkit.getDefaultToolkit().sync();
0362 sleep(info.flashTime);
0363 }
0364 graphics.setColor(oldColor);
0365 }
0366 graphics.drawRect(x, y, width, height);
0367 }
0368
0369 /**
0370 * Overrides <code>Graphics.fillRect</code>.
0371 */
0372 public void fillRect(int x, int y, int width, int height) {
0373 DebugGraphicsInfo info = info();
0374
0375 if (debugLog()) {
0376 info().log(
0377 toShortString() + " Filling rect: "
0378 + new Rectangle(x, y, width, height));
0379 }
0380
0381 if (isDrawingBuffer()) {
0382 if (debugBuffered()) {
0383 Graphics debugGraphics = debugGraphics();
0384
0385 debugGraphics.fillRect(x, y, width, height);
0386 debugGraphics.dispose();
0387 }
0388 } else if (debugFlash()) {
0389 Color oldColor = getColor();
0390 int i, count = (info.flashCount * 2) - 1;
0391
0392 for (i = 0; i < count; i++) {
0393 graphics.setColor((i % 2) == 0 ? info.flashColor
0394 : oldColor);
0395 graphics.fillRect(x, y, width, height);
0396 Toolkit.getDefaultToolkit().sync();
0397 sleep(info.flashTime);
0398 }
0399 graphics.setColor(oldColor);
0400 }
0401 graphics.fillRect(x, y, width, height);
0402 }
0403
0404 /**
0405 * Overrides <code>Graphics.clearRect</code>.
0406 */
0407 public void clearRect(int x, int y, int width, int height) {
0408 DebugGraphicsInfo info = info();
0409
0410 if (debugLog()) {
0411 info().log(
0412 toShortString() + " Clearing rect: "
0413 + new Rectangle(x, y, width, height));
0414 }
0415
0416 if (isDrawingBuffer()) {
0417 if (debugBuffered()) {
0418 Graphics debugGraphics = debugGraphics();
0419
0420 debugGraphics.clearRect(x, y, width, height);
0421 debugGraphics.dispose();
0422 }
0423 } else if (debugFlash()) {
0424 Color oldColor = getColor();
0425 int i, count = (info.flashCount * 2) - 1;
0426
0427 for (i = 0; i < count; i++) {
0428 graphics.setColor((i % 2) == 0 ? info.flashColor
0429 : oldColor);
0430 graphics.clearRect(x, y, width, height);
0431 Toolkit.getDefaultToolkit().sync();
0432 sleep(info.flashTime);
0433 }
0434 graphics.setColor(oldColor);
0435 }
0436 graphics.clearRect(x, y, width, height);
0437 }
0438
0439 /**
0440 * Overrides <code>Graphics.drawRoundRect</code>.
0441 */
0442 public void drawRoundRect(int x, int y, int width, int height,
0443 int arcWidth, int arcHeight) {
0444 DebugGraphicsInfo info = info();
0445
0446 if (debugLog()) {
0447 info().log(
0448 toShortString() + " Drawing round rect: "
0449 + new Rectangle(x, y, width, height)
0450 + " arcWidth: " + arcWidth
0451 + " archHeight: " + arcHeight);
0452 }
0453 if (isDrawingBuffer()) {
0454 if (debugBuffered()) {
0455 Graphics debugGraphics = debugGraphics();
0456
0457 debugGraphics.drawRoundRect(x, y, width, height,
0458 arcWidth, arcHeight);
0459 debugGraphics.dispose();
0460 }
0461 } else if (debugFlash()) {
0462 Color oldColor = getColor();
0463 int i, count = (info.flashCount * 2) - 1;
0464
0465 for (i = 0; i < count; i++) {
0466 graphics.setColor((i % 2) == 0 ? info.flashColor
0467 : oldColor);
0468 graphics.drawRoundRect(x, y, width, height, arcWidth,
0469 arcHeight);
0470 Toolkit.getDefaultToolkit().sync();
0471 sleep(info.flashTime);
0472 }
0473 graphics.setColor(oldColor);
0474 }
0475 graphics
0476 .drawRoundRect(x, y, width, height, arcWidth, arcHeight);
0477 }
0478
0479 /**
0480 * Overrides <code>Graphics.fillRoundRect</code>.
0481 */
0482 public void fillRoundRect(int x, int y, int width, int height,
0483 int arcWidth, int arcHeight) {
0484 DebugGraphicsInfo info = info();
0485
0486 if (debugLog()) {
0487 info().log(
0488 toShortString() + " Filling round rect: "
0489 + new Rectangle(x, y, width, height)
0490 + " arcWidth: " + arcWidth
0491 + " archHeight: " + arcHeight);
0492 }
0493 if (isDrawingBuffer()) {
0494 if (debugBuffered()) {
0495 Graphics debugGraphics = debugGraphics();
0496
0497 debugGraphics.fillRoundRect(x, y, width, height,
0498 arcWidth, arcHeight);
0499 debugGraphics.dispose();
0500 }
0501 } else if (debugFlash()) {
0502 Color oldColor = getColor();
0503 int i, count = (info.flashCount * 2) - 1;
0504
0505 for (i = 0; i < count; i++) {
0506 graphics.setColor((i % 2) == 0 ? info.flashColor
0507 : oldColor);
0508 graphics.fillRoundRect(x, y, width, height, arcWidth,
0509 arcHeight);
0510 Toolkit.getDefaultToolkit().sync();
0511 sleep(info.flashTime);
0512 }
0513 graphics.setColor(oldColor);
0514 }
0515 graphics
0516 .fillRoundRect(x, y, width, height, arcWidth, arcHeight);
0517 }
0518
0519 /**
0520 * Overrides <code>Graphics.drawLine</code>.
0521 */
0522 public void drawLine(int x1, int y1, int x2, int y2) {
0523 DebugGraphicsInfo info = info();
0524
0525 if (debugLog()) {
0526 info().log(
0527 toShortString() + " Drawing line: from "
0528 + pointToString(x1, y1) + " to "
0529 + pointToString(x2, y2));
0530 }
0531
0532 if (isDrawingBuffer()) {
0533 if (debugBuffered()) {
0534 Graphics debugGraphics = debugGraphics();
0535
0536 debugGraphics.drawLine(x1, y1, x2, y2);
0537 debugGraphics.dispose();
0538 }
0539 } else if (debugFlash()) {
0540 Color oldColor = getColor();
0541 int i, count = (info.flashCount * 2) - 1;
0542
0543 for (i = 0; i < count; i++) {
0544 graphics.setColor((i % 2) == 0 ? info.flashColor
0545 : oldColor);
0546 graphics.drawLine(x1, y1, x2, y2);
0547 Toolkit.getDefaultToolkit().sync();
0548 sleep(info.flashTime);
0549 }
0550 graphics.setColor(oldColor);
0551 }
0552 graphics.drawLine(x1, y1, x2, y2);
0553 }
0554
0555 /**
0556 * Overrides <code>Graphics.draw3DRect</code>.
0557 */
0558 public void draw3DRect(int x, int y, int width, int height,
0559 boolean raised) {
0560 DebugGraphicsInfo info = info();
0561
0562 if (debugLog()) {
0563 info().log(
0564 toShortString() + " Drawing 3D rect: "
0565 + new Rectangle(x, y, width, height)
0566 + " Raised bezel: " + raised);
0567 }
0568 if (isDrawingBuffer()) {
0569 if (debugBuffered()) {
0570 Graphics debugGraphics = debugGraphics();
0571
0572 debugGraphics.draw3DRect(x, y, width, height, raised);
0573 debugGraphics.dispose();
0574 }
0575 } else if (debugFlash()) {
0576 Color oldColor = getColor();
0577 int i, count = (info.flashCount * 2) - 1;
0578
0579 for (i = 0; i < count; i++) {
0580 graphics.setColor((i % 2) == 0 ? info.flashColor
0581 : oldColor);
0582 graphics.draw3DRect(x, y, width, height, raised);
0583 Toolkit.getDefaultToolkit().sync();
0584 sleep(info.flashTime);
0585 }
0586 graphics.setColor(oldColor);
0587 }
0588 graphics.draw3DRect(x, y, width, height, raised);
0589 }
0590
0591 /**
0592 * Overrides <code>Graphics.fill3DRect</code>.
0593 */
0594 public void fill3DRect(int x, int y, int width, int height,
0595 boolean raised) {
0596 DebugGraphicsInfo info = info();
0597
0598 if (debugLog()) {
0599 info().log(
0600 toShortString() + " Filling 3D rect: "
0601 + new Rectangle(x, y, width, height)
0602 + " Raised bezel: " + raised);
0603 }
0604 if (isDrawingBuffer()) {
0605 if (debugBuffered()) {
0606 Graphics debugGraphics = debugGraphics();
0607
0608 debugGraphics.fill3DRect(x, y, width, height, raised);
0609 debugGraphics.dispose();
0610 }
0611 } else if (debugFlash()) {
0612 Color oldColor = getColor();
0613 int i, count = (info.flashCount * 2) - 1;
0614
0615 for (i = 0; i < count; i++) {
0616 graphics.setColor((i % 2) == 0 ? info.flashColor
0617 : oldColor);
0618 graphics.fill3DRect(x, y, width, height, raised);
0619 Toolkit.getDefaultToolkit().sync();
0620 sleep(info.flashTime);
0621 }
0622 graphics.setColor(oldColor);
0623 }
0624 graphics.fill3DRect(x, y, width, height, raised);
0625 }
0626
0627 /**
0628 * Overrides <code>Graphics.drawOval</code>.
0629 */
0630 public void drawOval(int x, int y, int width, int height) {
0631 DebugGraphicsInfo info = info();
0632
0633 if (debugLog()) {
0634 info().log(
0635 toShortString() + " Drawing oval: "
0636 + new Rectangle(x, y, width, height));
0637 }
0638 if (isDrawingBuffer()) {
0639 if (debugBuffered()) {
0640 Graphics debugGraphics = debugGraphics();
0641
0642 debugGraphics.drawOval(x, y, width, height);
0643 debugGraphics.dispose();
0644 }
0645 } else if (debugFlash()) {
0646 Color oldColor = getColor();
0647 int i, count = (info.flashCount * 2) - 1;
0648
0649 for (i = 0; i < count; i++) {
0650 graphics.setColor((i % 2) == 0 ? info.flashColor
0651 : oldColor);
0652 graphics.drawOval(x, y, width, height);
0653 Toolkit.getDefaultToolkit().sync();
0654 sleep(info.flashTime);
0655 }
0656 graphics.setColor(oldColor);
0657 }
0658 graphics.drawOval(x, y, width, height);
0659 }
0660
0661 /**
0662 * Overrides <code>Graphics.fillOval</code>.
0663 */
0664 public void fillOval(int x, int y, int width, int height) {
0665 DebugGraphicsInfo info = info();
0666
0667 if (debugLog()) {
0668 info().log(
0669 toShortString() + " Filling oval: "
0670 + new Rectangle(x, y, width, height));
0671 }
0672 if (isDrawingBuffer()) {
0673 if (debugBuffered()) {
0674 Graphics debugGraphics = debugGraphics();
0675
0676 debugGraphics.fillOval(x, y, width, height);
0677 debugGraphics.dispose();
0678 }
0679 } else if (debugFlash()) {
0680 Color oldColor = getColor();
0681 int i, count = (info.flashCount * 2) - 1;
0682
0683 for (i = 0; i < count; i++) {
0684 graphics.setColor((i % 2) == 0 ? info.flashColor
0685 : oldColor);
0686 graphics.fillOval(x, y, width, height);
0687 Toolkit.getDefaultToolkit().sync();
0688 sleep(info.flashTime);
0689 }
0690 graphics.setColor(oldColor);
0691 }
0692 graphics.fillOval(x, y, width, height);
0693 }
0694
0695 /**
0696 * Overrides <code>Graphics.drawArc</code>.
0697 */
0698 public void drawArc(int x, int y, int width, int height,
0699 int startAngle, int arcAngle) {
0700 DebugGraphicsInfo info = info();
0701
0702 if (debugLog()) {
0703 info().log(
0704 toShortString() + " Drawing arc: "
0705 + new Rectangle(x, y, width, height)
0706 + " startAngle: " + startAngle
0707 + " arcAngle: " + arcAngle);
0708 }
0709 if (isDrawingBuffer()) {
0710 if (debugBuffered()) {
0711 Graphics debugGraphics = debugGraphics();
0712
0713 debugGraphics.drawArc(x, y, width, height, startAngle,
0714 arcAngle);
0715 debugGraphics.dispose();
0716 }
0717 } else if (debugFlash()) {
0718 Color oldColor = getColor();
0719 int i, count = (info.flashCount * 2) - 1;
0720
0721 for (i = 0; i < count; i++) {
0722 graphics.setColor((i % 2) == 0 ? info.flashColor
0723 : oldColor);
0724 graphics.drawArc(x, y, width, height, startAngle,
0725 arcAngle);
0726 Toolkit.getDefaultToolkit().sync();
0727 sleep(info.flashTime);
0728 }
0729 graphics.setColor(oldColor);
0730 }
0731 graphics.drawArc(x, y, width, height, startAngle, arcAngle);
0732 }
0733
0734 /**
0735 * Overrides <code>Graphics.fillArc</code>.
0736 */
0737 public void fillArc(int x, int y, int width, int height,
0738 int startAngle, int arcAngle) {
0739 DebugGraphicsInfo info = info();
0740
0741 if (debugLog()) {
0742 info().log(
0743 toShortString() + " Filling arc: "
0744 + new Rectangle(x, y, width, height)
0745 + " startAngle: " + startAngle
0746 + " arcAngle: " + arcAngle);
0747 }
0748 if (isDrawingBuffer()) {
0749 if (debugBuffered()) {
0750 Graphics debugGraphics = debugGraphics();
0751
0752 debugGraphics.fillArc(x, y, width, height, startAngle,
0753 arcAngle);
0754 debugGraphics.dispose();
0755 }
0756 } else if (debugFlash()) {
0757 Color oldColor = getColor();
0758 int i, count = (info.flashCount * 2) - 1;
0759
0760 for (i = 0; i < count; i++) {
0761 graphics.setColor((i % 2) == 0 ? info.flashColor
0762 : oldColor);
0763 graphics.fillArc(x, y, width, height, startAngle,
0764 arcAngle);
0765 Toolkit.getDefaultToolkit().sync();
0766 sleep(info.flashTime);
0767 }
0768 graphics.setColor(oldColor);
0769 }
0770 graphics.fillArc(x, y, width, height, startAngle, arcAngle);
0771 }
0772
0773 /**
0774 * Overrides <code>Graphics.drawPolyline</code>.
0775 */
0776 public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
0777 DebugGraphicsInfo info = info();
0778
0779 if (debugLog()) {
0780 info().log(
0781 toShortString() + " Drawing polyline: "
0782 + " nPoints: " + nPoints + " X's: "
0783 + xPoints + " Y's: " + yPoints);
0784 }
0785 if (isDrawingBuffer()) {
0786 if (debugBuffered()) {
0787 Graphics debugGraphics = debugGraphics();
0788
0789 debugGraphics.drawPolyline(xPoints, yPoints, nPoints);
0790 debugGraphics.dispose();
0791 }
0792 } else if (debugFlash()) {
0793 Color oldColor = getColor();
0794 int i, count = (info.flashCount * 2) - 1;
0795
0796 for (i = 0; i < count; i++) {
0797 graphics.setColor((i % 2) == 0 ? info.flashColor
0798 : oldColor);
0799 graphics.drawPolyline(xPoints, yPoints, nPoints);
0800 Toolkit.getDefaultToolkit().sync();
0801 sleep(info.flashTime);
0802 }
0803 graphics.setColor(oldColor);
0804 }
0805 graphics.drawPolyline(xPoints, yPoints, nPoints);
0806 }
0807
0808 /**
0809 * Overrides <code>Graphics.drawPolygon</code>.
0810 */
0811 public void drawPolygon(int xPoints[], int yPoints[], int nPoints) {
0812 DebugGraphicsInfo info = info();
0813
0814 if (debugLog()) {
0815 info().log(
0816 toShortString() + " Drawing polygon: "
0817 + " nPoints: " + nPoints + " X's: "
0818 + xPoints + " Y's: " + yPoints);
0819 }
0820 if (isDrawingBuffer()) {
0821 if (debugBuffered()) {
0822 Graphics debugGraphics = debugGraphics();
0823
0824 debugGraphics.drawPolygon(xPoints, yPoints, nPoints);
0825 debugGraphics.dispose();
0826 }
0827 } else if (debugFlash()) {
0828 Color oldColor = getColor();
0829 int i, count = (info.flashCount * 2) - 1;
0830
0831 for (i = 0; i < count; i++) {
0832 graphics.setColor((i % 2) == 0 ? info.flashColor
0833 : oldColor);
0834 graphics.drawPolygon(xPoints, yPoints, nPoints);
0835 Toolkit.getDefaultToolkit().sync();
0836 sleep(info.flashTime);
0837 }
0838 graphics.setColor(oldColor);
0839 }
0840 graphics.drawPolygon(xPoints, yPoints, nPoints);
0841 }
0842
0843 /**
0844 * Overrides <code>Graphics.fillPolygon</code>.
0845 */
0846 public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
0847 DebugGraphicsInfo info = info();
0848
0849 if (debugLog()) {
0850 info().log(
0851 toShortString() + " Filling polygon: "
0852 + " nPoints: " + nPoints + " X's: "
0853 + xPoints + " Y's: " + yPoints);
0854 }
0855 if (isDrawingBuffer()) {
0856 if (debugBuffered()) {
0857 Graphics debugGraphics = debugGraphics();
0858
0859 debugGraphics.fillPolygon(xPoints, yPoints, nPoints);
0860 debugGraphics.dispose();
0861 }
0862 } else if (debugFlash()) {
0863 Color oldColor = getColor();
0864 int i, count = (info.flashCount * 2) - 1;
0865
0866 for (i = 0; i < count; i++) {
0867 graphics.setColor((i % 2) == 0 ? info.flashColor
0868 : oldColor);
0869 graphics.fillPolygon(xPoints, yPoints, nPoints);
0870 Toolkit.getDefaultToolkit().sync();
0871 sleep(info.flashTime);
0872 }
0873 graphics.setColor(oldColor);
0874 }
0875 graphics.fillPolygon(xPoints, yPoints, nPoints);
0876 }
0877
0878 /**
0879 * Overrides <code>Graphics.drawString</code>.
0880 */
0881 public void drawString(String aString, int x, int y) {
0882 DebugGraphicsInfo info = info();
0883
0884 if (debugLog()) {
0885 info().log(
0886 toShortString() + " Drawing string: \"" + aString
0887 + "\" at: " + new Point(x, y));
0888 }
0889
0890 if (isDrawingBuffer()) {
0891 if (debugBuffered()) {
0892 Graphics debugGraphics = debugGraphics();
0893
0894 debugGraphics.drawString(aString, x, y);
0895 debugGraphics.dispose();
0896 }
0897 } else if (debugFlash()) {
0898 Color oldColor = getColor();
0899 int i, count = (info.flashCount * 2) - 1;
0900
0901 for (i = 0; i < count; i++) {
0902 graphics.setColor((i % 2) == 0 ? info.flashColor
0903 : oldColor);
0904 graphics.drawString(aString, x, y);
0905 Toolkit.getDefaultToolkit().sync();
0906 sleep(info.flashTime);
0907 }
0908 graphics.setColor(oldColor);
0909 }
0910 graphics.drawString(aString, x, y);
0911 }
0912
0913 /**
0914 * Overrides <code>Graphics.drawString</code>.
0915 */
0916 public void drawString(AttributedCharacterIterator iterator, int x,
0917 int y) {
0918 DebugGraphicsInfo info = info();
0919
0920 if (debugLog()) {
0921 info().log(
0922 toShortString() + " Drawing text: \"" + iterator
0923 + "\" at: " + new Point(x, y));
0924 }
0925
0926 if (isDrawingBuffer()) {
0927 if (debugBuffered()) {
0928 Graphics debugGraphics = debugGraphics();
0929
0930 debugGraphics.drawString(iterator, x, y);
0931 debugGraphics.dispose();
0932 }
0933 } else if (debugFlash()) {
0934 Color oldColor = getColor();
0935 int i, count = (info.flashCount * 2) - 1;
0936
0937 for (i = 0; i < count; i++) {
0938 graphics.setColor((i % 2) == 0 ? info.flashColor
0939 : oldColor);
0940 graphics.drawString(iterator, x, y);
0941 Toolkit.getDefaultToolkit().sync();
0942 sleep(info.flashTime);
0943 }
0944 graphics.setColor(oldColor);
0945 }
0946 graphics.drawString(iterator, x, y);
0947 }
0948
0949 /**
0950 * Overrides <code>Graphics.drawBytes</code>.
0951 */
0952 public void drawBytes(byte data[], int offset, int length, int x,
0953 int y) {
0954 DebugGraphicsInfo info = info();
0955
0956 Font font = graphics.getFont();
0957
0958 if (debugLog()) {
0959 info().log(
0960 toShortString() + " Drawing bytes at: "
0961 + new Point(x, y));
0962 }
0963
0964 if (isDrawingBuffer()) {
0965 if (debugBuffered()) {
0966 Graphics debugGraphics = debugGraphics();
0967
0968 debugGraphics.drawBytes(data, offset, length, x, y);
0969 debugGraphics.dispose();
0970 }
0971 } else if (debugFlash()) {
0972 Color oldColor = getColor();
0973 int i, count = (info.flashCount * 2) - 1;
0974
0975 for (i = 0; i < count; i++) {
0976 graphics.setColor((i % 2) == 0 ? info.flashColor
0977 : oldColor);
0978 graphics.drawBytes(data, offset, length, x, y);
0979 Toolkit.getDefaultToolkit().sync();
0980 sleep(info.flashTime);
0981 }
0982 graphics.setColor(oldColor);
0983 }
0984 graphics.drawBytes(data, offset, length, x, y);
0985 }
0986
0987 /**
0988 * Overrides <code>Graphics.drawChars</code>.
0989 */
0990 public void drawChars(char data[], int offset, int length, int x,
0991 int y) {
0992 DebugGraphicsInfo info = info();
0993
0994 Font font = graphics.getFont();
0995
0996 if (debugLog()) {
0997 info().log(
0998 toShortString() + " Drawing chars at "
0999 + new Point(x, y));
1000 }
1001
1002 if (isDrawingBuffer()) {
1003 if (debugBuffered()) {
1004 Graphics debugGraphics = debugGraphics();
1005
1006 debugGraphics.drawChars(data, offset, length, x, y);
1007 debugGraphics.dispose();
1008 }
1009 } else if (debugFlash()) {
1010 Color oldColor = getColor();
1011 int i, count = (info.flashCount * 2) - 1;
1012
1013 for (i = 0; i < count; i++) {
1014 graphics.setColor((i % 2) == 0 ? info.flashColor
1015 : oldColor);
1016 graphics.drawChars(data, offset, length, x, y);
1017 Toolkit.getDefaultToolkit().sync();
1018 sleep(info.flashTime);
1019 }
1020 graphics.setColor(oldColor);
1021 }
1022 graphics.drawChars(data, offset, length, x, y);
1023 }
1024
1025 /**
1026 * Overrides <code>Graphics.drawImage</code>.
1027 */
1028 public boolean drawImage(Image img, int x, int y,
1029 ImageObserver observer) {
1030 DebugGraphicsInfo info = info();
1031
1032 if (debugLog()) {
1033 info.log(toShortString() + " Drawing image: " + img
1034 + " at: " + new Point(x, y));
1035 }
1036
1037 if (isDrawingBuffer()) {
1038 if (debugBuffered()) {
1039 Graphics debugGraphics = debugGraphics();
1040
1041 debugGraphics.drawImage(img, x, y, observer);
1042 debugGraphics.dispose();
1043 }
1044 } else if (debugFlash()) {
1045 int i, count = (info.flashCount * 2) - 1;
1046 ImageProducer oldProducer = img.getSource();
1047 ImageProducer newProducer = new FilteredImageSource(
1048 oldProducer, new DebugGraphicsFilter(
1049 info.flashColor));
1050 Image newImage = Toolkit.getDefaultToolkit().createImage(
1051 newProducer);
1052 DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
1053
1054 Image imageToDraw;
1055 for (i = 0; i < count; i++) {
1056 imageToDraw = (i % 2) == 0 ? newImage : img;
1057 loadImage(imageToDraw);
1058 graphics.drawImage(imageToDraw, x, y, imageObserver);
1059 Toolkit.getDefaultToolkit().sync();
1060 sleep(info.flashTime);
1061 }
1062 }
1063 return graphics.drawImage(img, x, y, observer);
1064 }
1065
1066 /**
1067 * Overrides <code>Graphics.drawImage</code>.
1068 */
1069 public boolean drawImage(Image img, int x, int y, int width,
1070 int height, ImageObserver observer) {
1071 DebugGraphicsInfo info = info();
1072
1073 if (debugLog()) {
1074 info.log(toShortString() + " Drawing image: " + img
1075 + " at: " + new Rectangle(x, y, width, height));
1076 }
1077
1078 if (isDrawingBuffer()) {
1079 if (debugBuffered()) {
1080 Graphics debugGraphics = debugGraphics();
1081
1082 debugGraphics.drawImage(img, x, y, width, height,
1083 observer);
1084 debugGraphics.dispose();
1085 }
1086 } else if (debugFlash()) {
1087 int i, count = (info.flashCount * 2) - 1;
1088 ImageProducer oldProducer = img.getSource();
1089 ImageProducer newProducer = new FilteredImageSource(
1090 oldProducer, new DebugGraphicsFilter(
1091 info.flashColor));
1092 Image newImage = Toolkit.getDefaultToolkit().createImage(
1093 newProducer);
1094 DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
1095
1096 Image imageToDraw;
1097 for (i = 0; i < count; i++) {
1098 imageToDraw = (i % 2) == 0 ? newImage : img;
1099 loadImage(imageToDraw);
1100 graphics.drawImage(imageToDraw, x, y, width, height,
1101 imageObserver);
1102 Toolkit.getDefaultToolkit().sync();
1103 sleep(info.flashTime);
1104 }
1105 }
1106 return graphics.drawImage(img, x, y, width, height, observer);
1107 }
1108
1109 /**
1110 * Overrides <code>Graphics.drawImage</code>.
1111 */
1112 public boolean drawImage(Image img, int x, int y, Color bgcolor,
1113 ImageObserver observer) {
1114 DebugGraphicsInfo info = info();
1115
1116 if (debugLog()) {
1117 info.log(toShortString() + " Drawing image: " + img
1118 + " at: " + new Point(x, y) + ", bgcolor: "
1119 + bgcolor);
1120 }
1121
1122 if (isDrawingBuffer()) {
1123 if (debugBuffered()) {
1124 Graphics debugGraphics = debugGraphics();
1125
1126 debugGraphics.drawImage(img, x, y, bgcolor, observer);
1127 debugGraphics.dispose();
1128 }
1129 } else if (debugFlash()) {
1130 int i, count = (info.flashCount * 2) - 1;
1131 ImageProducer oldProducer = img.getSource();
1132 ImageProducer newProducer = new FilteredImageSource(
1133 oldProducer, new DebugGraphicsFilter(
1134 info.flashColor));
1135 Image newImage = Toolkit.getDefaultToolkit().createImage(
1136 newProducer);
1137 DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
1138
1139 Image imageToDraw;
1140 for (i = 0; i < count; i++) {
1141 imageToDraw = (i % 2) == 0 ? newImage : img;
1142 loadImage(imageToDraw);
1143 graphics.drawImage(imageToDraw, x, y, bgcolor,
1144 imageObserver);
1145 Toolkit.getDefaultToolkit().sync();
1146 sleep(info.flashTime);
1147 }
1148 }
1149 return graphics.drawImage(img, x, y, bgcolor, observer);
1150 }
1151
1152 /**
1153 * Overrides <code>Graphics.drawImage</code>.
1154 */
1155 public boolean drawImage(Image img, int x, int y, int width,
1156 int height, Color bgcolor, ImageObserver observer) {
1157 DebugGraphicsInfo info = info();
1158
1159 if (debugLog()) {
1160 info.log(toShortString() + " Drawing image: " + img
1161 + " at: " + new Rectangle(x, y, width, height)
1162 + ", bgcolor: " + bgcolor);
1163 }
1164
1165 if (isDrawingBuffer()) {
1166 if (debugBuffered()) {
1167 Graphics debugGraphics = debugGraphics();
1168
1169 debugGraphics.drawImage(img, x, y, width, height,
1170 bgcolor, observer);
1171 debugGraphics.dispose();
1172 }
1173 } else if (debugFlash()) {
1174 int i, count = (info.flashCount * 2) - 1;
1175 ImageProducer oldProducer = img.getSource();
1176 ImageProducer newProducer = new FilteredImageSource(
1177 oldProducer, new DebugGraphicsFilter(
1178 info.flashColor));
1179 Image newImage = Toolkit.getDefaultToolkit().createImage(
1180 newProducer);
1181 DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
1182
1183 Image imageToDraw;
1184 for (i = 0; i < count; i++) {
1185 imageToDraw = (i % 2) == 0 ? newImage : img;
1186 loadImage(imageToDraw);
1187 graphics.drawImage(imageToDraw, x, y, width, height,
1188 bgcolor, imageObserver);
1189 Toolkit.getDefaultToolkit().sync();
1190 sleep(info.flashTime);
1191 }
1192 }
1193 return graphics.drawImage(img, x, y, width, height, bgcolor,
1194 observer);
1195 }
1196
1197 /**
1198 * Overrides <code>Graphics.drawImage</code>.
1199 */
1200 public boolean drawImage(Image img, int dx1, int dy1, int dx2,
1201 int dy2, int sx1, int sy1, int sx2, int sy2,
1202 ImageObserver observer) {
1203 DebugGraphicsInfo info = info();
1204
1205 if (debugLog()) {
1206 info.log(toShortString() + " Drawing image: " + img
1207 + " destination: "
1208 + new Rectangle(dx1, dy1, dx2, dy2) + " source: "
1209 + new Rectangle(sx1, sy1, sx2, sy2));
1210 }
1211
1212 if (isDrawingBuffer()) {
1213 if (debugBuffered()) {
1214 Graphics debugGraphics = debugGraphics();
1215
1216 debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1,
1217 sy1, sx2, sy2, observer);
1218 debugGraphics.dispose();
1219 }
1220 } else if (debugFlash()) {
1221 int i, count = (info.flashCount * 2) - 1;
1222 ImageProducer oldProducer = img.getSource();
1223 ImageProducer newProducer = new FilteredImageSource(
1224 oldProducer, new DebugGraphicsFilter(
1225 info.flashColor));
1226 Image newImage = Toolkit.getDefaultToolkit().createImage(
1227 newProducer);
1228 DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
1229
1230 Image imageToDraw;
1231 for (i = 0; i < count; i++) {
1232 imageToDraw = (i % 2) == 0 ? newImage : img;
1233 loadImage(imageToDraw);
1234 graphics.drawImage(imageToDraw, dx1, dy1, dx2, dy2,
1235 sx1, sy1, sx2, sy2, imageObserver);
1236 Toolkit.getDefaultToolkit().sync();
1237 sleep(info.flashTime);
1238 }
1239 }
1240 return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1,
1241 sx2, sy2, observer);
1242 }
1243
1244 /**
1245 * Overrides <code>Graphics.drawImage</code>.
1246 */
1247 public boolean drawImage(Image img, int dx1, int dy1, int dx2,
1248 int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
1249 ImageObserver observer) {
1250 DebugGraphicsInfo info = info();
1251
1252 if (debugLog()) {
1253 info.log(toShortString() + " Drawing image: " + img
1254 + " destination: "
1255 + new Rectangle(dx1, dy1, dx2, dy2) + " source: "
1256 + new Rectangle(sx1, sy1, sx2, sy2) + ", bgcolor: "
1257 + bgcolor);
1258 }
1259
1260 if (isDrawingBuffer()) {
1261 if (debugBuffered()) {
1262 Graphics debugGraphics = debugGraphics();
1263
1264 debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1,
1265 sy1, sx2, sy2, bgcolor, observer);
1266 debugGraphics.dispose();
1267 }
1268 } else if (debugFlash()) {
1269 int i, count = (info.flashCount * 2) - 1;
1270 ImageProducer oldProducer = img.getSource();
1271 ImageProducer newProducer = new FilteredImageSource(
1272 oldProducer, new DebugGraphicsFilter(
1273 info.flashColor));
1274 Image newImage = Toolkit.getDefaultToolkit().createImage(
1275 newProducer);
1276 DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();
1277
1278 Image imageToDraw;
1279 for (i = 0; i < count; i++) {
1280 imageToDraw = (i % 2) == 0 ? newImage : img;
1281 loadImage(imageToDraw);
1282 graphics.drawImage(imageToDraw, dx1, dy1, dx2, dy2,
1283 sx1, sy1, sx2, sy2, bgcolor, imageObserver);
1284 Toolkit.getDefaultToolkit().sync();
1285 sleep(info.flashTime);
1286 }
1287 }
1288 return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1,
1289 sx2, sy2, bgcolor, observer);
1290 }
1291
1292 static void loadImage(Image img) {
1293 imageLoadingIcon.loadImage(img);
1294 }
1295
1296 /**
1297 * Overrides <code>Graphics.copyArea</code>.
1298 */
1299 public void copyArea(int x, int y, int width, int height,
1300 int destX, int destY) {
1301 if (debugLog()) {
1302 info().log(
1303 toShortString() + " Copying area from: "
1304 + new Rectangle(x, y, width, height)
1305 + " to: " + new Point(destX, destY));
1306 }
1307 graphics.copyArea(x, y, width, height, destX, destY);
1308 }
1309
1310 final void sleep(int mSecs) {
1311 try {
1312 Thread.sleep(mSecs);
1313 } catch (Exception e) {
1314 }
1315 }
1316
1317 /**
1318 * Overrides <code>Graphics.dispose</code>.
1319 */
1320 public void dispose() {
1321 graphics.dispose();
1322 graphics = null;
1323 }
1324
1325 // ALERT!
1326 /**
1327 * Returns the drawingBuffer value.
1328 *
1329 * @return true if this object is drawing from a Buffer
1330 */
1331 public boolean isDrawingBuffer() {
1332 return buffer != null;
1333 }
1334
1335 String toShortString() {
1336 StringBuffer buffer = new StringBuffer("Graphics"
1337 + (isDrawingBuffer() ? "<B>" : "") + "(" + graphicsID
1338 + "-" + debugOptions + ")");
1339 return buffer.toString();
1340 }
1341
1342 String pointToString(int x, int y) {
1343 StringBuffer buffer = new StringBuffer("(" + x + ", " + y + ")");
1344 return buffer.toString();
1345 }
1346
1347 /** Enables/disables diagnostic information about every graphics
1348 * operation. The value of <b>options</b> indicates how this information
1349 * should be displayed. LOG_OPTION causes a text message to be printed.
1350 * FLASH_OPTION causes the drawing to flash several times. BUFFERED_OPTION
1351 * creates a new Frame that shows each operation on an
1352 * offscreen buffer. The value of <b>options</b> is bitwise OR'd into
1353 * the current value. To disable debugging use NONE_OPTION.
1354 */
1355 public void setDebugOptions(int options) {
1356 if (options != 0) {
1357 if (options == NONE_OPTION) {
1358 if (debugOptions != 0) {
1359 System.err.println(toShortString()
1360 + " Disabling debug");
1361 debugOptions = 0;
1362 }
1363 } else {
1364 if (debugOptions != options) {
1365 debugOptions |= options;
1366 if (debugLog()) {
1367 System.err.println(toShortString()
1368 + " Enabling debug");
1369 }
1370 }
1371 }
1372 }
1373 }
1374
1375 /** Returns the current debugging options for this DebugGraphics.
1376 * @see #setDebugOptions
1377 */
1378 public int getDebugOptions() {
1379 return debugOptions;
1380 }
1381
1382 /** Static wrapper method for DebugGraphicsInfo.setDebugOptions(). Stores
1383 * options on a per component basis.
1384 */
1385 static void setDebugOptions(JComponent component, int options) {
1386 info().setDebugOptions(component, options);
1387 }
1388
1389 /** Static wrapper method for DebugGraphicsInfo.getDebugOptions().
1390 */
1391 static int getDebugOptions(JComponent component) {
1392 DebugGraphicsInfo debugGraphicsInfo = info();
1393 if (debugGraphicsInfo == null) {
1394 return 0;
1395 } else {
1396 return debugGraphicsInfo.getDebugOptions(component);
1397 }
1398 }
1399
1400 /** Returns non-zero if <b>component</b> should display with DebugGraphics,
1401 * zero otherwise. Walks the JComponent's parent tree to determine if
1402 * any debugging options have been set.
1403 */
1404 static int shouldComponentDebug(JComponent component) {
1405 DebugGraphicsInfo info = info();
1406 if (info == null) {
1407 return 0;
1408 } else {
1409 Container container = (Container) component;
1410 int debugOptions = 0;
1411
1412 while (container != null
1413 && (container instanceof JComponent)) {
1414 debugOptions |= info
1415 .getDebugOptions((JComponent) container);
1416 container = container.getParent();
1417 }
1418
1419 return debugOptions;
1420 }
1421 }
1422
1423 /** Returns the number of JComponents that have debugging options turned
1424 * on.
1425 */
1426 static int debugComponentCount() {
1427 DebugGraphicsInfo debugGraphicsInfo = info();
1428 if (debugGraphicsInfo != null
1429 && debugGraphicsInfo.componentToDebug != null) {
1430 return debugGraphicsInfo.componentToDebug.size();
1431 } else {
1432 return 0;
1433 }
1434 }
1435
1436 boolean debugLog() {
1437 return (debugOptions & LOG_OPTION) == LOG_OPTION;
1438 }
1439
1440 boolean debugFlash() {
1441 return (debugOptions & FLASH_OPTION) == FLASH_OPTION;
1442 }
1443
1444 boolean debugBuffered() {
1445 return (debugOptions & BUFFERED_OPTION) == BUFFERED_OPTION;
1446 }
1447
1448 /** Returns a DebugGraphics for use in buffering window.
1449 */
1450 private Graphics debugGraphics() {
1451 DebugGraphics debugGraphics;
1452 DebugGraphicsInfo info = info();
1453 JFrame debugFrame;
1454
1455 if (info.debugFrame == null) {
1456 info.debugFrame = new JFrame();
1457 info.debugFrame.setSize(500, 500);
1458 }
1459 debugFrame = info.debugFrame;
1460 debugFrame.show();
1461 debugGraphics = new DebugGraphics(debugFrame.getGraphics());
1462 debugGraphics.setFont(getFont());
1463 debugGraphics.setColor(getColor());
1464 debugGraphics.translate(xOffset, yOffset);
1465 debugGraphics.setClip(getClipBounds());
1466 if (debugFlash()) {
1467 debugGraphics.setDebugOptions(FLASH_OPTION);
1468 }
1469 return debugGraphics;
1470 }
1471
1472 /** Returns DebugGraphicsInfo, or creates one if none exists.
1473 */
1474 static DebugGraphicsInfo info() {
1475 DebugGraphicsInfo debugGraphicsInfo = (DebugGraphicsInfo) SwingUtilities
1476 .appContextGet(debugGraphicsInfoKey);
1477 if (debugGraphicsInfo == null) {
1478 debugGraphicsInfo = new DebugGraphicsInfo();
1479 SwingUtilities.appContextPut(debugGraphicsInfoKey,
1480 debugGraphicsInfo);
1481 }
1482 return debugGraphicsInfo;
1483 }
1484
1485 private static final Class debugGraphicsInfoKey = DebugGraphicsInfo.class;
1486
1487 }
|