1 19 package org.netbeans.modules.form; 20 21 import org.openide.awt.Mnemonics; 22 23 27 public class FormCustomEditorAdvanced extends javax.swing.JPanel { 28 29 static final int DEFAULT_WIDTH = 350; 30 static final int DEFAULT_HEIGHT = 300; 31 32 static final long serialVersionUID =-885210213146017493L; 33 34 35 public FormCustomEditorAdvanced(String preCode, String postCode) { 36 initComponents(); 37 Mnemonics.setLocalizedText(preCheckBox, FormUtils.getBundleString("CTL_GeneratePreInitializationCode")); Mnemonics.setLocalizedText(postCheckBox, FormUtils.getBundleString("CTL_GeneratePostInitializationCode")); preEditorPane.setContentType("text/x-java"); postEditorPane.setContentType("text/x-java"); 42 preCheckBox.setSelected(preCode != null); 44 postCheckBox.setSelected(postCode != null); 45 46 if (preCode != null) preEditorPane.setText(preCode); 48 if (postCode != null) postEditorPane.setText(postCode); 49 50 org.openide.util.HelpCtx.setHelpIDString(this, "gui.source.modifying.property"); 52 preEditorPane.setEnabled(preCode != null); 53 postEditorPane.setEnabled(postCode != null); 54 55 preEditorPane.getCaret().setVisible(preCheckBox.isSelected() && preEditorPane.hasFocus()); 57 postEditorPane.getCaret().setVisible(postCheckBox.isSelected() && postEditorPane.hasFocus()); 58 59 preEditorPane.getAccessibleContext().setAccessibleName(preCheckBox.getText()); 60 postEditorPane.getAccessibleContext().setAccessibleName(postCheckBox.getText()); 61 62 preCheckBox.getAccessibleContext().setAccessibleDescription( 63 FormUtils.getBundleString("ACSD_CTL_GeneratePreInitializationCode")); postCheckBox.getAccessibleContext().setAccessibleDescription( 65 FormUtils.getBundleString("ACSD_CTL_GeneratePostInitializationCode")); preEditorPane.getAccessibleContext().setAccessibleDescription( 67 FormUtils.getBundleString("ACSD_CTL_GeneratePreInitializationCodeArea")); postEditorPane.getAccessibleContext().setAccessibleDescription( 69 FormUtils.getBundleString("ACSD_CTL_GeneratePostInitializationCodeArea")); getAccessibleContext().setAccessibleDescription( 71 FormUtils.getBundleString("ACSD_FormCustomEditorAdvanced")); } 73 74 String getPreCode() { 75 if (!preCheckBox.isSelected()) return null; 76 if ("".equals(preEditorPane.getText())) return null; return preEditorPane.getText(); 78 } 79 80 String getPostCode() { 81 if (!postCheckBox.isSelected()) return null; 82 if ("".equals(postEditorPane.getText())) return null; return postEditorPane.getText(); 84 } 85 86 public java.awt.Dimension getPreferredSize() { 87 java.awt.Dimension inh = super.getPreferredSize(); 88 return new java.awt.Dimension (Math.max(inh.width, DEFAULT_WIDTH), Math.max(inh.height, DEFAULT_HEIGHT)); 89 } 90 91 96 private void initComponents() { prePanel = new javax.swing.JPanel (); 98 preCheckBox = new javax.swing.JCheckBox (); 99 preScrollPane = new javax.swing.JScrollPane (); 100 preEditorPane = new javax.swing.JEditorPane (); 101 postPanel = new javax.swing.JPanel (); 102 postCheckBox = new javax.swing.JCheckBox (); 103 postScrollPane = new javax.swing.JScrollPane (); 104 postEditorPane = new javax.swing.JEditorPane (); 105 106 setLayout(new java.awt.GridBagLayout ()); 107 java.awt.GridBagConstraints gridBagConstraints1; 108 109 prePanel.setLayout(new java.awt.GridBagLayout ()); 110 java.awt.GridBagConstraints gridBagConstraints2; 111 112 preCheckBox.setText("jCheckBox1"); 113 preCheckBox.addItemListener(new java.awt.event.ItemListener () { 114 public void itemStateChanged(java.awt.event.ItemEvent evt) { 115 preCheckBoxItemStateChanged(evt); 116 } 117 }); 118 119 gridBagConstraints2 = new java.awt.GridBagConstraints (); 120 gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER; 121 gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST; 122 prePanel.add(preCheckBox, gridBagConstraints2); 123 124 preScrollPane.setViewportView(preEditorPane); 125 126 gridBagConstraints2 = new java.awt.GridBagConstraints (); 127 gridBagConstraints2.gridx = 0; 128 gridBagConstraints2.gridy = 1; 129 gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER; 130 gridBagConstraints2.gridheight = java.awt.GridBagConstraints.REMAINDER; 131 gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH; 132 gridBagConstraints2.insets = new java.awt.Insets (5, 0, 0, 0); 133 gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST; 134 gridBagConstraints2.weightx = 1.0; 135 gridBagConstraints2.weighty = 1.0; 136 prePanel.add(preScrollPane, gridBagConstraints2); 137 138 gridBagConstraints1 = new java.awt.GridBagConstraints (); 139 gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER; 140 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; 141 gridBagConstraints1.insets = new java.awt.Insets (12, 12, 0, 11); 142 gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST; 143 gridBagConstraints1.weightx = 1.0; 144 gridBagConstraints1.weighty = 1.0; 145 add(prePanel, gridBagConstraints1); 146 147 postPanel.setLayout(new java.awt.GridBagLayout ()); 148 java.awt.GridBagConstraints gridBagConstraints3; 149 150 postCheckBox.setText("jCheckBox2"); 151 postCheckBox.addItemListener(new java.awt.event.ItemListener () { 152 public void itemStateChanged(java.awt.event.ItemEvent evt) { 153 postCheckBoxItemStateChanged(evt); 154 } 155 }); 156 157 gridBagConstraints3 = new java.awt.GridBagConstraints (); 158 gridBagConstraints3.gridwidth = java.awt.GridBagConstraints.REMAINDER; 159 gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST; 160 postPanel.add(postCheckBox, gridBagConstraints3); 161 162 postScrollPane.setViewportView(postEditorPane); 163 164 gridBagConstraints3 = new java.awt.GridBagConstraints (); 165 gridBagConstraints3.gridx = 0; 166 gridBagConstraints3.gridy = 1; 167 gridBagConstraints3.gridwidth = java.awt.GridBagConstraints.REMAINDER; 168 gridBagConstraints3.gridheight = java.awt.GridBagConstraints.REMAINDER; 169 gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH; 170 gridBagConstraints3.insets = new java.awt.Insets (5, 0, 0, 0); 171 gridBagConstraints3.anchor = java.awt.GridBagConstraints.NORTHWEST; 172 gridBagConstraints3.weightx = 1.0; 173 gridBagConstraints3.weighty = 1.0; 174 postPanel.add(postScrollPane, gridBagConstraints3); 175 176 gridBagConstraints1 = new java.awt.GridBagConstraints (); 177 gridBagConstraints1.gridx = 0; 178 gridBagConstraints1.gridy = 1; 179 gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER; 180 gridBagConstraints1.gridheight = java.awt.GridBagConstraints.REMAINDER; 181 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; 182 gridBagConstraints1.insets = new java.awt.Insets (12, 12, 0, 11); 183 gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTHWEST; 184 gridBagConstraints1.weightx = 1.0; 185 gridBagConstraints1.weighty = 1.0; 186 add(postPanel, gridBagConstraints1); 187 188 } 190 private void postCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) { postEditorPane.setEnabled(postCheckBox.isSelected()); 193 if (postCheckBox.isSelected()) { 194 postEditorPane.requestFocus(); 195 } 196 } 198 private void preCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) { preEditorPane.setEnabled(preCheckBox.isSelected()); 201 if (preCheckBox.isSelected()) { 202 preEditorPane.requestFocus(); 203 } 204 } 206 207 private javax.swing.JPanel prePanel; 209 private javax.swing.JCheckBox preCheckBox; 210 private javax.swing.JScrollPane preScrollPane; 211 private javax.swing.JEditorPane preEditorPane; 212 private javax.swing.JPanel postPanel; 213 private javax.swing.JCheckBox postCheckBox; 214 private javax.swing.JScrollPane postScrollPane; 215 private javax.swing.JEditorPane postEditorPane; 216 218 } 219 | Popular Tags |