1 19 package org.netbeans.modules.xml.tools.generator; 20 21 import java.awt.*; 22 import javax.swing.*; 23 import java.net.URL ; 24 import java.net.MalformedURLException ; 25 26 import org.netbeans.modules.xml.core.lib.A11YUtil; 27 28 36 public final class SAXGeneratorFilePanel extends SAXGeneratorAbstractPanel implements java.awt.event.ActionListener { 37 38 39 private static final long serialVersionUID =-8950908568784619306L; 40 41 private static final Util.NameCheck check = Util.JAVA_CHECK; 42 43 private java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(SAXGeneratorFilePanel.class); 44 45 46 public SAXGeneratorFilePanel() { 47 } 52 53 private final ValidatingTextField.Validator NAME_VALIDATOR = new ValidatingTextField.Validator() { 54 public boolean isValid(String value) { 55 boolean ret = check.checkName(value); 56 if (ret) { 57 setValid(checkNames()); 58 } else { 59 setValid(false); 60 } 61 62 return ret; 63 } 64 65 public String getReason() { 66 return Util.THIS.getString("MSG_file_err_1"); 67 } 68 }; 69 70 75 private void initComponents() { 77 java.awt.GridBagConstraints gridBagConstraints; 78 79 descTextArea = new javax.swing.JTextArea (); 80 interfaceLabel = new javax.swing.JLabel (); 81 interfaceTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField(); 82 handlerImplLabel = new javax.swing.JLabel (); 83 handlerImplTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField(); 84 stubLabel = new javax.swing.JLabel (); 85 stubTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField(); 86 parsletLabel = new javax.swing.JLabel (); 87 parsletTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField(); 88 parsletImplLabel = new javax.swing.JLabel (); 89 parsletImplTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField(); 90 saveCheckBox = new javax.swing.JCheckBox (); 91 saveLabel = new javax.swing.JLabel (); 92 saveTextField = new org.netbeans.modules.xml.tools.generator.ValidatingTextField(); 93 fillPanel = new javax.swing.JPanel (); 94 95 setLayout(new java.awt.GridBagLayout ()); 96 97 setName(Util.THIS.getString ("SAXGeneratorFilePanel.Form.name")); 98 setPreferredSize(new java.awt.Dimension (480, 350)); 99 addComponentListener(new java.awt.event.ComponentAdapter () { 100 public void componentHidden(java.awt.event.ComponentEvent evt) { 101 formComponentHidden(evt); 102 } 103 }); 104 addContainerListener(new java.awt.event.ContainerAdapter () { 105 public void componentRemoved(java.awt.event.ContainerEvent evt) { 106 formComponentRemoved(evt); 107 } 108 }); 109 110 descTextArea.setWrapStyleWord(true); 111 descTextArea.setLineWrap(true); 112 descTextArea.setEditable(false); 113 descTextArea.setForeground(new java.awt.Color (102, 102, 153)); 114 descTextArea.setFont(javax.swing.UIManager.getFont ("Label.font")); 115 descTextArea.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/tools/generator/Bundle").getString("DESC_saxw_files")); 116 descTextArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground")); 117 descTextArea.setEnabled(false); 118 descTextArea.setOpaque(false); 119 gridBagConstraints = new java.awt.GridBagConstraints (); 120 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 121 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 122 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 123 add(descTextArea, gridBagConstraints); 124 125 interfaceLabel.setLabelFor(interfaceTextField); 126 org.openide.awt.Mnemonics.setLocalizedText(interfaceLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorCustomizer.interfaceLabel.text")); 127 gridBagConstraints = new java.awt.GridBagConstraints (); 128 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 129 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 130 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 131 add(interfaceLabel, gridBagConstraints); 132 133 gridBagConstraints = new java.awt.GridBagConstraints (); 134 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 135 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 136 gridBagConstraints.weightx = 1.0; 137 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 138 add(interfaceTextField, gridBagConstraints); 139 140 handlerImplLabel.setLabelFor(handlerImplTextField); 141 org.openide.awt.Mnemonics.setLocalizedText(handlerImplLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorFilePanel.handlerImplLabel.text", new Object [] {})); 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 144 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 145 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 146 add(handlerImplLabel, gridBagConstraints); 147 148 gridBagConstraints = new java.awt.GridBagConstraints (); 149 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 150 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 151 gridBagConstraints.weightx = 1.0; 152 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 153 add(handlerImplTextField, gridBagConstraints); 154 155 stubLabel.setLabelFor(stubTextField); 156 org.openide.awt.Mnemonics.setLocalizedText(stubLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorCustomizer.stubLabel.text")); 157 gridBagConstraints = new java.awt.GridBagConstraints (); 158 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 160 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 161 add(stubLabel, gridBagConstraints); 162 163 gridBagConstraints = new java.awt.GridBagConstraints (); 164 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 166 gridBagConstraints.weightx = 1.0; 167 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 168 add(stubTextField, gridBagConstraints); 169 170 parsletLabel.setLabelFor(parsletTextField); 171 org.openide.awt.Mnemonics.setLocalizedText(parsletLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorCustomizer.parsletLabel.text")); 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 174 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 175 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 176 add(parsletLabel, gridBagConstraints); 177 178 gridBagConstraints = new java.awt.GridBagConstraints (); 179 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 180 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 181 gridBagConstraints.weightx = 1.0; 182 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 183 add(parsletTextField, gridBagConstraints); 184 185 parsletImplLabel.setLabelFor(parsletImplTextField); 186 org.openide.awt.Mnemonics.setLocalizedText(parsletImplLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "SAXGeneratorFilePanel.parsletImplLabel.text")); 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 189 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 190 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 191 add(parsletImplLabel, gridBagConstraints); 192 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 195 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 196 gridBagConstraints.weightx = 1.0; 197 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 198 add(parsletImplTextField, gridBagConstraints); 199 200 org.openide.awt.Mnemonics.setLocalizedText(saveCheckBox, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "PROP_save_it")); 201 gridBagConstraints = new java.awt.GridBagConstraints (); 202 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 203 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 204 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 205 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 206 add(saveCheckBox, gridBagConstraints); 207 208 saveLabel.setLabelFor(saveTextField); 209 org.openide.awt.Mnemonics.setLocalizedText(saveLabel, org.openide.util.NbBundle.getMessage(SAXGeneratorFilePanel.class, "PROP_bindings_label")); 210 gridBagConstraints = new java.awt.GridBagConstraints (); 211 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 212 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 213 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 214 add(saveLabel, gridBagConstraints); 215 216 saveTextField.setEditable(false); 217 gridBagConstraints = new java.awt.GridBagConstraints (); 218 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 219 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 220 gridBagConstraints.weightx = 1.0; 221 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 222 add(saveTextField, gridBagConstraints); 223 224 gridBagConstraints = new java.awt.GridBagConstraints (); 225 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 226 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 227 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 228 gridBagConstraints.weighty = 1.0; 229 add(fillPanel, gridBagConstraints); 230 231 } 232 234 private void formComponentHidden(java.awt.event.ComponentEvent evt) { updateModel(); } 238 private void formComponentRemoved(java.awt.event.ContainerEvent evt) { updateModel(); } 242 protected void updateModel() { 243 model.setHandler(interfaceTextField.getText()); 244 model.setParslet(parsletTextField.getText()); 245 model.setStub(stubTextField.getText()); 246 model.setParsletImpl(parsletImplTextField.getText()); 247 model.setHandlerImpl(handlerImplTextField.getText()); 248 model.setBindnings(saveCheckBox.isSelected() ? saveTextField.getText() : null); 249 } 250 251 252 protected void initView() { 253 initComponents(); 254 255 interfaceTextField.setText(model.getHandler()); 256 stubTextField.setText(model.getStub()); 257 handlerImplTextField.setText(model.getHandlerImpl()); 258 parsletTextField.setText(model.getParslet()); 259 parsletImplTextField.setText(model.getParsletImpl()); 260 saveTextField.setText(model.getBindings()); 261 262 interfaceTextField.setValidator(NAME_VALIDATOR); 263 stubTextField.setValidator(NAME_VALIDATOR); 264 handlerImplTextField.setValidator(NAME_VALIDATOR); 265 parsletTextField.setValidator(NAME_VALIDATOR); 266 parsletImplTextField.setValidator(NAME_VALIDATOR); 267 268 saveCheckBox.setSelected(model.getBindings() != null); 269 270 initAccessibility(); 271 } 272 273 protected void updateView() { 274 275 parsletTextField.setVisible(hasParslets()); 276 parsletLabel.setVisible(hasParslets()); 277 parsletImplTextField.setVisible(hasParslets()); 278 parsletImplLabel.setVisible(hasParslets()); 279 280 doLayout(); 281 setValid(checkNames()); 282 283 } 284 285 286 public void actionPerformed(java.awt.event.ActionEvent p1) { 287 updateModel(); 288 } 289 290 private boolean checkNames() { 294 295 return check.checkName(interfaceTextField.getText()) 296 && (not(hasParslets()) || check.checkName(parsletTextField.getText())) 297 && check.checkName(stubTextField.getText()) 298 && (not(hasParslets()) || check.checkName(parsletImplTextField.getText())) 299 && check.checkName(handlerImplTextField.getText()); 300 301 } 302 303 private boolean hasParslets() { 304 return (model.getParsletBindings().isEmpty() == false); 305 } 306 307 private javax.swing.JTextArea descTextArea; 309 private javax.swing.JPanel fillPanel; 310 private javax.swing.JLabel handlerImplLabel; 311 private org.netbeans.modules.xml.tools.generator.ValidatingTextField handlerImplTextField; 312 private javax.swing.JLabel interfaceLabel; 313 private org.netbeans.modules.xml.tools.generator.ValidatingTextField interfaceTextField; 314 private javax.swing.JLabel parsletImplLabel; 315 private org.netbeans.modules.xml.tools.generator.ValidatingTextField parsletImplTextField; 316 private javax.swing.JLabel parsletLabel; 317 private org.netbeans.modules.xml.tools.generator.ValidatingTextField parsletTextField; 318 private javax.swing.JCheckBox saveCheckBox; 319 private javax.swing.JLabel saveLabel; 320 private org.netbeans.modules.xml.tools.generator.ValidatingTextField saveTextField; 321 private javax.swing.JLabel stubLabel; 322 private org.netbeans.modules.xml.tools.generator.ValidatingTextField stubTextField; 323 325 327 public void initAccessibility(){ 328 329 interfaceTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_interfaceTextField")); 330 handlerImplTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_handlerImplTextField")); 331 stubTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_stubTextField")); 332 parsletTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_parsletTextField")); 333 parsletImplTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_parsletImplTextField")); 334 335 saveTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_saveTextField")); 336 saveTextField.addFocusListener(A11YUtil.getA11YJTextFieldSupport()); 337 338 saveCheckBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_saveCheckBox")); 339 saveCheckBox.getAccessibleContext().setAccessibleName(Util.THIS.getString("ACSN_saveCheckBox")); 340 341 this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_SAXGeneratorFilePanel")); 342 } 343 } 344 | Popular Tags |