APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing

public Class DebugGraphics

extends Graphics
Class Inheritance
Imports
java.awt.*, java.awt.image.*, java.text.AttributedCharacterIterator

Graphics subclass supporting graphics debugging. Overrides most methods from Graphics. DebugGraphics objects are rarely created by hand. They are most frequently created automatically when a JComponent's debugGraphicsOptions are changed using the setDebugGraphicsOptions() method.

Note

You must turn off double buffering to use DebugGraphics: RepaintManager repaintManager = RepaintManager.currentManager(component); repaintManager.setDoubleBufferingEnabled(false);

Author
Dave Karlton
Since
1.2
See Also
JComponent#setDebugGraphicsOptions, RepaintManager#currentManager, RepaintManager#setDoubleBufferingEnabled

Field Summary

Modifier and TypeField and Description
pack-priv Image
public static final int
BUFFERED_OPTION

Show buffered operations in a separate Frame.

private static DebugGraphicsInfo
pack-priv int
public static final int
FLASH_OPTION

Flash graphics operations.

pack-priv Graphics
private static int
pack-priv int
private static ImageIcon
public static final int
LOG_OPTION

Log graphics operations.

public static final int
NONE_OPTION

Don't debug graphics operations.

pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
public
DebugGraphics()

Constructs a new debug graphics context that supports slowed down drawing.

public
DebugGraphics(Graphics
the Graphics context to slow down
graphics
,
JComponent
the JComponent to draw slowly
component
)

Constructs a debug graphics context from an existing graphics context that slows down drawing for the specified component.

public
DebugGraphics(Graphics
the Graphics context to slow down
graphics
)

Constructs a debug graphics context from an existing graphics context that supports slowed down drawing.

Method Summary

Modifier and TypeMethod and Description
public void
clearRect(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.clearRect.

Overrides Graphics.clearRect.

public void
clipRect(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.clipRect.

Overrides Graphics.clipRect.

public void
copyArea(int x, int y, int width, int height, int destX, int destY)

Implements abstract java.awt.Graphics.copyArea.

Overrides Graphics.copyArea.

public Graphics
create()

Implements abstract java.awt.Graphics.create.

Overrides Graphics.create to return a DebugGraphics object.

public Graphics
create(int x, int y, int width, int height)

Overrides java.awt.Graphics.create.

Overrides Graphics.create to return a DebugGraphics object.

pack-priv boolean
pack-priv static int
debugComponentCount()

Returns the number of JComponents that have debugging options turned on.

pack-priv boolean
private Graphics
debugGraphics()

Returns a DebugGraphics for use in buffering window.

pack-priv boolean
public void
dispose()

Implements abstract java.awt.Graphics.dispose.

Overrides Graphics.dispose.

public void
draw3DRect(int x, int y, int width, int height, boolean raised)

Overrides java.awt.Graphics.draw3DRect.

Overrides Graphics.draw3DRect.

public void
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)

Implements abstract java.awt.Graphics.drawArc.

Overrides Graphics.drawArc.

public void
drawBytes(byte[] data, int offset, int length, int x, int y)

Overrides java.awt.Graphics.drawBytes.

Overrides Graphics.drawBytes.

public void
drawChars(char[] data, int offset, int length, int x, int y)

Overrides java.awt.Graphics.drawChars.

Overrides Graphics.drawChars.

public boolean
drawImage(Image img, int x, int y, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

public boolean
drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

public boolean
drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

public boolean
drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

public boolean
drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

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)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

public void
drawLine(int x1, int y1, int x2, int y2)

Implements abstract java.awt.Graphics.drawLine.

Overrides Graphics.drawLine.

public void
drawOval(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.drawOval.

Overrides Graphics.drawOval.

public void
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.drawPolygon.

Overrides Graphics.drawPolygon.

public void
drawPolyline(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.drawPolyline.

Overrides Graphics.drawPolyline.

public void
drawRect(int x, int y, int width, int height)

Overrides java.awt.Graphics.drawRect.

Overrides Graphics.drawRect.

public void
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

Implements abstract java.awt.Graphics.drawRoundRect.

Overrides Graphics.drawRoundRect.

public void
drawString(String aString, int x, int y)

Implements abstract java.awt.Graphics.drawString.

Overrides Graphics.drawString.

public void
drawString(AttributedCharacterIterator iterator, int x, int y)

Implements abstract java.awt.Graphics.drawString.

Overrides Graphics.drawString.

public void
fill3DRect(int x, int y, int width, int height, boolean raised)

Overrides java.awt.Graphics.fill3DRect.

Overrides Graphics.fill3DRect.

public void
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)

Implements abstract java.awt.Graphics.fillArc.

Overrides Graphics.fillArc.

public void
fillOval(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.fillOval.

Overrides Graphics.fillOval.

public void
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.fillPolygon.

Overrides Graphics.fillPolygon.

public void
fillRect(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.fillRect.

Overrides Graphics.fillRect.

public void
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

Implements abstract java.awt.Graphics.fillRoundRect.

Overrides Graphics.fillRoundRect.

public static Color

Returns:

the Color used to flash drawing operations
flashColor
()

Returns the Color used to flash drawing operations.

public static int

Returns:

the number of times that drawing operations will flash
flashCount
()

Returns the number of times that drawing operations will flash.

public static int

Returns:

the time delay of drawing operation flashing
flashTime
()

Returns the time delay of drawing operation flashing.

public Shape
getClip()

Implements abstract java.awt.Graphics.getClip.

Overrides Graphics.getClip.

public Rectangle
getClipBounds()

Implements abstract java.awt.Graphics.getClipBounds.

Overrides Graphics.getClipBounds.

public Color
getColor()

Implements abstract java.awt.Graphics.getColor.

Returns the Color used for text drawing operations.

public int

Returns:

the current debugging options for this DebugGraphics
getDebugOptions
()

Returns the current debugging options for this DebugGraphics.

pack-priv static int
getDebugOptions(JComponent component)

Static wrapper method for DebugGraphicsInfo.getDebugOptions().

public Font
getFont()

Implements abstract java.awt.Graphics.getFont.

Returns the Font used for text drawing operations.

public FontMetrics
getFontMetrics()

Overrides java.awt.Graphics.getFontMetrics.

Overrides Graphics.getFontMetrics.

public FontMetrics
getFontMetrics(Font f)

Implements abstract java.awt.Graphics.getFontMetrics.

Overrides Graphics.getFontMetrics.

pack-priv static DebugGraphicsInfo
info()

Returns DebugGraphicsInfo, or creates one if none exists.

public boolean

Returns:

true if this object is drawing from a Buffer
isDrawingBuffer
()

Returns the drawingBuffer value.

pack-priv static void
public static PrintStream

Returns:

the stream to which the DebugGraphics logs drawing operations
logStream
()

Returns the stream to which the DebugGraphics logs drawing operations.

pack-priv String
pointToString(int x, int y)

public void
setClip(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.setClip.

Overrides Graphics.setClip.

public void
setClip(Shape clip)

Implements abstract java.awt.Graphics.setClip.

Overrides Graphics.setClip.

public void
setColor(Color aColor)

Implements abstract java.awt.Graphics.setColor.

Sets the color to be used for drawing and filling lines and shapes.

public void
setDebugOptions(int
indicates how diagnostic information should be displayed
options
)

Enables/disables diagnostic information about every graphics operation.

pack-priv static void
setDebugOptions(JComponent component, int options)

Static wrapper method for DebugGraphicsInfo.setDebugOptions().

public static void
setFlashColor(Color
the Color used to flash drawing operations
flashColor
)

Sets the Color used to flash drawing operations.

public static void
setFlashCount(int
number of times that drawing operations will flash
flashCount
)

Sets the number of times that drawing operations will flash.

public static void
setFlashTime(int
the time delay of drawing operation flashing
flashTime
)

Sets the time delay of drawing operation flashing.

public void
setFont(Font aFont)

Implements abstract java.awt.Graphics.setFont.

Sets the Font used for text drawing operations.

public static void
setLogStream(PrintStream
the stream to which the DebugGraphics logs drawing operations
stream
)

Sets the stream to which the DebugGraphics logs drawing operations.

public void
setPaintMode()

Implements abstract java.awt.Graphics.setPaintMode.

Overrides Graphics.setPaintMode.

public void
setXORMode(Color aColor)

Implements abstract java.awt.Graphics.setXORMode.

Overrides Graphics.setXORMode.

pack-priv static int
shouldComponentDebug(JComponent component)

Returns non-zero if component should display with DebugGraphics, zero otherwise.

pack-priv final void
sleep(int mSecs)

pack-priv String
public void
translate(int x, int y)

Implements abstract java.awt.Graphics.translate.

Overrides Graphics.translate.

Inherited from java.awt.Graphics:
drawPolygonfillPolygonfinalizegetClipBoundsgetClipRecthitCliptoString

Field Detail

bufferback to summary
pack-priv Image buffer
BUFFERED_OPTIONback to summary
public static final int BUFFERED_OPTION

Show buffered operations in a separate Frame.

debugGraphicsInfoback to summary
private static DebugGraphicsInfo debugGraphicsInfo
debugOptionsback to summary
pack-priv int debugOptions
FLASH_OPTIONback to summary
public static final int FLASH_OPTION

Flash graphics operations.

graphicsback to summary
pack-priv Graphics graphics
graphicsCountback to summary
private static int graphicsCount
graphicsIDback to summary
pack-priv int graphicsID
imageLoadingIconback to summary
private static ImageIcon imageLoadingIcon
LOG_OPTIONback to summary
public static final int LOG_OPTION

Log graphics operations.

NONE_OPTIONback to summary
public static final int NONE_OPTION

Don't debug graphics operations.

xOffsetback to summary
pack-priv int xOffset
yOffsetback to summary
pack-priv int yOffset

Constructor Detail

DebugGraphicsback to summary
public DebugGraphics()

Constructs a new debug graphics context that supports slowed down drawing.

Note

This constructor should not be called by applications, it is for internal use only. When called directly it will create an un-usable instance.

DebugGraphicsback to summary
public DebugGraphics(Graphics graphics, JComponent component)

Constructs a debug graphics context from an existing graphics context that slows down drawing for the specified component.

Parameters
graphics:Graphics

the Graphics context to slow down

component:JComponent

the JComponent to draw slowly

DebugGraphicsback to summary
public DebugGraphics(Graphics graphics)

Constructs a debug graphics context from an existing graphics context that supports slowed down drawing.

Parameters
graphics:Graphics

the Graphics context to slow down

Method Detail

clearRectback to summary
public void clearRect(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.clearRect.

Overrides Graphics.clearRect.

clipRectback to summary
public void clipRect(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.clipRect.

Overrides Graphics.clipRect.

copyAreaback to summary
public void copyArea(int x, int y, int width, int height, int destX, int destY)

Implements abstract java.awt.Graphics.copyArea.

Overrides Graphics.copyArea.

createback to summary
public Graphics create()

Implements abstract java.awt.Graphics.create.

Overrides Graphics.create to return a DebugGraphics object.

createback to summary
public Graphics create(int x, int y, int width, int height)

Overrides java.awt.Graphics.create.

Overrides Graphics.create to return a DebugGraphics object.

debugBufferedback to summary
pack-priv boolean debugBuffered()
debugComponentCountback to summary
pack-priv static int debugComponentCount()

Returns the number of JComponents that have debugging options turned on.

debugFlashback to summary
pack-priv boolean debugFlash()
debugGraphicsback to summary
private Graphics debugGraphics()

Returns a DebugGraphics for use in buffering window.

Annotations
@SuppressWarnings:deprecation
debugLogback to summary
pack-priv boolean debugLog()
disposeback to summary
public void dispose()

Implements abstract java.awt.Graphics.dispose.

Overrides Graphics.dispose.

draw3DRectback to summary
public void draw3DRect(int x, int y, int width, int height, boolean raised)

Overrides java.awt.Graphics.draw3DRect.

Overrides Graphics.draw3DRect.

drawArcback to summary
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)

Implements abstract java.awt.Graphics.drawArc.

Overrides Graphics.drawArc.

drawBytesback to summary
public void drawBytes(byte[] data, int offset, int length, int x, int y)

Overrides java.awt.Graphics.drawBytes.

Overrides Graphics.drawBytes.

drawCharsback to summary
public void drawChars(char[] data, int offset, int length, int x, int y)

Overrides java.awt.Graphics.drawChars.

Overrides Graphics.drawChars.

drawImageback to summary
public boolean drawImage(Image img, int x, int y, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

drawImageback to summary
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

drawImageback to summary
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

drawImageback to summary
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

drawImageback to summary
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

drawImageback to summary
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)

Implements abstract java.awt.Graphics.drawImage.

Overrides Graphics.drawImage.

drawLineback to summary
public void drawLine(int x1, int y1, int x2, int y2)

Implements abstract java.awt.Graphics.drawLine.

Overrides Graphics.drawLine.

drawOvalback to summary
public void drawOval(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.drawOval.

Overrides Graphics.drawOval.

drawPolygonback to summary
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.drawPolygon.

Overrides Graphics.drawPolygon.

drawPolylineback to summary
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.drawPolyline.

Overrides Graphics.drawPolyline.

drawRectback to summary
public void drawRect(int x, int y, int width, int height)

Overrides java.awt.Graphics.drawRect.

Overrides Graphics.drawRect.

drawRoundRectback to summary
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

Implements abstract java.awt.Graphics.drawRoundRect.

Overrides Graphics.drawRoundRect.

drawStringback to summary
public void drawString(String aString, int x, int y)

Implements abstract java.awt.Graphics.drawString.

Overrides Graphics.drawString.

drawStringback to summary
public void drawString(AttributedCharacterIterator iterator, int x, int y)

Implements abstract java.awt.Graphics.drawString.

Overrides Graphics.drawString.

fill3DRectback to summary
public void fill3DRect(int x, int y, int width, int height, boolean raised)

Overrides java.awt.Graphics.fill3DRect.

Overrides Graphics.fill3DRect.

fillArcback to summary
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)

Implements abstract java.awt.Graphics.fillArc.

Overrides Graphics.fillArc.

fillOvalback to summary
public void fillOval(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.fillOval.

Overrides Graphics.fillOval.

fillPolygonback to summary
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)

Implements abstract java.awt.Graphics.fillPolygon.

Overrides Graphics.fillPolygon.

fillRectback to summary
public void fillRect(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.fillRect.

Overrides Graphics.fillRect.

fillRoundRectback to summary
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

Implements abstract java.awt.Graphics.fillRoundRect.

Overrides Graphics.fillRoundRect.

flashColorback to summary
public static Color flashColor()

Returns the Color used to flash drawing operations.

Returns:Color

the Color used to flash drawing operations

See Also
setFlashColor
flashCountback to summary
public static int flashCount()

Returns the number of times that drawing operations will flash.

Returns:int

the number of times that drawing operations will flash

See Also
setFlashCount
flashTimeback to summary
public static int flashTime()

Returns the time delay of drawing operation flashing.

Returns:int

the time delay of drawing operation flashing

See Also
setFlashTime
getClipback to summary
public Shape getClip()

Implements abstract java.awt.Graphics.getClip.

Overrides Graphics.getClip.

getClipBoundsback to summary
public Rectangle getClipBounds()

Implements abstract java.awt.Graphics.getClipBounds.

Overrides Graphics.getClipBounds.

getColorback to summary
public Color getColor()

Implements abstract java.awt.Graphics.getColor.

Returns the Color used for text drawing operations.

See Also
setColor
getDebugOptionsback to summary
public int getDebugOptions()

Returns the current debugging options for this DebugGraphics.

Returns:int

the current debugging options for this DebugGraphics

See Also
setDebugOptions
getDebugOptionsback to summary
pack-priv static int getDebugOptions(JComponent component)

Static wrapper method for DebugGraphicsInfo.getDebugOptions().

getFontback to summary
public Font getFont()

Implements abstract java.awt.Graphics.getFont.

Returns the Font used for text drawing operations.

See Also
setFont
getFontMetricsback to summary
public FontMetrics getFontMetrics()

Overrides java.awt.Graphics.getFontMetrics.

Overrides Graphics.getFontMetrics.

getFontMetricsback to summary
public FontMetrics getFontMetrics(Font f)

Implements abstract java.awt.Graphics.getFontMetrics.

Overrides Graphics.getFontMetrics.

infoback to summary
pack-priv static DebugGraphicsInfo info()

Returns DebugGraphicsInfo, or creates one if none exists.

isDrawingBufferback to summary
public boolean isDrawingBuffer()

Returns the drawingBuffer value.

Returns:boolean

true if this object is drawing from a Buffer

loadImageback to summary
pack-priv static void loadImage(Image img)
logStreamback to summary
public static PrintStream logStream()

Returns the stream to which the DebugGraphics logs drawing operations.

Returns:PrintStream

the stream to which the DebugGraphics logs drawing operations

See Also
setLogStream
pointToStringback to summary
pack-priv String pointToString(int x, int y)
setClipback to summary
public void setClip(int x, int y, int width, int height)

Implements abstract java.awt.Graphics.setClip.

Overrides Graphics.setClip.

setClipback to summary
public void setClip(Shape clip)

Implements abstract java.awt.Graphics.setClip.

Overrides Graphics.setClip.

setColorback to summary
public void setColor(Color aColor)

Implements abstract java.awt.Graphics.setColor.

Sets the color to be used for drawing and filling lines and shapes.

setDebugOptionsback to summary
public void setDebugOptions(int options)

Enables/disables diagnostic information about every graphics operation. The value of options 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 options is bitwise OR'd into the current value. To disable debugging use NONE_OPTION.

Parameters
options:int

indicates how diagnostic information should be displayed

setDebugOptionsback to summary
pack-priv static void setDebugOptions(JComponent component, int options)

Static wrapper method for DebugGraphicsInfo.setDebugOptions(). Stores options on a per component basis.

setFlashColorback to summary
public static void setFlashColor(Color flashColor)

Sets the Color used to flash drawing operations.

Parameters
flashColor:Color

the Color used to flash drawing operations

setFlashCountback to summary
public static void setFlashCount(int flashCount)

Sets the number of times that drawing operations will flash.

Parameters
flashCount:int

number of times that drawing operations will flash

setFlashTimeback to summary
public static void setFlashTime(int flashTime)

Sets the time delay of drawing operation flashing.

Parameters
flashTime:int

the time delay of drawing operation flashing

setFontback to summary
public void setFont(Font aFont)

Implements abstract java.awt.Graphics.setFont.

Sets the Font used for text drawing operations.

setLogStreamback to summary
public static void setLogStream(PrintStream stream)

Sets the stream to which the DebugGraphics logs drawing operations.

Parameters
stream:PrintStream

the stream to which the DebugGraphics logs drawing operations

setPaintModeback to summary
public void setPaintMode()

Implements abstract java.awt.Graphics.setPaintMode.

Overrides Graphics.setPaintMode.

setXORModeback to summary
public void setXORMode(Color aColor)

Implements abstract java.awt.Graphics.setXORMode.

Overrides Graphics.setXORMode.

shouldComponentDebugback to summary
pack-priv static int shouldComponentDebug(JComponent component)

Returns non-zero if component should display with DebugGraphics, zero otherwise. Walks the JComponent's parent tree to determine if any debugging options have been set.

sleepback to summary
pack-priv final void sleep(int mSecs)
toShortStringback to summary
pack-priv String toShortString()
translateback to summary
public void translate(int x, int y)

Implements abstract java.awt.Graphics.translate.

Overrides Graphics.translate.