1 19 20 package org.netbeans.modules.apisupport.project.ui.platform; 21 22 import java.awt.Container ; 23 import java.awt.Dialog ; 24 import java.awt.Window ; 25 import java.text.MessageFormat ; 26 import javax.swing.JButton ; 27 import javax.swing.JComponent ; 28 import javax.swing.JPanel ; 29 import javax.swing.event.ListSelectionEvent ; 30 import javax.swing.event.ListSelectionListener ; 31 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardPanel; 32 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 33 import org.openide.DialogDescriptor; 34 import org.openide.DialogDisplayer; 35 import org.openide.WizardDescriptor; 36 import org.openide.awt.Mnemonics; 37 import org.openide.util.HelpCtx; 38 import org.openide.util.NbBundle; 39 40 45 public final class NbPlatformCustomizer extends JPanel { 46 47 static final String CHOOSER_STEP = getMessage("MSG_ChoosePlatfrom"); static final String INFO_STEP = getMessage("MSG_PlatformName"); 50 static final String PLAF_DIR_PROPERTY = "selectedPlafDir"; static final String PLAF_LABEL_PROPERTY = "selectedPlafLabel"; 53 private NbPlatformCustomizerSources sourcesTab; 54 private NbPlatformCustomizerModules modulesTab; 55 private NbPlatformCustomizerJavadoc javadocTab; 56 private NbPlatformCustomizerHarness harnessTab; 57 58 public static void showCustomizer() { 59 HarnessUpgrader.checkForUpgrade(); 60 NbPlatformCustomizer customizer = new NbPlatformCustomizer(); 61 JButton closeButton = new JButton (); 62 Mnemonics.setLocalizedText(closeButton, 63 NbBundle.getMessage(NbPlatformCustomizer.class, "CTL_Close")); 64 DialogDescriptor descriptor = new DialogDescriptor( 65 customizer, 66 getMessage("CTL_NbPlatformManager_Title"), true, 68 new Object [] {closeButton}, 69 closeButton, 70 DialogDescriptor.DEFAULT_ALIGN, 71 new HelpCtx(NbPlatformCustomizer.class), 72 null); 73 Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor); 74 dlg.setVisible(true); 75 dlg.dispose(); 76 } 77 78 81 private NbPlatformCustomizer() { 82 initComponents(); 83 initAccessibility(); 84 initTabs(); 85 platformsList.addListSelectionListener(new ListSelectionListener () { 86 public void valueChanged(ListSelectionEvent e) { 87 refreshPlatform(); 88 } 89 }); 90 refreshPlatform(); 91 } 92 93 private void initTabs() { 94 if (platformsList.getModel().getSize() > 0) { 95 platformsList.setSelectedIndex(0); 96 sourcesTab = new NbPlatformCustomizerSources(); 97 modulesTab = new NbPlatformCustomizerModules(); 98 javadocTab = new NbPlatformCustomizerJavadoc(); 99 harnessTab = new NbPlatformCustomizerHarness(); 100 detailPane.addTab(getMessage("CTL_ModulesTab"), modulesTab); detailPane.addTab(getMessage("CTL_SourcesTab"), sourcesTab); detailPane.addTab(getMessage("CTL_JavadocTab"), javadocTab); detailPane.addTab(getMessage("CTL_HarnessTab"), harnessTab); Container window = this.getTopLevelAncestor(); 105 if (window != null && window instanceof Window ) { 106 ((Window ) window).pack(); 107 } 108 } 109 } 110 111 private void refreshPlatform() { 112 NbPlatform plaf = (NbPlatform) platformsList.getSelectedValue(); 113 if (plaf == null) { 114 removeButton.setEnabled(false); 115 return; 116 } 117 plfNameValue.setText(plaf.getLabel()); 118 plfFolderValue.setText(plaf.getDestDir().getAbsolutePath()); 119 boolean isValid = plaf.isValid(); 120 if (isValid) { 121 if (sourcesTab == null) { 122 initTabs(); 123 } 124 if (sourcesTab != null) { 125 modulesTab.setPlatform(plaf); 126 sourcesTab.setPlatform(plaf); 127 javadocTab.setPlatform(plaf); 128 harnessTab.setPlatform(plaf); 129 } 130 } else { 131 modulesTab.reset(); 132 detailPane.setSelectedIndex(0); 133 } 134 detailPane.setEnabledAt(0, isValid); 135 detailPane.setEnabledAt(1, isValid); 136 detailPane.setEnabledAt(2, isValid); 137 removeButton.setEnabled(!plaf.isDefault()); 138 } 139 140 private static String getMessage(String key) { 141 return NbBundle.getMessage(NbPlatformCustomizer.class, key); 142 } 143 144 149 private void initComponents() { 151 java.awt.GridBagConstraints gridBagConstraints; 152 153 platformLbl = new javax.swing.JLabel (); 154 platformsListSP = new javax.swing.JScrollPane (); 155 platformsList = PlatformComponentFactory.getNbPlatformsList(); 156 addButton = new javax.swing.JButton (); 157 removeButton = new javax.swing.JButton (); 158 infoPane = new javax.swing.JPanel (); 159 plfName = new javax.swing.JLabel (); 160 pflFolder = new javax.swing.JLabel (); 161 plfNameValue = new javax.swing.JTextField (); 162 plfFolderValue = new javax.swing.JTextField (); 163 detailPane = new javax.swing.JTabbedPane (); 164 165 setLayout(new java.awt.GridBagLayout ()); 166 167 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (12, 12, 12, 12))); 168 platformLbl.setLabelFor(platformsList); 169 org.openide.awt.Mnemonics.setLocalizedText(platformLbl, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "LBL_Platforms")); 170 gridBagConstraints = new java.awt.GridBagConstraints (); 171 gridBagConstraints.gridx = 0; 172 gridBagConstraints.gridy = 0; 173 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 174 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 175 add(platformLbl, gridBagConstraints); 176 177 platformsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 178 platformsListSP.setViewportView(platformsList); 179 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 0; 182 gridBagConstraints.gridy = 1; 183 gridBagConstraints.gridwidth = 2; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 185 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 186 gridBagConstraints.weighty = 1.0; 187 gridBagConstraints.insets = new java.awt.Insets (2, 0, 12, 6); 188 add(platformsListSP, gridBagConstraints); 189 190 org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "CTL_AddPlatform")); 191 addButton.addActionListener(new java.awt.event.ActionListener () { 192 public void actionPerformed(java.awt.event.ActionEvent evt) { 193 addPlatform(evt); 194 } 195 }); 196 197 gridBagConstraints = new java.awt.GridBagConstraints (); 198 gridBagConstraints.gridx = 0; 199 gridBagConstraints.gridy = 2; 200 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 201 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 6); 202 add(addButton, gridBagConstraints); 203 204 org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "CTL_RemovePlatfrom")); 205 removeButton.addActionListener(new java.awt.event.ActionListener () { 206 public void actionPerformed(java.awt.event.ActionEvent evt) { 207 removePlatform(evt); 208 } 209 }); 210 211 gridBagConstraints = new java.awt.GridBagConstraints (); 212 gridBagConstraints.gridx = 1; 213 gridBagConstraints.gridy = 2; 214 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 215 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 6); 216 add(removeButton, gridBagConstraints); 217 218 infoPane.setLayout(new java.awt.GridBagLayout ()); 219 220 plfName.setLabelFor(plfNameValue); 221 org.openide.awt.Mnemonics.setLocalizedText(plfName, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "LBL_PlatformName_N")); 222 gridBagConstraints = new java.awt.GridBagConstraints (); 223 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 224 infoPane.add(plfName, gridBagConstraints); 225 226 pflFolder.setLabelFor(plfFolderValue); 227 org.openide.awt.Mnemonics.setLocalizedText(pflFolder, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "LBL_PlatformFolder")); 228 gridBagConstraints = new java.awt.GridBagConstraints (); 229 gridBagConstraints.gridx = 0; 230 gridBagConstraints.gridy = 1; 231 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 232 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 233 infoPane.add(pflFolder, gridBagConstraints); 234 235 plfNameValue.setEditable(false); 236 gridBagConstraints = new java.awt.GridBagConstraints (); 237 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 238 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 239 gridBagConstraints.weightx = 1.0; 240 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 241 infoPane.add(plfNameValue, gridBagConstraints); 242 243 plfFolderValue.setEditable(false); 244 gridBagConstraints = new java.awt.GridBagConstraints (); 245 gridBagConstraints.gridx = 1; 246 gridBagConstraints.gridy = 1; 247 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 248 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 249 gridBagConstraints.weightx = 1.0; 250 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 251 infoPane.add(plfFolderValue, gridBagConstraints); 252 253 gridBagConstraints = new java.awt.GridBagConstraints (); 254 gridBagConstraints.gridx = 0; 255 gridBagConstraints.gridy = 2; 256 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 257 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 258 gridBagConstraints.weightx = 1.0; 259 gridBagConstraints.weighty = 1.0; 260 infoPane.add(detailPane, gridBagConstraints); 261 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 2; 264 gridBagConstraints.gridy = 1; 265 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 266 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 267 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 268 gridBagConstraints.weightx = 1.0; 269 gridBagConstraints.insets = new java.awt.Insets (2, 6, 12, 0); 270 add(infoPane, gridBagConstraints); 271 272 } 273 275 private PlatformComponentFactory.NbPlatformListModel getPlafListModel() { 276 return (PlatformComponentFactory.NbPlatformListModel) platformsList.getModel(); 277 } 278 279 private void removePlatform(java.awt.event.ActionEvent evt) { NbPlatform plaf = (NbPlatform) platformsList.getSelectedValue(); 281 if (plaf != null) { 282 getPlafListModel().removePlatform(plaf); 283 platformsList.setSelectedValue(NbPlatform.getDefaultPlatform(), true); 284 refreshPlatform(); 285 } 286 } 288 private void addPlatform(java.awt.event.ActionEvent evt) { PlatformChooserWizardPanel chooser = new PlatformChooserWizardPanel(null); 290 PlatformInfoWizardPanel info = new PlatformInfoWizardPanel(null); 291 WizardDescriptor wd = new WizardDescriptor(new WizardDescriptor.Panel[] { chooser, info }); 292 initPanel(chooser, wd, 0); 293 initPanel(info, wd, 1); 294 wd.setTitleFormat(new MessageFormat ("{0}")); Dialog dialog = DialogDisplayer.getDefault().createDialog(wd); 296 dialog.setTitle(getMessage("CTL_AddNetbeansPlatformTitle")); dialog.setVisible(true); 298 dialog.toFront(); 299 if (wd.getValue() == WizardDescriptor.FINISH_OPTION) { 300 String plafDir = (String ) wd.getProperty(PLAF_DIR_PROPERTY); 301 String plafLabel = (String ) wd.getProperty(PLAF_LABEL_PROPERTY); 302 String id = plafLabel.replace(' ', '_'); 303 NbPlatform plaf = getPlafListModel().addPlatform(id, plafDir, plafLabel); 304 if (plaf != null) { 305 platformsList.setSelectedValue(plaf, true); 306 refreshPlatform(); 307 } 308 } 309 } 311 private void initPanel(BasicWizardPanel panel, WizardDescriptor wd, int i) { 312 panel.setSettings(wd); 313 JComponent jc = (JComponent ) panel.getComponent(); 314 jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", new String [] { CHOOSER_STEP, INFO_STEP 320 }); 321 } 322 323 private javax.swing.JButton addButton; 325 private javax.swing.JTabbedPane detailPane; 326 private javax.swing.JPanel infoPane; 327 private javax.swing.JLabel pflFolder; 328 private javax.swing.JLabel platformLbl; 329 private javax.swing.JList platformsList; 330 private javax.swing.JScrollPane platformsListSP; 331 private javax.swing.JTextField plfFolderValue; 332 private javax.swing.JLabel plfName; 333 private javax.swing.JTextField plfNameValue; 334 private javax.swing.JButton removeButton; 335 337 private void initAccessibility() { 338 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NbPlatformCustomizer")); 339 platformsList.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_platformsList")); 340 plfFolderValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_plfFolderValue")); 341 plfNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_plfNameValue")); 342 removeButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_removeButton")); 343 addButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_addButton")); 344 } 345 } 346 | Popular Tags |