KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > forms > tutorial > building > FormDebugExample


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.building;
32
33 import javax.swing.*;
34
35 import com.jgoodies.forms.debug.FormDebugPanel;
36 import com.jgoodies.forms.debug.FormDebugUtils;
37 import com.jgoodies.forms.extras.DefaultFormBuilder;
38 import com.jgoodies.forms.layout.FormLayout;
39
40 /**
41  * Demonstrates how to find bugs in the layout using
42  * the {@link FormDebugPanel} and the {@link FormDebugUtils}.
43  * <p>
44  * The example also demonstrates efficient panel building with
45  * the DefaultFormBuilder. The builder has been configured
46  * to use a leading indent column.
47  *
48  * @author Karsten Lentzsch
49  * @version $Revision: 1.7 $
50  */

51
52 public final class FormDebugExample {
53     
54     private JTextField fileNumberField;
55     private JTextField rfqNumberField;
56     private JTextField blNumberField;
57     private JTextField mblNumberField;
58     
59     private JTextField customerKeyField;
60     private JTextField customerAddressField;
61     private JTextField shipperKeyField;
62     private JTextField shipperAddressField;
63     private JTextField consigneeKeyField;
64     private JTextField consigneeAddressField;
65     
66     private JTextField departureCodeField;
67     private JTextField departurePortField;
68     private JTextField destinationCodeField;
69     private JTextField destinationPortField;
70     private JTextField deliveryDateField;
71     
72
73     public static void main(String JavaDoc[] args) {
74         try {
75             UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
76         } catch (Exception JavaDoc e) {
77             // Likely PlasticXP is not in the class path; ignore.
78
}
79         JFrame frame = new JFrame();
80         frame.setTitle("Forms Tutorial :: Debug a Form");
81         frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
82         JComponent panel = new FormDebugExample().buildPanel();
83         frame.getContentPane().add(panel);
84         frame.pack();
85         frame.show();
86     }
87
88
89     // Component Creation and Initialization **********************************
90

91     /**
92      * Creates and intializes the UI components.
93      */

94     private void initComponents() {
95         fileNumberField = new JTextField();
96         rfqNumberField = new JTextField();
97         blNumberField = new JTextField();
98         mblNumberField = new JTextField();
99         customerKeyField = new JTextField();
100         customerAddressField = new JTextField();
101         customerAddressField.setEditable(false);
102         shipperKeyField = new JTextField();
103         shipperAddressField = new JTextField();
104         shipperAddressField.setEditable(false);
105         consigneeKeyField = new JTextField();
106         consigneeAddressField = new JTextField();
107         consigneeAddressField.setEditable(false);
108         departureCodeField = new JTextField();
109         departurePortField = new JTextField();
110         departurePortField.setEditable(false);
111         destinationCodeField = new JTextField();
112         destinationPortField = new JTextField();
113         destinationPortField.setEditable(false);
114         deliveryDateField = new JTextField();
115     }
116
117     // Building *************************************************************
118

119     /**
120      * Builds the pane.
121      */

122     public JComponent buildPanel() {
123         initComponents();
124         
125         FormLayout layout = new FormLayout(
126                 "12dlu, pref, 3dlu, max(45dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
127                 "");
128         layout.setColumnGroups(new int[][] { { 4, 6, 8, 10 } });
129         
130         DefaultFormBuilder builder =
131             new DefaultFormBuilder(new FormDebugPanel(), layout);
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); builder.nextLine();
140
141         builder.appendSeparator("Addresses");
142         builder.append("Customer", customerKeyField, customerAddressField, 5);
143         builder.append("Shipper", shipperKeyField, shipperAddressField, 5);
144         builder.append("Consignee", consigneeKeyField, consigneeAddressField, 5);
145
146         builder.appendSeparator("Transport");
147         builder.append("Departure", departureCodeField, departurePortField, 5);
148         builder.append("Destination", destinationCodeField, destinationPortField, 5);
149         builder.append("Delivery Date", deliveryDateField); builder.nextLine();
150         
151         FormDebugUtils.dumpAll(builder.getPanel());
152         
153         return builder.getPanel();
154     }
155
156
157 }
Popular Tags