KickJava   Java API By Example, From Geeks To Geeks.

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


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.TreeCharacterReference;
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 TreeCharacterReferenceCustomizer extends AbstractTreeCustomizer {
34
35     /** Serial Version UID */
36     private static final long serialVersionUID =-7799211701822931611L;
37
38
39     //
40
// init
41
//
42

43     /** Creates new customizer TreeCharacterReferenceCustomizer. */
44     public TreeCharacterReferenceCustomizer () {
45         super ();
46         
47         initComponents ();
48         nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_CharRef_name")); // NOI18N
49

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

58     protected TreeCharacterReference getCharacterReference () {
59         return (TreeCharacterReference)getTreeObject ();
60     }
61     
62     /**
63      * It will be called from AWT thread and it will never be caller during init stage.
64      */

65     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
66         super.safePropertyChange (pche);
67         
68         if (pche.getPropertyName ().equals (TreeCharacterReference.PROP_NAME)) {
69             updateNameComponent ();
70         }
71     }
72     
73     /**
74      */

75     protected void updateNameComponent () {
76         nameField.setText (getCharacterReference ().getName ());
77     }
78     
79     /**
80      */

81     protected void updateCharacterReferenceName () {
82         try {
83             getCharacterReference ().setName (nameField.getText ());
84         } catch (TreeException exc) {
85             updateNameComponent ();
86             TAXUtil.notifyTreeException (exc);
87         }
88     }
89     
90     /**
91      */

92     protected void initComponentValues () {
93         updateNameComponent ();
94     }
95     
96     /**
97      */

98     protected void updateReadOnlyStatus (boolean editable) {
99         nameField.setEditable (editable);
100     }
101     
102     /** This method is called from within the constructor to
103      * initialize the form.
104      * WARNING: Do NOT modify this code. The content of this method is
105      * always regenerated by the FormEditor.
106      */

107     private void initComponents() {//GEN-BEGIN:initComponents
108
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
109
110         nameLabel = new javax.swing.JLabel JavaDoc();
111         nameField = new javax.swing.JTextField JavaDoc();
112         fillPanel = new javax.swing.JPanel JavaDoc();
113
114         setLayout(new java.awt.GridBagLayout JavaDoc());
115
116         nameLabel.setText(Util.THIS.getString ("PROP_CharRef_name"));
117         nameLabel.setLabelFor(nameField);
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 0;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
123         add(nameLabel, gridBagConstraints);
124
125         nameField.setColumns(20);
126         nameField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
127             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
128                 nameFieldActionPerformed(evt);
129             }
130         });
131
132         nameField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
133             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
134                 nameFieldFocusGained(evt);
135             }
136             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
137                 nameFieldFocusLost(evt);
138             }
139         });
140
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 1;
143         gridBagConstraints.gridy = 0;
144         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
145         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146         gridBagConstraints.weightx = 1.0;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
148         add(nameField, gridBagConstraints);
149
150         fillPanel.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
153         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
154         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
155         gridBagConstraints.weightx = 1.0;
156         gridBagConstraints.weighty = 1.0;
157         add(fillPanel, gridBagConstraints);
158
159     }//GEN-END:initComponents
160

161     private void nameFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusGained
162
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
163
nameField.selectAll();
164         }
165     }//GEN-LAST:event_nameFieldFocusGained
166

167     private void nameFieldFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusLost
168
// Add your handling code here:
169
updateCharacterReferenceName ();
170     }//GEN-LAST:event_nameFieldFocusLost
171

172     private void nameFieldActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldActionPerformed
173
// Add your handling code here:
174
updateCharacterReferenceName ();
175     }//GEN-LAST:event_nameFieldActionPerformed
176

177     // Variables declaration - do not modify//GEN-BEGIN:variables
178
private javax.swing.JLabel JavaDoc nameLabel;
179     private javax.swing.JTextField JavaDoc nameField;
180     private javax.swing.JPanel JavaDoc fillPanel;
181     // End of variables declaration//GEN-END:variables
182

183     /** Initialize accesibility
184      */

185     public void initAccessibility (){
186         
187         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeCharacterReferenceCustomizer"));
188         nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField5"));
189     }
190 }
191
Popular Tags