2
* Copyright (c) 2002-2008 JGoodies Karsten Lentzsch. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of JGoodies Karsten Lentzsch nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
package com.jgoodies.forms.builder;
33
import java.util.MissingResourceException;
34
import java.util.ResourceBundle;
36
import javax.swing.JPanel;
38
import com.jgoodies.forms.layout.FormLayout;
41
* A general purpose panel builder that uses the {@link FormLayout}
42
* to lay out <code>JPanel</code>s. In addition to its superclass
43
* {@link PanelBuilder} this class provides convenience behavior to map
44
* resource keys to their associated internationalized (i15d) strings
45
* when adding labels, titles and titled separators.<p>
47
* The localized texts used in methods <code>#addI15dLabel</code>
48
* and <code>#addI15dTitle</code> can contain an optional mnemonic marker.
49
* The mnemonic and mnemonic index are indicated by a single ampersand
50
* (<tt>&</tt>). For example <tt>"&Save"</tt>, or
51
* <tt>"Save &as"</tt>. To use the ampersand itself,
52
* duplicate it, for example <tt>"Look&&Feel"</tt>.<p>
54
* @author Karsten Lentzsch
55
* @version $Revision: 1.7 $
60
public class I15dPanelBuilder extends AbstractI15dPanelBuilder {
63
* Holds the <code>ResourceBundle</code> used to lookup internationalized
64
* (i15d) String resources.
66
private final ResourceBundle bundle;
69
// Instance Creation ****************************************************
72
* Constructs an <code>I15dPanelBuilder</code> for the given
73
* layout and resource bundle. Uses an instance of <code>JPanel</code>
74
* as layout container.
76
* @param layout the <code>FormLayout</code> used to layout the container
77
* @param bundle the <code>ResourceBundle</code> used to lookup i15d strings
79
public I15dPanelBuilder(FormLayout layout, ResourceBundle bundle){
80
this(layout, bundle, new JPanel(null));
85
* Constructs an <code>I15dPanelBuilder</code>
86
* for the given FormLayout, resource bundle, and layout container.
88
* @param layout the <code>FormLayout</code> used to layout the container
89
* @param bundle the <code>ResourceBundle</code> used to lookup i15d strings
90
* @param panel the layout container
92
public I15dPanelBuilder(FormLayout layout, ResourceBundle bundle, JPanel panel){
98
// Implementing Abstract Behavior *****************************************
101
* Looks up and returns the internationalized (i15d) string for the given
102
* resource key from the <code>ResourceBundle</code>.
104
* @param resourceKey the key to look for in the resource bundle
105
* @return the associated internationalized string, or the resource key
106
* itself in case of a missing resource
107
* @throws IllegalStateException if no <code>ResourceBundle</code>
110
protected String getI15dString(String resourceKey) {
112
throw new IllegalStateException("You must specify a ResourceBundle" +
0
113
" before using the internationalization support.");
115
return bundle.getString(resourceKey);
116
} catch (MissingResourceException mre) {