KickJava   Java API By Example, From Geeks To Geeks.

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


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.TreeDocument;
24 import org.netbeans.tax.TreeException;
25
26 import org.netbeans.modules.xml.tax.beans.editor.VersionEditor;
27 import org.netbeans.modules.xml.tax.beans.editor.EncodingEditor;
28 import org.netbeans.modules.xml.tax.beans.editor.StandaloneEditor;
29 import org.netbeans.modules.xml.tax.util.TAXUtil;
30
31 /**
32  *
33  * @author Libor Kramolis
34  * @version 0.1
35  */

36 public class TreeDocumentCustomizer extends AbstractTreeCustomizer {
37
38     /** Serial Version UID */
39     private static final long serialVersionUID = 8592875472261625357L;
40     
41     
42     //
43
// init
44
//
45

46     /** */
47     public TreeDocumentCustomizer () {
48         super ();
49         
50         initComponents ();
51         
52         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeDocumentCustomizer::init"); // NOI18N
53

54         versionLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_document_version")); // NOI18N
55
encodingLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_document_encoding")); // NOI18N
56
standaloneLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_document_standalone")); // NOI18N
57

58         initAccessibility ();
59     }
60     
61     
62     //
63
// itself
64
//
65

66     /**
67      */

68     protected final TreeDocument getDocument () {
69         return (TreeDocument)getTreeObject ();
70     }
71     
72     /**
73      */

74     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
75         super.safePropertyChange (pche);
76         
77         if (pche.getPropertyName ().equals (TreeDocument.PROP_VERSION)) {
78             updateVersionComponent ();
79         } else if (pche.getPropertyName ().equals (TreeDocument.PROP_ENCODING)) {
80             updateEncodingComponent ();
81         } else if (pche.getPropertyName ().equals (TreeDocument.PROP_STANDALONE)) {
82             updateStandaloneComponent ();
83         }
84     }
85     
86     
87     /**
88      */

89     protected final void updateDocumentVersion () {
90         if ( cbVersion.getSelectedItem () == null ) {
91             return;
92         }
93         
94         try {
95             getDocument ().setVersion (text2null ((String JavaDoc) cbVersion.getSelectedItem ()));
96         } catch (TreeException exc) {
97             updateVersionComponent ();
98             TAXUtil.notifyTreeException (exc);
99         }
100         
101     }
102     
103     /**
104      */

105     protected final void updateVersionComponent () {
106         cbVersion.setSelectedItem (null2text (getDocument ().getVersion ()));
107     }
108     
109     /**
110      */

111     protected final void updateDocumentEncoding () {
112         if ( cbEncoding.getSelectedItem () == null ) {
113             return;
114         }
115         
116         try {
117             getDocument ().setEncoding (text2null ((String JavaDoc) cbEncoding.getSelectedItem ()));
118         } catch (TreeException exc) {
119             updateEncodingComponent ();
120             TAXUtil.notifyTreeException (exc);
121         }
122         
123     }
124     
125     /**
126      */

127     protected final void updateEncodingComponent () {
128         cbEncoding.setSelectedItem (null2text (getDocument ().getEncoding ()));
129     }
130     
131     /**
132      */

133     protected final void updateDocumentStandalone () {
134         if ( cbStandalone.getSelectedItem () == null ) {
135             return;
136         }
137         
138         try {
139             getDocument ().setStandalone (text2null ((String JavaDoc) cbStandalone.getSelectedItem ()));
140         } catch (TreeException exc) {
141             updateStandaloneComponent ();
142             TAXUtil.notifyTreeException (exc);
143         }
144     }
145     
146     /**
147      */

148     protected final void updateStandaloneComponent () {
149         cbStandalone.setSelectedItem (null2text (getDocument ().getStandalone ()));
150     }
151     
152     /**
153      */

154     protected final void initComponentValues () {
155         updateVersionComponent ();
156         updateEncodingComponent ();
157         updateStandaloneComponent ();
158     }
159     
160     
161     /**
162      */

163     protected final void updateReadOnlyStatus (boolean editable) {
164         
165         cbVersion.setEnabled (editable);
166         cbEncoding.setEnabled (editable);
167         cbStandalone.setEnabled (editable);
168     }
169     
170     /** This method is called from within the constructor to
171      * initialize the form.
172      * WARNING: Do NOT modify this code. The content of this method is
173      * always regenerated by the FormEditor.
174      */

175     private void initComponents() {//GEN-BEGIN:initComponents
176
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
177
178         versionLabel = new javax.swing.JLabel JavaDoc();
179         cbVersion = new javax.swing.JComboBox JavaDoc();
180         encodingLabel = new javax.swing.JLabel JavaDoc();
181         cbEncoding = new javax.swing.JComboBox JavaDoc();
182         standaloneLabel = new javax.swing.JLabel JavaDoc();
183         cbStandalone = new javax.swing.JComboBox JavaDoc();
184         fillPanel = new javax.swing.JPanel JavaDoc();
185
186         setLayout(new java.awt.GridBagLayout JavaDoc());
187
188         versionLabel.setText(Util.THIS.getString ("PROP_document_version"));
189         versionLabel.setLabelFor(cbVersion);
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
193         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
194         add(versionLabel, gridBagConstraints);
195
196         cbVersion.setModel((new javax.swing.DefaultComboBoxModel JavaDoc(VersionEditor.getItems())));
197         cbVersion.addActionListener(new java.awt.event.ActionListener JavaDoc() {
198             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
199                 cbVersionActionPerformed(evt);
200             }
201         });
202
203         cbVersion.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
204             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
205                 cbVersionFocusLost(evt);
206             }
207         });
208
209         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
210         gridBagConstraints.gridx = 1;
211         gridBagConstraints.gridy = 0;
212         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
213         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
214         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
215         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
216         gridBagConstraints.weightx = 1.0;
217         add(cbVersion, gridBagConstraints);
218
219         encodingLabel.setText(Util.THIS.getString ("PROP_document_encoding"));
220         encodingLabel.setLabelFor(cbEncoding);
221         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
222         gridBagConstraints.gridx = 0;
223         gridBagConstraints.gridy = 1;
224         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
225         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
226         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
227         add(encodingLabel, gridBagConstraints);
228
229         cbEncoding.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(EncodingEditor.getItems())
230         );
231         cbEncoding.setEditable(true);
232         cbEncoding.addActionListener(new java.awt.event.ActionListener JavaDoc() {
233             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
234                 cbEncodingActionPerformed(evt);
235             }
236         });
237
238         cbEncoding.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
239             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
240                 cbEncodingFocusLost(evt);
241             }
242         });
243
244         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
245         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
246         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
248         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
249         add(cbEncoding, gridBagConstraints);
250
251         standaloneLabel.setText(Util.THIS.getString ("PROP_document_standalone"));
252         standaloneLabel.setLabelFor(cbStandalone);
253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 2;
256         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
257         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
258         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
259         add(standaloneLabel, gridBagConstraints);
260
261         cbStandalone.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(StandaloneEditor.getItems()));
262         cbStandalone.addActionListener(new java.awt.event.ActionListener JavaDoc() {
263             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
264                 cbStandaloneActionPerformed(evt);
265             }
266         });
267
268         cbStandalone.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
269             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
270                 cbStandaloneFocusLost(evt);
271             }
272         });
273
274         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
275         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
276         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
277         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
278         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
279         add(cbStandalone, gridBagConstraints);
280
281         fillPanel.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
282         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
283         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
284         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
285         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
286         gridBagConstraints.weightx = 1.0;
287         gridBagConstraints.weighty = 1.0;
288         add(fillPanel, gridBagConstraints);
289
290     }//GEN-END:initComponents
291

292     private void cbStandaloneFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_cbStandaloneFocusLost
293
// Add your handling code here:
294
updateDocumentStandalone ();
295     }//GEN-LAST:event_cbStandaloneFocusLost
296

297     private void cbStandaloneActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbStandaloneActionPerformed
298
// Add your handling code here:
299
updateDocumentStandalone ();
300     }//GEN-LAST:event_cbStandaloneActionPerformed
301

302     private void cbEncodingFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_cbEncodingFocusLost
303
// Add your handling code here:
304
updateDocumentEncoding ();
305     }//GEN-LAST:event_cbEncodingFocusLost
306

307     private void cbEncodingActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbEncodingActionPerformed
308
// Add your handling code here:
309
updateDocumentEncoding ();
310     }//GEN-LAST:event_cbEncodingActionPerformed
311

312     private void cbVersionFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_cbVersionFocusLost
313
// Add your handling code here:
314
updateDocumentVersion ();
315     }//GEN-LAST:event_cbVersionFocusLost
316

317     private void cbVersionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbVersionActionPerformed
318
// Add your handling code here:
319
updateDocumentVersion ();
320     }//GEN-LAST:event_cbVersionActionPerformed
321

322     // Variables declaration - do not modify//GEN-BEGIN:variables
323
private javax.swing.JLabel JavaDoc standaloneLabel;
324     private javax.swing.JComboBox JavaDoc cbVersion;
325     private javax.swing.JLabel JavaDoc versionLabel;
326     private javax.swing.JComboBox JavaDoc cbEncoding;
327     private javax.swing.JComboBox JavaDoc cbStandalone;
328     private javax.swing.JLabel JavaDoc encodingLabel;
329     private javax.swing.JPanel JavaDoc fillPanel;
330     // End of variables declaration//GEN-END:variables
331

332     /** Initialize accesibility
333      */

334     public void initAccessibility (){
335         
336         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeDocumentCustomizer"));
337         
338         cbVersion.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbVersion"));
339         cbEncoding.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbEncoding1"));
340         cbStandalone.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbStandalone"));
341     }
342 }
343
Popular Tags