KickJava   Java API By Example, From Geeks To Geeks.

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


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

43     /** */
44     public TreeProcessingInstructionCustomizer () {
45         super ();
46         
47         initComponents ();
48         targetLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlTarget")); // NOI18N
49

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

58     /**
59      */

60     protected final TreeProcessingInstruction getProcessingInstruction () {
61         return (TreeProcessingInstruction)getTreeObject ();
62     }
63     
64     /**
65      */

66     protected final void safePropertyChange (PropertyChangeEvent JavaDoc pche) {
67         super.safePropertyChange (pche);
68         
69         if (pche.getPropertyName ().equals (TreeProcessingInstruction.PROP_TARGET)) {
70             updateTargetComponent ();
71         } else if (pche.getPropertyName ().equals (TreeProcessingInstruction.PROP_DATA)) {
72             updateDataComponent ();
73         }
74     }
75     
76     /**
77      */

78     protected final void updateProcessingInstructionTarget () {
79         try {
80             getProcessingInstruction ().setTarget (targetField.getText ());
81         } catch (TreeException exc) {
82             updateTargetComponent ();
83             TAXUtil.notifyTreeException (exc);
84         }
85     }
86     
87     /**
88      */

89     protected final void updateTargetComponent () {
90         targetField.setText (getProcessingInstruction ().getTarget ());
91     }
92     
93     /**
94      */

95     protected final void updateProcessingInstructionData () {
96         try {
97             getProcessingInstruction ().setData (dataTextArea.getText ());
98         } catch (TreeException exc) {
99             updateDataComponent ();
100             TAXUtil.notifyTreeException (exc);
101         }
102     }
103     
104     /**
105      */

106     protected final void updateDataComponent () {
107         dataTextArea.setText (getProcessingInstruction ().getData ());
108     }
109     
110     /**
111      */

112     protected final void initComponentValues () {
113         updateTargetComponent ();
114         updateDataComponent ();
115     }
116     
117     
118     /**
119      */

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

130     private void initComponents() {//GEN-BEGIN:initComponents
131
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
132
133         targetLabel = new javax.swing.JLabel JavaDoc();
134         targetField = new javax.swing.JTextField JavaDoc();
135         dataPanel = new javax.swing.JPanel JavaDoc();
136         dataScroll = new javax.swing.JScrollPane JavaDoc();
137         dataTextArea = new javax.swing.JTextArea JavaDoc();
138
139         setLayout(new java.awt.GridBagLayout JavaDoc());
140
141         setPreferredSize(new java.awt.Dimension JavaDoc(350, 230));
142         targetLabel.setText(Util.THIS.getString ("PROP_xmlTarget"));
143         targetLabel.setLabelFor(targetField);
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 0;
146         gridBagConstraints.gridy = 0;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
148         add(targetLabel, gridBagConstraints);
149
150         targetField.setColumns(20);
151         targetField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
152             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
153                 targetFieldActionPerformed(evt);
154             }
155         });
156
157         targetField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
158             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
159                 targetFieldFocusGained(evt);
160             }
161             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
162                 targetFieldFocusLost(evt);
163             }
164         });
165
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridx = 1;
168         gridBagConstraints.gridy = 0;
169         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
170         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171         gridBagConstraints.weightx = 1.0;
172         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
173         add(targetField, gridBagConstraints);
174
175         dataPanel.setLayout(new java.awt.BorderLayout JavaDoc());
176
177         dataPanel.setPreferredSize(new java.awt.Dimension JavaDoc(350, 230));
178         dataTextArea.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
179             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
180                 dataTextAreaFocusGained(evt);
181             }
182             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
183                 dataTextAreaFocusLost(evt);
184             }
185         });
186
187         dataTextArea.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
188             public void keyPressed(java.awt.event.KeyEvent JavaDoc evt) {
189                 dataTextAreaKeyPressed(evt);
190             }
191         });
192
193         dataScroll.setViewportView(dataTextArea);
194
195         dataPanel.add(dataScroll, java.awt.BorderLayout.CENTER);
196
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
199         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
201         gridBagConstraints.weighty = 1.0;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
203         add(dataPanel, gridBagConstraints);
204
205     }//GEN-END:initComponents
206

207     private void dataTextAreaFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_dataTextAreaFocusGained
208
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
209
dataTextArea.selectAll();
210         }
211     }//GEN-LAST:event_dataTextAreaFocusGained
212

213     private void targetFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_targetFieldFocusGained
214
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
215
targetField.selectAll();
216         }
217
218     }//GEN-LAST:event_targetFieldFocusGained
219

220     private void dataTextAreaKeyPressed(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_dataTextAreaKeyPressed
221
// Add your handling code here:
222
if ( applyKeyPressed (evt) ) {
223             updateProcessingInstructionData ();
224         }
225     }//GEN-LAST:event_dataTextAreaKeyPressed
226

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

232     /**
233      */

234     private void targetFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_targetFieldFocusLost
235
// Add your handling code here:
236
updateProcessingInstructionTarget ();
237     }//GEN-LAST:event_targetFieldFocusLost
238

239     
240     /**
241      */

242     private void targetFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_targetFieldActionPerformed
243
// Add your handling code here:
244
updateProcessingInstructionTarget ();
245     }//GEN-LAST:event_targetFieldActionPerformed
246

247         
248     
249     // Variables declaration - do not modify//GEN-BEGIN:variables
250
private javax.swing.JTextArea JavaDoc dataTextArea;
251     private javax.swing.JLabel JavaDoc targetLabel;
252     private javax.swing.JPanel JavaDoc dataPanel;
253     private javax.swing.JTextField JavaDoc targetField;
254     private javax.swing.JScrollPane JavaDoc dataScroll;
255     // End of variables declaration//GEN-END:variables
256

257     /** Initialize accesibility
258      */

259     public void initAccessibility (){
260         this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeProcessingInstructionCustomizer"));
261         targetField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_targetField"));
262         dataTextArea.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_dataPanel1"));
263         dataTextArea.getAccessibleContext ().setAccessibleName (Util.THIS.getString ("ACSN_dataPanel1"));
264     }
265 }
266
Popular Tags