1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.options; 21 22 import java.io.File ; 23 import javax.swing.JFileChooser ; 24 import javax.swing.event.DocumentEvent ; 25 import javax.swing.event.DocumentListener ; 26 import org.netbeans.modules.apisupport.project.ui.UIUtil; 27 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator; 28 import org.openide.WizardDescriptor; 29 import org.openide.util.HelpCtx; 30 import org.openide.util.NbBundle; 31 32 35 final class OptionsPanel0 extends BasicWizardIterator.Panel { 36 private NewOptionsIterator.DataModel data; 37 private DocumentListener fieldsDL; 38 39 public OptionsPanel0(final WizardDescriptor setting, final NewOptionsIterator.DataModel data) { 40 super(setting); 41 this.data = data; 42 initComponents(); 43 initAccessibility(); 44 putClientProperty("NewFileWizard_Title", NbBundle.getMessage(OptionsPanel0.class,"LBL_OptionsWizardTitle")); 47 } 48 49 private void addListeners() { 50 if (fieldsDL == null) { 51 fieldsDL = new UIUtil.DocumentAdapter() { 52 public void insertUpdate(DocumentEvent e) { updateData(); } 53 }; 54 55 categoryNameField.getDocument().addDocumentListener(fieldsDL); 56 displayNameField1.getDocument().addDocumentListener(fieldsDL); 57 iconField.getDocument().addDocumentListener(fieldsDL); 58 titleField.getDocument().addDocumentListener(fieldsDL); 59 tooltipField1.getDocument().addDocumentListener(fieldsDL); 60 } 61 } 62 63 private void removeListeners() { 64 if (fieldsDL != null) { 65 categoryNameField.getDocument().removeDocumentListener(fieldsDL); 66 displayNameField1.getDocument().removeDocumentListener(fieldsDL); 67 iconField.getDocument().removeDocumentListener(fieldsDL); 68 titleField.getDocument().removeDocumentListener(fieldsDL); 69 tooltipField1.getDocument().removeDocumentListener(fieldsDL); 70 fieldsDL = null; 71 } 72 } 73 74 75 protected void storeToDataModel() { 76 removeListeners(); 77 updateData(); 78 } 79 protected void readFromDataModel() { 80 addListeners(); 81 } 82 83 private void updateData() { 84 int retCode = 0; 85 if (advancedButton.isSelected()) { 86 assert !optionsCategoryButton.isSelected(); 87 retCode = data.setDataForAdvanced(displayNameField1.getText(), tooltipField1.getText()); 88 } else { 89 assert optionsCategoryButton.isSelected(); 90 retCode = data.setDataForOptionCategory(titleField.getText(), 91 categoryNameField.getText(), iconField.getText()); 92 } 93 if (data.isSuccessCode(retCode)) { 94 markValid(); 95 } else if (data.isErrorCode(retCode)) { 96 setError(data.getErrorMessage(retCode)); 97 } else if (data.isWarningCode(retCode)) { 98 setWarning(data.getWarningMessage(retCode)); 99 } else { 100 assert false : retCode; 101 } 102 } 103 104 protected String getPanelName() { 105 return NbBundle.getMessage(OptionsPanel0.class,"LBL_OptionsPanel0_Title"); } 107 108 109 protected HelpCtx getHelp() { 110 return new HelpCtx(OptionsPanel0.class); 111 } 112 113 private static String getMessage(String key) { 114 return NbBundle.getMessage(OptionsPanel0.class, key); 115 } 116 117 private void initAccessibility() { 118 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_OptionsPanel0")); 119 advancedButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_Advanced")); 120 optionsCategoryButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_OptionsCategory")); 121 titleField.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Title")); 122 tooltipField1.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Tooltip")); 123 displayNameField1.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_DisplayName")); 124 categoryNameField.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CategoryName")); 125 iconField.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconPath")); 126 iconButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton")); 127 } 128 129 public void addNotify() { 130 super.addNotify(); 131 addListeners(); 132 updateData(); 133 } 134 135 public void removeNotify() { 136 super.removeNotify(); 137 removeListeners(); 138 } 139 140 private void enableDisable() { 141 boolean advancedEnabled = advancedButton.isSelected(); 142 assert advancedEnabled != optionsCategoryButton.isSelected(); 143 144 categoryNameField.setEnabled(!advancedEnabled); 145 categoryNameLbl.setEnabled(!advancedEnabled); 146 iconButton.setEnabled(!advancedEnabled); 147 iconField.setEnabled(!advancedEnabled); 148 iconLbl.setEnabled(!advancedEnabled); 149 titleField.setEnabled(!advancedEnabled); 150 titleLbl.setEnabled(!advancedEnabled); 151 152 displayNameField1.setEnabled(advancedEnabled); 153 displayNameLbl1.setEnabled(advancedEnabled); 154 tooltipField1.setEnabled(advancedEnabled); 155 tooltipLbl1.setEnabled(advancedEnabled); 156 } 157 158 163 private void initComponents() { 165 java.awt.GridBagConstraints gridBagConstraints; 166 167 buttonGroup1 = new javax.swing.ButtonGroup (); 168 advancedButton = new javax.swing.JRadioButton (); 169 optionsCategoryButton = new javax.swing.JRadioButton (); 170 dummyPanel = new javax.swing.JPanel (); 171 categoryNameLbl = new javax.swing.JLabel (); 172 categoryNameField = new javax.swing.JTextField (); 173 displayNameLbl1 = new javax.swing.JLabel (); 174 displayNameField1 = new javax.swing.JTextField (); 175 tooltipLbl1 = new javax.swing.JLabel (); 176 tooltipField1 = new javax.swing.JTextField (); 177 titleLbl = new javax.swing.JLabel (); 178 titleField = new javax.swing.JTextField (); 179 iconLbl = new javax.swing.JLabel (); 180 iconField = new javax.swing.JTextField (); 181 iconButton = new javax.swing.JButton (); 182 183 setLayout(new java.awt.GridBagLayout ()); 184 185 buttonGroup1.add(advancedButton); 186 advancedButton.setSelected(true); 187 org.openide.awt.Mnemonics.setLocalizedText(advancedButton, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_Advanced")); 188 advancedButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 189 advancedButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 190 advancedButton.addActionListener(new java.awt.event.ActionListener () { 191 public void actionPerformed(java.awt.event.ActionEvent evt) { 192 advancedButtonActionPerformed(evt); 193 } 194 }); 195 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 198 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 199 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 200 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 201 add(advancedButton, gridBagConstraints); 202 203 buttonGroup1.add(optionsCategoryButton); 204 org.openide.awt.Mnemonics.setLocalizedText(optionsCategoryButton, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_OptionsCategory")); 205 optionsCategoryButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 206 optionsCategoryButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 207 optionsCategoryButton.addActionListener(new java.awt.event.ActionListener () { 208 public void actionPerformed(java.awt.event.ActionEvent evt) { 209 optionsCategoryButtonActionPerformed(evt); 210 } 211 }); 212 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.gridx = 0; 215 gridBagConstraints.gridy = 3; 216 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 217 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 219 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 220 add(optionsCategoryButton, gridBagConstraints); 221 222 gridBagConstraints = new java.awt.GridBagConstraints (); 223 gridBagConstraints.gridx = 0; 224 gridBagConstraints.gridy = 7; 225 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 226 gridBagConstraints.weightx = 1.0; 227 gridBagConstraints.weighty = 1.0; 228 add(dummyPanel, gridBagConstraints); 229 230 categoryNameLbl.setLabelFor(categoryNameField); 231 org.openide.awt.Mnemonics.setLocalizedText(categoryNameLbl, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_CategoryName")); 232 categoryNameLbl.setEnabled(false); 233 gridBagConstraints = new java.awt.GridBagConstraints (); 234 gridBagConstraints.gridx = 0; 235 gridBagConstraints.gridy = 5; 236 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 237 gridBagConstraints.insets = new java.awt.Insets (0, 18, 6, 12); 238 add(categoryNameLbl, gridBagConstraints); 239 240 categoryNameField.setEnabled(false); 241 gridBagConstraints = new java.awt.GridBagConstraints (); 242 gridBagConstraints.gridx = 1; 243 gridBagConstraints.gridy = 5; 244 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 245 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 246 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 247 gridBagConstraints.weightx = 1.0; 248 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 249 add(categoryNameField, gridBagConstraints); 250 251 displayNameLbl1.setLabelFor(displayNameField1); 252 org.openide.awt.Mnemonics.setLocalizedText(displayNameLbl1, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_DisplaName")); 253 gridBagConstraints = new java.awt.GridBagConstraints (); 254 gridBagConstraints.gridx = 0; 255 gridBagConstraints.gridy = 1; 256 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 257 gridBagConstraints.insets = new java.awt.Insets (0, 18, 6, 12); 258 add(displayNameLbl1, gridBagConstraints); 259 260 gridBagConstraints = new java.awt.GridBagConstraints (); 261 gridBagConstraints.gridx = 1; 262 gridBagConstraints.gridy = 1; 263 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 264 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 266 gridBagConstraints.weightx = 1.0; 267 add(displayNameField1, gridBagConstraints); 268 269 tooltipLbl1.setLabelFor(tooltipField1); 270 org.openide.awt.Mnemonics.setLocalizedText(tooltipLbl1, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_Tooltip")); 271 gridBagConstraints = new java.awt.GridBagConstraints (); 272 gridBagConstraints.gridx = 0; 273 gridBagConstraints.gridy = 2; 274 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 275 gridBagConstraints.insets = new java.awt.Insets (6, 18, 6, 12); 276 add(tooltipLbl1, gridBagConstraints); 277 278 gridBagConstraints = new java.awt.GridBagConstraints (); 279 gridBagConstraints.gridx = 1; 280 gridBagConstraints.gridy = 2; 281 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 282 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 283 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 284 gridBagConstraints.weightx = 1.0; 285 add(tooltipField1, gridBagConstraints); 286 287 titleLbl.setLabelFor(titleField); 288 org.openide.awt.Mnemonics.setLocalizedText(titleLbl, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_Title")); 289 titleLbl.setEnabled(false); 290 gridBagConstraints = new java.awt.GridBagConstraints (); 291 gridBagConstraints.gridx = 0; 292 gridBagConstraints.gridy = 4; 293 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 294 gridBagConstraints.insets = new java.awt.Insets (6, 18, 6, 12); 295 add(titleLbl, gridBagConstraints); 296 297 titleField.setEnabled(false); 298 gridBagConstraints = new java.awt.GridBagConstraints (); 299 gridBagConstraints.gridx = 1; 300 gridBagConstraints.gridy = 4; 301 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 302 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 303 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 304 gridBagConstraints.weightx = 1.0; 305 add(titleField, gridBagConstraints); 306 307 iconLbl.setLabelFor(iconField); 308 org.openide.awt.Mnemonics.setLocalizedText(iconLbl, org.openide.util.NbBundle.getMessage(OptionsPanel0.class, "LBL_Icon")); 309 iconLbl.setEnabled(false); 310 gridBagConstraints = new java.awt.GridBagConstraints (); 311 gridBagConstraints.gridx = 0; 312 gridBagConstraints.gridy = 6; 313 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 314 gridBagConstraints.insets = new java.awt.Insets (0, 18, 0, 0); 315 add(iconLbl, gridBagConstraints); 316 317 iconField.setEditable(false); 318 iconField.setText(org.openide.util.NbBundle.getMessage(OptionsPanel0.class, "CTL_None")); 319 iconField.setEnabled(false); 320 gridBagConstraints = new java.awt.GridBagConstraints (); 321 gridBagConstraints.gridx = 1; 322 gridBagConstraints.gridy = 6; 323 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 324 gridBagConstraints.weightx = 1.0; 325 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 326 add(iconField, gridBagConstraints); 327 328 org.openide.awt.Mnemonics.setLocalizedText(iconButton, org.openide.util.NbBundle.getMessage(OptionsPanel0.class, "LBL_Icon_Browse")); 329 iconButton.setEnabled(false); 330 iconButton.addActionListener(new java.awt.event.ActionListener () { 331 public void actionPerformed(java.awt.event.ActionEvent evt) { 332 iconButtonActionPerformed(evt); 333 } 334 }); 335 336 gridBagConstraints = new java.awt.GridBagConstraints (); 337 gridBagConstraints.gridx = 2; 338 gridBagConstraints.gridy = 6; 339 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 340 gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE; 341 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 342 add(iconButton, gridBagConstraints); 343 344 } 346 private void optionsCategoryButtonActionPerformed(java.awt.event.ActionEvent evt) { enableDisable(); 348 updateData(); 349 } 351 private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) { enableDisable(); 353 updateData(); 354 } 356 private void iconButtonActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = UIUtil.getIconFileChooser(iconField.getText()); 358 int ret = chooser.showDialog(this, getMessage("LBL_Select")); if (ret == JFileChooser.APPROVE_OPTION) { 360 File iconFile = chooser.getSelectedFile(); 361 iconField.setText(iconFile.getAbsolutePath()); 362 } 364 } 366 private javax.swing.JRadioButton advancedButton; 368 private javax.swing.ButtonGroup buttonGroup1; 369 private javax.swing.JTextField categoryNameField; 370 private javax.swing.JLabel categoryNameLbl; 371 private javax.swing.JTextField displayNameField1; 372 private javax.swing.JLabel displayNameLbl1; 373 private javax.swing.JPanel dummyPanel; 374 private javax.swing.JButton iconButton; 375 private javax.swing.JTextField iconField; 376 private javax.swing.JLabel iconLbl; 377 private javax.swing.JRadioButton optionsCategoryButton; 378 private javax.swing.JTextField titleField; 379 private javax.swing.JLabel titleLbl; 380 private javax.swing.JTextField tooltipField1; 381 private javax.swing.JLabel tooltipLbl1; 382 384 } 385 | Popular Tags |