KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.Component JavaDoc;
22 import java.awt.BorderLayout JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24
25 import org.netbeans.tax.TreeNamedObjectMap;
26 import org.netbeans.tax.TreeElement;
27 import org.netbeans.tax.TreeException;
28
29 import org.netbeans.modules.xml.tax.beans.Lib;
30 import org.netbeans.modules.xml.tax.util.TAXUtil;
31
32 /**
33  *
34  * @author Libor Kramolis
35  * @version 0.1
36  */

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

47     /** */
48     public TreeElementCustomizer () {
49         super ();
50         
51         initComponents ();
52         nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); // NOI18N
53
tableLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_element_attributelist_label")); // NOI18N
54
initAccessibility ();
55     }
56     
57     
58     //
59
// itself
60
//
61

62     /**
63      */

64     protected final TreeElement getElement () {
65         return (TreeElement)getTreeObject ();
66     }
67     
68     /**
69      */

70     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
71         super.safePropertyChange (pche);
72         
73         if (pche.getPropertyName ().equals (TreeElement.PROP_TAG_NAME)) {
74             updateNameComponent ();
75         }
76     }
77     
78     /**
79      */

80     protected final void updateElementName () {
81         try {
82             getElement ().setQName (nameField.getText ());
83         } catch (TreeException exc) {
84             updateNameComponent ();
85             TAXUtil.notifyTreeException (exc);
86         }
87     }
88     
89     /**
90      */

91     protected final void updateNameComponent () {
92         nameField.setText (getElement ().getQName ());
93     }
94     
95     /**
96      */

97     protected final void initComponentValues () {
98         updateNameComponent ();
99     }
100     
101     /**
102      */

103     protected void ownInitComponents () {
104         TreeNamedObjectMap attributes = getElement ().getAttributes ();
105         
106         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeElementCustomizer::ownInitComponents: attributes = " + attributes); // NOI18N
107

108         attributesCustomizer = Lib.getCustomizer (TreeElement.class, attributes, "attributes"); // "attributes" - name of TreeElement property // NOI18N
109

110         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeElementCustomizer::ownInitComponents: attributesCustomizer = " + attributesCustomizer); // NOI18N
111

112         if (attributesCustomizer != null) {
113             attributeListPanel.add (attributesCustomizer, BorderLayout.CENTER);
114         }
115     }
116     
117     /**
118      */

119     protected void updateReadOnlyStatus (boolean editable) {
120         nameField.setEditable (editable);
121         if ( attributesCustomizer != null )
122             attributesCustomizer.setEnabled (editable); //???
123
}
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         jPanel2 = new javax.swing.JPanel JavaDoc();
137         jPanel1 = new javax.swing.JPanel JavaDoc();
138         tableLabel = new javax.swing.JLabel JavaDoc();
139         attributeListPanel = new javax.swing.JPanel JavaDoc();
140
141         setLayout(new java.awt.GridBagLayout JavaDoc());
142
143         setPreferredSize(new java.awt.Dimension JavaDoc(350, 230));
144         nameLabel.setText(Util.THIS.getString ("PROP_xmlName"));
145         nameLabel.setLabelFor(nameField);
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridy = 0;
148         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
150         add(nameLabel, gridBagConstraints);
151
152         nameField.setColumns(20);
153         nameField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
154             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
155                 nameFieldActionPerformed(evt);
156             }
157         });
158
159         nameField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
160             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
161                 nameFieldFocusGained(evt);
162             }
163             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
164                 nameFieldFocusLost(evt);
165             }
166         });
167
168         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
169         gridBagConstraints.gridy = 0;
170         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
171         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172         gridBagConstraints.weightx = 1.0;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
174         add(nameField, gridBagConstraints);
175
176         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
177
178         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
179
180         tableLabel.setText(Util.THIS.getString ("TEXT_element_attributelist_label"));
181         tableLabel.setLabelFor(attributeListPanel);
182         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
183         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
184         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
185         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
187         gridBagConstraints.weightx = 1.0;
188         gridBagConstraints.weighty = 1.0;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
190         jPanel1.add(tableLabel, gridBagConstraints);
191
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
195         jPanel2.add(jPanel1, gridBagConstraints);
196
197         attributeListPanel.setLayout(new java.awt.BorderLayout JavaDoc());
198
199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridx = 0;
201         gridBagConstraints.gridy = 1;
202         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
203         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
205         gridBagConstraints.weightx = 1.0;
206         gridBagConstraints.weighty = 1.0;
207         jPanel2.add(attributeListPanel, gridBagConstraints);
208
209         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
210         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
211         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
212         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
213         gridBagConstraints.weightx = 1.0;
214         gridBagConstraints.weighty = 1.0;
215         add(jPanel2, gridBagConstraints);
216
217     }//GEN-END:initComponents
218

219     private void nameFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusGained
220
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
221
nameField.selectAll();
222         }
223     }//GEN-LAST:event_nameFieldFocusGained
224

225     /**
226      */

227     private void nameFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusLost
228
// Add your handling code here:
229
updateElementName ();
230     }//GEN-LAST:event_nameFieldFocusLost
231

232     /**
233      */

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

239     // Variables declaration - do not modify//GEN-BEGIN:variables
240
private javax.swing.JLabel JavaDoc nameLabel;
241     private javax.swing.JLabel JavaDoc tableLabel;
242     private javax.swing.JTextField JavaDoc nameField;
243     private javax.swing.JPanel JavaDoc attributeListPanel;
244     private javax.swing.JPanel JavaDoc jPanel2;
245     private javax.swing.JPanel JavaDoc jPanel1;
246     // End of variables declaration//GEN-END:variables
247

248     private Component JavaDoc attributesCustomizer;
249     
250     /** Initialize accesibility
251      */

252     public void initAccessibility (){
253         
254         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeElementCustomizer"));
255         nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField7"));
256     }
257     
258 }
259
Popular Tags