ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Rectangle(x, y, width, height)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, width, height, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, width, height, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, width, height, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y) + ", bgcolor: " + bgcolor); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, bgcolor, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, bgcolor, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, bgcolor, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y,int width, int height, Color bgcolor, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Rectangle(x, y, width, height) + ", bgcolor: " + bgcolor); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, width, height, bgcolor, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, width, height, bgcolor, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, width, height, bgcolor, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " destination: " + new Rectangle(dx1, dy1, dx2, dy2) + " source: " + new Rectangle(sx1, sy1, sx2, sy2)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " destination: " + new Rectangle(dx1, dy1, dx2, dy2) + " source: " + new Rectangle(sx1, sy1, sx2, sy2) + ", bgcolor: " + bgcolor); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } static void loadImage(Image img) { imageLoadingIcon.loadImage(img); } /** * Overrides <code>Graphics.copyArea</code>. */ public void copyArea(int x, int y, int width, int height, int destX, int destY) { if (debugLog()) { info().log(toShortString() + " Copying area from: " + new Rectangle(x, y, width, height) + " to: " + new Point(destX, destY)); } graphics.copyArea(x, y, width, height, destX, destY); } final void sleep(int mSecs) { try { Thread.sleep(mSecs); } catch (Exception e) { } } /** * Overrides <code>Graphics.dispose</code>. */ public void dispose() { graphics.dispose(); graphics = null; } // ALERT! /** * Returns the drawingBuffer value. * * @return true if this object is drawing from a Buffer */ public boolean isDrawingBuffer() { return buffer != null; } String toShortString() { return "Graphics" + (isDrawingBuffer() ? "<B>" : "") + "(" + graphicsID + "-" + debugOptions + ")"; } String pointToString(int x, int y) { return "(" + x + ", " + y + ")"; } /** Enables/disables diagnostic information about every graphics * operation. The value of <b>options</b> indicates how this information * should be displayed. LOG_OPTION causes a text message to be printed. * FLASH_OPTION causes the drawing to flash several times. BUFFERED_OPTION * creates a new Frame that shows each operation on an * offscreen buffer. The value of <b>options</b> is bitwise OR'd into * the current value. To disable debugging use NONE_OPTION. */ public void setDebugOptions(int options) { if (options != 0) { if (options == NONE_OPTION) { if (debugOptions != 0) { System.err.println(toShortString() + " Disabling debug"); debugOptions = 0; } } else { if (debugOptions != options) { debugOptions |= options; if (debugLog()) { System.err.println(toShortString() + " Enabling debug"); } } } } } /** Returns the current debugging options for this DebugGraphics. * @see #setDebugOptions */ public int getDebugOptions() { return debugOptions; } /** Static wrapper method for DebugGraphicsInfo.setDebugOptions(). Stores * options on a per component basis. */ static void setDebugOptions(JComponent component, int options) { info().setDebugOptions(component, options); } /** Static wrapper method for DebugGraphicsInfo.getDebugOptions(). */ static int getDebugOptions(JComponent component) { DebugGraphicsInfo debugGraphicsInfo = info(); if (debugGraphicsInfo == null) { return 0; } else { return debugGraphicsInfo.getDebugOptions(component); } } /** Returns non-zero if <b>component</b> should display with DebugGraphics, * zero otherwise. Walks the JComponent's parent tree to determine if * any debugging options have been set. */ static int shouldComponentDebug(JComponent component) { DebugGraphicsInfo info = info(); if (info == null) { return 0; } else { Container container = (Container)component; int debugOptions = 0; while (container != null && (container instanceof JComponent)) { debugOptions |= info.getDebugOptions((JComponent)container); container = container.getParent(); } return debugOptions; } } /** Returns the number of JComponents that have debugging options turned * on. */ static int debugComponentCount() { DebugGraphicsInfo debugGraphicsInfo = info(); if (debugGraphicsInfo != null && debugGraphicsInfo.componentToDebug != null) { return debugGraphicsInfo.componentToDebug.size(); } else { return 0; } } boolean debugLog() { return (debugOptions & LOG_OPTION) == LOG_OPTION; } boolean debugFlash() { return (debugOptions & FLASH_OPTION) == FLASH_OPTION; } boolean debugBuffered() { return (debugOptions & BUFFERED_OPTION) == BUFFERED_OPTION; } /** Returns a DebugGraphics for use in buffering window. */ private Graphics debugGraphics() { DebugGraphics debugGraphics; DebugGraphicsInfo info = info(); JFrame debugFrame; if (info.debugFrame == null) { info.debugFrame = new JFrame(); info.debugFrame.setSize(500, 500); } debugFrame = info.debugFrame; debugFrame.show(); debugGraphics = new DebugGraphics(debugFrame.getGraphics()); debugGraphics.setFont(getFont()); debugGraphics.setColor(getColor()); debugGraphics.translate(xOffset, yOffset); debugGraphics.setClip(getClipBounds()); if (debugFlash()) { debugGraphics.setDebugOptions(FLASH_OPTION); } return debugGraphics; } /** Returns DebugGraphicsInfo, or creates one if none exists. */ static DebugGraphicsInfo info() { DebugGraphicsInfo debugGraphicsInfo = (DebugGraphicsInfo) SwingUtilities.appContextGet(debugGraphicsInfoKey); if (debugGraphicsInfo == null) { debugGraphicsInfo = new DebugGraphicsInfo(); SwingUtilities.appContextPut(debugGraphicsInfoKey, debugGraphicsInfo); } return debugGraphicsInfo; } private static final Class debugGraphicsInfoKey = DebugGraphicsInfo.class; }Lines 1001–1468 of 1468. Previous lines
ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Rectangle(x, y, width, height)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, width, height, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, width, height, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, width, height, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y) + ", bgcolor: " + bgcolor); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, bgcolor, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, bgcolor, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, bgcolor, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y,int width, int height, Color bgcolor, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Rectangle(x, y, width, height) + ", bgcolor: " + bgcolor); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, width, height, bgcolor, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, width, height, bgcolor, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, width, height, bgcolor, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " destination: " + new Rectangle(dx1, dy1, dx2, dy2) + " source: " + new Rectangle(sx1, sy1, sx2, sy2)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } /** * Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " destination: " + new Rectangle(dx1, dy1, dx2, dy2) + " source: " + new Rectangle(sx1, sy1, sx2, sy2) + ", bgcolor: " + bgcolor); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } static void loadImage(Image img) { imageLoadingIcon.loadImage(img); } /** * Overrides <code>Graphics.copyArea</code>. */ public void copyArea(int x, int y, int width, int height, int destX, int destY) { if (debugLog()) { info().log(toShortString() + " Copying area from: " + new Rectangle(x, y, width, height) + " to: " + new Point(destX, destY)); } graphics.copyArea(x, y, width, height, destX, destY); } final void sleep(int mSecs) { try { Thread.sleep(mSecs); } catch (Exception e) { } } /** * Overrides <code>Graphics.dispose</code>. */ public void dispose() { graphics.dispose(); graphics = null; } // ALERT! /** * Returns the drawingBuffer value. * * @return true if this object is drawing from a Buffer */ public boolean isDrawingBuffer() { return buffer != null; } String toShortString() { return "Graphics" + (isDrawingBuffer() ? "<B>" : "") + "(" + graphicsID + "-" + debugOptions + ")"; } String pointToString(int x, int y) { return "(" + x + ", " + y + ")"; } /** Enables/disables diagnostic information about every graphics * operation. The value of <b>options</b> indicates how this information * should be displayed. LOG_OPTION causes a text message to be printed. * FLASH_OPTION causes the drawing to flash several times. BUFFERED_OPTION * creates a new Frame that shows each operation on an * offscreen buffer. The value of <b>options</b> is bitwise OR'd into * the current value. To disable debugging use NONE_OPTION. */ public void setDebugOptions(int options) { if (options != 0) { if (options == NONE_OPTION) { if (debugOptions != 0) { System.err.println(toShortString() + " Disabling debug"); debugOptions = 0; } } else { if (debugOptions != options) { debugOptions |= options; if (debugLog()) { System.err.println(toShortString() + " Enabling debug"); } } } } } /** Returns the current debugging options for this DebugGraphics. * @see #setDebugOptions */ public int getDebugOptions() { return debugOptions; } /** Static wrapper method for DebugGraphicsInfo.setDebugOptions(). Stores * options on a per component basis. */ static void setDebugOptions(JComponent component, int options) { info().setDebugOptions(component, options); } /** Static wrapper method for DebugGraphicsInfo.getDebugOptions(). */ static int getDebugOptions(JComponent component) { DebugGraphicsInfo debugGraphicsInfo = info(); if (debugGraphicsInfo == null) { return 0; } else { return debugGraphicsInfo.getDebugOptions(component); } } /** Returns non-zero if <b>component</b> should display with DebugGraphics, * zero otherwise. Walks the JComponent's parent tree to determine if * any debugging options have been set. */ static int shouldComponentDebug(JComponent component) { DebugGraphicsInfo info = info(); if (info == null) { return 0; } else { Container container = (Container)component; int debugOptions = 0; while (container != null && (container instanceof JComponent)) { debugOptions |= info.getDebugOptions((JComponent)container); container = container.getParent(); } return debugOptions; } } /** Returns the number of JComponents that have debugging options turned * on. */ static int debugComponentCount() { DebugGraphicsInfo debugGraphicsInfo = info(); if (debugGraphicsInfo != null && debugGraphicsInfo.componentToDebug != null) { return debugGraphicsInfo.componentToDebug.size(); } else { return 0; } } boolean debugLog() { return (debugOptions & LOG_OPTION) == LOG_OPTION; } boolean debugFlash() { return (debugOptions & FLASH_OPTION) == FLASH_OPTION; } boolean debugBuffered() { return (debugOptions & BUFFERED_OPTION) == BUFFERED_OPTION; } /** Returns a DebugGraphics for use in buffering window. */ private Graphics debugGraphics() { DebugGraphics debugGraphics; DebugGraphicsInfo info = info(); JFrame debugFrame; if (info.debugFrame == null) { info.debugFrame = new JFrame(); info.debugFrame.setSize(500, 500); } debugFrame = info.debugFrame; debugFrame.show(); debugGraphics = new DebugGraphics(debugFrame.getGraphics()); debugGraphics.setFont(getFont()); debugGraphics.setColor(getColor()); debugGraphics.translate(xOffset, yOffset); debugGraphics.setClip(getClipBounds()); if (debugFlash()) { debugGraphics.setDebugOptions(FLASH_OPTION); } return debugGraphics; } /** Returns DebugGraphicsInfo, or creates one if none exists. */ static DebugGraphicsInfo info() { DebugGraphicsInfo debugGraphicsInfo = (DebugGraphicsInfo) SwingUtilities.appContextGet(debugGraphicsInfoKey); if (debugGraphicsInfo == null) { debugGraphicsInfo = new DebugGraphicsInfo(); SwingUtilities.appContextPut(debugGraphicsInfoKey, debugGraphicsInfo); } return debugGraphicsInfo; } private static final Class debugGraphicsInfoKey = DebugGraphicsInfo.class; }