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