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.plaf.ext.transform;
033    
034    import javax.swing.JComponent;
035    import javax.swing.RepaintManager;
036    
037    import org.jdesktop.swingx.ForwardingRepaintManager;
038    import org.pbjar.jxlayer.repaint.RepaintManagerProvider;
039    import org.pbjar.jxlayer.repaint.RepaintManagerUtils;
040    
041    /**
042     * A specialized {@link RepaintManager} that checks for every JComponent that is
043     * being set dirty, if it has a JXLayer ancestor, equipped with a TransformUI.
044     * In that case, the transformed region on the JXLayer is also marked dirty.
045     * <p>
046     * If this class cannot be instantiated because the SwingX packages are not on
047     * the class path, use {@link TransformRPMFallBack}
048     * </p>
049     * 
050     * @see TransformRPMFallBack
051     * @see RepaintManagerProvider
052     * @see RepaintManagerUtils
053     * @author Piet Blok
054     */
055    @TransformRPMAnnotation
056    public class TransformRPMSwingX extends
057            ForwardingRepaintManager {
058    
059        /**
060         * Sole constructor.
061         * 
062         * @param delegate
063         *            the delegate {@link RepaintManager}
064         */
065        public TransformRPMSwingX(RepaintManager delegate) {
066            super(delegate);
067            TransformRPMImpl.hackInitialization(delegate, this);
068        }
069    
070        /**
071         * Delegates and then marks a JXLayer ancestor as dirty with the transformed
072         * rectangle.
073         */
074        @Override
075        public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
076            if (!TransformRPMImpl.addDirtyRegion(c, x, y, w, h,this)) {
077                super.addDirtyRegion(c, x, y, w, h);
078            }
079        }
080    
081    }