001/*
002 * $Id: RepaintManagerX.java 3789 2010-09-27 19:10:48Z kschaefe $
003 *
004 * Copyright 2004 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
022package org.jdesktop.swingx;
023
024import java.awt.Point;
025
026import javax.swing.JComponent;
027import javax.swing.RepaintManager;
028import javax.swing.SwingUtilities;
029
030/**
031 * <p>An implementation of {@link RepaintManager} which adds support for transparency
032 * in {@link JXPanel}s. <code>JXPanel</code> (which supports translucency) will 
033 * replace the current RepaintManager with an instance of RepaintManagerX 
034 * <em>unless</em> the current RepaintManager is tagged by the {@link TranslucentRepaintManager}
035 * annotation.</p>
036 *
037 * @author zixle
038 * @author rbair
039 * @author Karl Schaefer
040 */
041@TranslucentRepaintManager
042public class RepaintManagerX extends ForwardingRepaintManager {
043    /**
044     * Creates a new manager that forwards all calls to the delegate.
045     * 
046     * @param delegate
047     *            the manager backing this {@code RepaintManagerX}
048     * @throws NullPointerException
049     *             if {@code delegate} is {@code null}
050     */
051    public RepaintManagerX(RepaintManager delegate) {
052        super(delegate);
053    }
054    
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
060        JXPanel panel = SwingXUtilities.getAncestor(JXPanel.class, c);
061        
062        if (panel != null && !panel.isOpaque()) {
063            Point p = SwingUtilities.convertPoint(c, x, y, panel);
064            addDirtyRegion(panel, p.x, p.y, w, h);
065        } else {
066            super.addDirtyRegion(c, x, y, w, h);
067        }
068    }
069}