001 /*
002 * $Id: ForwardingRepaintManager.java 3355 2009-05-29 20:10:53Z 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 */
021 package org.jdesktop.swingx;
022
023 import java.awt.Component;
024 import java.awt.Dimension;
025 import java.awt.Image;
026 import java.awt.Rectangle;
027
028 import javax.swing.JComponent;
029 import javax.swing.RepaintManager;
030
031 import org.jdesktop.swingx.util.Contract;
032
033 /**
034 * A {@code RepaintManager} that is designed to forward all calls to a contained
035 * delegate. This class is designed for extension, such that subclasses should
036 * override method as appropriate and allow the original repaint manager to
037 * handle the rest of the work.
038 * <p>
039 * Install a forwarding repaint manager:
040 *
041 * <pre>
042 * RepaintManager manager = RepaintManager.currentManager(this);
043 * RepaintManager frm = new ForwardingRepaintManager(manager);
044 * RepaintManager.setCurrentManager(frm);
045 * </pre>
046 *
047 * @author Karl George Schaefer
048 * @author pietblok (original facade/delegate idea)
049 */
050 public class ForwardingRepaintManager extends RepaintManager {
051 private RepaintManager delegate;
052
053 /**
054 * Creates a new forwarding manager that forwards all calls to the delegate.
055 *
056 * @param delegate
057 * the manager backing this {@code ForwardingRepaintManager}
058 * @throws NullPointerException
059 * if {@code delegate} is {@code null}
060 */
061 public ForwardingRepaintManager(RepaintManager delegate) {
062 this.delegate = Contract.asNotNull(delegate, "delegate is null");
063 }
064
065 //TODO in 1.6
066 // /**
067 // * {@inheritDoc}
068 // */
069 // public void addDirtyRegion(Applet applet, int x, int y, int w, int h) {
070 // delegate.addDirtyRegion(applet, x, y, w, h);
071 // }
072
073 /**
074 * {@inheritDoc}
075 */
076 public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
077 delegate.addDirtyRegion(c, x, y, w, h);
078 }
079
080 //TODO in 1.6
081 // /**
082 // * {@inheritDoc}
083 // */
084 // public void addDirtyRegion(Window window, int x, int y, int w, int h) {
085 // delegate.addDirtyRegion(window, x, y, w, h);
086 // }
087
088 /**
089 * {@inheritDoc}
090 */
091 public void addInvalidComponent(JComponent invalidComponent) {
092 delegate.addInvalidComponent(invalidComponent);
093 }
094
095 /**
096 * {@inheritDoc}
097 */
098 public Rectangle getDirtyRegion(JComponent component) {
099 return delegate.getDirtyRegion(component);
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 public Dimension getDoubleBufferMaximumSize() {
106 return delegate.getDoubleBufferMaximumSize();
107 }
108
109 /**
110 * {@inheritDoc}
111 */
112 public Image getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
113 return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight);
114 }
115
116 /**
117 * {@inheritDoc}
118 */
119 public Image getVolatileOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
120 return delegate.getVolatileOffscreenBuffer(c, proposedWidth, proposedHeight);
121 }
122
123 /**
124 * {@inheritDoc}
125 */
126 public boolean isCompletelyDirty(JComponent component) {
127 return delegate.isCompletelyDirty(component);
128 }
129
130 /**
131 * {@inheritDoc}
132 */
133 public boolean isDoubleBufferingEnabled() {
134 return delegate.isDoubleBufferingEnabled();
135 }
136
137 /**
138 * {@inheritDoc}
139 */
140 public void markCompletelyClean(JComponent component) {
141 delegate.markCompletelyClean(component);
142 }
143
144 /**
145 * {@inheritDoc}
146 */
147 public void markCompletelyDirty(JComponent component) {
148 delegate.markCompletelyDirty(component);
149 }
150
151 /**
152 * {@inheritDoc}
153 */
154 public void paintDirtyRegions() {
155 delegate.paintDirtyRegions();
156 }
157
158 /**
159 * {@inheritDoc}
160 */
161 public void removeInvalidComponent(JComponent component) {
162 delegate.removeInvalidComponent(component);
163 }
164
165 /**
166 * {@inheritDoc}
167 */
168 public void setDoubleBufferingEnabled(boolean flag) {
169 delegate.setDoubleBufferingEnabled(flag);
170 }
171
172 /**
173 * {@inheritDoc}
174 */
175 public void setDoubleBufferMaximumSize(Dimension d) {
176 delegate.setDoubleBufferMaximumSize(d);
177 }
178
179 /**
180 * {@inheritDoc}
181 */
182 public String toString() {
183 return delegate.toString();
184 }
185
186 /**
187 * {@inheritDoc}
188 */
189 public void validateInvalidComponents() {
190 delegate.validateInvalidComponents();
191 }
192
193 /**
194 * Gets the delegate repaint manager backing this forwarding repaint
195 * manager.
196 *
197 * @return the delegate for this forwarding manager
198 */
199 public final RepaintManager getDelegateManager() {
200 return delegate;
201 }
202 }