1 19 20 package org.netbeans.modules.i18n.java; 21 22 23 import java.awt.AWTEvent ; 24 import java.awt.Dialog ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 import java.lang.reflect.Modifier ; 28 import java.util.ResourceBundle ; 29 import javax.swing.ButtonGroup ; 30 import javax.swing.JPanel ; 31 32 import org.netbeans.modules.i18n.HelpStringCustomEditor; 33 import org.netbeans.modules.i18n.I18nUtil; 34 35 import org.openide.DialogDescriptor; 36 import org.openide.DialogDisplayer; 37 import org.openide.loaders.DataObject; 38 39 40 46 public class JavaReplacePanel extends JPanel { 47 48 49 private JavaI18nSupport javaI18nSupport; 50 51 52 private final ResourceBundle bundle; 53 54 55 57 public JavaReplacePanel(JavaI18nSupport javaI18nSupport) { 58 this.javaI18nSupport = javaI18nSupport; 59 60 bundle = org.openide.util.NbBundle.getBundle(Util.class); 62 initComponents(); 63 initAccessibility(); 64 65 updateValues(); 66 } 67 68 69 70 private void updateValues() { 71 javaI18nSupport.createIdentifier(); 72 73 generateCheck.setSelected(javaI18nSupport.isGenerateField()); 75 setAllEnabled(generateCheck.isSelected()); 76 77 identifierTextField.setText(javaI18nSupport.getIdentifier()); 78 79 initTextField.setText(javaI18nSupport.getInitString()); 80 } 81 82 83 private void updateModifiers() { 84 } 120 121 122 private void initAccessibility() { 123 this.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_JavaReplacePanel")); 124 fieldTextField.selectAll(); 125 initTextField.selectAll(); 126 staticCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_staticCheck")); 127 identifierTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_identifierTextField")); 128 transientCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_transientCheck")); 129 defaultRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_defaultRadio")); 130 fieldTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_fieldTextField")); 131 initButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_initButton")); 132 publicRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_publicRadio")); 133 generateCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_generateCheck")); 134 finalCheck.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_finalCheck")); 135 privateRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_privateRadio")); 136 initTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_initTextField")); 137 protectedRadio.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_protectedRadio")); 138 139 } 140 141 146 private void initComponents() { 148 java.awt.GridBagConstraints gridBagConstraints; 149 150 generateCheck = new javax.swing.JCheckBox (); 151 modifiersLabel = new javax.swing.JLabel (); 152 defaultRadio = new javax.swing.JRadioButton (); 153 privateRadio = new javax.swing.JRadioButton (); 154 protectedRadio = new javax.swing.JRadioButton (); 155 publicRadio = new javax.swing.JRadioButton (); 156 staticCheck = new javax.swing.JCheckBox (); 157 finalCheck = new javax.swing.JCheckBox (); 158 transientCheck = new javax.swing.JCheckBox (); 159 identifierLabel = new javax.swing.JLabel (); 160 identifierTextField = new javax.swing.JTextField (); 161 initLabel = new javax.swing.JLabel (); 162 initTextField = new javax.swing.JTextField (); 163 fieldLabel = new javax.swing.JLabel (); 164 fieldTextField = new javax.swing.JTextField (); 165 initButton = new javax.swing.JButton (); 166 167 setLayout(new java.awt.GridBagLayout ()); 168 169 generateCheck.setSelected(true); 170 org.openide.awt.Mnemonics.setLocalizedText(generateCheck, bundle.getString("CTL_GenerateField")); generateCheck.addActionListener(new java.awt.event.ActionListener () { 172 public void actionPerformed(java.awt.event.ActionEvent evt) { 173 generateCheckActionPerformed(evt); 174 } 175 }); 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridwidth = 2; 178 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 179 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 180 add(generateCheck, gridBagConstraints); 181 182 modifiersLabel.setText(bundle.getString("LBL_Modifiers")); gridBagConstraints = new java.awt.GridBagConstraints (); 184 gridBagConstraints.gridx = 0; 185 gridBagConstraints.gridy = 1; 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 187 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 188 add(modifiersLabel, gridBagConstraints); 189 190 org.openide.awt.Mnemonics.setLocalizedText(defaultRadio, bundle.getString("CTL_DefaultRadio")); defaultRadio.setEnabled(false); 192 defaultRadio.addActionListener(new java.awt.event.ActionListener () { 193 public void actionPerformed(java.awt.event.ActionEvent evt) { 194 defaultRadioActionPerformed(evt); 195 } 196 }); 197 gridBagConstraints = new java.awt.GridBagConstraints (); 198 gridBagConstraints.gridx = 1; 199 gridBagConstraints.gridy = 1; 200 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 201 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 202 add(defaultRadio, gridBagConstraints); 203 204 privateRadio.setSelected(true); 205 org.openide.awt.Mnemonics.setLocalizedText(privateRadio, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_PrivateRadio")); privateRadio.setEnabled(false); 207 privateRadio.addActionListener(new java.awt.event.ActionListener () { 208 public void actionPerformed(java.awt.event.ActionEvent evt) { 209 privateRadioActionPerformed(evt); 210 } 211 }); 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 1; 214 gridBagConstraints.gridy = 2; 215 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 216 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 217 add(privateRadio, gridBagConstraints); 218 219 org.openide.awt.Mnemonics.setLocalizedText(protectedRadio, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_ProtectedRadio")); protectedRadio.setEnabled(false); 221 protectedRadio.addActionListener(new java.awt.event.ActionListener () { 222 public void actionPerformed(java.awt.event.ActionEvent evt) { 223 protectedRadioActionPerformed(evt); 224 } 225 }); 226 gridBagConstraints = new java.awt.GridBagConstraints (); 227 gridBagConstraints.gridx = 1; 228 gridBagConstraints.gridy = 3; 229 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 230 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 231 add(protectedRadio, gridBagConstraints); 232 233 org.openide.awt.Mnemonics.setLocalizedText(publicRadio, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_PublicRadio")); publicRadio.setEnabled(false); 235 ButtonGroup radioGroup = new ButtonGroup (); 236 237 radioGroup.add(defaultRadio); 238 radioGroup.add(privateRadio); 239 radioGroup.add(protectedRadio); 240 radioGroup.add(publicRadio); 241 publicRadio.addActionListener(new java.awt.event.ActionListener () { 242 public void actionPerformed(java.awt.event.ActionEvent evt) { 243 publicRadioActionPerformed(evt); 244 } 245 }); 246 gridBagConstraints = new java.awt.GridBagConstraints (); 247 gridBagConstraints.gridx = 1; 248 gridBagConstraints.gridy = 4; 249 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 250 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 251 add(publicRadio, gridBagConstraints); 252 253 staticCheck.setSelected(true); 254 org.openide.awt.Mnemonics.setLocalizedText(staticCheck, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_StaticCheck")); staticCheck.setEnabled(false); 256 staticCheck.addActionListener(new java.awt.event.ActionListener () { 257 public void actionPerformed(java.awt.event.ActionEvent evt) { 258 staticCheckActionPerformed(evt); 259 } 260 }); 261 gridBagConstraints = new java.awt.GridBagConstraints (); 262 gridBagConstraints.gridx = 2; 263 gridBagConstraints.gridy = 1; 264 gridBagConstraints.gridwidth = 3; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 266 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 267 add(staticCheck, gridBagConstraints); 268 269 finalCheck.setSelected(true); 270 org.openide.awt.Mnemonics.setLocalizedText(finalCheck, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_FinalCheck")); finalCheck.setEnabled(false); 272 finalCheck.addActionListener(new java.awt.event.ActionListener () { 273 public void actionPerformed(java.awt.event.ActionEvent evt) { 274 finalCheckActionPerformed(evt); 275 } 276 }); 277 gridBagConstraints = new java.awt.GridBagConstraints (); 278 gridBagConstraints.gridx = 2; 279 gridBagConstraints.gridy = 2; 280 gridBagConstraints.gridwidth = 3; 281 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 282 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 11); 283 add(finalCheck, gridBagConstraints); 284 285 org.openide.awt.Mnemonics.setLocalizedText(transientCheck, org.openide.util.NbBundle.getMessage(JavaReplacePanel.class, "CTL_TransientCheck")); transientCheck.setEnabled(false); 287 transientCheck.addActionListener(new java.awt.event.ActionListener () { 288 public void actionPerformed(java.awt.event.ActionEvent evt) { 289 transientCheckActionPerformed(evt); 290 } 291 }); 292 gridBagConstraints = new java.awt.GridBagConstraints (); 293 gridBagConstraints.gridx = 2; 294 gridBagConstraints.gridy = 3; 295 gridBagConstraints.gridwidth = 3; 296 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 297 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 11); 298 add(transientCheck, gridBagConstraints); 299 300 identifierLabel.setLabelFor(identifierTextField); 301 org.openide.awt.Mnemonics.setLocalizedText(identifierLabel, bundle.getString("LBL_Identifier")); gridBagConstraints = new java.awt.GridBagConstraints (); 303 gridBagConstraints.gridx = 0; 304 gridBagConstraints.gridy = 5; 305 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 306 gridBagConstraints.insets = new java.awt.Insets (11, 12, 0, 0); 307 add(identifierLabel, gridBagConstraints); 308 309 identifierTextField.addActionListener(new java.awt.event.ActionListener () { 310 public void actionPerformed(java.awt.event.ActionEvent evt) { 311 identifierTextFieldActionPerformed(evt); 312 } 313 }); 314 identifierTextField.addFocusListener(new java.awt.event.FocusAdapter () { 315 public void focusLost(java.awt.event.FocusEvent evt) { 316 identifierTextFieldFocusLost(evt); 317 } 318 }); 319 gridBagConstraints = new java.awt.GridBagConstraints (); 320 gridBagConstraints.gridx = 1; 321 gridBagConstraints.gridy = 5; 322 gridBagConstraints.gridwidth = 4; 323 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 324 gridBagConstraints.weightx = 1.0; 325 gridBagConstraints.insets = new java.awt.Insets (11, 12, 0, 11); 326 add(identifierTextField, gridBagConstraints); 327 328 initLabel.setLabelFor(initTextField); 329 org.openide.awt.Mnemonics.setLocalizedText(initLabel, bundle.getString("LBL_InitFormat")); gridBagConstraints = new java.awt.GridBagConstraints (); 331 gridBagConstraints.gridx = 0; 332 gridBagConstraints.gridy = 6; 333 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 334 gridBagConstraints.insets = new java.awt.Insets (11, 12, 0, 0); 335 add(initLabel, gridBagConstraints); 336 337 initTextField.setEditable(false); 338 initTextField.addFocusListener(new java.awt.event.FocusAdapter () { 339 public void focusGained(java.awt.event.FocusEvent evt) { 340 initTextFieldFocusGained(evt); 341 } 342 }); 343 gridBagConstraints = new java.awt.GridBagConstraints (); 344 gridBagConstraints.gridx = 1; 345 gridBagConstraints.gridy = 6; 346 gridBagConstraints.gridwidth = 2; 347 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 348 gridBagConstraints.weightx = 1.0; 349 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 350 add(initTextField, gridBagConstraints); 351 352 fieldLabel.setLabelFor(fieldTextField); 353 org.openide.awt.Mnemonics.setLocalizedText(fieldLabel, bundle.getString("LBL_Field")); gridBagConstraints = new java.awt.GridBagConstraints (); 355 gridBagConstraints.gridx = 0; 356 gridBagConstraints.gridy = 7; 357 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 358 gridBagConstraints.insets = new java.awt.Insets (11, 12, 11, 0); 359 add(fieldLabel, gridBagConstraints); 360 361 fieldTextField.setEditable(false); 362 fieldTextField.addFocusListener(new java.awt.event.FocusAdapter () { 363 public void focusGained(java.awt.event.FocusEvent evt) { 364 fieldTextFieldFocusGained(evt); 365 } 366 }); 367 gridBagConstraints = new java.awt.GridBagConstraints (); 368 gridBagConstraints.gridx = 1; 369 gridBagConstraints.gridy = 7; 370 gridBagConstraints.gridwidth = 4; 371 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 372 gridBagConstraints.weightx = 1.0; 373 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 11); 374 add(fieldTextField, gridBagConstraints); 375 376 org.openide.awt.Mnemonics.setLocalizedText(initButton, bundle.getString("CTL_Format")); initButton.addActionListener(new java.awt.event.ActionListener () { 378 public void actionPerformed(java.awt.event.ActionEvent evt) { 379 initButtonActionPerformed(evt); 380 } 381 }); 382 gridBagConstraints = new java.awt.GridBagConstraints (); 383 gridBagConstraints.gridx = 3; 384 gridBagConstraints.gridy = 6; 385 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 386 gridBagConstraints.insets = new java.awt.Insets (12, 5, 0, 11); 387 add(initButton, gridBagConstraints); 388 } 390 private void fieldTextFieldFocusGained(java.awt.event.FocusEvent evt) { fieldTextField.selectAll(); 393 } 395 private void initTextFieldFocusGained(java.awt.event.FocusEvent evt) { initTextField.selectAll(); 398 } 400 private void initButtonActionPerformed(java.awt.event.ActionEvent evt) { final Dialog [] dialogs = new Dialog [1]; 402 final HelpStringCustomEditor customPanel = new HelpStringCustomEditor( 403 javaI18nSupport.getInitFormat(), 404 I18nUtil.getInitFormatItems(), 405 I18nUtil.getInitHelpItems(), 406 Util.getString("LBL_InitCodeFormat"), 407 I18nUtil.PE_BUNDLE_CODE_HELP_ID); 408 409 DialogDescriptor dd = new DialogDescriptor( 410 customPanel, 411 bundle.getString("LBL_InitStringFormatEditor"), 412 true, 413 DialogDescriptor.OK_CANCEL_OPTION, 414 DialogDescriptor.OK_OPTION, 415 new ActionListener () { 416 public void actionPerformed(ActionEvent ev) { 417 if (ev.getSource() == DialogDescriptor.OK_OPTION) { 418 String newText = (String )customPanel.getPropertyValue(); 419 420 if(!newText.equals(javaI18nSupport.getInitFormat())) { 421 javaI18nSupport.setInitFormat(newText); 422 initTextField.setText(javaI18nSupport.getInitString()); 423 424 I18nUtil.getOptions().setInitJavaCode(newText); 426 } 427 428 dialogs[0].setVisible(false); 429 dialogs[0].dispose(); 430 } else if (ev.getSource() == DialogDescriptor.CANCEL_OPTION) { 431 dialogs[0].setVisible(false); 432 dialogs[0].dispose(); 433 } 434 } 435 }); 436 dialogs[0] = DialogDisplayer.getDefault().createDialog(dd); 437 dialogs[0].setVisible(true); 438 } 440 private void identifierTextFieldFocusLost(java.awt.event.FocusEvent evt) { identifierTextFieldEventHandlerDelegate(evt); 442 } 444 private void identifierTextFieldActionPerformed(java.awt.event.ActionEvent evt) { identifierTextFieldEventHandlerDelegate(evt); 446 } 448 449 public void identifierTextFieldEventHandlerDelegate(AWTEvent evt) { 450 if(!identifierTextField.getText().equals(javaI18nSupport.getIdentifier())) { 452 javaI18nSupport.setIdentifier(identifierTextField.getText()); 453 updateModifiers(); 454 } 455 } 456 457 private void transientCheckActionPerformed(java.awt.event.ActionEvent evt) { if(transientCheck.isSelected()) { 459 staticCheck.setSelected(false); 460 staticCheck.setEnabled(false); 461 } else { 462 staticCheck.setEnabled(true); 463 } 464 modifiersActionPerformed(); 465 } 467 private void finalCheckActionPerformed(java.awt.event.ActionEvent evt) { modifiersActionPerformed(); 469 } 471 private void staticCheckActionPerformed(java.awt.event.ActionEvent evt) { if(staticCheck.isSelected()) { 473 transientCheck.setSelected(false); 474 transientCheck.setEnabled(false); 475 } else { 476 transientCheck.setEnabled(true); 477 } 478 479 modifiersActionPerformed(); 480 } 482 private void publicRadioActionPerformed(java.awt.event.ActionEvent evt) { modifiersActionPerformed(); 484 } 486 private void protectedRadioActionPerformed(java.awt.event.ActionEvent evt) { modifiersActionPerformed(); 488 } 490 private void privateRadioActionPerformed(java.awt.event.ActionEvent evt) { modifiersActionPerformed(); 492 } 494 private void defaultRadioActionPerformed(java.awt.event.ActionEvent evt) { modifiersActionPerformed(); 496 } 498 private void generateCheckActionPerformed(java.awt.event.ActionEvent evt) { boolean selected = generateCheck.isSelected(); 500 501 if(selected != javaI18nSupport.isGenerateField()) { 502 javaI18nSupport.setGenerateField(selected); 503 504 setAllEnabled(selected); 505 } 506 } 508 509 private void modifiersActionPerformed() { 510 int modifiers = 0; 511 512 if(privateRadio.isSelected()) 513 modifiers |= Modifier.PRIVATE; 514 else if(protectedRadio.isSelected()) 515 modifiers |= Modifier.PROTECTED; 516 else if(publicRadio.isSelected()) 517 modifiers |= Modifier.PUBLIC; 518 519 if(staticCheck.isSelected()) 520 modifiers |= Modifier.STATIC; 521 if(finalCheck.isSelected()) 522 modifiers |= Modifier.FINAL; 523 if(transientCheck.isSelected()) 524 modifiers |= Modifier.TRANSIENT; 525 526 if(modifiers != javaI18nSupport.getModifiers()) 527 javaI18nSupport.setModifiers(modifiers); 528 } 529 530 private javax.swing.JRadioButton defaultRadio; 532 private javax.swing.JLabel fieldLabel; 533 private javax.swing.JTextField fieldTextField; 534 private javax.swing.JCheckBox finalCheck; 535 private javax.swing.JCheckBox generateCheck; 536 private javax.swing.JLabel identifierLabel; 537 private javax.swing.JTextField identifierTextField; 538 private javax.swing.JButton initButton; 539 private javax.swing.JLabel initLabel; 540 private javax.swing.JTextField initTextField; 541 private javax.swing.JLabel modifiersLabel; 542 private javax.swing.JRadioButton privateRadio; 543 private javax.swing.JRadioButton protectedRadio; 544 private javax.swing.JRadioButton publicRadio; 545 private javax.swing.JCheckBox staticCheck; 546 private javax.swing.JCheckBox transientCheck; 547 549 550 private void setAllEnabled(boolean enable) { 551 defaultRadio.setEnabled(enable); 552 privateRadio.setEnabled(enable); 553 protectedRadio.setEnabled(enable); 554 publicRadio.setEnabled(enable); 555 556 staticCheck.setEnabled(enable); 557 transientCheck.setEnabled(enable); 558 finalCheck.setEnabled(enable); 559 560 identifierTextField.setEnabled(enable); 561 fieldTextField.setEnabled(enable); 562 initButton.setEnabled(enable); 563 564 if(enable) 565 updateModifiers(); 566 } 567 568 570 597 598 private void enableModifiers(boolean enable) { 599 defaultRadio.setEnabled(enable); 600 privateRadio.setEnabled(enable); 601 protectedRadio.setEnabled(enable); 602 publicRadio.setEnabled(enable); 603 staticCheck.setEnabled(enable); 604 finalCheck.setEnabled(enable); 605 transientCheck.setEnabled(enable); 606 607 initTextField.setEnabled(enable); 609 initButton.setEnabled(enable); 610 } 611 612 } 613 | Popular Tags |