001    /**
002     * Copyright (c) 2009, Piet Blok
003     * All rights reserved.
004     *
005     * Redistribution and use in source and binary forms, with or without
006     * modification, are permitted provided that the following conditions
007     * are met:
008     *
009     *   * Redistributions of source code must retain the above copyright
010     *     notice, this list of conditions and the following disclaimer.
011     *   * Redistributions in binary form must reproduce the above
012     *     copyright notice, this list of conditions and the following
013     *     disclaimer in the documentation and/or other materials provided
014     *     with the distribution.
015     *   * Neither the name of the copyright holder nor the names of the
016     *     contributors may be used to endorse or promote products derived
017     *     from this software without specific prior written permission.
018     *
019     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
020     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
021     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
022     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
023     * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     */
031    
032    package org.pbjar.jxlayer.repaint;
033    
034    import java.applet.Applet;
035    import java.awt.Component;
036    import java.awt.Dimension;
037    import java.awt.Image;
038    import java.awt.Rectangle;
039    import java.awt.Window;
040    
041    import javax.swing.JComponent;
042    import javax.swing.RepaintManager;
043    import org.jdesktop.swingx.ForwardingRepaintManager;
044    
045    /**
046     * A fall back class for when the SwingX class {@link ForwardingRepaintManager}
047     * is not available on the class path.
048     * <p>
049     * A {@link RepaintManager} that preserves functionality of a wrapped {@code
050     * RepaintManager}. All methods will delegate to the wrapped {@code
051     * RepaintManager}.
052     * </p>
053     * <p>
054     * When sub classing this class, one must in all overridden methods call the
055     * {@code super} method.
056     * </p>
057     * 
058     * @see RepaintManagerUtils
059     * @see RepaintManagerProvider
060     * @see ForwardingRepaintManager
061     * @author Piet Blok
062     */
063    public class WrappedRepaintManager extends RepaintManager {
064    
065        /**
066         * The wrapped manager.
067         */
068        private final RepaintManager delegate;
069    
070        /**
071         * Construct a {@code RepaintManager} wrapping an existing {@code
072         * RepaintManager}.
073         * 
074         * @param delegate
075         *            an existing RepaintManager
076         */
077        public WrappedRepaintManager(RepaintManager delegate) {
078            if (delegate == null) {
079                throw new NullPointerException();
080            }
081            this.delegate = delegate;
082        }
083    
084        /**
085         * Just delegates. {@inheritDoc}
086         */
087        @Override
088        public void addDirtyRegion(Applet applet, int x, int y, int w, int h) {
089            delegate.addDirtyRegion(applet, x, y, w, h);
090        }
091    
092        /**
093         * Just delegates. {@inheritDoc}
094         */
095        @Override
096        public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
097            delegate.addDirtyRegion(c, x, y, w, h);
098        }
099    
100        /**
101         * Just delegates. {@inheritDoc}
102         */
103        @Override
104        public void addDirtyRegion(Window window, int x, int y, int w, int h) {
105            delegate.addDirtyRegion(window, x, y, w, h);
106        }
107    
108        /**
109         * Just delegates. {@inheritDoc}
110         */
111        @Override
112        public void addInvalidComponent(JComponent invalidComponent) {
113            delegate.addInvalidComponent(invalidComponent);
114        }
115    
116        /**
117         * Just delegates. {@inheritDoc}
118         */
119        @Override
120        public Rectangle getDirtyRegion(JComponent aComponent) {
121            return delegate.getDirtyRegion(aComponent);
122        }
123    
124        /**
125         * Just delegates. {@inheritDoc}
126         */
127        @Override
128        public Dimension getDoubleBufferMaximumSize() {
129            return delegate.getDoubleBufferMaximumSize();
130        }
131    
132        /**
133         * Just delegates. {@inheritDoc}
134         */
135        @Override
136        public Image getOffscreenBuffer(Component c, int proposedWidth,
137                int proposedHeight) {
138            return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight);
139        }
140    
141        /**
142         * Just delegates. {@inheritDoc}
143         */
144        @Override
145        public Image getVolatileOffscreenBuffer(Component c, int proposedWidth,
146                int proposedHeight) {
147            return delegate.getVolatileOffscreenBuffer(c, proposedWidth,
148                    proposedHeight);
149        }
150    
151        /**
152         * Just delegates. {@inheritDoc}
153         */
154        @Override
155        public boolean isCompletelyDirty(JComponent aComponent) {
156            return delegate.isCompletelyDirty(aComponent);
157        }
158    
159        /**
160         * Just delegates. {@inheritDoc}
161         */
162        @Override
163        public boolean isDoubleBufferingEnabled() {
164            return delegate.isDoubleBufferingEnabled();
165        }
166    
167        /**
168         * Just delegates. {@inheritDoc}
169         */
170        @Override
171        public void markCompletelyClean(JComponent aComponent) {
172            delegate.markCompletelyClean(aComponent);
173        }
174    
175        /**
176         * Just delegates. {@inheritDoc}
177         */
178        @Override
179        public void markCompletelyDirty(JComponent aComponent) {
180            delegate.markCompletelyDirty(aComponent);
181        }
182    
183        /**
184         * Just delegates. {@inheritDoc}
185         */
186        @Override
187        public void paintDirtyRegions() {
188            delegate.paintDirtyRegions();
189        }
190    
191        /**
192         * Just delegates. {@inheritDoc}
193         */
194        @Override
195        public void removeInvalidComponent(JComponent component) {
196            delegate.removeInvalidComponent(component);
197        }
198    
199        /**
200         * Just delegates. {@inheritDoc}
201         */
202        @Override
203        public void setDoubleBufferingEnabled(boolean aFlag) {
204            delegate.setDoubleBufferingEnabled(aFlag);
205        }
206    
207        /**
208         * Just delegates. {@inheritDoc}
209         */
210        @Override
211        public void setDoubleBufferMaximumSize(Dimension d) {
212            delegate.setDoubleBufferMaximumSize(d);
213        }
214    
215        /**
216         * Just delegates. {@inheritDoc}
217         */
218        @Override
219        public void validateInvalidComponents() {
220            delegate.validateInvalidComponents();
221        }
222    
223        /**
224         * Get the delegate.
225         * 
226         * @return the delegate
227         */
228        public RepaintManager getDelegateManager() {
229            return delegate;
230        }
231    
232    }