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

« back to all changes in this revision

Viewing changes to src/tutorial/com/jgoodies/forms/tutorial/factories/ButtonBarFactoryExample.java

  • Committer: Bazaar Package Importer
  • Author(s): Eric Lavarde
  • Date: 2006-03-23 20:54:19 UTC
  • Revision ID: james.westby@ubuntu.com-20060323205419-emo7oazp2lspvl3b
Tags: upstream-1.0.5
ImportĀ upstreamĀ versionĀ 1.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2002-2004 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.tutorial.factories;
 
32
 
 
33
import java.awt.Component;
 
34
 
 
35
import javax.swing.*;
 
36
 
 
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;
 
41
 
 
42
/**
 
43
 * Demonstrates the use of Factories as provided by the Forms framework.
 
44
 *
 
45
 * @author      Karsten Lentzsch
 
46
 * @version $Revision: 1.7 $
 
47
 * 
 
48
 * @see ButtonBarFactory
 
49
 */
 
50
public final class ButtonBarFactoryExample {
 
51
    
 
52
    public static void main(String[] args) {
 
53
        try {
 
54
            UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
 
55
        } catch (Exception e) {
 
56
            // Likely PlasticXP is not in the class path; ignore.
 
57
        }
 
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);
 
63
        frame.pack();
 
64
        frame.setVisible(true);
 
65
    }
 
66
 
 
67
 
 
68
    public JComponent buildPanel() {
 
69
        JTabbedPane tabbedPane = new JTabbedPane();
 
70
        tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE);
 
71
 
 
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");
 
77
        return tabbedPane;
 
78
    }
 
79
    
 
80
    private Component buildButtonBar1Panel() {
 
81
        FormLayout layout = new FormLayout(
 
82
                        "default:grow",
 
83
                        "0:grow, p, 4dlu, p, 4dlu, p, 4dlu, p");
 
84
                        
 
85
        PanelBuilder builder = new PanelBuilder(layout);
 
86
        builder.setDefaultDialogBorder();
 
87
        
 
88
        builder.nextRow();
 
89
        builder.add(ButtonBarFactory.buildCloseBar(
 
90
            new JButton("Close")
 
91
        ));                      
 
92
        builder.nextRow(2);
 
93
        builder.add(ButtonBarFactory.buildOKBar(
 
94
            new JButton("OK")
 
95
        ));                         
 
96
        builder.nextRow(2);
 
97
        builder.add(ButtonBarFactory.buildOKCancelBar(
 
98
            new JButton("OK"), new JButton("Cancel")
 
99
        ));                   
 
100
        builder.nextRow(2);
 
101
        builder.add(ButtonBarFactory.buildOKCancelApplyBar(
 
102
            new JButton("OK"), new JButton("Cancel"), new JButton("Apply")
 
103
        ));   
 
104
                   
 
105
        return builder.getContainer();
 
106
    }
 
107
    
 
108
 
 
109
    private Component buildButtonBar2Panel() {
 
110
        FormLayout layout = new FormLayout(
 
111
                        "default:grow",
 
112
                        "0:grow, p, 4dlu, p, 4dlu, p, 4dlu, p");
 
113
                        
 
114
        PanelBuilder builder = new PanelBuilder(layout);
 
115
        builder.setDefaultDialogBorder();
 
116
        
 
117
        builder.nextRow();
 
118
        builder.add(ButtonBarFactory.buildCloseHelpBar(
 
119
            new JButton("Close"), new JButton("Help")
 
120
        ));                      
 
121
        builder.nextRow(2);
 
122
        builder.add(ButtonBarFactory.buildOKHelpBar(
 
123
            new JButton("OK"), new JButton("Help")
 
124
        ));                         
 
125
        builder.nextRow(2);
 
126
        builder.add(ButtonBarFactory.buildOKCancelHelpBar(
 
127
            new JButton("OK"), new JButton("Cancel"), new JButton("Help")
 
128
        ));                   
 
129
        builder.nextRow(2);
 
130
        builder.add(ButtonBarFactory.buildOKCancelApplyHelpBar(
 
131
            new JButton("OK"), new JButton("Cancel"), new JButton("Apply"), new JButton("Help")
 
132
        ));   
 
133
                   
 
134
        return builder.getContainer();
 
135
    }
 
136
    
 
137
 
 
138
    private Component buildButtonBar3Panel() {
 
139
        FormLayout layout = new FormLayout(
 
140
                        "default:grow",
 
141
                        "0:grow, p, 4dlu, p, 4dlu, p, 4dlu, p");
 
142
                        
 
143
        PanelBuilder builder = new PanelBuilder(layout);
 
144
        builder.setDefaultDialogBorder();
 
145
        
 
146
        builder.nextRow();
 
147
        builder.add(ButtonBarFactory.buildHelpCloseBar(
 
148
            new JButton("Help"), new JButton("Close")
 
149
        ));                      
 
150
        builder.nextRow(2);
 
151
        builder.add(ButtonBarFactory.buildHelpOKBar(
 
152
            new JButton("Help"), new JButton("OK")
 
153
        ));                         
 
154
        builder.nextRow(2);
 
155
        builder.add(ButtonBarFactory.buildHelpOKCancelBar(
 
156
            new JButton("Help"), new JButton("OK"), new JButton("Cancel")
 
157
        ));                   
 
158
        builder.nextRow(2);
 
159
        builder.add(ButtonBarFactory.buildHelpOKCancelApplyBar(
 
160
            new JButton("Help"), new JButton("OK"), new JButton("Cancel"), new JButton("Apply")
 
161
        ));     
 
162
             
 
163
        return builder.getContainer();
 
164
    }
 
165
    
 
166
 
 
167
    private Component buildAddRemovePropertiesPanel() {
 
168
        FormLayout layout = new FormLayout(
 
169
                        "fill:default:grow",
 
170
                        "fill:p:grow, 4dlu, p, 14dlu, " +
 
171
                        "fill:p:grow, 4dlu, p");
 
172
                        
 
173
        PanelBuilder builder = new PanelBuilder(layout);
 
174
        builder.setDefaultDialogBorder();
 
175
 
 
176
        builder.add(new JScrollPane(new JTextArea()));
 
177
        builder.nextRow(2);
 
178
        builder.add(ButtonBarFactory.buildAddRemovePropertiesLeftBar(
 
179
            new JButton("Add..."), new JButton("Remove"), new JButton("Properties...")
 
180
        ));
 
181
        builder.nextRow(2);
 
182
 
 
183
        builder.add(new JScrollPane(new JTextArea()));
 
184
        builder.nextRow(2);
 
185
        builder.add(ButtonBarFactory.buildAddRemovePropertiesRightBar(
 
186
            new JButton("Add..."), new JButton("Remove"), new JButton("Properties...")
 
187
        ));  
 
188
        return builder.getContainer();
 
189
    }
 
190
    
 
191
    private Component buildAddRemovePanel() {
 
192
        FormLayout layout = new FormLayout(
 
193
                        "fill:default:grow, 9dlu, fill:default:grow",
 
194
                        "fill:p:grow, 4dlu, p");
 
195
                        
 
196
        PanelBuilder builder = new PanelBuilder(layout);
 
197
        builder.setDefaultDialogBorder();
 
198
        CellConstraints cc = new CellConstraints();
 
199
 
 
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));
 
203
                
 
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();
 
208
    }
 
209
    
 
210
    
 
211
}
 
212