KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > method > impl > FieldCustomizerPanel


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.j2ee.common.method.impl;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.SwingUtilities JavaDoc;
26 import javax.swing.event.DocumentEvent JavaDoc;
27 import javax.swing.event.DocumentListener JavaDoc;
28 import org.netbeans.modules.j2ee.common.method.MethodModel;
29
30 /**
31  * Customizer for FieldElement
32  *
33  * @author Petr Hamernik
34  * @author Martin Adamek
35  */

36 public class FieldCustomizerPanel extends JPanel JavaDoc {
37
38     public static final String JavaDoc NAME = "name";
39     public static final String JavaDoc RETURN_TYPE = "returnType";
40     public static final String JavaDoc INTERFACES = "interfaces";
41
42     /**
43      * Create new FieldCustomizer component
44      *
45      * @param element The field to be customized
46      * @param description
47      * @param localGetter
48      * @param localSetter
49      * @param remoteGetter
50      * @param remoteSetter
51      */

52     public FieldCustomizerPanel(MethodModel.Variable element, String JavaDoc description, boolean localEnabled, boolean remoteEnabled,
53             boolean localGetter, boolean localSetter, boolean remoteGetter, boolean remoteSetter) {
54         initComponents();
55
56         descriptionTextField.setText(description);
57         localGetterCheckBox.setEnabled(localEnabled);
58         localSetterCheckBox.setEnabled(localEnabled);
59         remoteGetterCheckBox.setEnabled(remoteEnabled);
60         remoteSetterCheckBox.setEnabled(remoteEnabled);
61         localGetterCheckBox.setSelected(localGetter && localEnabled);
62         localSetterCheckBox.setSelected(localSetter && localEnabled);
63         remoteGetterCheckBox.setSelected(remoteGetter && remoteEnabled);
64         remoteSetterCheckBox.setSelected(remoteSetter && remoteEnabled);
65         nameTextField.setText(element.getName());
66         typeTextField.setText(element.getType());
67         
68         nameTextField.getDocument().addDocumentListener(new SimpleListener(NAME));
69         typeTextField.getDocument().addDocumentListener(new SimpleListener(RETURN_TYPE));
70         SimpleListener interfacesListener = new SimpleListener(INTERFACES);
71         localGetterCheckBox.addActionListener(interfacesListener);
72         localSetterCheckBox.addActionListener(interfacesListener);
73         remoteGetterCheckBox.addActionListener(interfacesListener);
74         remoteSetterCheckBox.addActionListener(interfacesListener);
75     }
76
77     public void addNotify() {
78         super.addNotify();
79
80         // select the name
81
int nameLength = nameTextField.getText().length();
82         nameTextField.setCaretPosition(0);
83         nameTextField.moveCaretPosition(nameLength);
84         nameTextField.requestFocus();
85         SwingUtilities.invokeLater(new Runnable JavaDoc() {
86             public void run() {
87                 nameTextField.requestFocus();
88             }
89         });
90     }
91
92     /** This method is called from within the constructor to
93      * initialize the form.
94      * WARNING: Do NOT modify this code. The content of this method is
95      * always regenerated by the FormEditor.
96      */

97     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
98
private void initComponents() {
99
100         nameLabel = new javax.swing.JLabel JavaDoc();
101         nameTextField = new javax.swing.JTextField JavaDoc();
102         descriptionLabel = new javax.swing.JLabel JavaDoc();
103         descriptionTextField = new javax.swing.JTextField JavaDoc();
104         typeLabel = new javax.swing.JLabel JavaDoc();
105         addToLocalLabel = new javax.swing.JLabel JavaDoc();
106         localGetterCheckBox = new javax.swing.JCheckBox JavaDoc();
107         localSetterCheckBox = new javax.swing.JCheckBox JavaDoc();
108         addToRemoteLabel = new javax.swing.JLabel JavaDoc();
109         remoteGetterCheckBox = new javax.swing.JCheckBox JavaDoc();
110         remoteSetterCheckBox = new javax.swing.JCheckBox JavaDoc();
111         typeTextField = new javax.swing.JTextField JavaDoc();
112         errorTextField = new javax.swing.JTextField JavaDoc();
113
114         setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6, 6));
115
116         nameLabel.setLabelFor(nameTextField);
117         org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Name_")); // NOI18N
118

119         nameTextField.setColumns(30);
120
121         descriptionLabel.setLabelFor(descriptionTextField);
122         org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Description")); // NOI18N
123

124         typeLabel.setLabelFor(typeTextField);
125         org.openide.awt.Mnemonics.setLocalizedText(typeLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Type")); // NOI18N
126

127         org.openide.awt.Mnemonics.setLocalizedText(addToLocalLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "LBL_AddToLocalInterface")); // NOI18N
128

129         org.openide.awt.Mnemonics.setLocalizedText(localGetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Getter_Local")); // NOI18N
130

131         org.openide.awt.Mnemonics.setLocalizedText(localSetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Setter_Local")); // NOI18N
132

133         org.openide.awt.Mnemonics.setLocalizedText(addToRemoteLabel, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "LBL_AddToRemoteInterface")); // NOI18N
134

135         org.openide.awt.Mnemonics.setLocalizedText(remoteGetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Getter_Remote")); // NOI18N
136

137         org.openide.awt.Mnemonics.setLocalizedText(remoteSetterCheckBox, org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "CTL_Setter_Remote")); // NOI18N
138

139         errorTextField.setEditable(false);
140         errorTextField.setText(org.openide.util.NbBundle.getMessage(FieldCustomizerPanel.class, "FieldCustomizerPanel.errorTextField.text")); // NOI18N
141
errorTextField.setBorder(null);
142
143         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
144         this.setLayout(layout);
145         layout.setHorizontalGroup(
146             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
147             .add(layout.createSequentialGroup()
148                 .addContainerGap()
149                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150                     .add(errorTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
151                     .add(layout.createSequentialGroup()
152                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153                             .add(layout.createSequentialGroup()
154                                 .add(42, 42, 42)
155                                 .add(typeLabel))
156                             .add(layout.createSequentialGroup()
157                                 .add(37, 37, 37)
158                                 .add(nameLabel))
159                             .add(descriptionLabel))
160                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
161                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
162                             .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
163                             .add(descriptionTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
164                             .add(typeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)))
165                     .add(layout.createSequentialGroup()
166                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
167                             .add(addToLocalLabel)
168                             .add(addToRemoteLabel))
169                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
170                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
171                             .add(layout.createSequentialGroup()
172                                 .add(localGetterCheckBox)
173                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
174                                 .add(localSetterCheckBox))
175                             .add(layout.createSequentialGroup()
176                                 .add(remoteGetterCheckBox)
177                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
178                                 .add(remoteSetterCheckBox)))
179                         .add(190, 190, 190)))
180                 .addContainerGap())
181         );
182         layout.setVerticalGroup(
183             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184             .add(layout.createSequentialGroup()
185                 .addContainerGap()
186                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
187                     .add(nameLabel)
188                     .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
189                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
190                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
191                     .add(descriptionLabel)
192                     .add(descriptionTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
193                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
194                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
195                     .add(typeLabel)
196                     .add(typeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
197                 .add(18, 18, 18)
198                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
199                     .add(localGetterCheckBox)
200                     .add(localSetterCheckBox)
201                     .add(addToLocalLabel))
202                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
203                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
204                     .add(addToRemoteLabel)
205                     .add(remoteGetterCheckBox)
206                     .add(remoteSetterCheckBox))
207                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
208                 .add(errorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
209                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
210         );
211
212         nameTextField.getAccessibleContext().setAccessibleDescription(null);
213         descriptionTextField.getAccessibleContext().setAccessibleDescription(null);
214         localGetterCheckBox.getAccessibleContext().setAccessibleName(null);
215         localGetterCheckBox.getAccessibleContext().setAccessibleDescription(null);
216         localSetterCheckBox.getAccessibleContext().setAccessibleName(null);
217         localSetterCheckBox.getAccessibleContext().setAccessibleDescription(null);
218         remoteGetterCheckBox.getAccessibleContext().setAccessibleName(null);
219         remoteGetterCheckBox.getAccessibleContext().setAccessibleDescription(null);
220         remoteSetterCheckBox.getAccessibleContext().setAccessibleName(null);
221         remoteSetterCheckBox.getAccessibleContext().setAccessibleDescription(null);
222     }// </editor-fold>//GEN-END:initComponents
223

224     // Variables declaration - do not modify//GEN-BEGIN:variables
225
private javax.swing.JLabel JavaDoc addToLocalLabel;
226     private javax.swing.JLabel JavaDoc addToRemoteLabel;
227     private javax.swing.JLabel JavaDoc descriptionLabel;
228     private javax.swing.JTextField JavaDoc descriptionTextField;
229     private javax.swing.JTextField JavaDoc errorTextField;
230     private javax.swing.JCheckBox JavaDoc localGetterCheckBox;
231     private javax.swing.JCheckBox JavaDoc localSetterCheckBox;
232     private javax.swing.JLabel JavaDoc nameLabel;
233     private javax.swing.JTextField JavaDoc nameTextField;
234     private javax.swing.JCheckBox JavaDoc remoteGetterCheckBox;
235     private javax.swing.JCheckBox JavaDoc remoteSetterCheckBox;
236     private javax.swing.JLabel JavaDoc typeLabel;
237     private javax.swing.JTextField JavaDoc typeTextField;
238     // End of variables declaration//GEN-END:variables
239

240     public void setError(String JavaDoc message) {
241         errorTextField.setText(message);
242     }
243
244     public String JavaDoc getMethodName() {
245         return nameTextField.getText();
246     }
247     
248     public String JavaDoc getReturnType() {
249         return typeTextField.getText();
250     }
251     
252     public String JavaDoc getDescription() {
253         return descriptionTextField.getText();
254     }
255
256     public boolean isLocalGetter() {
257         return localGetterCheckBox.isSelected();
258     }
259
260     public boolean isLocalSetter() {
261         return localSetterCheckBox.isSelected();
262     }
263
264     public boolean isRemoteGetter() {
265         return remoteGetterCheckBox.isSelected();
266     }
267
268     public boolean isRemoteSetter() {
269         return remoteSetterCheckBox.isSelected();
270     }
271
272     /**
273      * Listener on text fields.
274      * Fires change event for specified property of this JPanel,
275      * old and new value of event is null.
276      * After receiving event, client can get property value by
277      * calling {@link #getProperty(String)}
278      */

279     private class SimpleListener implements DocumentListener JavaDoc, ActionListener JavaDoc {
280         
281         private final String JavaDoc propertyName;
282         
283         public SimpleListener(String JavaDoc propertyName) {
284             this.propertyName = propertyName;
285         }
286         
287         public void insertUpdate(DocumentEvent JavaDoc documentEvent) { fire(); }
288         
289         public void removeUpdate(DocumentEvent JavaDoc documentEvent) { fire(); }
290         
291         public void changedUpdate(DocumentEvent JavaDoc documentEvent) {}
292         
293         public void actionPerformed(ActionEvent JavaDoc actionEvent) { fire(); }
294
295         private void fire() {
296             firePropertyChange(propertyName, null, null);
297         }
298         
299     }
300 }
301
Popular Tags