KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tax > beans > customizer > TreeDocumentTypeCustomizer


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.tax.beans.customizer;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22
23 import org.netbeans.tax.TreeException;
24 import org.netbeans.tax.TreeDocumentType;
25
26 import org.netbeans.modules.xml.tax.util.TAXUtil;
27
28 /**
29  *
30  * @author Libor Kramolis
31  * @version 0.1
32  */

33 public class TreeDocumentTypeCustomizer extends AbstractTreeCustomizer {
34
35     /** Serial Version UID */
36     private static final long serialVersionUID = -6111125131099262050L;
37
38
39     //
40
// init
41
//
42

43     /** */
44     public TreeDocumentTypeCustomizer () {
45         super ();
46         
47         initComponents ();
48         nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); // NOI18N
49
systemLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlSystemID")); // NOI18N
50
publicLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlPublicID")); // NOI18N
51

52         initAccessibility ();
53     }
54     
55     
56     //
57
// itself
58
//
59

60     /**
61      */

62     protected final TreeDocumentType getDocumentType () {
63         return (TreeDocumentType)getTreeObject ();
64     }
65     
66     /**
67      */

68     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
69         if (initializing)
70             return;
71         
72         super.safePropertyChange (pche);
73         
74         if (pche.getPropertyName ().equals (TreeDocumentType.PROP_ELEMENT_NAME)) {
75             updateNameComponent ();
76         } else if (pche.getPropertyName ().equals (TreeDocumentType.PROP_PUBLIC_ID)) {
77             updatePublicIdComponent ();
78         } else if (pche.getPropertyName ().equals (TreeDocumentType.PROP_SYSTEM_ID)) {
79             updateSystemIdComponent ();
80         }
81     }
82     
83     /**
84      */

85     protected final void updateDocumentTypeName () {
86         try {
87             getDocumentType ().setElementName (nameField.getText ());
88         } catch (TreeException exc) {
89             updateNameComponent ();
90             TAXUtil.notifyTreeException (exc);
91         }
92     }
93     
94     /**
95      */

96     protected final void updateNameComponent () {
97         nameField.setText (getDocumentType ().getElementName ());
98     }
99     
100     /**
101      */

102     protected final void updateDocumentTypePublicId () {
103         try {
104             getDocumentType ().setPublicId (text2null (publicField.getText ()));
105         } catch (TreeException exc) {
106             updatePublicIdComponent ();
107             TAXUtil.notifyTreeException (exc);
108         }
109     }
110     
111     /**
112      */

113     protected final void updatePublicIdComponent () {
114         publicField.setText (null2text (getDocumentType ().getPublicId ()));
115     }
116     
117     /**
118      */

119     protected final void updateDocumentTypeSystemId () {
120         try {
121             String JavaDoc systemId = systemField.getText ();
122             if ( ( getDocumentType ().getPublicId () == null ) &&
123             ( "".equals (systemId) == false ) ) { // NOI18N
124
systemId = text2null (systemId);
125             }
126             getDocumentType ().setSystemId (systemId);
127         } catch (TreeException exc) {
128             updateSystemIdComponent ();
129             TAXUtil.notifyTreeException (exc);
130         }
131     }
132     
133     /**
134      */

135     protected final void updateSystemIdComponent () {
136         systemField.setText (null2text (getDocumentType ().getSystemId ()));
137     }
138     
139     
140     /**
141      */

142     protected final void initComponentValues () {
143         updateNameComponent ();
144         updatePublicIdComponent ();
145         updateSystemIdComponent ();
146     }
147     
148     /**
149      */

150     protected void updateReadOnlyStatus (boolean editable) {
151         nameField.setEditable (editable);
152         publicField.setEditable (editable);
153         systemField.setEditable (editable);
154     }
155     
156     
157     /** This method is called from within the constructor to
158      * initialize the form.
159      * WARNING: Do NOT modify this code. The content of this method is
160      * always regenerated by the FormEditor.
161      */

162     private void initComponents() {//GEN-BEGIN:initComponents
163
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
164
165         nameLabel = new javax.swing.JLabel JavaDoc();
166         nameField = new javax.swing.JTextField JavaDoc();
167         publicLabel = new javax.swing.JLabel JavaDoc();
168         publicField = new javax.swing.JTextField JavaDoc();
169         systemLabel = new javax.swing.JLabel JavaDoc();
170         systemField = new javax.swing.JTextField JavaDoc();
171         fillPanel = new javax.swing.JPanel JavaDoc();
172
173         setLayout(new java.awt.GridBagLayout JavaDoc());
174
175         nameLabel.setText(Util.THIS.getString ("PROP_xmlName"));
176         nameLabel.setLabelFor(nameField);
177         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
181         add(nameLabel, gridBagConstraints);
182
183         nameField.setColumns(20);
184         nameField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
185             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
186                 nameFieldActionPerformed(evt);
187             }
188         });
189
190         nameField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
191             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
192                 nameFieldFocusGained(evt);
193             }
194             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
195                 nameFieldFocusLost(evt);
196             }
197         });
198
199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
201         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
202         gridBagConstraints.weightx = 1.0;
203         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
204         add(nameField, gridBagConstraints);
205
206         publicLabel.setText(Util.THIS.getString ("PROP_xmlPublicID"));
207         publicLabel.setLabelFor(publicField);
208         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints.gridx = 0;
210         gridBagConstraints.gridy = 1;
211         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
214         add(publicLabel, gridBagConstraints);
215
216         publicField.setColumns(20);
217         publicField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
218             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
219                 publicFieldActionPerformed(evt);
220             }
221         });
222
223         publicField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
224             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
225                 publicFieldFocusGained(evt);
226             }
227             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
228                 publicFieldFocusLost(evt);
229             }
230         });
231
232         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints.gridx = 1;
234         gridBagConstraints.gridy = 1;
235         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
236         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
237         gridBagConstraints.weightx = 1.0;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
239         add(publicField, gridBagConstraints);
240
241         systemLabel.setText(Util.THIS.getString ("PROP_xmlSystemID"));
242         systemLabel.setLabelFor(systemField);
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 0;
245         gridBagConstraints.gridy = 2;
246         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
248         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
249         add(systemLabel, gridBagConstraints);
250
251         systemField.setColumns(20);
252         systemField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
253             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
254                 systemFieldActionPerformed(evt);
255             }
256         });
257
258         systemField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
259             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
260                 systemFieldFocusGained(evt);
261             }
262             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
263                 systemFieldFocusLost(evt);
264             }
265         });
266
267         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
268         gridBagConstraints.gridx = 1;
269         gridBagConstraints.gridy = 2;
270         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
271         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
272         gridBagConstraints.weightx = 1.0;
273         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
274         add(systemField, gridBagConstraints);
275
276         fillPanel.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
277         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
278         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
279         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
280         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
281         gridBagConstraints.weightx = 1.0;
282         gridBagConstraints.weighty = 1.0;
283         add(fillPanel, gridBagConstraints);
284
285     }//GEN-END:initComponents
286

287     private void systemFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_systemFieldFocusGained
288
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
289
systemField.selectAll();
290         }
291     }//GEN-LAST:event_systemFieldFocusGained
292

293     private void publicFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_publicFieldFocusGained
294
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
295
publicField.selectAll();
296         }
297
298     }//GEN-LAST:event_publicFieldFocusGained
299

300     private void nameFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusGained
301
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
302
nameField.selectAll();
303         }
304     }//GEN-LAST:event_nameFieldFocusGained
305

306     /**
307      */

308     private void publicFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_publicFieldFocusLost
309
// Add your handling code here:
310
updateDocumentTypePublicId ();
311     }//GEN-LAST:event_publicFieldFocusLost
312

313     /**
314      */

315     private void systemFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_systemFieldFocusLost
316
// Add your handling code here:
317
updateDocumentTypeSystemId ();
318     }//GEN-LAST:event_systemFieldFocusLost
319

320     /**
321      */

322     private void nameFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusLost
323
// Add your handling code here:
324
updateDocumentTypeName ();
325     }//GEN-LAST:event_nameFieldFocusLost
326

327     /**
328      */

329     private void publicFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_publicFieldActionPerformed
330
// Add your handling code here:
331
updateDocumentTypePublicId ();
332     }//GEN-LAST:event_publicFieldActionPerformed
333

334     /**
335      */

336     private void systemFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_systemFieldActionPerformed
337
// Add your handling code here:
338
updateDocumentTypeSystemId ();
339     }//GEN-LAST:event_systemFieldActionPerformed
340

341     /**
342      */

343     private void nameFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldActionPerformed
344
// Add your handling code here:
345
updateDocumentTypeName ();
346     }//GEN-LAST:event_nameFieldActionPerformed
347

348     // Variables declaration - do not modify//GEN-BEGIN:variables
349
private javax.swing.JLabel JavaDoc nameLabel;
350     private javax.swing.JLabel JavaDoc publicLabel;
351     private javax.swing.JTextField JavaDoc nameField;
352     private javax.swing.JTextField JavaDoc publicField;
353     private javax.swing.JLabel JavaDoc systemLabel;
354     private javax.swing.JTextField JavaDoc systemField;
355     private javax.swing.JPanel JavaDoc fillPanel;
356     // End of variables declaration//GEN-END:variables
357

358     /** Initialize accesibility
359      */

360     public void initAccessibility (){
361         
362         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeDocumentTypeCustomizer"));
363         
364         nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField4"));
365         systemField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_systemField2"));
366         publicField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_publicField3"));
367     }
368 }
369
Popular Tags