KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > forms > tutorial > basics > BoundedSizesExample


1 /*
2  * Copyright (c) 2003 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.basics;
32
33 import javax.swing.*;
34
35 import com.jgoodies.forms.builder.PanelBuilder;
36 import com.jgoodies.forms.layout.CellConstraints;
37 import com.jgoodies.forms.layout.FormLayout;
38
39 /**
40  * Demonstrates the basic FormLayout sizes: constant, minimum, preferred.
41  *
42  * @author Karsten Lentzsch
43  * @version $Revision: 1.6 $
44  */

45 public final class BoundedSizesExample {
46
47     
48     public static void main(String JavaDoc[] args) {
49         try {
50             UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
51         } catch (Exception JavaDoc e) {
52             // Likely PlasticXP is not in the class path; ignore.
53
}
54         JFrame frame = new JFrame();
55         frame.setTitle("Forms Tutorial :: Bounded Sizes");
56         frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
57         JComponent panel = new BoundedSizesExample().buildPanel();
58         frame.getContentPane().add(panel);
59         frame.pack();
60         frame.show();
61     }
62
63
64     public JComponent buildPanel() {
65         JTabbedPane tabbedPane = new JTabbedPane();
66         tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE);
67
68         tabbedPane.add("Jumping 1", buildJumping1Panel());
69         tabbedPane.add("Jumping 2", buildJumping2Panel());
70         tabbedPane.add("Stable 1", buildStable1Panel());
71         tabbedPane.add("Stable 2", buildStable2Panel());
72         return tabbedPane;
73     }
74     
75         
76     private JComponent buildJumping1Panel() {
77         FormLayout layout = new FormLayout(
78                 "right:pref, 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
79                 EDITOR_ROW_SPEC);
80         return buildEditorGeneralPanel(layout);
81     }
82     
83     private JComponent buildJumping2Panel() {
84         FormLayout layout = new FormLayout(
85                 "right:pref, 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
86                 EDITOR_ROW_SPEC);
87         return buildEditorTransportPanel(layout);
88     }
89     
90     private JComponent buildStable1Panel() {
91         FormLayout layout = new FormLayout(
92                 "right:max(50dlu;pref), 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
93                 EDITOR_ROW_SPEC);
94         return buildEditorGeneralPanel(layout);
95     }
96     
97     private JComponent buildStable2Panel() {
98         FormLayout layout = new FormLayout(
99                 "right:max(50dlu;pref), 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
100                 EDITOR_ROW_SPEC);
101         return buildEditorTransportPanel(layout);
102     }
103     
104     private static final String JavaDoc EDITOR_ROW_SPEC =
105         "p, 3dlu, p, 3dlu, p, 3dlu, p";
106
107
108     /**
109      * Builds and answer the editor's general tab for the given layout.
110      */

111     private JComponent buildEditorGeneralPanel(FormLayout layout) {
112         layout.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
113         PanelBuilder builder = new PanelBuilder(layout);
114             
115         builder.setDefaultDialogBorder();
116         CellConstraints cc = new CellConstraints();
117
118         builder.addLabel("File number:", cc.xy (1, 1));
119         builder.add(new JTextField(), cc.xywh(3, 1, 7, 1));
120         builder.addLabel("RFQ number:", cc.xy (1, 3));
121         builder.add(new JTextField(), cc.xywh(3, 3, 7, 1));
122         builder.addLabel("Entry date:", cc.xy (1, 5));
123         builder.add(new JTextField(), cc.xy (3, 5));
124         builder.addLabel("Sales Person:", cc.xy (1, 7));
125         builder.add(new JTextField(), cc.xywh(3, 7, 7, 1));
126         
127         return builder.getPanel();
128     }
129     
130     /**
131      * Builds and answer the editor's transport tab for the given layout.
132      */

133     private JComponent buildEditorTransportPanel(FormLayout layout) {
134         layout.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
135         PanelBuilder builder = new PanelBuilder(layout);
136             
137         builder.setDefaultDialogBorder();
138         CellConstraints cc = new CellConstraints();
139
140         builder.addLabel("Shipper:", cc.xy (1, 1));
141         builder.add(new JTextField(), cc.xy (3, 1));
142         builder.add(new JTextField(), cc.xywh(5, 1, 5, 1));
143         builder.addLabel("Consignee:", cc.xy (1, 3));
144         builder.add(new JTextField(), cc.xy (3, 3));
145         builder.add(new JTextField(), cc.xywh(5, 3, 5, 1));
146         builder.addLabel("Departure:", cc.xy (1, 5));
147         builder.add(new JTextField(), cc.xy (3, 5));
148         builder.add(new JTextField(), cc.xywh(5, 5, 5, 1));
149         builder.addLabel("Destination:", cc.xy (1, 7));
150         builder.add(new JTextField(), cc.xy (3, 7));
151         builder.add(new JTextField(), cc.xywh(5, 7, 5, 1));
152         
153         return builder.getPanel();
154     }
155     
156     
157     
158     
159 }
160
161
Popular Tags