![]() |
|||
![]() ![]() |
![]() |
|
![]() |
The RepaintManager ClassThe 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 JFCthe component argument is currently not used by the currentManager method. However, its 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 methodsapplications do not normally call these methods directly. Likewise, the addInvalidComponent, removeInvalidComponent, and validateInvalidComponents methods are for managing component revalidations. Applications also dont normally call these methods directly. The repaint manager provides the getDoubleBufferMaximumSize, isDoubleBufferingEnabled, setDoubleBufferingEnabled, and setDoubleBufferMaximumSize methods for applications to manage double bufferingthe 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 classapplications do not normally need to access the repaint managers offscreen buffer. Using the Repaint Manager to Manage Repaint and Revalidation OperationsThe 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 components 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 components 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.
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.
|
![]() |
|