001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.tax.beans.customizer;
042:
043: import java.beans.PropertyChangeEvent;
044:
045: import org.netbeans.tax.TreeCDATASection;
046: import org.netbeans.tax.TreeException;
047: import org.netbeans.tax.TreeData;
048:
049: import org.netbeans.modules.xml.tax.util.TAXUtil;
050:
051: /**
052: *
053: * @author Libor Kramolis
054: * @version 0.1
055: */
056: public class TreeCDATASectionCustomizer extends AbstractTreeCustomizer {
057:
058: /** Serial Version UID */
059: private static final long serialVersionUID = -7665482206368732519L;
060:
061: //
062: // init
063: //
064:
065: /** */
066: public TreeCDATASectionCustomizer() {
067: super ();
068:
069: initComponents();
070: initAccessibility();
071: }
072:
073: //
074: // itself
075: //
076:
077: /**
078: */
079: protected final TreeCDATASection getCDATASection() {
080: return (TreeCDATASection) getTreeObject();
081: }
082:
083: /**
084: */
085: protected final void safePropertyChange(PropertyChangeEvent pche) {
086: super .safePropertyChange(pche);
087:
088: if (pche.getPropertyName().equals(TreeData.PROP_DATA)) {
089: updateDataComponent();
090: }
091: }
092:
093: /**
094: */
095: protected final void updateCDATASectionData() {
096: try {
097: getCDATASection().setData(dataTextArea.getText());
098: } catch (TreeException exc) {
099: updateDataComponent();
100: TAXUtil.notifyTreeException(exc);
101: }
102: }
103:
104: /**
105: */
106: protected final void updateDataComponent() {
107: dataTextArea.setText(getCDATASection().getData());
108: }
109:
110: /**
111: */
112: protected final void initComponentValues() {
113: updateDataComponent();
114: }
115:
116: /**
117: */
118: protected final void updateReadOnlyStatus(boolean editable) {
119: dataTextArea.setEditable(editable);
120: }
121:
122: /** This method is called from within the constructor to
123: * initialize the form.
124: * WARNING: Do NOT modify this code. The content of this method is
125: * always regenerated by the FormEditor.
126: */
127: private void initComponents() {//GEN-BEGIN:initComponents
128: java.awt.GridBagConstraints gridBagConstraints;
129:
130: dataPanel = new javax.swing.JPanel();
131: dataScroll = new javax.swing.JScrollPane();
132: dataTextArea = new javax.swing.JTextArea();
133:
134: setLayout(new java.awt.GridBagLayout());
135:
136: setPreferredSize(new java.awt.Dimension(350, 230));
137: dataPanel.setLayout(new java.awt.BorderLayout());
138:
139: dataTextArea
140: .addFocusListener(new java.awt.event.FocusAdapter() {
141: public void focusGained(
142: java.awt.event.FocusEvent evt) {
143: dataTextAreaFocusGained(evt);
144: }
145:
146: public void focusLost(java.awt.event.FocusEvent evt) {
147: dataTextAreaFocusLost(evt);
148: }
149: });
150:
151: dataTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
152: public void keyPressed(java.awt.event.KeyEvent evt) {
153: dataTextAreaKeyPressed(evt);
154: }
155: });
156:
157: dataScroll.setViewportView(dataTextArea);
158:
159: dataPanel.add(dataScroll, java.awt.BorderLayout.CENTER);
160:
161: gridBagConstraints = new java.awt.GridBagConstraints();
162: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
163: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
164: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
165: gridBagConstraints.weightx = 1.0;
166: gridBagConstraints.weighty = 1.0;
167: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
168: add(dataPanel, gridBagConstraints);
169:
170: }//GEN-END:initComponents
171:
172: private void dataTextAreaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dataTextAreaFocusGained
173: if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
174: dataTextArea.selectAll();
175: }
176: }//GEN-LAST:event_dataTextAreaFocusGained
177:
178: private void dataTextAreaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dataTextAreaKeyPressed
179: // Add your handling code here:
180: if (applyKeyPressed(evt)) {
181: updateCDATASectionData();
182: }
183: }//GEN-LAST:event_dataTextAreaKeyPressed
184:
185: private void dataTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dataTextAreaFocusLost
186: // Add your handling code here:
187: updateCDATASectionData();
188: }//GEN-LAST:event_dataTextAreaFocusLost
189:
190: // Variables declaration - do not modify//GEN-BEGIN:variables
191: private javax.swing.JTextArea dataTextArea;
192: private javax.swing.JPanel dataPanel;
193: private javax.swing.JScrollPane dataScroll;
194:
195: // End of variables declaration//GEN-END:variables
196:
197: /** Initialize accesibility
198: */
199: public void initAccessibility() {
200:
201: this .getAccessibleContext().setAccessibleDescription(
202: Util.THIS.getString("ACSD_TreeCDATASectionCustomizer"));
203: dataTextArea.getAccessibleContext().setAccessibleDescription(
204: Util.THIS.getString("ACSD_dataPanel2"));
205: dataTextArea.getAccessibleContext().setAccessibleName(
206: Util.THIS.getString("ACSN_dataPanel2"));
207: }
208: }
|