001 /*
002 * $Id: BasicTaskPaneContainerUI.java,v 1.4 2005/10/10 18:02:53 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 package org.jdesktop.swingx.plaf.basic;
022
023 import java.awt.Color;
024 import java.awt.GradientPaint;
025 import java.awt.Graphics;
026 import java.awt.Graphics2D;
027 import java.awt.Paint;
028
029 import javax.swing.BorderFactory;
030 import javax.swing.JComponent;
031 import javax.swing.UIManager;
032 import javax.swing.plaf.ColorUIResource;
033 import javax.swing.plaf.ComponentUI;
034
035 import org.jdesktop.swingx.JXTaskPaneContainer;
036 import org.jdesktop.swingx.VerticalLayout;
037 import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
038
039 /**
040 * Base implementation of the <code>JXTaskPaneContainer</code> UI.
041 *
042 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
043 */
044 public class BasicTaskPaneContainerUI extends TaskPaneContainerUI {
045
046 public static ComponentUI createUI(JComponent c) {
047 return new BasicTaskPaneContainerUI();
048 }
049
050 protected JXTaskPaneContainer taskPane;
051 protected boolean useGradient;
052 protected Color gradientStart;
053 protected Color gradientEnd;
054
055 public void installUI(JComponent c) {
056 super.installUI(c);
057 taskPane = (JXTaskPaneContainer)c;
058 taskPane.setLayout(new VerticalLayout(14));
059 taskPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
060 taskPane.setOpaque(true);
061
062 if (taskPane.getBackground() == null
063 || taskPane.getBackground() instanceof ColorUIResource) {
064 taskPane
065 .setBackground(UIManager.getColor("TaskPaneContainer.background"));
066 }
067
068 useGradient = UIManager.getBoolean("TaskPaneContainer.useGradient");
069 if (useGradient) {
070 gradientStart = UIManager
071 .getColor("TaskPaneContainer.backgroundGradientStart");
072 gradientEnd = UIManager
073 .getColor("TaskPaneContainer.backgroundGradientEnd");
074 }
075 }
076
077 @Override
078 public void paint(Graphics g, JComponent c) {
079 Graphics2D g2d = (Graphics2D)g;
080 if (useGradient) {
081 Paint old = g2d.getPaint();
082 GradientPaint gradient = new GradientPaint(0, 0, gradientStart, 0, c
083 .getHeight(), gradientEnd);
084 g2d.setPaint(gradient);
085 g.fillRect(0, 0, c.getWidth(), c.getHeight());
086 g2d.setPaint(old);
087 }
088 }
089
090 }