APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class RepaintManager

extends Object
Class Inheritance
Imports
java.awt.*, java.awt.event.*, java.awt.image.VolatileImage, java.util.*, java.util.concurrent.atomic.AtomicInteger, sun.awt.AWTAccessor, .DisplayChangedListener, .SunToolkit, sun.java2d.SunGraphicsEnvironment, .SunGraphics2D, com.sun.java.swing.SwingUtilities3, java.awt.geom.AffineTransform, sun.java2d.pipe.Region, sun.swing.SwingAccessor, .SwingUtilities2, .SwingUtilities2.RepaintListener

This class manages repaint requests, allowing the number of repaints to be minimized, for example by collapsing multiple requests into a single repaint for members of a component tree.

As of 1.6 RepaintManager handles repaint requests for Swing's top level components (JWindow, JFrame and JDialog). Any calls to repaint on one of these will call into the appropriate addDirtyRegion method.

Author
Arnaud Weber
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
RepaintManager.DisplayChangedHandler

Listener installed to detect display changes.

private static class
private static class
pack-priv static class
RepaintManager.PaintManager

PaintManager is used to handle all double buffered painting for Swing.

private class
RepaintManager.ProcessingRunnable

Runnable used to process all repaint/revalidate requests.

Field Summary

Modifier and TypeField and Description
private static final short
private static final short
private static final short
private static final short
private short
bufferStrategyType

Type of buffer strategy to use.

private Map<Component, Rectangle>
private static final DisplayChangedListener
displayChangedHandler

Listener installed to detect display changes.

pack-priv boolean
private Dimension
pack-priv static final boolean
HANDLE_TOP_LEVEL_PAINT

Whether or not the RepaintManager should handle paint requests for top levels.

private Map<Container, Rectangle>
private List<Component>
private boolean
private static boolean
nativeDoubleBuffering

Value of the system property awt.nativeDoubleBuffering.

private int
paintDepth

Number of beginPaint that have been invoked.

private boolean
painting

True if we're in the process of painting the dirty regions.

private RepaintManager.PaintManager
paintManager

Object responsible for handling core paint functionality.

private Thread
paintThread

The Thread that has initiated painting.

private final RepaintManager.ProcessingRunnable
processingRunnable

Runnable used to process all repaint/revalidate requests.

private List<SwingUtilities2.RepaintListener>
private static RepaintManager
private JComponent
repaintRoot

If the PaintManager calls into repaintRoot during painting this field will be set to the root.

private List<Runnable>
pack-priv RepaintManager.DoubleBufferInfo
pack-priv Rectangle
private Map<Component, Rectangle>
private static final int
private static final int
volatileBufferType

Type of VolatileImage which should be used for double-buffered painting.

pack-priv static boolean
private Map<GraphicsConfiguration, VolatileImage>
volatileMap

Maps from GraphicsConfiguration to VolatileImage.

Constructor Summary

AccessConstructor and Description
public
RepaintManager()

Create a new RepaintManager instance.

private
RepaintManager(short bufferStrategyType)

Method Summary

Modifier and TypeMethod and Description
private Image
_getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight)

public void
addDirtyRegion(JComponent
Component to repaint, null results in nothing happening.
c
,
int
X coordinate of the region to repaint
x
,
int
Y coordinate of the region to repaint
y
,
int
Width of the region to repaint
w
,
int
Height of the region to repaint
h
)

Add a component in the list of components that should be refreshed.

public void
addDirtyRegion(Window
Window to repaint, null results in nothing happening.
window
,
int
X coordinate of the region to repaint
x
,
int
Y coordinate of the region to repaint
y
,
int
Width of the region to repaint
w
,
int
Height of the region to repaint
h
)

Adds window to the list of Components that need to be repainted.

private void
addDirtyRegion0(Container c, int x, int y, int w, int h)

Add a component in the list of components that should be refreshed.

public synchronized void
addInvalidComponent(JComponent
a component
invalidComponent
)

Mark the component as in need of layout and queue a runnable for the event dispatching thread that will validate the components first isValidateRoot() ancestor.

private void
private void
adjustRoots(JComponent root, List<Component> roots, int index)

Removes any components from roots that are children of root.

pack-priv void
beginPaint()

Invoked prior to any paint/copyArea method calls.

private void
private void
clearImages(int width, int height)

pack-priv void
collectDirtyComponents(Map<Component, Rectangle> dirtyComponents, Component dirtyComponent, List<Component> roots)

pack-priv void
copyArea(JComponent c, Graphics g, int x, int y, int w, int h, int deltaX, int deltaY, boolean
Whether or not the copyArea needs to be clipped to the Component's bounds.
clip
)

Does a copy area on the specified region.

public static RepaintManager

Returns:

the RepaintManager object
currentManager
(Component
a Component -- unused in the default implementation, but could be used by an overridden version to return a different RepaintManager depending on the Component
c
)

Return the RepaintManager given a Component.

public static RepaintManager

Returns:

the RepaintManager object
currentManager
(JComponent
a JComponent -- unused
c
)

Return the RepaintManager for the calling thread given a JComponent.

private void
pack-priv void
doubleBufferingChanged(JRootPane rootPane)

Invoked when the doubleBuffered or useTrueDoubleBuffering properties of a JRootPane change.

pack-priv void
endPaint()

Invoked after beginPaint has been invoked.

private synchronized boolean

Returns:

false if c is not yet marked dirty.
extendDirtyRegion
(Component c, int x, int y, int w, int h)

Extends the dirty region for the specified component to include the new region.

private RepaintManager
public Rectangle

Returns:

the region
getDirtyRegion
(JComponent
a component
aComponent
)

Return the current dirty region for a component.

public Dimension

Returns:

a Dimension object representing the maximum size
getDoubleBufferMaximumSize
()

Returns the maximum double buffer size.

public Image

Returns:

the image
getOffscreenBuffer
(Component
the component
c
,
int
the width of the buffer
proposedWidth
,
int
the height of the buffer
proposedHeight
)

Return the offscreen buffer that should be used as a double buffer with the component c.

private synchronized RepaintManager.PaintManager
public Image

Returns:

the volatile image
getVolatileOffscreenBuffer
(Component
the component
c
,
int
the width of the buffer
proposedWidth
,
int
the height of the buffer
proposedHeight
)

Return a volatile offscreen buffer that should be used as a double buffer with the specified component c.

public boolean

Returns:

true if aComponent will be completely painted during the next paintDirtyRegions().
isCompletelyDirty
(JComponent
a component
aComponent
)

Convenience method that returns true if aComponent will be completely painted during the next paintDirtyRegions().

public boolean

Returns:

true if this object is double buffered
isDoubleBufferingEnabled
()

Returns true if this RepaintManager is double buffered.

pack-priv boolean
private synchronized boolean
isPaintingThread()

Returns true if the current thread is the thread painting.

public void
markCompletelyClean(JComponent
a component
aComponent
)

Mark a component completely clean.

public void
markCompletelyDirty(JComponent
a component
aComponent
)

Mark a component completely dirty.

pack-priv void
nativeAddDirtyRegion(Container c, int x, int y, int w, int h)

pack-priv void
pack-priv void
notifyRepaintPerformed(JComponent
the component
c
,
int
the x coordinate of the area
x
,
int
the y coordinate of the area
y
,
int
the width of the area
w
,
int
the height of the area
h
)

Notify the attached repaint listeners that an area of the c component has been immediately repainted, that is without scheduling a repaint runnable, due to performing a "blit" (via calling the copyArea method).

pack-priv void
paint(JComponent
Component to paint
paintingComponent
,
JComponent
Component to obtain buffer for
bufferComponent
,
Graphics
Graphics to paint to
g
,
int
X-coordinate
x
,
int
Y-coordinate
y
,
int
Width
w
,
int
Height
h
)

Paints a region of a component

public void
paintDirtyRegions()

Paint all of the components that have been marked dirty.

private void
paintDirtyRegions(final Map<Component, Rectangle> tmpDirtyComponents)

private void
prePaintDirtyRegions()

This is invoked to process paint requests.

public synchronized void
removeInvalidComponent(JComponent
a component
component
)

Remove a component from the list of invalid components.

private void
pack-priv void
resetDoubleBuffer()

This resets the double buffer.

pack-priv void
resetVolatileDoubleBuffer(GraphicsConfiguration gc)

This resets the volatile double buffer.

pack-priv void
private void
public static void
setCurrentManager(RepaintManager
the RepaintManager object to use
aRepaintManager
)

Set the RepaintManager.

public void
setDoubleBufferingEnabled(boolean
true to activate double buffering
aFlag
)

Enables or disables double buffering in this RepaintManager.

public void
setDoubleBufferMaximumSize(Dimension
the dimension
d
)

Set the maximum double buffer size.

pack-priv void
setPaintManager(RepaintManager.PaintManager
The PaintManager to use. Passing in null indicates the fallback PaintManager should be used.
paintManager
)

Sets the PaintManager that is used to handle all double buffered painting.

pack-priv boolean
show(Container c, int x, int y, int w, int h)

If possible this will show a previously rendered portion of a Component.

public synchronized String

Returns:

a String representation of this object
toString
()

Overrides java.lang.Object.toString.

Returns a string that displays and identifies this object's properties.

private void
updateWindows(Map<Component, Rectangle> dirtyComponents)

pack-priv boolean
useVolatileDoubleBuffer()

Returns true if we should use the Image returned from getVolatileOffscreenBuffer to do double buffering.

public void
validateInvalidComponents()

Validate all of the components that have been marked invalid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait