KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > palette > items > ForEachCustomizer


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.web.core.palette.items;
21 import java.awt.Dialog JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import javax.swing.DefaultComboBoxModel JavaDoc;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.util.NbBundle;
29
30
31
32
33
34 /**
35  *
36  * @author Libor Kotouc
37  */

38 public class ForEachCustomizer extends javax.swing.JPanel JavaDoc {
39
40     private Dialog JavaDoc dialog = null;
41     private DialogDescriptor descriptor = null;
42     private boolean dialogOK = false;
43
44     ForEach forEach;
45     JTextComponent JavaDoc target;
46             
47     public ForEachCustomizer(ForEach forEach, JTextComponent JavaDoc target) {
48         this.forEach = forEach;
49         this.target = target;
50         
51         initComponents();
52
53     }
54     
55     public boolean showDialog() {
56         
57         dialogOK = false;
58         
59         String JavaDoc displayName = "";
60         try {
61             displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-ForEach"); // NOI18N
62
}
63         catch (Exception JavaDoc e) {}
64         
65         descriptor = new DialogDescriptor
66                 (this, NbBundle.getMessage(ForEachCustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
67                  DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
68                  new ActionListener JavaDoc() {
69                      public void actionPerformed(ActionEvent JavaDoc e) {
70                         if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
71                             evaluateInput();
72                             dialogOK = true;
73                         }
74                         dialog.dispose();
75              }
76          }
77                 );
78         
79         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
80         dialog.setVisible(true);
81         repaint();
82         
83         return dialogOK;
84     }
85     
86     private void evaluateInput() {
87         
88         
89         String JavaDoc collection = jTextField1.getText();
90         forEach.setCollection(collection);
91         
92         String JavaDoc variable = jTextField2.getText();
93         forEach.setVariable(variable);
94         
95         forEach.setFixed(jCheckBox1.isSelected());
96         
97         String JavaDoc begin = jTextField3.getText();
98         forEach.setBegin(begin);
99         
100         String JavaDoc end = jTextField4.getText();
101         forEach.setEnd(end);
102         
103         String JavaDoc step = jTextField5.getText();
104         forEach.setStep(step);
105         
106     }
107     
108     /** This method is called from within the constructor to
109      * initialize the form.
110      * WARNING: Do NOT modify this code. The content of this method is
111      * always regenerated by the Form Editor.
112      */

113     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
114
private void initComponents() {
115         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
116
117         jFileChooser1 = new javax.swing.JFileChooser JavaDoc();
118         jTextField1 = new javax.swing.JTextField JavaDoc();
119         jLabel1 = new javax.swing.JLabel JavaDoc();
120         jTextField2 = new javax.swing.JTextField JavaDoc();
121         jLabel5 = new javax.swing.JLabel JavaDoc();
122         jCheckBox1 = new javax.swing.JCheckBox JavaDoc();
123         jLabel3 = new javax.swing.JLabel JavaDoc();
124         jLabel6 = new javax.swing.JLabel JavaDoc();
125         jLabel7 = new javax.swing.JLabel JavaDoc();
126         jTextField3 = new javax.swing.JTextField JavaDoc();
127         jTextField4 = new javax.swing.JTextField JavaDoc();
128         jTextField5 = new javax.swing.JTextField JavaDoc();
129
130         jFileChooser1.setCurrentDirectory(null);
131
132         setLayout(new java.awt.GridBagLayout JavaDoc());
133
134         jTextField1.setColumns(35);
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.gridx = 1;
137         gridBagConstraints.gridy = 0;
138         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
139         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
141         add(jTextField1, gridBagConstraints);
142
143         jLabel1.setLabelFor(jTextField1);
144         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "LBL_ForEach_Collection"));
145         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
146         gridBagConstraints.gridx = 0;
147         gridBagConstraints.gridy = 0;
148         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
150         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
151         add(jLabel1, gridBagConstraints);
152         jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSN_ForEach_Collection"));
153         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSD_ForEach_Collection"));
154
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.gridx = 1;
157         gridBagConstraints.gridy = 1;
158         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
161         add(jTextField2, gridBagConstraints);
162
163         jLabel5.setLabelFor(jTextField2);
164         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "LBL_ForEach_VariableHelp"));
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 0;
167         gridBagConstraints.gridy = 1;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
171         add(jLabel5, gridBagConstraints);
172         jLabel5.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSN_ForEach_VariableHelp"));
173         jLabel5.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSD_ForEach_VariableHelp"));
174
175         org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "LBL_ForEach_Fixed"));
176         jCheckBox1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 0, 0, 0)));
177         jCheckBox1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
178         jCheckBox1.addItemListener(new java.awt.event.ItemListener JavaDoc() {
179             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
180                 jCheckBox1ItemStateChanged(evt);
181             }
182         });
183
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridx = 0;
186         gridBagConstraints.gridy = 2;
187         gridBagConstraints.gridwidth = 2;
188         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
190         add(jCheckBox1, gridBagConstraints);
191         jCheckBox1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSN_ForEach_Fixed"));
192         jCheckBox1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSD_ForEach_Fixed"));
193
194         jLabel3.setLabelFor(jTextField3);
195         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "LBL_ForEach_Begin"));
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 0;
198         gridBagConstraints.gridy = 3;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 24, 0, 0);
202         add(jLabel3, gridBagConstraints);
203         jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSN_ForEach_Begin"));
204         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSD_ForEach_Begin"));
205
206         jLabel6.setLabelFor(jTextField4);
207         org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "LBL_ForEach_End"));
208         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints.gridx = 0;
210         gridBagConstraints.gridy = 4;
211         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 24, 0, 0);
214         add(jLabel6, gridBagConstraints);
215         jLabel6.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSN_ForEach_End"));
216         jLabel6.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSD_ForEach_End"));
217
218         jLabel7.setLabelFor(jTextField5);
219         org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "LBL_ForEach_Step"));
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 0;
222         gridBagConstraints.gridy = 5;
223         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
224         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
225         gridBagConstraints.weightx = 1.0;
226         gridBagConstraints.weighty = 1.0;
227         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 24, 12, 0);
228         add(jLabel7, gridBagConstraints);
229         jLabel7.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSN_ForEach_Step"));
230         jLabel7.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForEachCustomizer.class, "ACSD_ForEach_Step"));
231
232         jTextField3.setEditable(false);
233         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
234         gridBagConstraints.gridx = 1;
235         gridBagConstraints.gridy = 3;
236         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
237         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
239         add(jTextField3, gridBagConstraints);
240
241         jTextField4.setEditable(false);
242         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
243         gridBagConstraints.gridx = 1;
244         gridBagConstraints.gridy = 4;
245         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
246         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
247         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
248         add(jTextField4, gridBagConstraints);
249
250         jTextField5.setEditable(false);
251         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
252         gridBagConstraints.gridx = 1;
253         gridBagConstraints.gridy = 5;
254         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
255         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
256         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 12, 12);
257         add(jTextField5, gridBagConstraints);
258
259     }
260     // </editor-fold>//GEN-END:initComponents
261

262     private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
263

264         if (jCheckBox1.isSelected()) {
265             jTextField3.setEditable(true);
266             jTextField4.setEditable(true);
267             jTextField5.setEditable(true);
268         }
269         else {
270             jTextField3.setEditable(false);
271             jTextField4.setEditable(false);
272             jTextField5.setEditable(false);
273         }
274     }//GEN-LAST:event_jCheckBox1ItemStateChanged
275

276     
277     // Variables declaration - do not modify//GEN-BEGIN:variables
278
private javax.swing.JCheckBox JavaDoc jCheckBox1;
279     private javax.swing.JFileChooser JavaDoc jFileChooser1;
280     private javax.swing.JLabel JavaDoc jLabel1;
281     private javax.swing.JLabel JavaDoc jLabel3;
282     private javax.swing.JLabel JavaDoc jLabel5;
283     private javax.swing.JLabel JavaDoc jLabel6;
284     private javax.swing.JLabel JavaDoc jLabel7;
285     private javax.swing.JTextField JavaDoc jTextField1;
286     private javax.swing.JTextField JavaDoc jTextField2;
287     private javax.swing.JTextField JavaDoc jTextField3;
288     private javax.swing.JTextField JavaDoc jTextField4;
289     private javax.swing.JTextField JavaDoc jTextField5;
290     // End of variables declaration//GEN-END:variables
291

292 }
293
Popular Tags