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:
042: package org.netbeans.modules.form.editors;
043:
044: import javax.swing.text.Document;
045:
046: import org.openide.nodes.Node;
047: import org.openide.loaders.DataObject;
048:
049: /** Customizer for "code properties" used by JavaCodeGenerator.
050: *
051: * @author vzboril
052: */
053:
054: public class CustomCodeEditor extends javax.swing.JPanel {
055: /** Creates new form CustomCodeEditor */
056: public CustomCodeEditor(Node.Property property,
057: DataObject dataObject) {
058: initComponents();
059:
060: codeEditorPane.setContentType("text/x-java"); // NOI18N
061: try {
062: codeEditorPane.setText((String) property.getValue());
063: } catch (Exception ex) { // ignore - should not happen
064: ex.printStackTrace();
065: }
066:
067: java.util.ResourceBundle bundle = org.openide.util.NbBundle
068: .getBundle(CustomCodeEditor.class);
069:
070: jLabel1.setText(bundle.getString("CustomCodeEditor.label1")); // NOI18N
071: jLabel1.setDisplayedMnemonic(bundle.getString(
072: "CustomCodeEditor.label1.mnemonic").charAt(0)); // NOI18N
073: jLabel1.setLabelFor(codeEditorPane);
074: codeEditorPane.getDocument().putProperty(
075: Document.StreamDescriptionProperty, dataObject);
076: codeEditorPane
077: .setPreferredSize(new java.awt.Dimension(440, 200));
078: codeEditorPane.requestFocus();
079: codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
080:
081: codeEditorPane.getAccessibleContext().setAccessibleDescription(
082: bundle.getString("ACSD_CustomCodeEditor.label1")); // NOI18N
083: getAccessibleContext().setAccessibleDescription(
084: bundle.getString("ACSD_CustomCodeEditor")); // NOI18N
085: }
086:
087: /** This method is called from within the constructor to
088: * initialize the form.
089: * WARNING: Do NOT modify this code. The content of this method is
090: * always regenerated by the Form Editor.
091: */
092: private void initComponents() {//GEN-BEGIN:initComponents
093: java.awt.GridBagConstraints gridBagConstraints;
094:
095: jScrollPane1 = new javax.swing.JScrollPane();
096: codeEditorPane = new javax.swing.JEditorPane();
097: jLabel1 = new javax.swing.JLabel();
098:
099: setLayout(new java.awt.GridBagLayout());
100:
101: addComponentListener(new java.awt.event.ComponentAdapter() {
102: public void componentShown(java.awt.event.ComponentEvent evt) {
103: formComponentShown(evt);
104: }
105: });
106:
107: addFocusListener(new java.awt.event.FocusAdapter() {
108: public void focusGained(java.awt.event.FocusEvent evt) {
109: formFocusGained(evt);
110: }
111: });
112:
113: codeEditorPane
114: .addFocusListener(new java.awt.event.FocusAdapter() {
115: public void focusGained(
116: java.awt.event.FocusEvent evt) {
117: codeEditorPaneFocusGained(evt);
118: }
119:
120: public void focusLost(java.awt.event.FocusEvent evt) {
121: codeEditorPaneFocusLost(evt);
122: }
123: });
124:
125: jScrollPane1.setViewportView(codeEditorPane);
126:
127: gridBagConstraints = new java.awt.GridBagConstraints();
128: gridBagConstraints.gridx = 0;
129: gridBagConstraints.gridy = 1;
130: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
131: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
132: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
133: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
134: gridBagConstraints.weightx = 1.0;
135: gridBagConstraints.weighty = 1.0;
136: gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 11);
137: add(jScrollPane1, gridBagConstraints);
138:
139: jLabel1.setText("jLabel1");
140: gridBagConstraints = new java.awt.GridBagConstraints();
141: gridBagConstraints.gridx = 0;
142: gridBagConstraints.gridy = 0;
143: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
144: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
145: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
146: add(jLabel1, gridBagConstraints);
147:
148: }//GEN-END:initComponents
149:
150: private void codeEditorPaneFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_codeEditorPaneFocusLost
151: // Add your handling code here:
152: codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
153: }//GEN-LAST:event_codeEditorPaneFocusLost
154:
155: private void codeEditorPaneFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_codeEditorPaneFocusGained
156: // Add your handling code here:
157: codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
158: }//GEN-LAST:event_codeEditorPaneFocusGained
159:
160: private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
161: // Add your handling code here:
162: codeEditorPane.requestFocus();
163: codeEditorPane.getCaret().setVisible(true); // true is HARDCODED here due to BUG in MAC OS X
164: }//GEN-LAST:event_formFocusGained
165:
166: private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
167: // Add your handling code here:
168: codeEditorPane.requestFocus();
169: codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
170: }//GEN-LAST:event_formComponentShown
171:
172: // Variables declaration - do not modify//GEN-BEGIN:variables
173: private javax.swing.JEditorPane codeEditorPane;
174: private javax.swing.JScrollPane jScrollPane1;
175: private javax.swing.JLabel jLabel1;
176:
177: // End of variables declaration//GEN-END:variables
178:
179: public Object getPropertyValue() throws IllegalStateException {
180: return codeEditorPane.getText();
181: }
182: }
|