001/*
002 * $Id: ForwardingRepaintManager.java 3690 2010-05-03 17:55:44Z kschaefe $
003 *
004 * Copyright 2009 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020 */
021package org.jdesktop.swingx;
022
023import java.applet.Applet;
024import java.awt.Component;
025import java.awt.Dimension;
026import java.awt.Image;
027import java.awt.Rectangle;
028import java.awt.Window;
029
030import javax.swing.JComponent;
031import javax.swing.RepaintManager;
032
033import org.jdesktop.swingx.util.Contract;
034
035/**
036 * A {@code RepaintManager} that is designed to forward all calls to a contained
037 * delegate. This class is designed for extension, such that subclasses should
038 * override method as appropriate and allow the original repaint manager to
039 * handle the rest of the work.
040 * <p>
041 * Install a forwarding repaint manager:
042 * 
043 * <pre>
044 * RepaintManager manager = RepaintManager.currentManager(this);
045 * RepaintManager frm = new ForwardingRepaintManager(manager);
046 * RepaintManager.setCurrentManager(frm);
047 * </pre>
048 * 
049 * @author Karl George Schaefer
050 * @author pietblok (original facade/delegate idea)
051 */
052public class ForwardingRepaintManager extends RepaintManager {
053    private RepaintManager delegate;
054
055    /**
056     * Creates a new forwarding manager that forwards all calls to the delegate.
057     * 
058     * @param delegate
059     *            the manager backing this {@code ForwardingRepaintManager}
060     * @throws NullPointerException
061     *             if {@code delegate} is {@code null}
062     */
063    public ForwardingRepaintManager(RepaintManager delegate) {
064        this.delegate = Contract.asNotNull(delegate, "delegate is null");
065    }
066    
067    /**
068     * {@inheritDoc}
069     */
070    @Override
071    public void addDirtyRegion(Applet applet, int x, int y, int w, int h) {
072        delegate.addDirtyRegion(applet, x, y, w, h);
073    }
074
075    /**
076     * {@inheritDoc}
077     */
078    @Override
079    public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
080        delegate.addDirtyRegion(c, x, y, w, h);
081    }
082
083    /**
084     * {@inheritDoc}
085     */
086    @Override
087    public void addDirtyRegion(Window window, int x, int y, int w, int h) {
088        delegate.addDirtyRegion(window, x, y, w, h);
089    }
090
091    /**
092     * {@inheritDoc}
093     */
094    @Override
095    public synchronized void addInvalidComponent(JComponent invalidComponent) {
096        delegate.addInvalidComponent(invalidComponent);
097    }
098
099    /**
100     * {@inheritDoc}
101     */
102    @Override
103    public Rectangle getDirtyRegion(JComponent component) {
104        return delegate.getDirtyRegion(component);
105    }
106
107    /**
108     * {@inheritDoc}
109     */
110    @Override
111    public Dimension getDoubleBufferMaximumSize() {
112        return delegate.getDoubleBufferMaximumSize();
113    }
114
115    /**
116     * {@inheritDoc}
117     */
118    @Override
119    public Image getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
120        return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight);
121    }
122
123    /**
124     * {@inheritDoc}
125     */
126    @Override
127    public Image getVolatileOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
128        return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight);
129    }
130
131    /**
132     * {@inheritDoc}
133     */
134    @Override
135    public boolean isCompletelyDirty(JComponent component) {
136        return delegate.isCompletelyDirty(component);
137    }
138
139    /**
140     * {@inheritDoc}
141     */
142    @Override
143    public boolean isDoubleBufferingEnabled() {
144        return delegate.isDoubleBufferingEnabled();
145    }
146
147    /**
148     * {@inheritDoc}
149     */
150    @Override
151    public void markCompletelyClean(JComponent component) {
152        delegate.markCompletelyClean(component);
153    }
154
155    /**
156     * {@inheritDoc}
157     */
158    @Override
159    public void markCompletelyDirty(JComponent component) {
160        delegate.markCompletelyDirty(component);
161    }
162
163    /**
164     * {@inheritDoc}
165     */
166    @Override
167    public void paintDirtyRegions() {
168        delegate.paintDirtyRegions();
169    }
170
171    /**
172     * {@inheritDoc}
173     */
174    @Override
175    public synchronized void removeInvalidComponent(JComponent component) {
176        delegate.removeInvalidComponent(component);
177    }
178
179    /**
180     * {@inheritDoc}
181     */
182    @Override
183    public void setDoubleBufferingEnabled(boolean flag) {
184        delegate.setDoubleBufferingEnabled(flag);
185    }
186
187    /**
188     * {@inheritDoc}
189     */
190    @Override
191    public void setDoubleBufferMaximumSize(Dimension d) {
192        delegate.setDoubleBufferMaximumSize(d);
193    }
194
195    /**
196     * {@inheritDoc}
197     */
198    @Override
199    public synchronized String toString() {
200        return delegate.toString();
201    }
202
203    /**
204     * {@inheritDoc}
205     */
206    @Override
207    public void validateInvalidComponents() {
208        delegate.validateInvalidComponents();
209    }
210
211    /**
212     * Gets the delegate repaint manager backing this forwarding repaint
213     * manager.
214     * 
215     * @return the delegate for this forwarding manager
216     */
217    public final RepaintManager getDelegateManager() {
218        return delegate;
219    }
220}