View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.component;
21  
22  import java.awt.BorderLayout;
23  import java.awt.Color;
24  import java.awt.Font;
25  
26  import javax.swing.Icon;
27  import javax.swing.JComponent;
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  import javax.swing.border.EmptyBorder;
31  import javax.swing.border.EtchedBorder;
32  
33  public class TitledPanel extends JPanel {
34      
35      //--- Data Field(s) ---
36  
37      JLabel jlTitle;
38  
39      //--- Constructor(s) ---
40  
41      public TitledPanel(String title, String description, Icon icon, 
42  					   JComponent c)
43      {
44  		JPanel jpTop = new JPanel(new BorderLayout());
45  		jpTop.setBackground(Color.white);
46  		jpTop.setBorder(new EtchedBorder());
47  
48  		if (title != null) {
49  			jlTitle = new JLabel(" " + title + " ");
50  			jlTitle.setFont(new Font("Dialog", Font.BOLD, 12));
51  			if (icon != null) {
52  				jlTitle.setIcon(icon);
53  			}
54  			jpTop.add(jlTitle, "North");
55  		}
56  
57  		if (description != null) {
58  			MultiLineLabel jtaInfo = new MultiLineLabel(description);
59  			jtaInfo.setBackground(Color.white);
60  			jtaInfo.setBorder(new EmptyBorder(2, 2, 2, 2));
61  			jpTop.add(jtaInfo, "Center");
62  		}
63  
64  		// spacer
65  		JPanel p = new JPanel(new BorderLayout());
66  		p.setBorder(new EmptyBorder(0, 0, 3, 0));
67  		p.add(jpTop, "Center");
68  
69  		setLayout(new BorderLayout());
70  		add(p, "North");
71  		if (c != null) {
72  			c.setBorder(new EtchedBorder());
73  			add(c, "Center");
74  		}
75      }
76  
77      public TitledPanel(String title, String description, JComponent c)
78      {
79  		this(title, description, null, c);
80      }
81  
82      public TitledPanel(JComponent c)
83      {
84  		this(null, null, null, c);
85      }
86  
87      //--- Method(s) ---
88  
89      public String getTitle()
90      {
91  		return jlTitle.getText();
92      }
93  
94      public void setTitle(String newValue)
95      {
96  		jlTitle.setText(newValue);
97      }
98  
99  }
100