KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > generator > SAXGeneratorFilePanel


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 package org.netbeans.modules.xml.tools.generator;
20
21 import java.awt.*;
22 import javax.swing.*;
23 import java.net.URL JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25
26 import org.netbeans.modules.xml.core.lib.A11YUtil;
27
28 /**
29  * A panel allowing to customize SAX generator i.e. setting file locations and element mapping.
30  * <p>
31  * The UI performs name checks and colors appropriate input fields giving a user feedback.
32  *
33  * @author Petr Kuzel
34  * @version 1.0
35  */

36 public final class SAXGeneratorFilePanel extends SAXGeneratorAbstractPanel implements java.awt.event.ActionListener JavaDoc {
37
38     /** Serial Version UID */
39     private static final long serialVersionUID =-8950908568784619306L;
40         
41     private static final Util.NameCheck check = Util.JAVA_CHECK;
42    
43     private java.util.ResourceBundle JavaDoc bundle = org.openide.util.NbBundle.getBundle(SAXGeneratorFilePanel.class);
44
45     /** Creates new form SAXGeneratorCustomizer */
46     public SAXGeneratorFilePanel() {
47 // try {
48
// this.putClientProperty("WizardPanel_helpURL", new URL("nbresloc:/org/netbeans/modules/xml/tools/generator/SAXGeneratorFilePanel.html")); //NOI18N
49
// } catch (MalformedURLException ex) {
50
// }
51
}
52     
53     private final ValidatingTextField.Validator NAME_VALIDATOR = new ValidatingTextField.Validator() {
54         public boolean isValid(String JavaDoc value) {
55             boolean ret = check.checkName(value);
56             if (ret) {
57                 setValid(checkNames());
58             } else {
59                 setValid(false);
60             }
61             
62             return ret;
63         }
64         
65         public String JavaDoc getReason() {
66             return Util.THIS.getString("MSG_file_err_1");
67         }
68     };
69     
70     /** This method is called from within the constructor to
71      * initialize the form.
72      * WARNING: Do NOT modify this code. The content of this method is
73      * always regenerated by the FormEditor.
74      */

75     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
76
private void initComponents() {
77         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
78
79         descTextArea = new javax.swing.JTextArea JavaDoc();
80         interfaceLabel = new javax.swing.JLabel JavaDoc();
81         interfaceTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField();
82         handlerImplLabel = new javax.swing.JLabel JavaDoc();
83         handlerImplTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField();
84         stubLabel = new javax.swing.JLabel JavaDoc();
85         stubTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField();
86         parsletLabel = new javax.swing.JLabel JavaDoc();
87         parsletTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField();
88         parsletImplLabel = new javax.swing.JLabel JavaDoc();
89         parsletImplTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField();
90         saveCheckBox = new javax.swing.JCheckBox JavaDoc();
91         saveLabel = new javax.swing.JLabel JavaDoc();
92         saveTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField();
93         fillPanel = new javax.swing.JPanel JavaDoc();
94
95         setLayout(new java.awt.GridBagLayout JavaDoc());
96
97         setName(Util.THIS.getString ("SAXGeneratorFilePanel.Form.name"));
98         setPreferredSize(new java.awt.Dimension JavaDoc(480, 350));
99         addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
100             public void componentHidden(java.awt.event.ComponentEvent JavaDoc evt) {
101                 formComponentHidden(evt);
102             }
103         });
104         addContainerListener(new java.awt.event.ContainerAdapter JavaDoc() {
105             public void componentRemoved(java.awt.event.ContainerEvent JavaDoc evt) {
106                 formComponentRemoved(evt);
107             }
108         });
109
110         descTextArea.setWrapStyleWord(true);
111         descTextArea.setLineWrap(true);
112         descTextArea.setEditable(false);
113         descTextArea.setForeground(new java.awt.Color JavaDoc(102, 102, 153));
114         descTextArea.setFont(javax.swing.UIManager.getFont ("Label.font"));
115         descTextArea.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/tools/generator/Bundle").getString("DESC_saxw_files"));
116         descTextArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground"));
117         descTextArea.setEnabled(false);
118         descTextArea.setOpaque(false);
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
121         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
122         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
123         add(descTextArea, gridBagConstraints);
124
125         interfaceLabel.setLabelFor(interfaceTextField);
126         org.openide.awt.Mnemonics.setLocalizedText(interfaceLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorCustomizer.interfaceLabel.text"));
127         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
129         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
131         add(interfaceLabel, gridBagConstraints);
132
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.weightx = 1.0;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
138         add(interfaceTextField, gridBagConstraints);
139
140         handlerImplLabel.setLabelFor(handlerImplTextField);
141         org.openide.awt.Mnemonics.setLocalizedText(handlerImplLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorFilePanel.handlerImplLabel.text", new Object JavaDoc[] {}));
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
146         add(handlerImplLabel, gridBagConstraints);
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
150         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151         gridBagConstraints.weightx = 1.0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
153         add(handlerImplTextField, gridBagConstraints);
154
155         stubLabel.setLabelFor(stubTextField);
156         org.openide.awt.Mnemonics.setLocalizedText(stubLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorCustomizer.stubLabel.text"));
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
161         add(stubLabel, gridBagConstraints);
162
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.weightx = 1.0;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
168         add(stubTextField, gridBagConstraints);
169
170         parsletLabel.setLabelFor(parsletTextField);
171         org.openide.awt.Mnemonics.setLocalizedText(parsletLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorCustomizer.parsletLabel.text"));
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
174         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
175         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
176         add(parsletLabel, gridBagConstraints);
177
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
179         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
180         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
181         gridBagConstraints.weightx = 1.0;
182         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
183         add(parsletTextField, gridBagConstraints);
184
185         parsletImplLabel.setLabelFor(parsletImplTextField);
186         org.openide.awt.Mnemonics.setLocalizedText(parsletImplLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorFilePanel.parsletImplLabel.text"));
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
191         add(parsletImplLabel, gridBagConstraints);
192
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
195         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196         gridBagConstraints.weightx = 1.0;
197         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
198         add(parsletImplTextField, gridBagConstraints);
199
200         org.openide.awt.Mnemonics.setLocalizedText(saveCheckBox, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "PROP_save_it"));
201         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
202         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
203         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
204         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
205         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
206         add(saveCheckBox, gridBagConstraints);
207
208         saveLabel.setLabelFor(saveTextField);
209         org.openide.awt.Mnemonics.setLocalizedText(saveLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "PROP_bindings_label"));
210         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
211         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
214         add(saveLabel, gridBagConstraints);
215
216         saveTextField.setEditable(false);
217         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
218         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
219         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
220         gridBagConstraints.weightx = 1.0;
221         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
222         add(saveTextField, gridBagConstraints);
223
224         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
225         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
226         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
227         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
228         gridBagConstraints.weighty = 1.0;
229         add(fillPanel, gridBagConstraints);
230
231     }
232     // </editor-fold>//GEN-END:initComponents
233

234     private void formComponentHidden(java.awt.event.ComponentEvent JavaDoc evt) {//GEN-FIRST:event_formComponentHidden
235
updateModel(); //??? does not occur
236
}//GEN-LAST:event_formComponentHidden
237

238     private void formComponentRemoved(java.awt.event.ContainerEvent JavaDoc evt) {//GEN-FIRST:event_formComponentRemoved
239
updateModel(); //??? does not occur
240
}//GEN-LAST:event_formComponentRemoved
241

242     protected void updateModel() {
243         model.setHandler(interfaceTextField.getText());
244         model.setParslet(parsletTextField.getText());
245         model.setStub(stubTextField.getText());
246         model.setParsletImpl(parsletImplTextField.getText());
247         model.setHandlerImpl(handlerImplTextField.getText());
248         model.setBindnings(saveCheckBox.isSelected() ? saveTextField.getText() : null);
249     }
250   
251   
252     protected void initView() {
253         initComponents();
254                     
255         interfaceTextField.setText(model.getHandler());
256         stubTextField.setText(model.getStub());
257         handlerImplTextField.setText(model.getHandlerImpl());
258         parsletTextField.setText(model.getParslet());
259         parsletImplTextField.setText(model.getParsletImpl());
260         saveTextField.setText(model.getBindings());
261
262         interfaceTextField.setValidator(NAME_VALIDATOR);
263         stubTextField.setValidator(NAME_VALIDATOR);
264         handlerImplTextField.setValidator(NAME_VALIDATOR);
265         parsletTextField.setValidator(NAME_VALIDATOR);
266         parsletImplTextField.setValidator(NAME_VALIDATOR);
267         
268         saveCheckBox.setSelected(model.getBindings() != null);
269         
270         initAccessibility();
271     }
272   
273     protected void updateView() {
274         
275         parsletTextField.setVisible(hasParslets());
276         parsletLabel.setVisible(hasParslets());
277         parsletImplTextField.setVisible(hasParslets());
278         parsletImplLabel.setVisible(hasParslets());
279         
280         doLayout();
281         setValid(checkNames());
282         
283     }
284   
285     /** Get notified by DialigDescriptor */
286     public void actionPerformed(java.awt.event.ActionEvent JavaDoc p1) {
287         updateModel();
288     }
289   
290     //
291
// Check all entered names
292
//
293
private boolean checkNames() {
294
295         return check.checkName(interfaceTextField.getText())
296                 && (not(hasParslets()) || check.checkName(parsletTextField.getText()))
297                 && check.checkName(stubTextField.getText())
298                 && (not(hasParslets()) || check.checkName(parsletImplTextField.getText()))
299                 && check.checkName(handlerImplTextField.getText());
300         
301     }
302
303     private boolean hasParslets() {
304         return (model.getParsletBindings().isEmpty() == false);
305     }
306     
307     // Variables declaration - do not modify//GEN-BEGIN:variables
308
private javax.swing.JTextArea JavaDoc descTextArea;
309     private javax.swing.JPanel JavaDoc fillPanel;
310     private javax.swing.JLabel JavaDoc handlerImplLabel;
311     private org.netbeans.modules.xml.tools.generator.ValidatingTextField handlerImplTextField;
312     private javax.swing.JLabel JavaDoc interfaceLabel;
313     private org.netbeans.modules.xml.tools.generator.ValidatingTextField interfaceTextField;
314     private javax.swing.JLabel JavaDoc parsletImplLabel;
315     private org.netbeans.modules.xml.tools.generator.ValidatingTextField parsletImplTextField;
316     private javax.swing.JLabel JavaDoc parsletLabel;
317     private org.netbeans.modules.xml.tools.generator.ValidatingTextField parsletTextField;
318     private javax.swing.JCheckBox JavaDoc saveCheckBox;
319     private javax.swing.JLabel JavaDoc saveLabel;
320     private org.netbeans.modules.xml.tools.generator.ValidatingTextField saveTextField;
321     private javax.swing.JLabel JavaDoc stubLabel;
322     private org.netbeans.modules.xml.tools.generator.ValidatingTextField stubTextField;
323     // End of variables declaration//GEN-END:variables
324

325     /** Initialize accesibility
326      */

327     public void initAccessibility(){
328
329         interfaceTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_interfaceTextField"));
330         handlerImplTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_handlerImplTextField"));
331         stubTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_stubTextField"));
332         parsletTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_parsletTextField"));
333         parsletImplTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_parsletImplTextField"));
334         
335         saveTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_saveTextField"));
336         saveTextField.addFocusListener(A11YUtil.getA11YJTextFieldSupport());
337         
338         saveCheckBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_saveCheckBox"));
339         saveCheckBox.getAccessibleContext().setAccessibleName(Util.THIS.getString("ACSN_saveCheckBox"));
340         
341         this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_SAXGeneratorFilePanel"));
342     }
343 }
344
Popular Tags