01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.swing.plaf.basic;
18:
19: import com.l2fprod.common.swing.JTaskPane;
20: import com.l2fprod.common.swing.PercentLayout;
21: import com.l2fprod.common.swing.plaf.TaskPaneUI;
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: /**
36: * Base implementation of the <code>JTaskPane</code> UI.
37: */
38: public class BasicTaskPaneUI extends TaskPaneUI {
39:
40: public static ComponentUI createUI(JComponent c) {
41: return new BasicTaskPaneUI();
42: }
43:
44: protected JTaskPane taskPane;
45: protected boolean useGradient;
46: protected Color gradientStart;
47: protected Color gradientEnd;
48:
49: public void installUI(JComponent c) {
50: super .installUI(c);
51: taskPane = (JTaskPane) c;
52: taskPane
53: .setLayout(new PercentLayout(PercentLayout.VERTICAL, 14));
54: taskPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0,
55: 10));
56: taskPane.setOpaque(true);
57:
58: if (taskPane.getBackground() == null
59: || taskPane.getBackground() instanceof ColorUIResource) {
60: taskPane.setBackground(UIManager
61: .getColor("TaskPane.background"));
62: }
63:
64: useGradient = UIManager.getBoolean("TaskPane.useGradient");
65: if (useGradient) {
66: gradientStart = UIManager
67: .getColor("TaskPane.backgroundGradientStart");
68: gradientEnd = UIManager
69: .getColor("TaskPane.backgroundGradientEnd");
70: }
71: }
72:
73: public void paint(Graphics g, JComponent c) {
74: Graphics2D g2d = (Graphics2D) g;
75: if (useGradient) {
76: Paint old = g2d.getPaint();
77: GradientPaint gradient = new GradientPaint(0, 0,
78: gradientStart, 0, c.getHeight(), gradientEnd);
79: g2d.setPaint(gradient);
80: g.fillRect(0, 0, c.getWidth(), c.getHeight());
81: g2d.setPaint(old);
82: }
83: }
84:
85: }
|