KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > wizard > ConnectionPanel3


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form.wizard;
21
22 import javax.swing.event.*;
23 import java.lang.reflect.Method JavaDoc;
24
25 import org.openide.util.NbBundle;
26 import org.netbeans.modules.form.*;
27
28 /**
29  * The UI component of the ConnectionWizardPanel3.
30  *
31  * @author Tomas Pavek
32  */

33
34 class ConnectionPanel3 extends javax.swing.JPanel JavaDoc {
35
36     private ConnectionWizardPanel3 wizardPanel;
37
38     private Class JavaDoc[] parameters;
39     private ParametersPicker[] pickers;
40     private boolean valid = false;
41
42     private ChangeListener paramsChangeListener = null;
43
44     /** Creates new form ConnectionPanel3 */
45     public ConnectionPanel3(ConnectionWizardPanel3 wizardPanel) {
46         this.wizardPanel = wizardPanel;
47
48         initComponents ();
49
50         java.util.ResourceBundle JavaDoc bundle = NbBundle.getBundle(ConnectionPanel3.class);
51
52         setName(bundle.getString("CTL_CW_Step3_Title")); // NOI18N
53

54         paramsChangeListener = new ChangeListener() {
55             public void stateChanged(ChangeEvent evt) {
56                 updatePreview();
57             }
58         };
59
60         paramLabel.setText(bundle.getString("CTL_CW_ParamTabs")); // NOI18N
61
paramLabel.setDisplayedMnemonic(
62             bundle.getString("CTL_CW_ParamTabs_Mnemonic").charAt(0)); // NOI18N
63
previewLabel.setText(
64             bundle.getString("CTL_CW_GeneratedPreview")); // NOI18N
65
previewLabel.setDisplayedMnemonic(
66             bundle.getString("CTL_CW_GeneratedPreview_Mnemonic").charAt(0)); // NOI18N
67
previewField.setText(bundle.getString("CTL_CW_Preview")); // NOI18N
68

69         previewField.getAccessibleContext().setAccessibleDescription(
70             bundle.getString("ACSD_CW_Preview")); // NOI18N
71
parameterTabs.getAccessibleContext().setAccessibleDescription(
72             bundle.getString("ACSD_CW_ParamTabs")); // NOI18N
73
getAccessibleContext().setAccessibleDescription(
74             bundle.getString("ACSD_CW_ConnectionPanel3")); // NOI18N
75

76         putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(2)); // NOI18N
77
}
78
79     public java.awt.Dimension JavaDoc getPreferredSize() {
80         return new java.awt.Dimension JavaDoc(450, 300);
81     }
82
83     void setMethod(Method JavaDoc m) {
84         parameterTabs.removeChangeListener(paramsChangeListener);
85         parameterTabs.removeAll();
86
87         parameters = m.getParameterTypes();
88         pickers = new ParametersPicker[parameters.length];
89         for (int i=0; i < parameters.length; i++) {
90             pickers[i] = new ParametersPicker(wizardPanel.getFormModel(),
91                                               parameters[i]);
92             pickers[i].addChangeListener(new ChangeListener() {
93                 public void stateChanged(ChangeEvent evt) {
94                     updatePreview();
95                 }
96             });
97             pickers[i].setBorder(new javax.swing.border.EmptyBorder JavaDoc(6, 6, 5, 5));
98
99             parameterTabs.addTab(
100                 org.openide.util.Utilities.getShortClassName(parameters[i]),
101                 null,
102                 pickers[i],
103                 parameters[i].getName());
104         }
105
106         valid = isValid();
107         parameterTabs.addChangeListener(paramsChangeListener);
108         updatePreview();
109     }
110
111     String JavaDoc getParametersText() {
112         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
113         for (int i = 0; i < pickers.length; i++) {
114             buf.append(pickers[i].getText());
115             if (i != pickers.length - 1)
116                 buf.append(", "); // NOI18N
117
}
118         return buf.toString();
119     }
120
121     Object JavaDoc[] getParameters() {
122         try {
123             Object JavaDoc values[] = new Object JavaDoc [pickers.length];
124             for (int i = 0; i < pickers.length; i++)
125                 values[i] = pickers[i].getPropertyValue();
126
127             return values;
128         }
129         catch (IllegalStateException JavaDoc e) {
130             e.printStackTrace();
131             return null;
132         }
133     }
134
135     private String JavaDoc getPreviewText() {
136         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
137         for (int i = 0; i < pickers.length; i++) {
138             buf.append(pickers[i].getPreviewText());
139             if (i != pickers.length - 1)
140                 buf.append(", "); // NOI18N
141
}
142         return buf.toString();
143     }
144
145     private void updatePreview() {
146         previewField.setText(getPreviewText());
147
148         boolean now = isFilled();
149         if (now != valid) {
150             valid = now;
151             wizardPanel.fireStateChanged();
152         }
153     }
154
155     boolean isFilled() {
156         for (int i=0; i < pickers.length; i++)
157             if (!pickers[i].isFilled())
158                 return false;
159         return true;
160     }
161
162     /** This method is called from within the constructor to
163      * initialize the form.
164      * WARNING: Do NOT modify this code. The content of this method is
165      * always regenerated by the Form Editor.
166      */

167     private void initComponents() {//GEN-BEGIN:initComponents
168
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
169
170         paramLabel = new javax.swing.JLabel JavaDoc();
171         parameterTabs = new javax.swing.JTabbedPane JavaDoc();
172         previewLabel = new javax.swing.JLabel JavaDoc();
173         previewField = new javax.swing.JTextField JavaDoc();
174
175         setLayout(new java.awt.GridBagLayout JavaDoc());
176
177         paramLabel.setText("jLabel2");
178         paramLabel.setLabelFor(parameterTabs);
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
180         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
182         add(paramLabel, gridBagConstraints);
183
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridx = 0;
186         gridBagConstraints.gridy = 1;
187         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
188         gridBagConstraints.weightx = 1.0;
189         gridBagConstraints.weighty = 1.0;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
191         add(parameterTabs, gridBagConstraints);
192
193         previewLabel.setText("jLabel1");
194         previewLabel.setLabelFor(previewField);
195         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
196         gridBagConstraints.gridx = 0;
197         gridBagConstraints.gridy = 2;
198         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
200         add(previewLabel, gridBagConstraints);
201
202         previewField.setEditable(false);
203         previewField.setText("jTextField1");
204         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
205         gridBagConstraints.gridx = 0;
206         gridBagConstraints.gridy = 3;
207         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
208         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
209         add(previewField, gridBagConstraints);
210
211     }//GEN-END:initComponents
212

213     // Variables declaration - do not modify//GEN-BEGIN:variables
214
private javax.swing.JLabel JavaDoc paramLabel;
215     private javax.swing.JTextField JavaDoc previewField;
216     private javax.swing.JLabel JavaDoc previewLabel;
217     private javax.swing.JTabbedPane JavaDoc parameterTabs;
218     // End of variables declaration//GEN-END:variables
219
}
220
Popular Tags