~ubuntu-branches/ubuntu/trusty/libswingx-java/trusty

« back to all changes in this revision

Viewing changes to src/java/org/jdesktop/swingx/RepaintManagerX.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2008-03-08 16:18:24 UTC
  • Revision ID: james.westby@ubuntu.com-20080308161824-wsahvl9pwzjcea3g
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: RepaintManagerX.java,v 1.9 2006/08/22 21:57:17 rbair Exp $
 
3
 *
 
4
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 
5
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * 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 && (((JXPanel)parent).getAlpha() < 1f ||
 
53
                    !parent.isOpaque())) {
 
54
                    x += lastDeltaX;
 
55
                    y += lastDeltaY;
 
56
                    lastDeltaX = lastDeltaY = 0;
 
57
                    c = (JComponent)parent;
 
58
                }
 
59
                lastDeltaX += parent.getX();
 
60
                lastDeltaY += parent.getY();
 
61
                parent = parent.getParent();
 
62
            }
 
63
        }
 
64
        super.addDirtyRegion(c, x, y, w, h);
 
65
    }
 
66
}
 
 
b'\\ No newline at end of file'