01: /*
02: * $Id: BasicTaskPaneContainerUI.java,v 1.4 2005/10/10 18:02:53 rbair Exp $
03: *
04: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
05: * Santa Clara, California 95054, U.S.A. All rights reserved.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: */
21: package org.jdesktop.swingx.plaf.basic;
22:
23: import java.awt.Color;
24: import java.awt.GradientPaint;
25: import java.awt.Graphics;
26: import java.awt.Graphics2D;
27: import java.awt.Paint;
28:
29: import javax.swing.BorderFactory;
30: import javax.swing.JComponent;
31: import javax.swing.UIManager;
32: import javax.swing.plaf.ColorUIResource;
33: import javax.swing.plaf.ComponentUI;
34:
35: import org.jdesktop.swingx.JXTaskPaneContainer;
36: import org.jdesktop.swingx.VerticalLayout;
37: import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
38:
39: /**
40: * Base implementation of the <code>JXTaskPaneContainer</code> UI.
41: *
42: * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
43: */
44: public class BasicTaskPaneContainerUI extends TaskPaneContainerUI {
45:
46: public static ComponentUI createUI(JComponent c) {
47: return new BasicTaskPaneContainerUI();
48: }
49:
50: protected JXTaskPaneContainer taskPane;
51: protected boolean useGradient;
52: protected Color gradientStart;
53: protected Color gradientEnd;
54:
55: public void installUI(JComponent c) {
56: super .installUI(c);
57: taskPane = (JXTaskPaneContainer) c;
58: taskPane.setLayout(new VerticalLayout(14));
59: taskPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0,
60: 10));
61: taskPane.setOpaque(true);
62:
63: if (taskPane.getBackground() == null
64: || taskPane.getBackground() instanceof ColorUIResource) {
65: taskPane.setBackground(UIManager
66: .getColor("TaskPaneContainer.background"));
67: }
68:
69: useGradient = UIManager
70: .getBoolean("TaskPaneContainer.useGradient");
71: if (useGradient) {
72: gradientStart = UIManager
73: .getColor("TaskPaneContainer.backgroundGradientStart");
74: gradientEnd = UIManager
75: .getColor("TaskPaneContainer.backgroundGradientEnd");
76: }
77: }
78:
79: @Override
80: public void paint(Graphics g, JComponent c) {
81: Graphics2D g2d = (Graphics2D) g;
82: if (useGradient) {
83: Paint old = g2d.getPaint();
84: GradientPaint gradient = new GradientPaint(0, 0,
85: gradientStart, 0, c.getHeight(), gradientEnd);
86: g2d.setPaint(gradient);
87: g.fillRect(0, 0, c.getWidth(), c.getHeight());
88: g2d.setPaint(old);
89: }
90: }
91:
92: }
|