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.debug.FormDebugPanel;
037: import com.jgoodies.forms.debug.FormDebugUtils;
038: import com.jgoodies.forms.layout.FormLayout;
039:
040: /**
041: * Demonstrates how to find bugs in the layout using
042: * the {@link FormDebugPanel} and the {@link FormDebugUtils}.<p>
043: *
044: * The example also demonstrates efficient panel building with
045: * the DefaultFormBuilder. The builder has been configured
046: * to use a leading indent column.
047: *
048: * @author Karsten Lentzsch
049: * @version $Revision: 1.16 $
050: */
051:
052: public final class FormDebugExample {
053:
054: private JTextField fileNumberField;
055: private JTextField rfqNumberField;
056: private JTextField blNumberField;
057: private JTextField mblNumberField;
058:
059: private JTextField customerKeyField;
060: private JTextField customerAddressField;
061: private JTextField shipperKeyField;
062: private JTextField shipperAddressField;
063: private JTextField consigneeKeyField;
064: private JTextField consigneeAddressField;
065:
066: private JTextField departureCodeField;
067: private JTextField departurePortField;
068: private JTextField destinationCodeField;
069: private JTextField destinationPortField;
070: private JTextField deliveryDateField;
071:
072: public static void main(String[] args) {
073: try {
074: UIManager
075: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
076: } catch (Exception e) {
077: // Likely PlasticXP is not in the class path; ignore.
078: }
079: JFrame frame = new JFrame();
080: frame.setTitle("Forms Tutorial :: Debug a Form");
081: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
082: JComponent panel = new FormDebugExample().buildPanel();
083: frame.getContentPane().add(panel);
084: frame.pack();
085: frame.setVisible(true);
086: }
087:
088: // Component Creation and Initialization **********************************
089:
090: /**
091: * Creates and intializes the UI components.
092: */
093: private void initComponents() {
094: fileNumberField = new JTextField();
095: rfqNumberField = new JTextField();
096: blNumberField = new JTextField();
097: mblNumberField = new JTextField();
098: customerKeyField = new JTextField();
099: customerAddressField = new JTextField();
100: customerAddressField.setEditable(false);
101: shipperKeyField = new JTextField();
102: shipperAddressField = new JTextField();
103: shipperAddressField.setEditable(false);
104: consigneeKeyField = new JTextField();
105: consigneeAddressField = new JTextField();
106: consigneeAddressField.setEditable(false);
107: departureCodeField = new JTextField();
108: departurePortField = new JTextField();
109: departurePortField.setEditable(false);
110: destinationCodeField = new JTextField();
111: destinationPortField = new JTextField();
112: destinationPortField.setEditable(false);
113: deliveryDateField = new JTextField();
114: }
115:
116: // Building *************************************************************
117:
118: /**
119: * Builds the panel.
120: *
121: * @return the built panel
122: */
123: public JComponent buildPanel() {
124: initComponents();
125:
126: FormLayout layout = new FormLayout(
127: "12dlu, pref, 3dlu, max(45dlu;min), 2dlu, min, 2dlu, min, 2dlu, min");
128: layout.setColumnGroups(new int[][] { { 4, 6, 8, 10 } });
129:
130: DefaultFormBuilder builder = new DefaultFormBuilder(layout,
131: new FormDebugPanel());
132:
133: builder.setDefaultDialogBorder();
134: builder.setLeadingColumnOffset(1);
135:
136: builder.appendSeparator("General");
137: builder.append("File Number", fileNumberField, 7);
138: builder.append("RFQ Number", rfqNumberField, 7);
139: builder.append("BL/MBL", blNumberField, mblNumberField);
140: builder.nextLine();
141:
142: builder.appendSeparator("Addresses");
143: builder.append("Customer", customerKeyField,
144: customerAddressField, 5);
145: builder.append("Shipper", shipperKeyField, shipperAddressField,
146: 5);
147: builder.append("Consignee", consigneeKeyField,
148: consigneeAddressField, 5);
149:
150: builder.appendSeparator("Transport");
151: builder.append("Departure", departureCodeField,
152: departurePortField, 5);
153: builder.append("Destination", destinationCodeField,
154: destinationPortField, 5);
155: builder.append("Delivery Date", deliveryDateField);
156: builder.nextLine();
157:
158: FormDebugUtils.dumpAll(builder.getPanel());
159:
160: return builder.getPanel();
161: }
162:
163: }
|