KickJava   Java API By Example, From Geeks To Geeks.

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


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.TreeDTD;
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.util.TAXUtil;
29
30 /**
31  *
32  * @author Libor Kramolis
33  * @version 0.1
34  */

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

45     /** */
46     public TreeDTDCustomizer () {
47         super ();
48         
49         initComponents ();
50         versionLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtd_version")); // NOI18N
51
encodingLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtd_encoding")); // NOI18N
52

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

61     /**
62      */

63     protected final TreeDTD getDTD () {
64         return (TreeDTD)getTreeObject ();
65     }
66     
67     /**
68      */

69     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
70         super.safePropertyChange (pche);
71         
72         if (pche.getPropertyName ().equals (TreeDTD.PROP_VERSION)) {
73             updateVersionComponent ();
74         } else if (pche.getPropertyName ().equals (TreeDTD.PROP_ENCODING)) {
75             updateEncodingComponent ();
76         }
77     }
78     
79     /**
80      */

81     protected final void updateDTDVersion () {
82         if ( cbVersion.getSelectedItem () == null ) {
83             return;
84         }
85         
86         try {
87             getDTD ().setVersion (text2null ((String JavaDoc) cbVersion.getSelectedItem ()));
88         } catch (TreeException exc) {
89             updateVersionComponent ();
90             TAXUtil.notifyTreeException (exc);
91         }
92     }
93     
94     /**
95      */

96     protected final void updateVersionComponent () {
97         cbVersion.setSelectedItem (null2text (getDTD ().getVersion ()));
98     }
99     
100     /**
101      */

102     protected final void updateDTDEncoding () {
103         if ( cbEncoding.getSelectedItem () == null ) {
104             return;
105         }
106         
107         try {
108             getDTD ().setEncoding (text2null ((String JavaDoc) cbEncoding.getSelectedItem ()));
109         } catch (TreeException exc) {
110             updateEncodingComponent ();
111             TAXUtil.notifyTreeException (exc);
112         }
113     }
114     
115     /**
116      */

117     protected final void updateEncodingComponent () {
118         cbEncoding.setSelectedItem (null2text (getDTD ().getEncoding ()));
119     }
120     
121     /**
122      */

123     protected void initComponentValues () {
124         updateVersionComponent ();
125         updateEncodingComponent ();
126     }
127     
128     
129     /**
130      */

131     protected void updateReadOnlyStatus (boolean editable) {
132         cbVersion.setEnabled (editable);
133         cbEncoding.setEnabled (editable);
134     }
135     
136     
137     /** This method is called from within the constructor to
138      * initialize the form.
139      * WARNING: Do NOT modify this code. The content of this method is
140      * always regenerated by the FormEditor.
141      */

142     private void initComponents() {//GEN-BEGIN:initComponents
143
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
144
145         versionLabel = new javax.swing.JLabel JavaDoc();
146         cbVersion = new javax.swing.JComboBox JavaDoc();
147         encodingLabel = new javax.swing.JLabel JavaDoc();
148         cbEncoding = new javax.swing.JComboBox JavaDoc();
149         fillPanel = new javax.swing.JPanel JavaDoc();
150
151         setLayout(new java.awt.GridBagLayout JavaDoc());
152
153         versionLabel.setText(Util.THIS.getString ("PROP_dtd_version"));
154         versionLabel.setLabelFor(cbVersion);
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
158         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
159         add(versionLabel, gridBagConstraints);
160
161         cbVersion.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(VersionEditor.getItems()));
162         cbVersion.addActionListener(new java.awt.event.ActionListener JavaDoc() {
163             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
164                 cbVersionActionPerformed(evt);
165             }
166         });
167
168         cbVersion.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
169             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
170                 cbVersionFocusLost(evt);
171             }
172         });
173
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 1;
176         gridBagConstraints.gridy = 0;
177         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
180         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
181         add(cbVersion, gridBagConstraints);
182
183         encodingLabel.setText(Util.THIS.getString ("PROP_dtd_encoding"));
184         encodingLabel.setLabelFor(cbEncoding);
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.gridx = 0;
187         gridBagConstraints.gridy = 1;
188         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
190         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
191         add(encodingLabel, gridBagConstraints);
192
193         cbEncoding.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(EncodingEditor.getItems()));
194         cbEncoding.setEditable(true);
195         cbEncoding.addActionListener(new java.awt.event.ActionListener JavaDoc() {
196             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
197                 cbEncodingActionPerformed(evt);
198             }
199         });
200
201         cbEncoding.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
202             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
203                 cbEncodingFocusLost(evt);
204             }
205         });
206
207         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
208         gridBagConstraints.gridx = 1;
209         gridBagConstraints.gridy = 1;
210         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
211         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
213         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
214         add(cbEncoding, gridBagConstraints);
215
216         fillPanel.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
217         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
218         gridBagConstraints.gridx = 0;
219         gridBagConstraints.gridy = 2;
220         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
221         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
222         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
223         gridBagConstraints.weightx = 1.0;
224         gridBagConstraints.weighty = 1.0;
225         add(fillPanel, gridBagConstraints);
226
227     }//GEN-END:initComponents
228

229     private void cbEncodingFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_cbEncodingFocusLost
230
// Add your handling code here:
231
updateDTDEncoding ();
232     }//GEN-LAST:event_cbEncodingFocusLost
233

234     private void cbEncodingActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbEncodingActionPerformed
235
// Add your handling code here:
236
updateDTDEncoding ();
237     }//GEN-LAST:event_cbEncodingActionPerformed
238

239     private void cbVersionFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_cbVersionFocusLost
240
// Add your handling code here:
241
updateDTDVersion ();
242     }//GEN-LAST:event_cbVersionFocusLost
243

244     private void cbVersionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbVersionActionPerformed
245
// Add your handling code here:
246
updateDTDVersion ();
247     }//GEN-LAST:event_cbVersionActionPerformed
248

249     // Variables declaration - do not modify//GEN-BEGIN:variables
250
private javax.swing.JComboBox JavaDoc cbVersion;
251     private javax.swing.JLabel JavaDoc versionLabel;
252     private javax.swing.JComboBox JavaDoc cbEncoding;
253     private javax.swing.JLabel JavaDoc encodingLabel;
254     private javax.swing.JPanel JavaDoc fillPanel;
255     // End of variables declaration//GEN-END:variables
256

257     /** Initialize accesibility
258      */

259     public void initAccessibility (){
260         
261         cbVersion.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbVersion"));
262         cbEncoding.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_cbEncoding"));
263         
264         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeDTDCustomizer"));
265     }
266 }
267
Popular Tags