1   package org.wcb.gui.component;
2   
3   import javax.swing.*;
4   import java.awt.*;
5   
6   /**
7    * <small>
8    * Copyright (c)  2006  wbogaardt.
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22   * <p/>
23   * $File:  $ <br>
24   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 30, 2006 5:05:39 PM $ <br>
25   * </small>
26   *
27   * @author wbogaardt
28   * @version 1
29   *          Date: Mar 30, 2006
30   *          Time: 5:05:39 PM
31   */
32  
33  public class TitlePanel extends JPanel {
34  
35      private Color barColor;
36      private JLabel textDisplay = new JLabel();
37  
38      /**
39       * Generic title panle
40       */
41      public TitlePanel() {
42          this(null);
43      }
44  
45      /**
46       * Generic title panel with blue background
47       * @param text Title you want displayed
48       */
49      public TitlePanel(String text) {
50          this(text, new Color(0xffa000));
51      }
52  
53      /**
54       * Generic Title Panel with set text and color
55       * @param text user defined text title
56       * @param color user defined base color
57       */
58      public TitlePanel(String text, Color color) {
59           this(text, null, color);
60      }
61  
62      /**
63       * Title panel with image icon.
64       * @param text The text for the title.
65       * @param icon an icon to display with the title.
66       * @param color base color.
67       */
68      public TitlePanel(String text, ImageIcon icon, Color color) {
69          setLayout(new BorderLayout());
70          setPreferredSize(new Dimension(10, 23));
71  
72          JPanel leftPanel = new JPanel(new BorderLayout());
73          if (icon != null) {
74              textDisplay = new JLabel(text, icon, JLabel.HORIZONTAL);
75          }
76          setText(text);
77          textDisplay.setForeground(Color.WHITE);
78          leftPanel.add(textDisplay, BorderLayout.SOUTH);
79          leftPanel.setOpaque(false);
80  
81          add(leftPanel, BorderLayout.WEST);
82          this.setBarColor(color);
83      }
84  
85      private void setText(String textString) {
86          textDisplay.setFont(new Font("Helvetic", Font.ITALIC, 12));
87          textDisplay.setText(textString);
88      }
89  
90      private void setBarColor(java.awt.Color bColor) {
91          barColor = bColor;
92          repaint();
93      }
94  
95       protected void paintComponent(Graphics g) {
96          super.paintComponent(g);
97          Graphics2D g2 = (Graphics2D) g;
98          Color grad_end = barColor.brighter();
99          Color grad_start = barColor.darker();
100         GradientPaint bg = new GradientPaint(new Point(0, 0), grad_start, new Point(this.getWidth(), 0), grad_end);
101         g2.setPaint(bg);
102         int scale = 2;
103         g2.fillRoundRect(0, 0, getWidth(), getHeight(), scale, scale);
104 
105     }
106 }