001/*
002 * $Id: PainterUIResource.java 4046 2011-07-19 18:45:40Z 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.plaf;
023
024import java.awt.Graphics2D;
025
026import javax.swing.JComponent;
027import javax.swing.plaf.UIResource;
028
029import org.jdesktop.swingx.painter.Painter;
030
031/**
032 * An implementation of Painter as a UIResource. UI classes that create Painters
033 * should use this class.
034 * 
035 * @author rbair
036 * @author Karl George Schaefer
037 * @param <T> a subclass of JComponent
038 */
039public class PainterUIResource<T extends JComponent> implements Painter<T>, UIResource {
040    private Painter<? super T> p;
041
042    /**
043     * Creates a new instance of PainterUIResource with the specified delegate
044     * painter.
045     * 
046     * @param p
047     *            the delegate painter
048     */
049    public PainterUIResource(Painter<? super T> p) {
050        this.p = p;
051    }
052    
053    /**
054     * {@inheritDoc}
055     */
056    @Override
057    public void paint(Graphics2D g, T component, int width, int height) {
058        if (p != null) {
059            p.paint(g, component, width, height);
060        }
061    }
062}