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.JComponent;
034: import javax.swing.JFrame;
035: import javax.swing.JTextField;
036: import javax.swing.UIManager;
037: import javax.swing.WindowConstants;
038:
039: import com.jgoodies.forms.builder.DefaultFormBuilder;
040: import com.jgoodies.forms.layout.FormLayout;
041:
042: /**
043: * Demonstrates how to efficiently build a panel with a leading
044: * indent column using the DefaultFormBuilder.<p>
045: *
046: * The default FocusTraversalPolicy will lead to a poor focus traversal,
047: * where non-editable fields are included in the focus cycle.
048: * Anyway, this tutorial is about layout, not focus, and so I favor
049: * a lean example over a fully functional.
050: *
051: * @author Karsten Lentzsch
052: * @version $Revision: 1.13 $
053: *
054: * @see DefaultFormBuilder
055: */
056:
057: public final class IndentColumnExample {
058:
059: private JTextField fileNumberField;
060: private JTextField rfqNumberField;
061: private JTextField blNumberField;
062: private JTextField mblNumberField;
063:
064: private JTextField customerKeyField;
065: private JTextField customerAddressField;
066: private JTextField shipperKeyField;
067: private JTextField shipperAddressField;
068: private JTextField consigneeKeyField;
069: private JTextField consigneeAddressField;
070:
071: private JTextField departureCodeField;
072: private JTextField departurePortField;
073: private JTextField destinationCodeField;
074: private JTextField destinationPortField;
075: private JTextField deliveryDateField;
076:
077: public static void main(String[] args) {
078: try {
079: UIManager
080: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
081: } catch (Exception e) {
082: // Likely PlasticXP is not in the class path; ignore.
083: }
084: JFrame frame = new JFrame();
085: frame.setTitle("Forms Tutorial :: Indent Column");
086: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
087: JComponent panel = new FormDebugExample().buildPanel();
088: frame.getContentPane().add(panel);
089: frame.pack();
090: frame.setVisible(true);
091: }
092:
093: // Component Creation and Initialization **********************************
094:
095: /**
096: * Creates and intializes the UI components.
097: */
098: private void initComponents() {
099: fileNumberField = new JTextField();
100: rfqNumberField = new JTextField();
101: blNumberField = new JTextField();
102: mblNumberField = new JTextField();
103: customerKeyField = new JTextField();
104: customerAddressField = new JTextField();
105: customerAddressField.setEditable(false);
106: shipperKeyField = new JTextField();
107: shipperAddressField = new JTextField();
108: shipperAddressField.setEditable(false);
109: consigneeKeyField = new JTextField();
110: consigneeAddressField = new JTextField();
111: consigneeAddressField.setEditable(false);
112: departureCodeField = new JTextField();
113: departurePortField = new JTextField();
114: departurePortField.setEditable(false);
115: destinationCodeField = new JTextField();
116: destinationPortField = new JTextField();
117: destinationPortField.setEditable(false);
118: deliveryDateField = new JTextField();
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: "12dlu, pref, 3dlu, max(45dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
133: "");
134: layout.setColumnGroups(new int[][] { { 4, 6, 8, 10 } });
135:
136: DefaultFormBuilder builder = new DefaultFormBuilder(layout);
137: builder.setDefaultDialogBorder();
138: builder.setLeadingColumnOffset(1);
139:
140: builder.appendSeparator("General");
141: builder.append("File Number", fileNumberField, 7);
142: builder.append("RFQ Number", rfqNumberField, 7);
143: builder.append("BL/MBL", blNumberField, mblNumberField);
144: builder.nextLine();
145:
146: builder.appendSeparator("Addresses");
147: builder.append("Customer", customerKeyField,
148: customerAddressField, 5);
149: builder.append("Shipper", shipperKeyField, shipperAddressField,
150: 5);
151: builder.append("Consignee", consigneeKeyField,
152: consigneeAddressField, 5);
153:
154: builder.appendSeparator("Transport");
155: builder.append("Departure", departureCodeField,
156: departurePortField, 5);
157: builder.append("Destination", destinationCodeField,
158: destinationPortField, 5);
159: builder.append("Delivery Date", deliveryDateField);
160: builder.nextLine();
161:
162: return builder.getPanel();
163: }
164:
165: }
|