2
* $Id: JXTitledPanel.java 3471 2009-08-27 13:10:39Z kleopatra $
4
* Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5
* Santa Clara, California 95054, U.S.A. All rights reserved.
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
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.
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
22
package org.jdesktop.swingx;
24
import java.awt.BorderLayout;
25
import java.awt.Color;
26
import java.awt.Container;
29
import javax.swing.BorderFactory;
30
import javax.swing.JComponent;
32
import org.jdesktop.swingx.painter.Painter;
33
import org.jdesktop.swingx.plaf.LookAndFeelAddons;
34
import org.jdesktop.swingx.plaf.TitledPanelAddon;
35
import org.jdesktop.swingx.plaf.TitledPanelUI;
38
* A special type of Panel that has a Title section and a Content section.<br>
39
* The following properties can be set with the UIManager to change the look
40
* and feel of the JXTitledPanel:
42
* <li>JXTitledPanel.titleForeground</li>
43
* <li>JXTitledPanel.titleBackground</li>
44
* <li>JXTitledPanel.titleFont</li>
45
* <li>JXTitledPanel.titlePainter</li>
46
* <li>JXTitledPanel.captionInsets</li>
47
* <li>JXTitledPanel.rightDecorationInsets</li>
48
* <li>JXTitledPanel.leftDecorationInsets</li>
51
* @author Richard Bair
52
* @author Nicola Ken Barozzi
53
* @author Jeanette Winzenburg
55
public class JXTitledPanel extends JXPanel {
58
* @see #getUIClassID // *
61
static public final String uiClassID = "TitledPanelUI";
63
public static final String LEFT_DECORATION = "JXTitledPanel.leftDecoration";
65
public static final String RIGHT_DECORATION = "JXTitledPanel.rightDecoration";
68
* Initialization that would ideally be moved into various look and feel
72
LookAndFeelAddons.contribute(new TitledPanelAddon());
76
* The text to use for the title
78
private String title = "";
81
* The Font to use for the Title
83
private Font titleFont;
86
* The foreground color to use for the Title (particularly for the text)
88
private Color titleForeground;
91
* The ContentPanel. Whatever this container is will be displayed in the
94
private Container contentPanel;
97
* The Painter to use for painting the title section of the JXTitledPanel
99
private Painter titlePainter;
102
* Create a new JTitledPanel with an empty string for the title.
104
public JXTitledPanel() {
109
* Create a new JTitledPanel with the given title as the title for the
114
public JXTitledPanel(String title) {
115
this(title, createDefaultContainer());
119
* Create a new JTitledPanel with the given String as the title, and the
120
* given Container as the content panel.
125
public JXTitledPanel(String title, Container content) {
127
setContentContainer(content);
131
* Returns the look and feel (L&F) object that renders this component.
133
* @return the TitledPanelUI object that renders this component
136
public TitledPanelUI getUI() {
137
return (TitledPanelUI) ui;
141
* Sets the look and feel (L&F) object that renders this component.
144
* the TitledPanelUI L&F object
145
* @see javax.swing.UIDefaults#getUI
146
* @beaninfo bound: true
147
* hidden: true attribute: visualUpdate true
148
* description: The UI object that implements the Component's LookAndFeel.
150
public void setUI(TitledPanelUI ui) {
155
* Returns a string that specifies the name of the L&F class that renders
158
* @return "TitledPanelUI"
159
* @see JComponent#getUIClassID
160
* @see javax.swing.UIDefaults#getUI
161
* @beaninfo expert: true
162
* description: A string that specifies the name of the L&F class.
165
public String getUIClassID() {
170
* Notification from the <code>UIManager</code> that the L&F has changed.
171
* Replaces the current UI object with the latest version from the
172
* <code>UIManager</code>.
174
* @see javax.swing.JComponent#updateUI
177
public void updateUI() {
178
setUI((TitledPanelUI) LookAndFeelAddons
179
.getUI(this, TitledPanelUI.class));
183
* Gets the title for this titled panel.
185
* @return the currently displayed title
187
public String getTitle() {
192
* Sets the title for this title panel.
195
* the title to display
197
public void setTitle(String title) {
198
String oldTitle = this.title;
199
this.title = (title == null ? "" : title);
200
// JW: fix swingx #9 - missing/incorrect notification
201
// let standard notification handle
202
// NOTE - "getting" the new property in the fire method is
203
// intentional: there's no way of missing any transformations
204
// on the parameter to set (like above: setting a
205
// value depending on whether the input is null).
206
firePropertyChange("title", oldTitle, getTitle());
209
public Container getContentContainer() {
210
if (contentPanel == null) {
211
contentPanel = new JXPanel();
212
((JXPanel) contentPanel).setBorder(BorderFactory
213
.createEmptyBorder());
214
this.add(contentPanel, BorderLayout.CENTER);
219
public void setContentContainer(Container contentPanel) {
220
if (this.contentPanel != null) {
221
remove(this.contentPanel);
223
add(contentPanel, BorderLayout.CENTER);
224
this.contentPanel = contentPanel;
228
* Adds the given JComponent as a decoration on the right of the title
232
public void setRightDecoration(JComponent decoration) {
233
JComponent old = getRightDecoration();
234
getUI().setRightDecoration(decoration);
235
firePropertyChange("rightDecoration", old, getRightDecoration());
238
public JComponent getRightDecoration() {
239
return getUI().getRightDecoration();
243
* Adds the given JComponent as a decoration on the left of the title
247
public void setLeftDecoration(JComponent decoration) {
248
JComponent old = getLeftDecoration();
249
getUI().setLeftDecoration(decoration);
250
firePropertyChange("leftDecoration", old, getLeftDecoration());
253
public JComponent getLeftDecoration() {
254
return getUI().getLeftDecoration();
257
public Font getTitleFont() {
261
public void setTitleFont(Font titleFont) {
262
Font old = getTitleFont();
263
this.titleFont = titleFont;
264
firePropertyChange("titleFont", old, getTitleFont());
268
* Set the Painter to use for painting the title section of the JXTitledPanel.
269
* This value may be null, which will cause the current look and feel to paint
270
* an appropriate look
272
* @param p The Painter to use. May be null
274
public void setTitlePainter(Painter p) {
275
Painter old = getTitlePainter();
276
this.titlePainter = p;
277
firePropertyChange("titlePainter", old, getTitlePainter());
281
* @return the Painter to use for painting the background of the title section
283
public Painter getTitlePainter() {
287
public Color getTitleForeground() {
288
return titleForeground;
291
public void setTitleForeground(Color titleForeground) {
292
Color old = getTitleForeground();
293
this.titleForeground = titleForeground;
294
firePropertyChange("titleForeground", old, getTitleForeground());
297
private static Container createDefaultContainer() {
298
//TODO: All this default container creation stuff should be in the UI
299
//delegate. Not enough time at the moment for me to do this right.
300
JXPanel p = new JXPanel();