KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > i18n > java > JavaReplacePanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.i18n.java;
21
22
23 import java.awt.AWTEvent JavaDoc;
24 import java.awt.Dialog JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.lang.reflect.Modifier JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29 import javax.swing.ButtonGroup JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31
32 import org.netbeans.modules.i18n.HelpStringCustomEditor;
33 import org.netbeans.modules.i18n.I18nUtil;
34
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.loaders.DataObject;
38
39
40 /**
41  * Custom panel used by i18n session for customizing java source
42  * specific replacing values stored in <code>JavaI18nSupport</code> instance.
43  *
44  * @author Peter Zavadsky
45  */

46 public class JavaReplacePanel extends JPanel JavaDoc {
47
48     /** <code>JavaI18nSupport</code> which additional values to customize. */
49     private JavaI18nSupport javaI18nSupport;
50     
51     /** Bundle in which are stored resources used in this source. */
52     private final ResourceBundle JavaDoc bundle;
53     
54     
55     /** Creates new form JavaCustomPanel.
56      * @param <code>JavaI18nSupport</code> which additional values to customize. */

57     public JavaReplacePanel(JavaI18nSupport javaI18nSupport) {
58         this.javaI18nSupport = javaI18nSupport;
59         
60         // Init bundle.
61
bundle = org.openide.util.NbBundle.getBundle(Util.class);
62         initComponents();
63         initAccessibility();
64
65         updateValues();
66     }
67
68     
69     /** Updates values to UI. */
70     private void updateValues() {
71         javaI18nSupport.createIdentifier();
72
73         // Init generate check and formats.
74
generateCheck.setSelected(javaI18nSupport.isGenerateField());
75         setAllEnabled(generateCheck.isSelected());
76         
77         identifierTextField.setText(javaI18nSupport.getIdentifier());
78         
79         initTextField.setText(javaI18nSupport.getInitString());
80     }
81
82     /** Updates modifier components according to identifier changes. */
83     private void updateModifiers() {
84 // FieldElement field = getFieldElement(identifierTextField.getText());
85
//
86
// int modifiers;
87
//
88
// if(field != null) {
89
// modifiers = field.getModifiers();
90
// enableModifiers(false);
91
// fieldTextField.setText(field.toString());
92
// } else {
93
// modifiers = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL;
94
// enableModifiers(true);
95
// fieldTextField.setText(""); // NOI18N
96
// }
97
//
98
// javaI18nSupport.setModifiers(modifiers);
99
//
100
// if(identifierTextField.getText().length() != 0) {
101
// if(Modifier.isPrivate(modifiers))
102
// privateRadio.setSelected(true);
103
// else if(Modifier.isProtected(modifiers))
104
// protectedRadio.setSelected(true);
105
// else if(Modifier.isPublic(modifiers))
106
// publicRadio.setSelected(true);
107
// else
108
// defaultRadio.setSelected(true);
109
//
110
// staticCheck.setSelected(Modifier.isStatic(modifiers));
111
// finalCheck.setSelected(Modifier.isFinal(modifiers));
112
// transientCheck.setSelected(Modifier.isTransient(modifiers));
113
// } else {
114
// // default set of modifiers
115
// privateRadio.setSelected(true);
116
// staticCheck.setSelected(true);
117
// finalCheck.setSelected(true);
118
// }
119
}
120
121     
122     private void initAccessibility() {
123         this.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_JavaReplacePanel"));
124         fieldTextField.selectAll();
125         initTextField.selectAll();
126         staticCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_staticCheck"));
127         identifierTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_identifierTextField"));
128         transientCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_transientCheck"));
129         defaultRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_defaultRadio"));
130         fieldTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_fieldTextField"));
131         initButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_initButton"));
132         publicRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_publicRadio"));
133         generateCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_generateCheck"));
134         finalCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_finalCheck"));
135         privateRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_privateRadio"));
136         initTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_initTextField"));
137         protectedRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_protectedRadio"));
138         
139     }
140     
141     /** This method is called from within the constructor to
142      * initialize the form.
143      * WARNING: Do NOT modify this code. The content of this method is
144      * always regenerated by the Form Editor.
145      */

146     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
147
private void initComponents() {
148         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
149
150         generateCheck = new javax.swing.JCheckBox JavaDoc();
151         modifiersLabel = new javax.swing.JLabel JavaDoc();
152         defaultRadio = new javax.swing.JRadioButton JavaDoc();
153         privateRadio = new javax.swing.JRadioButton JavaDoc();
154         protectedRadio = new javax.swing.JRadioButton JavaDoc();
155         publicRadio = new javax.swing.JRadioButton JavaDoc();
156         staticCheck = new javax.swing.JCheckBox JavaDoc();
157         finalCheck = new javax.swing.JCheckBox JavaDoc();
158         transientCheck = new javax.swing.JCheckBox JavaDoc();
159         identifierLabel = new javax.swing.JLabel JavaDoc();
160         identifierTextField = new javax.swing.JTextField JavaDoc();
161         initLabel = new javax.swing.JLabel JavaDoc();
162         initTextField = new javax.swing.JTextField JavaDoc();
163         fieldLabel = new javax.swing.JLabel JavaDoc();
164         fieldTextField = new javax.swing.JTextField JavaDoc();
165         initButton = new javax.swing.JButton JavaDoc();
166
167         setLayout(new java.awt.GridBagLayout JavaDoc());
168
169         generateCheck.setSelected(true);
170         org.openide.awt.Mnemonics.setLocalizedText(generateCheck, bundle.getString("CTL_GenerateField")); // NOI18N
171
generateCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
172             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
173                 generateCheckActionPerformed(evt);
174             }
175         });
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridwidth = 2;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
180         add(generateCheck, gridBagConstraints);
181
182         modifiersLabel.setText(bundle.getString("LBL_Modifiers")); // NOI18N
183
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
184         gridBagConstraints.gridx = 0;
185         gridBagConstraints.gridy = 1;
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
188         add(modifiersLabel, gridBagConstraints);
189
190         org.openide.awt.Mnemonics.setLocalizedText(defaultRadio, bundle.getString("CTL_DefaultRadio")); // NOI18N
191
defaultRadio.setEnabled(false);
192         defaultRadio.addActionListener(new java.awt.event.ActionListener JavaDoc() {
193             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
194                 defaultRadioActionPerformed(evt);
195             }
196         });
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridx = 1;
199         gridBagConstraints.gridy = 1;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
202         add(defaultRadio, gridBagConstraints);
203
204         privateRadio.setSelected(true);
205         org.openide.awt.Mnemonics.setLocalizedText(privateRadio, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_PrivateRadio")); // NOI18N
206
privateRadio.setEnabled(false);
207         privateRadio.addActionListener(new java.awt.event.ActionListener JavaDoc() {
208             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
209                 privateRadioActionPerformed(evt);
210             }
211         });
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 1;
214         gridBagConstraints.gridy = 2;
215         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
216         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
217         add(privateRadio, gridBagConstraints);
218
219         org.openide.awt.Mnemonics.setLocalizedText(protectedRadio, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_ProtectedRadio")); // NOI18N
220
protectedRadio.setEnabled(false);
221         protectedRadio.addActionListener(new java.awt.event.ActionListener JavaDoc() {
222             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
223                 protectedRadioActionPerformed(evt);
224             }
225         });
226         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
227         gridBagConstraints.gridx = 1;
228         gridBagConstraints.gridy = 3;
229         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
230         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
231         add(protectedRadio, gridBagConstraints);
232
233         org.openide.awt.Mnemonics.setLocalizedText(publicRadio, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_PublicRadio")); // NOI18N
234
publicRadio.setEnabled(false);
235         ButtonGroup JavaDoc radioGroup = new ButtonGroup JavaDoc();
236
237         radioGroup.add(defaultRadio);
238         radioGroup.add(privateRadio);
239         radioGroup.add(protectedRadio);
240         radioGroup.add(publicRadio);
241         publicRadio.addActionListener(new java.awt.event.ActionListener JavaDoc() {
242             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
243                 publicRadioActionPerformed(evt);
244             }
245         });
246         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
247         gridBagConstraints.gridx = 1;
248         gridBagConstraints.gridy = 4;
249         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
250         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
251         add(publicRadio, gridBagConstraints);
252
253         staticCheck.setSelected(true);
254         org.openide.awt.Mnemonics.setLocalizedText(staticCheck, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_StaticCheck")); // NOI18N
255
staticCheck.setEnabled(false);
256         staticCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
257             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
258                 staticCheckActionPerformed(evt);
259             }
260         });
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints.gridx = 2;
263         gridBagConstraints.gridy = 1;
264         gridBagConstraints.gridwidth = 3;
265         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
266         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
267         add(staticCheck, gridBagConstraints);
268
269         finalCheck.setSelected(true);
270         org.openide.awt.Mnemonics.setLocalizedText(finalCheck, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_FinalCheck")); // NOI18N
271
finalCheck.setEnabled(false);
272         finalCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
273             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
274                 finalCheckActionPerformed(evt);
275             }
276         });
277         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
278         gridBagConstraints.gridx = 2;
279         gridBagConstraints.gridy = 2;
280         gridBagConstraints.gridwidth = 3;
281         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
282         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 11);
283         add(finalCheck, gridBagConstraints);
284
285         org.openide.awt.Mnemonics.setLocalizedText(transientCheck, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_TransientCheck")); // NOI18N
286
transientCheck.setEnabled(false);
287         transientCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
288             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
289                 transientCheckActionPerformed(evt);
290             }
291         });
292         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
293         gridBagConstraints.gridx = 2;
294         gridBagConstraints.gridy = 3;
295         gridBagConstraints.gridwidth = 3;
296         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
297         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 11);
298         add(transientCheck, gridBagConstraints);
299
300         identifierLabel.setLabelFor(identifierTextField);
301         org.openide.awt.Mnemonics.setLocalizedText(identifierLabel, bundle.getString("LBL_Identifier")); // NOI18N
302
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
303         gridBagConstraints.gridx = 0;
304         gridBagConstraints.gridy = 5;
305         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
306         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 12, 0, 0);
307         add(identifierLabel, gridBagConstraints);
308
309         identifierTextField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
310             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
311                 identifierTextFieldActionPerformed(evt);
312             }
313         });
314         identifierTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
315             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
316                 identifierTextFieldFocusLost(evt);
317             }
318         });
319         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
320         gridBagConstraints.gridx = 1;
321         gridBagConstraints.gridy = 5;
322         gridBagConstraints.gridwidth = 4;
323         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
324         gridBagConstraints.weightx = 1.0;
325         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 12, 0, 11);
326         add(identifierTextField, gridBagConstraints);
327
328         initLabel.setLabelFor(initTextField);
329         org.openide.awt.Mnemonics.setLocalizedText(initLabel, bundle.getString("LBL_InitFormat")); // NOI18N
330
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
331         gridBagConstraints.gridx = 0;
332         gridBagConstraints.gridy = 6;
333         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
334         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 12, 0, 0);
335         add(initLabel, gridBagConstraints);
336
337         initTextField.setEditable(false);
338         initTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
339             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
340                 initTextFieldFocusGained(evt);
341             }
342         });
343         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
344         gridBagConstraints.gridx = 1;
345         gridBagConstraints.gridy = 6;
346         gridBagConstraints.gridwidth = 2;
347         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
348         gridBagConstraints.weightx = 1.0;
349         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
350         add(initTextField, gridBagConstraints);
351
352         fieldLabel.setLabelFor(fieldTextField);
353         org.openide.awt.Mnemonics.setLocalizedText(fieldLabel, bundle.getString("LBL_Field")); // NOI18N
354
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
355         gridBagConstraints.gridx = 0;
356         gridBagConstraints.gridy = 7;
357         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
358         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 12, 11, 0);
359         add(fieldLabel, gridBagConstraints);
360
361         fieldTextField.setEditable(false);
362         fieldTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
363             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
364                 fieldTextFieldFocusGained(evt);
365             }
366         });
367         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
368         gridBagConstraints.gridx = 1;
369         gridBagConstraints.gridy = 7;
370         gridBagConstraints.gridwidth = 4;
371         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
372         gridBagConstraints.weightx = 1.0;
373         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 11);
374         add(fieldTextField, gridBagConstraints);
375
376         org.openide.awt.Mnemonics.setLocalizedText(initButton, bundle.getString("CTL_Format")); // NOI18N
377
initButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
378             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
379                 initButtonActionPerformed(evt);
380             }
381         });
382         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
383         gridBagConstraints.gridx = 3;
384         gridBagConstraints.gridy = 6;
385         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
386         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 5, 0, 11);
387         add(initButton, gridBagConstraints);
388     }// </editor-fold>//GEN-END:initComponents
389

390     private void fieldTextFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_fieldTextFieldFocusGained
391
// Accessibility:
392
fieldTextField.selectAll();
393     }//GEN-LAST:event_fieldTextFieldFocusGained
394

395     private void initTextFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_initTextFieldFocusGained
396
// Accessibility:
397
initTextField.selectAll();
398     }//GEN-LAST:event_initTextFieldFocusGained
399

400     private void initButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_initButtonActionPerformed
401
final Dialog JavaDoc[] dialogs = new Dialog JavaDoc[1];
402         final HelpStringCustomEditor customPanel = new HelpStringCustomEditor(
403                                                     javaI18nSupport.getInitFormat(),
404                                                     I18nUtil.getInitFormatItems(),
405                                                     I18nUtil.getInitHelpItems(),
406                                                     Util.getString("LBL_InitCodeFormat"),
407                                                     I18nUtil.PE_BUNDLE_CODE_HELP_ID);
408
409         DialogDescriptor dd = new DialogDescriptor(
410             customPanel,
411             bundle.getString("LBL_InitStringFormatEditor"),
412             true,
413             DialogDescriptor.OK_CANCEL_OPTION,
414             DialogDescriptor.OK_OPTION,
415             new ActionListener JavaDoc() {
416                 public void actionPerformed(ActionEvent JavaDoc ev) {
417                     if (ev.getSource() == DialogDescriptor.OK_OPTION) {
418                         String JavaDoc newText = (String JavaDoc)customPanel.getPropertyValue();
419                         
420                         if(!newText.equals(javaI18nSupport.getInitFormat())) {
421                             javaI18nSupport.setInitFormat(newText);
422                             initTextField.setText(javaI18nSupport.getInitString());
423                             
424                             // Reset option as well.
425
I18nUtil.getOptions().setInitJavaCode(newText);
426                         }
427                         
428                         dialogs[0].setVisible(false);
429                         dialogs[0].dispose();
430                     } else if (ev.getSource() == DialogDescriptor.CANCEL_OPTION) {
431                         dialogs[0].setVisible(false);
432                         dialogs[0].dispose();
433                     }
434                 }
435        });
436        dialogs[0] = DialogDisplayer.getDefault().createDialog(dd);
437         dialogs[0].setVisible(true);
438     }//GEN-LAST:event_initButtonActionPerformed
439

440     private void identifierTextFieldFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_identifierTextFieldFocusLost
441
identifierTextFieldEventHandlerDelegate(evt);
442     }//GEN-LAST:event_identifierTextFieldFocusLost
443

444     private void identifierTextFieldActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_identifierTextFieldActionPerformed
445
identifierTextFieldEventHandlerDelegate(evt);
446     }//GEN-LAST:event_identifierTextFieldActionPerformed
447

448     /** Event handler delegate. */
449     public void identifierTextFieldEventHandlerDelegate(AWTEvent JavaDoc evt) {
450         // If the identifer was changed change identifier and update modifiers.
451
if(!identifierTextField.getText().equals(javaI18nSupport.getIdentifier())) {
452             javaI18nSupport.setIdentifier(identifierTextField.getText());
453             updateModifiers();
454         }
455     }
456     
457     private void transientCheckActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_transientCheckActionPerformed
458
if(transientCheck.isSelected()) {
459             staticCheck.setSelected(false);
460             staticCheck.setEnabled(false);
461         } else {
462             staticCheck.setEnabled(true);
463         }
464         modifiersActionPerformed();
465     }//GEN-LAST:event_transientCheckActionPerformed
466

467     private void finalCheckActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_finalCheckActionPerformed
468
modifiersActionPerformed();
469     }//GEN-LAST:event_finalCheckActionPerformed
470

471     private void staticCheckActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_staticCheckActionPerformed
472
if(staticCheck.isSelected()) {
473             transientCheck.setSelected(false);
474             transientCheck.setEnabled(false);
475         } else {
476             transientCheck.setEnabled(true);
477         }
478
479         modifiersActionPerformed();
480     }//GEN-LAST:event_staticCheckActionPerformed
481

482     private void publicRadioActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_publicRadioActionPerformed
483
modifiersActionPerformed();
484     }//GEN-LAST:event_publicRadioActionPerformed
485

486     private void protectedRadioActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_protectedRadioActionPerformed
487
modifiersActionPerformed();
488     }//GEN-LAST:event_protectedRadioActionPerformed
489

490     private void privateRadioActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_privateRadioActionPerformed
491
modifiersActionPerformed();
492     }//GEN-LAST:event_privateRadioActionPerformed
493

494     private void defaultRadioActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_defaultRadioActionPerformed
495
modifiersActionPerformed();
496     }//GEN-LAST:event_defaultRadioActionPerformed
497

498     private void generateCheckActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_generateCheckActionPerformed
499
boolean selected = generateCheck.isSelected();
500         
501         if(selected != javaI18nSupport.isGenerateField()) {
502             javaI18nSupport.setGenerateField(selected);
503             
504             setAllEnabled(selected);
505         }
506     }//GEN-LAST:event_generateCheckActionPerformed
507

508     /** Event handler delegate. */
509     private void modifiersActionPerformed() {
510         int modifiers = 0;
511         
512         if(privateRadio.isSelected())
513             modifiers |= Modifier.PRIVATE;
514         else if(protectedRadio.isSelected())
515             modifiers |= Modifier.PROTECTED;
516         else if(publicRadio.isSelected())
517             modifiers |= Modifier.PUBLIC;
518         
519         if(staticCheck.isSelected())
520             modifiers |= Modifier.STATIC;
521         if(finalCheck.isSelected())
522             modifiers |= Modifier.FINAL;
523         if(transientCheck.isSelected())
524             modifiers |= Modifier.TRANSIENT;
525         
526         if(modifiers != javaI18nSupport.getModifiers())
527             javaI18nSupport.setModifiers(modifiers);
528     }
529
530     // Variables declaration - do not modify//GEN-BEGIN:variables
531
private javax.swing.JRadioButton JavaDoc defaultRadio;
532     private javax.swing.JLabel JavaDoc fieldLabel;
533     private javax.swing.JTextField JavaDoc fieldTextField;
534     private javax.swing.JCheckBox JavaDoc finalCheck;
535     private javax.swing.JCheckBox JavaDoc generateCheck;
536     private javax.swing.JLabel JavaDoc identifierLabel;
537     private javax.swing.JTextField JavaDoc identifierTextField;
538     private javax.swing.JButton JavaDoc initButton;
539     private javax.swing.JLabel JavaDoc initLabel;
540     private javax.swing.JTextField JavaDoc initTextField;
541     private javax.swing.JLabel JavaDoc modifiersLabel;
542     private javax.swing.JRadioButton JavaDoc privateRadio;
543     private javax.swing.JRadioButton JavaDoc protectedRadio;
544     private javax.swing.JRadioButton JavaDoc publicRadio;
545     private javax.swing.JCheckBox JavaDoc staticCheck;
546     private javax.swing.JCheckBox JavaDoc transientCheck;
547     // End of variables declaration//GEN-END:variables
548

549     /** Helper method. Enables/disables all componnent in field panel. */
550     private void setAllEnabled(boolean enable) {
551         defaultRadio.setEnabled(enable);
552         privateRadio.setEnabled(enable);
553         protectedRadio.setEnabled(enable);
554         publicRadio.setEnabled(enable);
555         
556         staticCheck.setEnabled(enable);
557         transientCheck.setEnabled(enable);
558         finalCheck.setEnabled(enable);
559         
560         identifierTextField.setEnabled(enable);
561         fieldTextField.setEnabled(enable);
562         initButton.setEnabled(enable);
563         
564         if(enable)
565             updateModifiers();
566     }
567
568     /** Helper method to find <code>FieldElement</code> in <code>sourceDataObject</code>
569      * document for specified string. */

570 // private FieldElement getFieldElement(String identifier) {
571
// DataObject sourceDataObject = javaI18nSupport.getSourceDataObject();
572
// if(sourceDataObject == null)
573
// return null;
574
//
575
// SourceElement sourceElem = ((SourceCookie)sourceDataObject.getCookie(SourceCookie.class)).getSource();
576
// ClassElement sourceClass = sourceElem.getClass(Identifier.create(sourceDataObject.getName()));
577
//
578
// if(sourceClass == null) {
579
// ClassElement[] classes = sourceElem.getClasses();
580
//
581
// // Find source class.
582
// for(int i=0; i<classes.length; i++) {
583
// int modifs = classes[i].getModifiers();
584
// if(classes[i].isClass() && Modifier.isPublic(modifs)) {
585
// sourceClass = classes[i];
586
// break;
587
// }
588
// }
589
// }
590
//
591
// if(sourceClass == null)
592
// return null;
593
//
594
// return sourceClass.getField(Identifier.create(identifier));
595
// }
596

597     /** Helper method. Enables/disables modifiers components. */
598     private void enableModifiers(boolean enable) {
599         defaultRadio.setEnabled(enable);
600         privateRadio.setEnabled(enable);
601         protectedRadio.setEnabled(enable);
602         publicRadio.setEnabled(enable);
603         staticCheck.setEnabled(enable);
604         finalCheck.setEnabled(enable);
605         transientCheck.setEnabled(enable);
606         
607         // Enable/disable init format as well.
608
initTextField.setEnabled(enable);
609         initButton.setEnabled(enable);
610     }
611     
612 }
613
Popular Tags