~ubuntu-branches/ubuntu/trusty/libjgoodies-forms-java/trusty

« back to all changes in this revision

Viewing changes to src/core/com/jgoodies/forms/builder/I15dPanelBuilder.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-02-25 10:57:07 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080225105707-pe51fdbcq1dt3vi6
Tags: 1.2.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2002-2008 JGoodies Karsten Lentzsch. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
7
 *  o Redistributions of source code must retain the above copyright notice,
 
8
 *    this list of conditions and the following disclaimer.
 
9
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
package com.jgoodies.forms.builder;
 
32
 
 
33
import java.util.MissingResourceException;
 
34
import java.util.ResourceBundle;
 
35
 
 
36
import javax.swing.JPanel;
 
37
 
 
38
import com.jgoodies.forms.layout.FormLayout;
 
39
 
 
40
/**
 
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>
 
46
 *
 
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>&amp;</tt>). For example <tt>&quot;&amp;Save&quot</tt>, or
 
51
 * <tt>&quot;Save&nbsp;&amp;as&quot</tt>. To use the ampersand itself,
 
52
 * duplicate it, for example <tt>&quot;Look&amp;&amp;Feel&quot</tt>.<p>
 
53
 *
 
54
 * @author      Karsten Lentzsch
 
55
 * @version $Revision: 1.7 $
 
56
 * @since 1.0.3
 
57
 *
 
58
 * @see ResourceBundle
 
59
 */
 
60
public class I15dPanelBuilder extends AbstractI15dPanelBuilder {
 
61
 
 
62
    /**
 
63
     * Holds the <code>ResourceBundle</code> used to lookup internationalized
 
64
     * (i15d) String resources.
 
65
     */
 
66
    private final ResourceBundle bundle;
 
67
 
 
68
 
 
69
    // Instance Creation ****************************************************
 
70
 
 
71
    /**
 
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.
 
75
     *
 
76
     * @param layout    the <code>FormLayout</code> used to layout the container
 
77
     * @param bundle    the <code>ResourceBundle</code> used to lookup i15d strings
 
78
     */
 
79
    public I15dPanelBuilder(FormLayout layout, ResourceBundle bundle){
 
80
        this(layout, bundle, new JPanel(null));
 
81
    }
 
82
 
 
83
 
 
84
    /**
 
85
     * Constructs an <code>I15dPanelBuilder</code>
 
86
     * for the given FormLayout, resource bundle, and layout container.
 
87
     *
 
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
 
91
     */
 
92
    public I15dPanelBuilder(FormLayout layout, ResourceBundle bundle, JPanel panel){
 
93
        super(layout, panel);
 
94
        this.bundle = bundle;
 
95
    }
 
96
 
 
97
 
 
98
    // Implementing Abstract Behavior *****************************************
 
99
 
 
100
    /**
 
101
     * Looks up and returns the internationalized (i15d) string for the given
 
102
     * resource key from the <code>ResourceBundle</code>.
 
103
     *
 
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>
 
108
     *     has been set
 
109
     */
 
110
    protected String getI15dString(String resourceKey) {
 
111
        if (bundle == null)
 
112
            throw new IllegalStateException("You must specify a ResourceBundle" +
0
113
               " before using the internationalization support.");
 
114
        try {
 
115
            return bundle.getString(resourceKey);
 
116
        } catch (MissingResourceException mre) {
 
117
            return resourceKey;
 
118
        }
 
119
    }
 
120
 
 
121
 
 
122
 
 
123
}