KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > editors > CustomCodeEditor


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
20 package org.netbeans.modules.form.editors;
21
22 import javax.swing.text.Document JavaDoc;
23
24 import org.openide.nodes.Node;
25 import org.openide.loaders.DataObject;
26 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
27
28 /** Customizer for "code properties" used by JavaCodeGenerator.
29  *
30  * @author vzboril
31  */

32
33 public class CustomCodeEditor extends javax.swing.JPanel JavaDoc
34                               implements EnhancedCustomPropertyEditor
35 {
36     /** Creates new form CustomCodeEditor */
37     public CustomCodeEditor(Node.Property property, DataObject dataObject) {
38         initComponents();
39
40         codeEditorPane.setContentType("text/x-java"); // NOI18N
41
try {
42             codeEditorPane.setText((String JavaDoc) property.getValue());
43         }
44         catch (Exception JavaDoc ex) { // ignore - should not happen
45
ex.printStackTrace();
46         }
47
48         java.util.ResourceBundle JavaDoc bundle =
49             org.openide.util.NbBundle.getBundle(CustomCodeEditor.class);
50
51         jLabel1.setText(bundle.getString("CustomCodeEditor.label1")); // NOI18N
52
jLabel1.setDisplayedMnemonic(
53             bundle.getString("CustomCodeEditor.label1.mnemonic").charAt(0)); // NOI18N
54
jLabel1.setLabelFor(codeEditorPane);
55         codeEditorPane.getDocument().putProperty(Document.StreamDescriptionProperty, dataObject);
56         codeEditorPane.setPreferredSize(new java.awt.Dimension JavaDoc(440, 200));
57         codeEditorPane.requestFocus();
58         codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
59         
60         codeEditorPane.getAccessibleContext().setAccessibleDescription(
61             bundle.getString("ACSD_CustomCodeEditor.label1")); // NOI18N
62
getAccessibleContext().setAccessibleDescription(
63             bundle.getString("ACSD_CustomCodeEditor")); // NOI18N
64
}
65
66     /** This method is called from within the constructor to
67      * initialize the form.
68      * WARNING: Do NOT modify this code. The content of this method is
69      * always regenerated by the Form Editor.
70      */

71     private void initComponents() {//GEN-BEGIN:initComponents
72
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
73
74         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
75         codeEditorPane = new javax.swing.JEditorPane JavaDoc();
76         jLabel1 = new javax.swing.JLabel JavaDoc();
77
78         setLayout(new java.awt.GridBagLayout JavaDoc());
79
80         addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
81             public void componentShown(java.awt.event.ComponentEvent JavaDoc evt) {
82                 formComponentShown(evt);
83             }
84         });
85
86         addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
87             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
88                 formFocusGained(evt);
89             }
90         });
91
92         codeEditorPane.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
93             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
94                 codeEditorPaneFocusGained(evt);
95             }
96             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
97                 codeEditorPaneFocusLost(evt);
98             }
99         });
100
101         jScrollPane1.setViewportView(codeEditorPane);
102
103         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
104         gridBagConstraints.gridx = 0;
105         gridBagConstraints.gridy = 1;
106         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
107         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
108         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
110         gridBagConstraints.weightx = 1.0;
111         gridBagConstraints.weighty = 1.0;
112         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 11);
113         add(jScrollPane1, gridBagConstraints);
114
115         jLabel1.setText("jLabel1");
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.gridx = 0;
118         gridBagConstraints.gridy = 0;
119         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
120         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
121         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
122         add(jLabel1, gridBagConstraints);
123
124     }//GEN-END:initComponents
125

126     private void codeEditorPaneFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_codeEditorPaneFocusLost
127
// Add your handling code here:
128
codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
129     }//GEN-LAST:event_codeEditorPaneFocusLost
130

131     private void codeEditorPaneFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_codeEditorPaneFocusGained
132
// Add your handling code here:
133
codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
134     }//GEN-LAST:event_codeEditorPaneFocusGained
135

136     private void formFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_formFocusGained
137
// Add your handling code here:
138
codeEditorPane.requestFocus();
139         codeEditorPane.getCaret().setVisible(true); // true is HARDCODED here due to BUG in MAC OS X
140
}//GEN-LAST:event_formFocusGained
141

142     private void formComponentShown(java.awt.event.ComponentEvent JavaDoc evt) {//GEN-FIRST:event_formComponentShown
143
// Add your handling code here:
144
codeEditorPane.requestFocus();
145         codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus());
146     }//GEN-LAST:event_formComponentShown
147

148
149     // Variables declaration - do not modify//GEN-BEGIN:variables
150
private javax.swing.JEditorPane JavaDoc codeEditorPane;
151     private javax.swing.JScrollPane JavaDoc jScrollPane1;
152     private javax.swing.JLabel JavaDoc jLabel1;
153     // End of variables declaration//GEN-END:variables
154

155     public Object JavaDoc getPropertyValue() throws IllegalStateException JavaDoc {
156         return codeEditorPane.getText();
157     }
158 }
159
Popular Tags