javax.swing

Class RepaintManager


public class RepaintManager
extends Object

The repaint manager holds a set of dirty regions, invalid components, and a double buffer surface. The dirty regions and invalid components are used to coalesce multiple revalidate() and repaint() calls in the component tree into larger groups to be refreshed "all at once"; the double buffer surface is used by root components to paint themselves.

In general, painting is very confusing in swing. see this document for more details.

Nested Class Summary

protected class
RepaintManager.RepaintWorker
A helper class which is placed into the system event queue at various times in order to facilitate repainting and layout.

Constructor Summary

RepaintManager()
Create a new RepaintManager object.

Method Summary

void
addDirtyRegion(JComponent component, int x, int y, int w, int h)
Add a region to the set of dirty regions for a specified component.
void
addInvalidComponent(JComponent component)
Add a component to the RepaintManager vector.
static RepaintManager
currentManager(Component component)
Get the value of the shared RepaintManager instance, possibly returning a special manager associated with the specified component.
static RepaintManager
currentManager(JComponent component)
Get the value of the shared RepaintManager instance, possibly returning a special manager associated with the specified component.
Rectangle
getDirtyRegion(JComponent component)
Get the dirty region associated with a component, or null if the component has no dirty region.
Dimension
getDoubleBufferMaximumSize()
Get the value of the RepaintManager property.
Image
getOffscreenBuffer(Component component, int proposedWidth, int proposedHeight)
Get an offscreen buffer for painting a component's image.
Image
getVolatileOffscreenBuffer(Component comp, int proposedWidth, int proposedHeight)
Creates and returns a volatile offscreen buffer for the specified component that can be used as a double buffer.
boolean
isCompletelyDirty(JComponent component)
Return true if the specified component is completely contained within its dirty region, otherwise false
boolean
isDoubleBufferingEnabled()
Get the value of the RepaintManager property.
void
markCompletelyClean(JComponent component)
Remove all dirty regions for a specified component
void
markCompletelyDirty(JComponent component)
Mark a component as dirty over its entire bounds.
void
paintDirtyRegions()
Repaint all regions of all components which have been marked dirty in the RepaintManager table.
void
removeInvalidComponent(JComponent component)
Remove a component from the RepaintManager vector.
static void
setCurrentManager(RepaintManager manager)
Set the value of the shared RepaintManager instance.
void
setDoubleBufferMaximumSize(Dimension size)
Set the value of the RepaintManager property.
void
setDoubleBufferingEnabled(boolean buffer)
Set the value of the RepaintManager property.
String
toString()
Convert this Object to a human-readable String.
void
validateInvalidComponents()
Validate all components which have been marked invalid in the RepaintManager vector.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

RepaintManager

public RepaintManager()
Create a new RepaintManager object.

Method Details

addDirtyRegion

public void addDirtyRegion(JComponent component,
                           int x,
                           int y,
                           int w,
                           int h)
Add a region to the set of dirty regions for a specified component. This involves union'ing the new region with any existing dirty region associated with the component. If the RepaintManager class is not active, insert it in the system event queue.

Parameters:
component - The component to add a dirty region for
x - The left x coordinate of the new dirty region
y - The top y coordinate of the new dirty region
w - The width of the new dirty region
h - The height of the new dirty region

See Also:
addDirtyRegion(JComponent,int,int,int,int), getDirtyRegion(JComponent), isCompletelyDirty(JComponent), markCompletelyClean(JComponent), markCompletelyDirty(JComponent)


addInvalidComponent

public void addInvalidComponent(JComponent component)
Add a component to the RepaintManager vector. If the RepaintManager class is not active, insert it in the system event queue.

Parameters:
component - The component to add

See Also:
removeInvalidComponent(JComponent)


currentManager

public static RepaintManager currentManager(Component component)
Get the value of the shared RepaintManager instance, possibly returning a special manager associated with the specified component. The default implementaiton ignores the component parameter.

Parameters:
component - A component to look up the manager of

Returns:
The current repaint manager

See Also:
setCurrentManager(RepaintManager)


currentManager

public static RepaintManager currentManager(JComponent component)
Get the value of the shared RepaintManager instance, possibly returning a special manager associated with the specified component. The default implementaiton ignores the component parameter.

Parameters:
component - A component to look up the manager of

Returns:
The current repaint manager

See Also:
setCurrentManager(RepaintManager)


getDirtyRegion

public Rectangle getDirtyRegion(JComponent component)
Get the dirty region associated with a component, or null if the component has no dirty region.

Parameters:
component - The component to get the dirty region of

Returns:
The dirty region of the component

See Also:
RepaintManager, addDirtyRegion(JComponent,int,int,int,int), isCompletelyDirty(JComponent), markCompletelyClean(JComponent), markCompletelyDirty(JComponent)


getDoubleBufferMaximumSize

public Dimension getDoubleBufferMaximumSize()
Get the value of the RepaintManager property.

Returns:
The current value of the property

See Also:
setDoubleBufferMaximumSize(Dimension)


getOffscreenBuffer

public Image getOffscreenBuffer(Component component,
                                int proposedWidth,
                                int proposedHeight)
Get an offscreen buffer for painting a component's image. This image may be smaller than the proposed dimensions, depending on the value of the RepaintManager property.

Parameters:
component - The component to return an offscreen buffer for
proposedWidth - The proposed width of the offscreen buffer
proposedHeight - The proposed height of the offscreen buffer

Returns:
A shared offscreen buffer for painting

See Also:
RepaintManager


getVolatileOffscreenBuffer

public Image getVolatileOffscreenBuffer(Component comp,
                                        int proposedWidth,
                                        int proposedHeight)
Creates and returns a volatile offscreen buffer for the specified component that can be used as a double buffer. The returned image is a VolatileImage. Its size will be (proposedWidth, proposedHeight) except when the maximum double buffer size has been set in this RepaintManager.

Parameters:
comp - the Component for which to create a volatile buffer
proposedWidth - the proposed width of the buffer
proposedHeight - the proposed height of the buffer

Since:
1.4

See Also:
VolatileImage}


isCompletelyDirty

public boolean isCompletelyDirty(JComponent component)
Return true if the specified component is completely contained within its dirty region, otherwise false

Parameters:
component - The component to check for complete dirtyness

Returns:
Whether the component is completely dirty

See Also:
RepaintManager, addDirtyRegion(JComponent,int,int,int,int), getDirtyRegion(JComponent), isCompletelyDirty(JComponent), markCompletelyClean(JComponent)


isDoubleBufferingEnabled

public boolean isDoubleBufferingEnabled()
Get the value of the RepaintManager property.

Returns:
The current value of the property

See Also:
setDoubleBufferingEnabled(boolean)


markCompletelyClean

public void markCompletelyClean(JComponent component)
Remove all dirty regions for a specified component

Parameters:
component - The component to mark as clean

See Also:
RepaintManager, addDirtyRegion(JComponent,int,int,int,int), getDirtyRegion(JComponent), isCompletelyDirty(JComponent), markCompletelyDirty(JComponent)


markCompletelyDirty

public void markCompletelyDirty(JComponent component)
Mark a component as dirty over its entire bounds.

Parameters:
component - The component to mark as dirty

See Also:
RepaintManager, addDirtyRegion(JComponent,int,int,int,int), getDirtyRegion(JComponent), isCompletelyDirty(JComponent), markCompletelyClean(JComponent)


paintDirtyRegions

public void paintDirtyRegions()
Repaint all regions of all components which have been marked dirty in the RepaintManager table.


removeInvalidComponent

public void removeInvalidComponent(JComponent component)
Remove a component from the RepaintManager vector.

Parameters:
component - The component to remove

See Also:
addInvalidComponent(JComponent)


setCurrentManager

public static void setCurrentManager(RepaintManager manager)
Set the value of the shared RepaintManager instance.

Parameters:
manager - The new value of the shared instance

See Also:
currentManager


setDoubleBufferMaximumSize

public void setDoubleBufferMaximumSize(Dimension size)
Set the value of the RepaintManager property.

Parameters:
size - The new value of the property

See Also:
getDoubleBufferMaximumSize()


setDoubleBufferingEnabled

public void setDoubleBufferingEnabled(boolean buffer)
Set the value of the RepaintManager property.

Parameters:
buffer - The new value of the property

See Also:
RepaintManager


toString

public String toString()
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() and such.

It is typical, but not required, to ensure that this method never completes abruptly with a RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).

Overrides:
toString in interface Object

Returns:
the String representing this Object, which may be null

See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)


validateInvalidComponents

public void validateInvalidComponents()
Validate all components which have been marked invalid in the RepaintManager vector.


RepaintManager.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.