01: /*
02: * $Id: RepaintManagerX.java,v 1.9 2006/08/22 21:57:17 rbair Exp $
03: *
04: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
05: * Santa Clara, California 95054, U.S.A. All rights reserved.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: */
21:
22: package org.jdesktop.swingx;
23:
24: import java.awt.Container;
25: import java.awt.Rectangle;
26:
27: import javax.swing.JComponent;
28: import javax.swing.RepaintManager;
29:
30: /**
31: * <p>An implementation of {@link RepaintManager} which adds support for transparency
32: * in {@link JXPanel}s. <code>JXPanel</code> (which supports translucency) will
33: * replace the current RepaintManager with an instance of RepaintManagerX
34: * <em>unless</em> the current RepaintManager is tagged by the {@link TranslucentRepaintManager}
35: * annotation.</p>
36: *
37: * @author zixle
38: * @author rbair
39: */
40: @TranslucentRepaintManager
41: public class RepaintManagerX extends RepaintManager {
42: public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
43: Rectangle dirtyRegion = getDirtyRegion(c);
44: if (dirtyRegion.width == 0 && dirtyRegion.height == 0) {
45: int lastDeltaX = c.getX();
46: int lastDeltaY = c.getY();
47: Container parent = c.getParent();
48: while (parent instanceof JComponent) {
49: if (!parent.isVisible() || (parent.getPeer() == null)) {
50: return;
51: }
52: if (parent instanceof JXPanel
53: && (((JXPanel) parent).getAlpha() < 1f || !parent
54: .isOpaque())) {
55: x += lastDeltaX;
56: y += lastDeltaY;
57: lastDeltaX = lastDeltaY = 0;
58: c = (JComponent) parent;
59: }
60: lastDeltaX += parent.getX();
61: lastDeltaY += parent.getY();
62: parent = parent.getParent();
63: }
64: }
65: super.addDirtyRegion(c, x, y, w, h);
66: }
67: }
|