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.DefaultFormBuilder;
036: import com.jgoodies.forms.layout.FormLayout;
037:
038: /**
039: * Uses the FormLayout and the <code>DefaultFormBuilder</code>.
040: * Columns are specified before the panel is filled with components,
041: * rows are added dynamically. The builder is used to hold a cursor,
042: * to add rows dynamically, and to fill components.
043: * The builder's convenience methods are used to add labels and separators.<p>
044: *
045: * This panel building style is recommended unless you have a more
046: * powerful builder or don't want to add rows dynamically.
047: * See the {@link DynamicRowsExample} for an implementation that specifies
048: * rows before the panel is filled with components.
049: *
050: * @author Karsten Lentzsch
051: * @version $Revision: 1.14 $
052: *
053: * @see DefaultFormBuilder
054: * @see PlainExample
055: * @see RowCounterExample
056: * @see DynamicRowsExample
057: */
058:
059: public final class DefaultFormBuilderExample {
060:
061: private JTextField identifierField;
062: private JTextField ptiField;
063: private JTextField powerField;
064: private JTextField sField;
065: private JTextField daField;
066: private JTextField diField;
067: private JTextField da2Field;
068: private JTextField di2Field;
069: private JTextField rField;
070: private JTextField dField;
071: private JComboBox locationCombo;
072: private JTextField kFactorField;
073:
074: public static void main(String[] args) {
075: try {
076: UIManager
077: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
078: } catch (Exception e) {
079: // Likely PlasticXP is not in the class path; ignore.
080: }
081: JFrame frame = new JFrame();
082: frame.setTitle("Forms Tutorial :: Default Form");
083: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
084: JComponent panel = new DefaultFormBuilderExample().buildPanel();
085: frame.getContentPane().add(panel);
086: frame.pack();
087: frame.setVisible(true);
088: }
089:
090: // Component Creation and Initialization **********************************
091:
092: /**
093: * Creates and intializes the UI components.
094: */
095: private void initComponents() {
096: identifierField = new JTextField();
097: ptiField = new JTextField();
098: powerField = new JTextField();
099: sField = new JTextField();
100: daField = new JTextField();
101: diField = new JTextField();
102: da2Field = new JTextField();
103: di2Field = new JTextField();
104: rField = new JTextField();
105: dField = new JTextField();
106: locationCombo = createLocationComboBox();
107: kFactorField = new JTextField();
108: }
109:
110: /**
111: * Creates and returns a combo box for the locations.
112: *
113: * @return a combo box for three locations
114: */
115: private JComboBox createLocationComboBox() {
116: return new JComboBox(new String[] { "Propeller nut thread",
117: "Stern tube front area", "Shaft taper" });
118: }
119:
120: // Building ***************************************************************
121:
122: /**
123: * Builds the flange editor panel.
124: * Columns are specified before components are added to the form,
125: * rows are added dynamically using the {@link DefaultFormBuilder}.<p>
126: *
127: * The builder combines a step that is done again and again:
128: * add a label, proceed to the next data column and add a component.
129: *
130: * @return the built panel
131: */
132: public JComponent buildPanel() {
133: initComponents();
134:
135: // Column specs only, rows will be added dynamically.
136: FormLayout layout = new FormLayout(
137: "right:max(40dlu;pref), 3dlu, 70dlu, 7dlu, "
138: + "right:max(40dlu;pref), 3dlu, 70dlu");
139: DefaultFormBuilder builder = new DefaultFormBuilder(layout);
140: builder.setDefaultDialogBorder();
141:
142: builder.appendSeparator("Flange");
143:
144: builder.append("&Identifier", identifierField);
145: builder.nextLine();
146:
147: builder.append("PTI/kW", ptiField);
148: builder.append("Power/kW", powerField);
149:
150: builder.append("s/mm", sField);
151: builder.nextLine();
152:
153: builder.appendSeparator("Diameters");
154:
155: builder.append("&da/mm", daField);
156: builder.append("di/mm", diField);
157:
158: builder.append("da2/mm", da2Field);
159: builder.append("di2/mm", di2Field);
160:
161: builder.append("R/mm", rField);
162: builder.append("D/mm", dField);
163:
164: builder.appendSeparator("Criteria");
165:
166: builder.append("&Location", locationCombo);
167: builder.append("k-factor", kFactorField);
168:
169: return builder.getPanel();
170: }
171:
172: }
|