2
* Copyright (c) 2002-2004 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.tutorial.factories;
33
import java.awt.Component;
37
import com.jgoodies.forms.builder.PanelBuilder;
38
import com.jgoodies.forms.factories.ButtonBarFactory;
39
import com.jgoodies.forms.layout.CellConstraints;
40
import com.jgoodies.forms.layout.FormLayout;
43
* Demonstrates the use of Factories as provided by the Forms framework.
45
* @author Karsten Lentzsch
46
* @version $Revision: 1.7 $
48
* @see ButtonBarFactory
50
public final class ButtonBarFactoryExample {
52
public static void main(String[] args) {
54
UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
55
} catch (Exception e) {
56
// Likely PlasticXP is not in the class path; ignore.
58
JFrame frame = new JFrame();
59
frame.setTitle("Forms Tutorial :: ButtonBarFactory");
60
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
61
JComponent panel = new ButtonBarFactoryExample().buildPanel();
62
frame.getContentPane().add(panel);
64
frame.setVisible(true);
68
public JComponent buildPanel() {
69
JTabbedPane tabbedPane = new JTabbedPane();
70
tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE);
72
tabbedPane.add(buildButtonBar1Panel(), "Dialog 1");
73
tabbedPane.add(buildButtonBar2Panel(), "Dialog 2");
74
tabbedPane.add(buildButtonBar3Panel(), "Dialog 3");
75
tabbedPane.add(buildAddRemovePropertiesPanel(), "List 1");
76
tabbedPane.add(buildAddRemovePanel(), "List 2");
80
private Component buildButtonBar1Panel() {
81
FormLayout layout = new FormLayout(
83
"0:grow, p, 4dlu, p, 4dlu, p, 4dlu, p");
85
PanelBuilder builder = new PanelBuilder(layout);
86
builder.setDefaultDialogBorder();
89
builder.add(ButtonBarFactory.buildCloseBar(
93
builder.add(ButtonBarFactory.buildOKBar(
97
builder.add(ButtonBarFactory.buildOKCancelBar(
98
new JButton("OK"), new JButton("Cancel")
101
builder.add(ButtonBarFactory.buildOKCancelApplyBar(
102
new JButton("OK"), new JButton("Cancel"), new JButton("Apply")
105
return builder.getContainer();
109
private Component buildButtonBar2Panel() {
110
FormLayout layout = new FormLayout(
112
"0:grow, p, 4dlu, p, 4dlu, p, 4dlu, p");
114
PanelBuilder builder = new PanelBuilder(layout);
115
builder.setDefaultDialogBorder();
118
builder.add(ButtonBarFactory.buildCloseHelpBar(
119
new JButton("Close"), new JButton("Help")
122
builder.add(ButtonBarFactory.buildOKHelpBar(
123
new JButton("OK"), new JButton("Help")
126
builder.add(ButtonBarFactory.buildOKCancelHelpBar(
127
new JButton("OK"), new JButton("Cancel"), new JButton("Help")
130
builder.add(ButtonBarFactory.buildOKCancelApplyHelpBar(
131
new JButton("OK"), new JButton("Cancel"), new JButton("Apply"), new JButton("Help")
134
return builder.getContainer();
138
private Component buildButtonBar3Panel() {
139
FormLayout layout = new FormLayout(
141
"0:grow, p, 4dlu, p, 4dlu, p, 4dlu, p");
143
PanelBuilder builder = new PanelBuilder(layout);
144
builder.setDefaultDialogBorder();
147
builder.add(ButtonBarFactory.buildHelpCloseBar(
148
new JButton("Help"), new JButton("Close")
151
builder.add(ButtonBarFactory.buildHelpOKBar(
152
new JButton("Help"), new JButton("OK")
155
builder.add(ButtonBarFactory.buildHelpOKCancelBar(
156
new JButton("Help"), new JButton("OK"), new JButton("Cancel")
159
builder.add(ButtonBarFactory.buildHelpOKCancelApplyBar(
160
new JButton("Help"), new JButton("OK"), new JButton("Cancel"), new JButton("Apply")
163
return builder.getContainer();
167
private Component buildAddRemovePropertiesPanel() {
168
FormLayout layout = new FormLayout(
170
"fill:p:grow, 4dlu, p, 14dlu, " +
171
"fill:p:grow, 4dlu, p");
173
PanelBuilder builder = new PanelBuilder(layout);
174
builder.setDefaultDialogBorder();
176
builder.add(new JScrollPane(new JTextArea()));
178
builder.add(ButtonBarFactory.buildAddRemovePropertiesLeftBar(
179
new JButton("Add..."), new JButton("Remove"), new JButton("Properties...")
183
builder.add(new JScrollPane(new JTextArea()));
185
builder.add(ButtonBarFactory.buildAddRemovePropertiesRightBar(
186
new JButton("Add..."), new JButton("Remove"), new JButton("Properties...")
188
return builder.getContainer();
191
private Component buildAddRemovePanel() {
192
FormLayout layout = new FormLayout(
193
"fill:default:grow, 9dlu, fill:default:grow",
194
"fill:p:grow, 4dlu, p");
196
PanelBuilder builder = new PanelBuilder(layout);
197
builder.setDefaultDialogBorder();
198
CellConstraints cc = new CellConstraints();
200
builder.add(new JScrollPane(new JTextArea()), cc.xy(1, 1));
201
builder.add(ButtonBarFactory.buildAddRemoveLeftBar(
202
new JButton("Add..."), new JButton("Remove")), cc.xy(1, 3));
204
builder.add(new JScrollPane(new JTextArea()), cc.xy(3, 1));
205
builder.add(ButtonBarFactory.buildAddRemoveRightBar(
206
new JButton("Add..."), new JButton("Remove")), cc.xy(3, 3));
207
return builder.getContainer();