001 /*
002 * $Id: Painter.java,v 1.2 2006/03/23 20:03:07 rbair Exp $
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
022 package org.jdesktop.swingx.painter;
023
024 import java.awt.Graphics2D;
025 import javax.swing.JComponent;
026
027 /**
028 * <p>Simple API for delegating painting. The JXPanel supports using this class
029 * as a delegate for painting the background of the panel. This allows developers
030 * to be able to customize the background painting of a JXPanel without having
031 * to override it. Since many components within SwingX extend JXPanel, the
032 * developer can implement custom painting on many parts of SwingX.</p>
033 *
034 * <p>Painters are generally expected to work with JComponent or one of its
035 * subclasses. Most painters don't use the component beyond requesting its width
036 * and height, but it is conceivable that certain painters will only work with
037 * specific subclasses (JXTitledPanel, for instance, so that the text can
038 * be extracted and used to paint a glow effect).</p>
039 *
040 * <p>Painters can be combined together by using the CompoundPainter. CompoundPainter
041 * uses an array to store several painters, and the order in which they should be
042 * painted.</p>
043 *
044 * <p>For example, if I want to create a CompoundPainter that started with a blue
045 * background, had pinstripes on it running at a 45 degree angle, and those
046 * pinstripes appeared to "fade in" from left to right, I would write the following:
047 * <pre><code>
048 * Color blue = new Color(0x417DDD);
049 * Color translucent = new Color(blue.getRed(), blue.getGreen(), blue.getBlue(), 0);
050 * panel.setBackground(blue);
051 * panel.setForeground(Color.LIGHT_GRAY);
052 * GradientPaint blueToTranslucent = new GradientPaint(
053 * new Point2D.Double(.4, 0),
054 * blue,
055 * new Point2D.Double(1, 0),
056 * translucent);
057 * Painter veil = new BasicGradientPainter(blueToTranslucent);
058 * Painter pinstripes = new PinstripePainter(45);
059 * Painter backgroundPainter = new BackgroundPainter();
060 * Painter p = new CompoundPainter(backgroundPainter, pinstripes, veil);
061 * panel.setBackgroundPainter(p);
062 * </code></pre></p>
063 *
064 * <p>For convenience, AbstractPainter handles some basic painting chores and
065 * should be extended for most concrete Painter implementations</p>
066 *
067 *
068 * @author rbair
069 */
070 public interface Painter<T extends JComponent> {
071 /**
072 * <p>Paints on the given Graphics2D object some effect which may or may not
073 * be related to the given component. For example, BackgroundPainter will
074 * use the background property of the component and the width/height of the
075 * component to perform a fill rect. Most other Painters will disregard the
076 * component entirely, except to get the component width/height.</p>
077 *
078 * <p>The Graphics2D object must be returned to the same state it started
079 * at by the end of the method. For example, if "setColor(c)" was called
080 * on the graphics object, it should be reset to the original color before
081 * the method returns.</p>
082 *
083 *
084 * @param g The Graphics2D object in which to paint
085 * @param component The JComponent that the Painter is delegate for.
086 */
087 public void paint(Graphics2D g, T component);
088 }