1 19 20 package org.netbeans.modules.form.editors; 21 22 import javax.swing.text.Document ; 23 24 import org.openide.nodes.Node; 25 import org.openide.loaders.DataObject; 26 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; 27 28 32 33 public class CustomCodeEditor extends javax.swing.JPanel 34 implements EnhancedCustomPropertyEditor 35 { 36 37 public CustomCodeEditor(Node.Property property, DataObject dataObject) { 38 initComponents(); 39 40 codeEditorPane.setContentType("text/x-java"); try { 42 codeEditorPane.setText((String ) property.getValue()); 43 } 44 catch (Exception ex) { ex.printStackTrace(); 46 } 47 48 java.util.ResourceBundle bundle = 49 org.openide.util.NbBundle.getBundle(CustomCodeEditor.class); 50 51 jLabel1.setText(bundle.getString("CustomCodeEditor.label1")); jLabel1.setDisplayedMnemonic( 53 bundle.getString("CustomCodeEditor.label1.mnemonic").charAt(0)); jLabel1.setLabelFor(codeEditorPane); 55 codeEditorPane.getDocument().putProperty(Document.StreamDescriptionProperty, dataObject); 56 codeEditorPane.setPreferredSize(new java.awt.Dimension (440, 200)); 57 codeEditorPane.requestFocus(); 58 codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus()); 59 60 codeEditorPane.getAccessibleContext().setAccessibleDescription( 61 bundle.getString("ACSD_CustomCodeEditor.label1")); getAccessibleContext().setAccessibleDescription( 63 bundle.getString("ACSD_CustomCodeEditor")); } 65 66 71 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 73 74 jScrollPane1 = new javax.swing.JScrollPane (); 75 codeEditorPane = new javax.swing.JEditorPane (); 76 jLabel1 = new javax.swing.JLabel (); 77 78 setLayout(new java.awt.GridBagLayout ()); 79 80 addComponentListener(new java.awt.event.ComponentAdapter () { 81 public void componentShown(java.awt.event.ComponentEvent evt) { 82 formComponentShown(evt); 83 } 84 }); 85 86 addFocusListener(new java.awt.event.FocusAdapter () { 87 public void focusGained(java.awt.event.FocusEvent evt) { 88 formFocusGained(evt); 89 } 90 }); 91 92 codeEditorPane.addFocusListener(new java.awt.event.FocusAdapter () { 93 public void focusGained(java.awt.event.FocusEvent evt) { 94 codeEditorPaneFocusGained(evt); 95 } 96 public void focusLost(java.awt.event.FocusEvent evt) { 97 codeEditorPaneFocusLost(evt); 98 } 99 }); 100 101 jScrollPane1.setViewportView(codeEditorPane); 102 103 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (5, 12, 0, 11); 113 add(jScrollPane1, gridBagConstraints); 114 115 jLabel1.setText("jLabel1"); 116 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 12, 0, 11); 122 add(jLabel1, gridBagConstraints); 123 124 } 126 private void codeEditorPaneFocusLost(java.awt.event.FocusEvent evt) { codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus()); 129 } 131 private void codeEditorPaneFocusGained(java.awt.event.FocusEvent evt) { codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus()); 134 } 136 private void formFocusGained(java.awt.event.FocusEvent evt) { codeEditorPane.requestFocus(); 139 codeEditorPane.getCaret().setVisible(true); } 142 private void formComponentShown(java.awt.event.ComponentEvent evt) { codeEditorPane.requestFocus(); 145 codeEditorPane.getCaret().setVisible(codeEditorPane.hasFocus()); 146 } 148 149 private javax.swing.JEditorPane codeEditorPane; 151 private javax.swing.JScrollPane jScrollPane1; 152 private javax.swing.JLabel jLabel1; 153 155 public Object getPropertyValue() throws IllegalStateException { 156 return codeEditorPane.getText(); 157 } 158 } 159 | Popular Tags |