001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.forms.tutorial.building;
032:
033: import javax.swing.*;
034:
035: import com.jgoodies.forms.builder.PanelBuilder;
036: import com.jgoodies.forms.layout.FormLayout;
037:
038: /**
039: * Combines the FormLayout with the PanelBuilder.
040: * Columns and rows are specified before the panel is filled
041: * with components. The builder's cursor is used to determine the location
042: * of the next component. And the builder's convenience methods are used
043: * to add labels and separators.<p>
044: *
045: * This panel building style is intended for learning purposes only.
046: * The recommended style is demonstrated in the {@link DefaultFormBuilderExample}.
047: *
048: * @author Karsten Lentzsch
049: * @version $Revision: 1.13 $
050: *
051: * @see PlainExample
052: * @see RowCounterExample
053: * @see DefaultFormBuilderExample
054: */
055:
056: public final class DynamicRowsExample {
057:
058: private JTextField identifierField;
059: private JTextField ptiField;
060: private JTextField powerField;
061: private JTextField lenField;
062: private JTextField daField;
063: private JTextField diField;
064: private JTextField da2Field;
065: private JTextField di2Field;
066: private JTextField rField;
067: private JTextField dField;
068: private JComboBox locationCombo;
069: private JTextField kFactorField;
070: private JCheckBox holesCheckBox;
071: private JCheckBox slotsCheckBox;
072:
073: public static void main(String[] args) {
074: try {
075: UIManager
076: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
077: } catch (Exception e) {
078: // Likely PlasticXP is not in the class path; ignore.
079: }
080: JFrame frame = new JFrame();
081: frame.setTitle("Forms Tutorial :: Dynamic Rows");
082: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
083: JComponent panel = new DynamicRowsExample().buildPanel();
084: frame.getContentPane().add(panel);
085: frame.pack();
086: frame.setVisible(true);
087: }
088:
089: // Component Creation and Initialization **********************************
090:
091: /**
092: * Creates and intializes the UI components.
093: */
094: private void initComponents() {
095: identifierField = new JTextField();
096: ptiField = new JTextField();
097: powerField = new JTextField();
098: lenField = new JTextField();
099: daField = new JTextField();
100: diField = new JTextField();
101: da2Field = new JTextField();
102: di2Field = new JTextField();
103: rField = new JTextField();
104: dField = new JTextField();
105: locationCombo = createLocationComboBox();
106: kFactorField = new JTextField();
107: holesCheckBox = new JCheckBox("Has radial holes", true);
108: slotsCheckBox = new JCheckBox("Has longitudinal slots");
109: }
110:
111: /**
112: * Creates and returns a combo box for the locations.
113: *
114: * @return a combo box for three locations
115: */
116: private JComboBox createLocationComboBox() {
117: return new JComboBox(new String[] { "Propeller nut thread",
118: "Stern tube front area", "Shaft taper" });
119: }
120:
121: // Building *************************************************************
122:
123: /**
124: * Builds the pane.
125: *
126: * @return the built panel
127: */
128: public JComponent buildPanel() {
129: initComponents();
130:
131: FormLayout layout = new FormLayout(
132: "right:max(40dlu;pref), 3dlu, 70dlu, 7dlu, "
133: + "right:max(40dlu;pref), 3dlu, 70dlu",
134: "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, "
135: + "p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, "
136: + "p, 3dlu, p, 3dlu, p, 3dlu, p");
137:
138: PanelBuilder builder = new PanelBuilder(layout);
139: builder.setDefaultDialogBorder();
140:
141: builder.addSeparator("Segment");
142: builder.nextLine(2);
143:
144: builder.addLabel("Identifier");
145: builder.nextColumn(2);
146: builder.add(identifierField);
147: builder.nextLine(2);
148:
149: builder.addLabel("PTI/kW");
150: builder.nextColumn(2);
151: builder.add(ptiField);
152: builder.nextColumn(2);
153: builder.addLabel("Power/kW");
154: builder.nextColumn(2);
155: builder.add(powerField);
156: builder.nextLine(2);
157:
158: builder.addLabel("len/mm");
159: builder.nextColumn(2);
160: builder.add(lenField);
161: builder.nextLine(2);
162:
163: builder.addSeparator("Diameters");
164: builder.nextLine(2);
165:
166: builder.addLabel("da/mm");
167: builder.nextColumn(2);
168: builder.add(daField);
169: builder.nextColumn(2);
170: builder.addLabel("di/mm");
171: builder.nextColumn(2);
172: builder.add(diField);
173: builder.nextLine(2);
174:
175: builder.addLabel("da2/mm");
176: builder.nextColumn(2);
177: builder.add(da2Field);
178: builder.nextColumn(2);
179: builder.addLabel("di2/mm");
180: builder.nextColumn(2);
181: builder.add(di2Field);
182:
183: builder.nextLine(2);
184: builder.addLabel("R/mm");
185: builder.nextColumn(2);
186: builder.add(rField);
187: builder.nextColumn(2);
188: builder.addLabel("D/mm");
189: builder.nextColumn(2);
190: builder.add(dField);
191: builder.nextLine(2);
192:
193: builder.addSeparator("Criteria");
194: builder.nextLine(2);
195:
196: builder.addLabel("Location");
197: builder.nextColumn(2);
198: builder.add(locationCombo);
199: builder.nextColumn(2);
200: builder.addLabel("k-factor");
201: builder.nextColumn(2);
202: builder.add(kFactorField);
203: builder.nextLine(2);
204:
205: builder.addLabel("Holes");
206: builder.nextColumn(2);
207: builder.setColumnSpan(5);
208: builder.add(holesCheckBox);
209: builder.setColumnSpan(1);
210: builder.nextLine(2);
211:
212: builder.addLabel("Slots");
213: builder.nextColumn(2);
214: builder.setColumnSpan(5);
215: builder.add(slotsCheckBox);
216: builder.setColumnSpan(1);
217:
218: return builder.getPanel();
219: }
220:
221: }
|