KickJava   Java API By Example, From Geeks To Geeks.

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


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.TreeElementDecl;
24 import org.netbeans.tax.TreeException;
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 TreeElementDeclCustomizer extends AbstractTreeCustomizer {
34
35     /** Serial Version UID */
36     private static final long serialVersionUID = -4904653355576437639L;
37
38
39     //
40
// init
41
//
42

43     /** */
44     public TreeElementDeclCustomizer () {
45         super ();
46         
47         initComponents ();
48         nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); // NOI18N
49
contentLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtdContent")); // NOI18N
50

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

59     /**
60      */

61     protected final TreeElementDecl getElementDecl () {
62         return (TreeElementDecl)getTreeObject ();
63     }
64     
65     /**
66      */

67     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
68         super.safePropertyChange (pche);
69         
70         if (pche.getPropertyName ().equals (TreeElementDecl.PROP_NAME)) {
71             updateNameComponent ();
72         } else if (pche.getPropertyName ().equals (TreeElementDecl.PROP_CONTENT_TYPE)) {
73             updateContentTypeComponent ();
74         }
75     }
76     
77     /**
78      */

79     protected final void updateElementDeclName () {
80         try {
81             getElementDecl ().setName (nameField.getText ());
82         } catch (TreeException exc) {
83             updateNameComponent ();
84             TAXUtil.notifyTreeException (exc);
85         }
86     }
87     
88     /**
89      */

90     protected final void updateNameComponent () {
91         nameField.setText (getElementDecl ().getName ());
92     }
93     
94     /**
95      */

96     protected final void updateElementDeclContentType () {
97         try {
98             getElementDecl ().setContentType (contentField.getText ());
99         } catch (TreeException exc) {
100             updateContentTypeComponent ();
101             TAXUtil.notifyTreeException (exc);
102         }
103     }
104     
105     /**
106      */

107     protected final void updateContentTypeComponent () {
108         contentField.setText (getElementDecl ().getContentType ().toString ());
109     }
110     
111     /**
112      */

113     protected final void initComponentValues () {
114         updateNameComponent ();
115         updateContentTypeComponent ();
116     }
117     
118     
119     /**
120      */

121     protected void updateReadOnlyStatus (boolean editable) {
122         nameField.setEditable (editable);
123         contentField.setEditable (editable);
124     }
125     
126     /** This method is called from within the constructor to
127      * initialize the form.
128      * WARNING: Do NOT modify this code. The content of this method is
129      * always regenerated by the FormEditor.
130      */

131     private void initComponents() {//GEN-BEGIN:initComponents
132
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
133
134         nameLabel = new javax.swing.JLabel JavaDoc();
135         nameField = new javax.swing.JTextField JavaDoc();
136         contentLabel = new javax.swing.JLabel JavaDoc();
137         contentField = new javax.swing.JTextField JavaDoc();
138         fillPanel = new javax.swing.JPanel JavaDoc();
139
140         setLayout(new java.awt.GridBagLayout JavaDoc());
141
142         nameLabel.setText(Util.THIS.getString ("PROP_xmlName"));
143         nameLabel.setLabelFor(nameField);
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 0;
146         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
149         add(nameLabel, gridBagConstraints);
150
151         nameField.setColumns(20);
152         nameField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
153             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
154                 nameFieldFocusGained(evt);
155             }
156         });
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridx = 1;
160         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
163         gridBagConstraints.weightx = 1.0;
164         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
165         add(nameField, gridBagConstraints);
166
167         contentLabel.setText(Util.THIS.getString ("PROP_dtdContent"));
168         contentLabel.setLabelFor(contentField);
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 1;
172         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
174         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
175         add(contentLabel, gridBagConstraints);
176
177         contentField.setColumns(20);
178         contentField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
179             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
180                 contentFieldFocusGained(evt);
181             }
182         });
183
184         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridx = 1;
186         gridBagConstraints.gridy = 1;
187         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
188         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
190         add(contentField, gridBagConstraints);
191
192         fillPanel.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridx = 0;
195         gridBagConstraints.gridy = 2;
196         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
197         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
198         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
199         gridBagConstraints.weightx = 1.0;
200         gridBagConstraints.weighty = 1.0;
201         add(fillPanel, gridBagConstraints);
202
203     }//GEN-END:initComponents
204

205     private void contentFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_contentFieldFocusGained
206
// Accessibility:
207
contentField.selectAll ();
208     }//GEN-LAST:event_contentFieldFocusGained
209

210     private void nameFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusGained
211
// Accessibility:
212
nameField.selectAll ();
213     }//GEN-LAST:event_nameFieldFocusGained
214

215     // Variables declaration - do not modify//GEN-BEGIN:variables
216
private javax.swing.JLabel JavaDoc nameLabel;
217     private javax.swing.JLabel JavaDoc contentLabel;
218     private javax.swing.JTextField JavaDoc nameField;
219     private javax.swing.JTextField JavaDoc contentField;
220     private javax.swing.JPanel JavaDoc fillPanel;
221     // End of variables declaration//GEN-END:variables
222

223     
224     /** Initialize accesibility
225      */

226     public void initAccessibility (){
227         
228         nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField"));
229         nameField.selectAll ();
230         contentField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_contentField"));
231         contentField.selectAll ();
232         
233         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeElementDeclCustomizer"));
234     }
235 }
236
Popular Tags