| Method from javax.swing.RepaintManager Detail: |
public void addDirtyRegion(JComponent c,
int x,
int y,
int w,
int h) {
addDirtyRegion0(c, x, y, w, h);
}
Add a component in the list of components that should be refreshed.
If c already has a dirty region, the rectangle (x,y,w,h)
will be unioned with the region that should be redrawn. |
public void addDirtyRegion(Window window,
int x,
int y,
int w,
int h) {
addDirtyRegion0(window, x, y, w, h);
}
Adds window to the list of Components that
need to be repainted. |
public void addDirtyRegion(Applet applet,
int x,
int y,
int w,
int h) {
addDirtyRegion0(applet, x, y, w, h);
}
Adds applet to the list of Components that
need to be repainted. |
public synchronized void addInvalidComponent(JComponent invalidComponent) {
Component validateRoot = null;
/* Find the first JComponent ancestor of this component whose
* isValidateRoot() method returns true.
*/
for(Component c = invalidComponent; c != null; c = c.getParent()) {
if ((c instanceof CellRendererPane) || (c.getPeer() == null)) {
return;
}
if ((c instanceof JComponent) && (((JComponent)c).isValidateRoot())) {
validateRoot = c;
break;
}
}
/* There's no validateRoot to apply validate to, so we're done.
*/
if (validateRoot == null) {
return;
}
/* If the validateRoot and all of its ancestors aren't visible
* then we don't do anything. While we're walking up the tree
* we find the root Window or Applet.
*/
Component root = null;
for(Component c = validateRoot; c != null; c = c.getParent()) {
if (!c.isVisible() || (c.getPeer() == null)) {
return;
}
if ((c instanceof Window) || (c instanceof Applet)) {
root = c;
break;
}
}
if (root == null) {
return;
}
/* Lazily create the invalidateComponents vector and add the
* validateRoot if it's not there already. If this validateRoot
* is already in the vector, we're done.
*/
if (invalidComponents == null) {
invalidComponents = new ArrayList< Component >();
}
else {
int n = invalidComponents.size();
for(int i = 0; i < n; i++) {
if(validateRoot == invalidComponents.get(i)) {
return;
}
}
}
invalidComponents.add(validateRoot);
// Queue a Runnable to invoke paintDirtyRegions and
// validateInvalidComponents.
scheduleProcessingRunnable();
}
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. |
void beginPaint() {
boolean multiThreadedPaint = false;
int paintDepth = 0;
Thread currentThread = Thread.currentThread();
synchronized(this) {
paintDepth = this.paintDepth;
if (paintThread == null || currentThread == paintThread) {
paintThread = currentThread;
this.paintDepth++;
} else {
multiThreadedPaint = true;
}
}
if (!multiThreadedPaint && paintDepth == 0) {
getPaintManager().beginPaint();
}
}
Invoked prior to any paint/copyArea method calls. This will
be followed by an invocation of endPaint.
WARNING: Callers of this method need to wrap the call
in a try/finally, otherwise if an exception is thrown
during the course of painting the RepaintManager may
be left in a state in which the screen is not updated, eg:
repaintManager.beginPaint();
try {
repaintManager.paint(...);
} finally {
repaintManager.endPaint();
}
|
void collectDirtyComponents(Map dirtyComponents,
Component dirtyComponent,
List roots) {
int dx, dy, rootDx, rootDy;
Component component, rootDirtyComponent,parent;
Rectangle cBounds;
// Find the highest parent which is dirty. When we get out of this
// rootDx and rootDy will contain the translation from the
// rootDirtyComponent's coordinate system to the coordinates of the
// original dirty component. The tmp Rect is also used to compute the
// visible portion of the dirtyRect.
component = rootDirtyComponent = dirtyComponent;
int x = dirtyComponent.getX();
int y = dirtyComponent.getY();
int w = dirtyComponent.getWidth();
int h = dirtyComponent.getHeight();
dx = rootDx = 0;
dy = rootDy = 0;
tmp.setBounds((Rectangle) dirtyComponents.get(dirtyComponent));
// System.out.println("Collect dirty component for bound " + tmp +
// "component bounds is " + cBounds);;
SwingUtilities.computeIntersection(0,0,w,h,tmp);
if (tmp.isEmpty()) {
// System.out.println("Empty 1");
return;
}
for(;;) {
if(!(component instanceof JComponent))
break;
parent = component.getParent();
if(parent == null)
break;
component = parent;
dx += x;
dy += y;
tmp.setLocation(tmp.x + x, tmp.y + y);
x = component.getX();
y = component.getY();
w = component.getWidth();
h = component.getHeight();
tmp = SwingUtilities.computeIntersection(0,0,w,h,tmp);
if (tmp.isEmpty()) {
// System.out.println("Empty 2");
return;
}
if (dirtyComponents.get(component) != null) {
rootDirtyComponent = component;
rootDx = dx;
rootDy = dy;
}
}
if (dirtyComponent != rootDirtyComponent) {
Rectangle r;
tmp.setLocation(tmp.x + rootDx - dx,
tmp.y + rootDy - dy);
r = (Rectangle)dirtyComponents.get(rootDirtyComponent);
SwingUtilities.computeUnion(tmp.x,tmp.y,tmp.width,tmp.height,r);
}
// If we haven't seen this root before, then we need to add it to the
// list of root dirty Views.
if (!roots.contains(rootDirtyComponent))
roots.add(rootDirtyComponent);
}
|
void copyArea(JComponent c,
Graphics g,
int x,
int y,
int w,
int h,
int deltaX,
int deltaY,
boolean clip) {
getPaintManager().copyArea(c, g, x, y, w, h, deltaX, deltaY, clip);
}
Does a copy area on the specified region. |
public static RepaintManager currentManager(Component c) {
volatileImageBufferEnabled = "true".equals(AccessController.
doPrivileged(new GetPropertyAction(
"swing.volatileImageBufferEnabled", "true")));
boolean headless = GraphicsEnvironment.isHeadless();
if (volatileImageBufferEnabled && headless) {
volatileImageBufferEnabled = false;
}
nativeDoubleBuffering = "true".equals(AccessController.doPrivileged(
new GetPropertyAction("awt.nativeDoubleBuffering")));
String bs = AccessController.doPrivileged(
new GetPropertyAction("swing.bufferPerWindow"));
if (headless) {
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
}
else if (bs == null) {
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_NOT_SPECIFIED;
}
else if ("true".equals(bs)) {
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_ON;
}
else {
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
}
HANDLE_TOP_LEVEL_PAINT = "true".equals(AccessController.doPrivileged(
new GetPropertyAction("swing.handleTopLevelPaint", "true")));
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
if (ge instanceof SunGraphicsEnvironment) {
((SunGraphicsEnvironment)ge).addDisplayChangedListener(
new DisplayChangedHandler());
}
// Note: DisplayChangedRunnable passes in null as the component, so if
// component is ever used to determine the current
// RepaintManager, DisplayChangedRunnable will need to be modified
// accordingly.
return currentManager(AppContext.getAppContext());
}
Return the RepaintManager for the calling thread given a Component. |
static RepaintManager currentManager(AppContext appContext) {
RepaintManager rm = (RepaintManager)appContext.get(repaintManagerKey);
if (rm == null) {
rm = new RepaintManager(BUFFER_STRATEGY_TYPE);
appContext.put(repaintManagerKey, rm);
}
return rm;
}
Returns the RepaintManager for the specified AppContext. If
a RepaintManager has not been created for the specified
AppContext this will return null. |
public static RepaintManager currentManager(JComponent c) {
return currentManager((Component)c);
}
Return the RepaintManager for the calling thread given a JComponent.
Note: This method exists for backward binary compatibility with earlier
versions of the Swing library. It simply returns the result returned by
#currentManager(Component) . |
void doubleBufferingChanged(JRootPane rootPane) {
getPaintManager().doubleBufferingChanged(rootPane);
}
Invoked when the doubleBuffered or useTrueDoubleBuffering
properties of a JRootPane change. This may come in on any thread. |
void endPaint() {
if (isPaintingThread()) {
PaintManager paintManager = null;
synchronized(this) {
if (--paintDepth == 0) {
paintManager = getPaintManager();
}
}
if (paintManager != null) {
paintManager.endPaint();
synchronized(this) {
paintThread = null;
}
}
}
}
Invoked after beginPaint has been invoked. |
public Rectangle getDirtyRegion(JComponent aComponent) {
Rectangle r = null;
synchronized(this) {
r = (Rectangle)dirtyComponents.get(aComponent);
}
if(r == null)
return new Rectangle(0,0,0,0);
else
return new Rectangle(r);
}
Return the current dirty region for a component.
Return an empty rectangle if the component is not
dirty. |
public Dimension getDoubleBufferMaximumSize() {
if (doubleBufferMaxSize == null) {
try {
Rectangle virtualBounds = new Rectangle();
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
for (GraphicsDevice gd : ge.getScreenDevices()) {
GraphicsConfiguration gc = gd.getDefaultConfiguration();
virtualBounds = virtualBounds.union(gc.getBounds());
}
doubleBufferMaxSize = new Dimension(virtualBounds.width,
virtualBounds.height);
} catch (HeadlessException e) {
doubleBufferMaxSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
}
return doubleBufferMaxSize;
}
Returns the maximum double buffer size. |
public Image getOffscreenBuffer(Component c,
int proposedWidth,
int proposedHeight) {
return _getOffscreenBuffer(c, proposedWidth, proposedHeight);
}
Return the offscreen buffer that should be used as a double buffer with
the component c.
By default there is a double buffer per RepaintManager.
The buffer might be smaller than (proposedWidth,proposedHeight)
This happens when the maximum double buffer size as been set for the receiving
repaint manager. |
public Image getVolatileOffscreenBuffer(Component c,
int proposedWidth,
int proposedHeight) {
GraphicsConfiguration config = c.getGraphicsConfiguration();
if (config == null) {
config = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
Dimension maxSize = getDoubleBufferMaximumSize();
int width = proposedWidth < 1 ? 1 :
(proposedWidth > maxSize.width? maxSize.width : proposedWidth);
int height = proposedHeight < 1 ? 1 :
(proposedHeight > maxSize.height? maxSize.height : proposedHeight);
VolatileImage image = volatileMap.get(config);
if (image == null || image.getWidth() < width ||
image.getHeight() < height) {
if (image != null) {
image.flush();
}
image = config.createCompatibleVolatileImage(width, height);
volatileMap.put(config, image);
}
return image;
}
Return a volatile offscreen buffer that should be used as a
double buffer with the specified component c.
The image returned will be an instance of VolatileImage, or null
if a VolatileImage object could not be instantiated.
This buffer might be smaller than (proposedWidth,proposedHeight).
This happens when the maximum double buffer size has been set for this
repaint manager. |
public boolean isCompletelyDirty(JComponent aComponent) {
Rectangle r;
r = getDirtyRegion(aComponent);
if(r.width == Integer.MAX_VALUE &&
r.height == Integer.MAX_VALUE)
return true;
else
return false;
}
Convenience method that returns true if aComponent will be completely
painted during the next paintDirtyRegions(). If computing dirty regions is
expensive for your component, use this method and avoid computing dirty region
if it return true. |
public boolean isDoubleBufferingEnabled() {
return doubleBufferingEnabled;
}
Returns true if this RepaintManager is double buffered.
The default value for this property may vary from platform
to platform. On platforms where native double buffering
is supported in the AWT, the default value will be false
to avoid unnecessary buffering in Swing.
On platforms where native double buffering is not supported,
the default value will be true. |
public void markCompletelyClean(JComponent aComponent) {
synchronized(this) {
dirtyComponents.remove(aComponent);
}
}
Mark a component completely clean. aComponent will not
get painted during the next paintDirtyRegions() call. |
public void markCompletelyDirty(JComponent aComponent) {
addDirtyRegion(aComponent,0,0,Integer.MAX_VALUE,Integer.MAX_VALUE);
}
Mark a component completely dirty. aComponent will be
completely painted during the next paintDirtyRegions() call. |
void nativeAddDirtyRegion(AppContext appContext,
Container c,
int x,
int y,
int w,
int h) {
if (w > 0 && h > 0) {
synchronized(this) {
Rectangle dirty = hwDirtyComponents.get(c);
if (dirty == null) {
hwDirtyComponents.put(c, new Rectangle(x, y, w, h));
}
else {
hwDirtyComponents.put(c, SwingUtilities.computeUnion(
x, y, w, h, dirty));
}
}
scheduleProcessingRunnable(appContext);
}
}
|
void nativeQueueSurfaceDataRunnable(AppContext appContext,
Component c,
Runnable r) {
synchronized(this) {
if (runnableList == null) {
runnableList = new LinkedList< Runnable >();
}
runnableList.add(r);
}
scheduleProcessingRunnable(appContext);
}
|
void paint(JComponent paintingComponent,
JComponent bufferComponent,
Graphics g,
int x,
int y,
int w,
int h) {
PaintManager paintManager = getPaintManager();
if (!isPaintingThread()) {
// We're painting to two threads at once. PaintManager deals
// with this a bit better than BufferStrategyPaintManager, use
// it to avoid possible exceptions/corruption.
if (paintManager.getClass() != PaintManager.class) {
paintManager = new PaintManager();
paintManager.repaintManager = this;
}
}
if (!paintManager.paint(paintingComponent, bufferComponent, g,
x, y, w, h)) {
g.setClip(x, y, w, h);
paintingComponent.paintToOffscreen(g, x, y, w, h, x + w, y + h);
}
}
Paints a region of a component |
public void paintDirtyRegions() {
synchronized(this) { // swap for thread safety
Map< Component,Rectangle > tmp = tmpDirtyComponents;
tmpDirtyComponents = dirtyComponents;
dirtyComponents = tmp;
dirtyComponents.clear();
}
paintDirtyRegions(tmpDirtyComponents);
}
Paint all of the components that have been marked dirty. |
public synchronized void removeInvalidComponent(JComponent component) {
if(invalidComponents != null) {
int index = invalidComponents.indexOf(component);
if(index != -1) {
invalidComponents.remove(index);
}
}
}
Remove a component from the list of invalid components. |
void resetDoubleBuffer() {
if (standardDoubleBuffer != null) {
standardDoubleBuffer.needsReset = true;
}
}
This resets the double buffer. Actually, it marks the double buffer
as invalid, the double buffer will then be recreated on the next
invocation of getOffscreenBuffer. |
void resetVolatileDoubleBuffer(GraphicsConfiguration gc) {
Image image = volatileMap.remove(gc);
if (image != null) {
image.flush();
}
}
This resets the volatile double buffer. |
void scheduleHeavyWeightPaints() {
Map< Container,Rectangle > hws;
synchronized(this) {
if (hwDirtyComponents.size() == 0) {
return;
}
hws = hwDirtyComponents;
hwDirtyComponents = new IdentityHashMap< Container,Rectangle >();
}
for (Container hw : hws.keySet()) {
Rectangle dirty = hws.get(hw);
if (hw instanceof Window) {
addDirtyRegion((Window)hw, dirty.x, dirty.y,
dirty.width, dirty.height);
}
else if (hw instanceof Applet) {
addDirtyRegion((Applet)hw, dirty.x, dirty.y,
dirty.width, dirty.height);
}
else { // SwingHeavyWeight
addDirtyRegion0(hw, dirty.x, dirty.y,
dirty.width, dirty.height);
}
}
}
|
public static void setCurrentManager(RepaintManager aRepaintManager) {
if (aRepaintManager != null) {
SwingUtilities.appContextPut(repaintManagerKey, aRepaintManager);
} else {
SwingUtilities.appContextRemove(repaintManagerKey);
}
}
Set the RepaintManager that should be used for the calling
thread. aRepaintManager will become the current RepaintManager
for the calling thread's thread group. |
public void setDoubleBufferMaximumSize(Dimension d) {
doubleBufferMaxSize = d;
if (doubleBufferMaxSize == null) {
clearImages();
} else {
clearImages(d.width, d.height);
}
}
Set the maximum double buffer size. |
public void setDoubleBufferingEnabled(boolean aFlag) {
doubleBufferingEnabled = aFlag;
PaintManager paintManager = getPaintManager();
if (!aFlag && paintManager.getClass() != PaintManager.class) {
setPaintManager(new PaintManager());
}
}
Enables or disables double buffering in this RepaintManager.
CAUTION: The default value for this property is set for optimal
paint performance on the given platform and it is not recommended
that programs modify this property directly. |
void setPaintManager(RepaintManager.PaintManager paintManager) {
if (paintManager == null) {
paintManager = new PaintManager();
}
PaintManager oldPaintManager;
synchronized(this) {
oldPaintManager = this.paintManager;
this.paintManager = paintManager;
paintManager.repaintManager = this;
}
if (oldPaintManager != null) {
oldPaintManager.dispose();
}
}
Sets the PaintManager that is used to handle all
double buffered painting. |
boolean show(Container c,
int x,
int y,
int w,
int h) {
return getPaintManager().show(c, x, y, w, h);
}
If possible this will show a previously rendered portion of
a Component. If successful, this will return true, otherwise false.
WARNING: This method is invoked from the native toolkit thread, be
very careful as to what methods this invokes! |
public synchronized String toString() {
StringBuffer sb = new StringBuffer();
if(dirtyComponents != null)
sb.append("" + dirtyComponents);
return sb.toString();
}
Returns a string that displays and identifies this
object's properties. |
boolean useVolatileDoubleBuffer() {
return volatileImageBufferEnabled;
}
Returns true if we should use the Image returned
from getVolatileOffscreenBuffer to do double buffering. |
public void validateInvalidComponents() {
java.util.List< Component > ic;
synchronized(this) {
if(invalidComponents == null) {
return;
}
ic = invalidComponents;
invalidComponents = null;
}
int n = ic.size();
for(int i = 0; i < n; i++) {
ic.get(i).validate();
}
}
Validate all of the components that have been marked invalid. |