Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Find:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


The RepaintManager Class

The repaint manager is represented by the RepaintManager class. Listing 4.1 gives the class signature of this class.

Listing 4.1 RepaintManager Class Signature

public class RepaintManager extends Object
{
  // Public constructors
    public RepaintManager();
  // Public class methods
    public static RepaintManager currentManager(JComponent component);
    public static void setCurrentManager(RepaintManager manager);
  // Public instance methods
    public void addDirtyRegion(JComponent component component,
                               int x, int y,
                               int width, int height);
    public synchronized void addInvalidComponent(JComponent component);
    public Rectangle getDirtyRegion(JComponent component);
    public Dimension getDoubleBufferMaximumSize();
    public Image getOffscreenBuffer(Component component,
                                    int desiredWidth,
                                    int desiredHeight);
    public boolean isCompletelyDirty(JComponent component);
    public boolean isDoubleBufferingEnabled();
    public void markCompletelyClean(JComponent component);
    public void markCompletelyDirty(JComponent component);
    public void paintDirtyRegions();
    public synchronized void
                        removeInvalidComponent(JComponent component);
    public void setDoubleBufferingEnabled(boolean enable);
    public void setDoubleBufferMaximumSize(Dimension size);
    public synchronized String toString();
    public void validateInvalidComponents();
}

There is a public constructor for RepaintManager, but you would use it only if you were writing your own custom repaint manager and wanted to subclass the JFC repaint manager. JFC maintains a single repaint manager instance for each thread group (application). You can access the current repaint manager by calling a static class method, currentManager. The following line of code illustrates how to get the current repaint manager and use it to disable double buffering.

RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);

Note that the currentManager method takes a component as an argument. This construction is an artifact from an early version of the JFC—the component argument is currently not used by the currentManager method. However, it’s a good idea to provide a non-null component for this parameter because future versions of the JFC may depend on it.

The repaint manager provides the addDirtyRegion, getDirtyRegion, isCompletelyDirty, markCompletelyClean, markCompletelyDirty, and paintDirtyRegions methods for managing component repaint operations. The JComponent class and the repaint manager itself use these methods—applications do not normally call these methods directly. Likewise, the addInvalidComponent, removeInvalidComponent, and validateInvalidComponents methods are for managing component revalidations. Applications also don’t normally call these methods directly.

The repaint manager provides the getDoubleBufferMaximumSize, isDoubleBufferingEnabled, setDoubleBufferingEnabled, and setDoubleBufferMaximumSize methods for applications to manage double buffering—the use of these methods is discussed in the “Using the Repaint Manager to Manage Double Buffering” section later in this chapter. The getOffscreenBuffer method is used only by the JComponent class—applications do not normally need to access the repaint manager’s offscreen buffer.

Using the Repaint Manager to Manage Repaint and Revalidation Operations

The internal operation of the repaint manager is closely integrated with the various painting and layout validation methods in the JComponent class. When you call a component’s revalidate method, the repaint manager adds the component to a list of components that require revalidation. It then queues a component work request (if one is not already queued) to be executed on the event-dispatch thread. Likewise, when you call a component’s repaint method, the repaint manager adds the region to be painted to a list of dirty regions and, if necessary, queues a component work request. When the component work request is executed, it validates the invalid components, paints the dirty regions to an offscreen buffer, and then copies the contents of the offscreen buffer to the display. Figure 4.1 illustrates the role of the repaint manager in executing component repaint and revalidate requests.


Figure 4.1  Repaint manager operation.

If you use the revalidate and repaint methods, your application will automatically take advantage of the services of the repaint manager. Be sure to use the new revalidate method in place of the older invalidate/validate method pair.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.