1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.net.URL ; 25 import java.util.SortedSet ; 26 import java.util.TreeSet ; 27 import javax.swing.DefaultListModel ; 28 import javax.swing.JPanel ; 29 import org.netbeans.modules.apisupport.project.ManifestManager; 30 import org.netbeans.modules.apisupport.project.Util; 31 import org.netbeans.modules.apisupport.project.ui.UIUtil; 32 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 33 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 34 import org.openide.awt.HtmlBrowser; 35 import org.openide.util.NbBundle; 36 37 43 public final class EditDependencyPanel extends JPanel { 44 45 private final ModuleDependency origDep; 46 private final URL javadoc; 47 48 private final ManifestManager.PackageExport[] pp; 49 private final DefaultListModel packagesModel = new DefaultListModel (); 50 51 52 public EditDependencyPanel(final ModuleDependency dep, final NbPlatform platform) { 53 this.origDep = dep; 54 this.pp = origDep.getModuleEntry().getPublicPackages(); 55 initComponents(); 56 initDependency(); 57 if (platform == null) { javadoc = Util.findJavadocForNetBeansOrgModules(origDep); 59 } else { 60 javadoc = Util.findJavadoc(origDep, platform); 61 } 62 showJavadocButton.setEnabled(javadoc != null); 63 getAccessibleContext().setAccessibleDescription( 64 NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.title.AccessibleContext.accessibleName")); 65 } 66 67 private void refresh() { 68 specVerValue.setEnabled(specVer.isSelected()); 69 includeInCP.setEnabled(hasAvailablePackages()); 70 if (!includeInCP.isEnabled()) { 71 includeInCP.setSelected(false); 72 } } 74 75 private boolean hasAvailablePackages() { 76 return implVer.isSelected() || pp.length > 0; 77 } 78 79 80 private void initDependency() { 81 ModuleEntry me = origDep.getModuleEntry(); 82 UIUtil.setText(codeNameBaseValue, me.getCodeNameBase()); 83 UIUtil.setText(jarLocationValue, me.getJarLocation().getAbsolutePath()); 84 UIUtil.setText(releaseVersionValue, origDep.getReleaseVersion()); 85 UIUtil.setText(specVerValue, origDep.hasImplementationDepedendency() ? 86 me.getSpecificationVersion() : 87 origDep.getSpecificationVersion()); 88 implVer.setSelected(origDep.hasImplementationDepedendency()); 89 availablePkg.setEnabled(hasAvailablePackages()); 90 includeInCP.setSelected(origDep.hasCompileDependency()); 91 refreshAvailablePackages(); 92 refresh(); 93 ActionListener versionListener = new ActionListener () { 94 public void actionPerformed(ActionEvent arg0) { 95 refreshAvailablePackages(); 96 } 97 }; 98 implVer.addActionListener(versionListener); 99 specVer.addActionListener(versionListener); 100 } 101 102 public void refreshAvailablePackages() { 103 packagesModel.clear(); 104 if (hasAvailablePackages()) { 105 SortedSet <String > packages = new TreeSet <String >(); 108 for (int i = 0; i < pp.length; i++) { packages.add(pp[i].getPackage() + (pp[i].isRecursive() ? ".**" : "")); } 111 if (implVer.isSelected()) { packages.addAll(origDep.getModuleEntry().getAllPackageNames()); 113 } 114 for (String pkg : packages) { 115 packagesModel.addElement(pkg); 116 } 117 } else { 118 packagesModel.addElement(NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel_empty")); 119 } 120 availablePkg.setModel(packagesModel); 121 } 122 123 public ModuleDependency getEditedDependency() { 124 ModuleDependency dep = new ModuleDependency(origDep.getModuleEntry(), 125 releaseVersionValue.getText().trim(), 126 specVerValue.getText().trim(), 127 includeInCP.isSelected(), 128 implVer.isSelected()); 129 return dep; 130 } 131 132 137 private void initComponents() { 139 java.awt.GridBagConstraints gridBagConstraints; 140 141 versionGroup = new javax.swing.ButtonGroup (); 142 codeNameBase = new javax.swing.JLabel (); 143 jarLocation = new javax.swing.JLabel (); 144 releaseVersion = new javax.swing.JLabel (); 145 releaseVersionValue = new javax.swing.JTextField (); 146 specVer = new javax.swing.JRadioButton (); 147 specVerValue = new javax.swing.JTextField (); 148 implVer = new javax.swing.JRadioButton (); 149 includeInCP = new javax.swing.JCheckBox (); 150 availablePkgSP = new javax.swing.JScrollPane (); 151 availablePkg = new javax.swing.JList (); 152 codeNameBaseValue = new javax.swing.JTextField (); 153 jarLocationValue = new javax.swing.JTextField (); 154 showJavadocButton = new javax.swing.JButton (); 155 156 setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6, 6)); 157 setPreferredSize(new java.awt.Dimension (400, 300)); 158 setLayout(new java.awt.GridBagLayout ()); 159 160 codeNameBase.setLabelFor(codeNameBaseValue); 161 org.openide.awt.Mnemonics.setLocalizedText(codeNameBase, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_CNB")); gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 0; 164 gridBagConstraints.gridy = 0; 165 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 166 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 167 add(codeNameBase, gridBagConstraints); 168 codeNameBase.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.codeNameBase.AccessibleContext.accessibleDescription")); 170 jarLocation.setLabelFor(jarLocationValue); 171 org.openide.awt.Mnemonics.setLocalizedText(jarLocation, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_JAR")); gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 0; 174 gridBagConstraints.gridy = 1; 175 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 176 gridBagConstraints.insets = new java.awt.Insets (2, 0, 0, 12); 177 add(jarLocation, gridBagConstraints); 178 jarLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.jarLocation.AccessibleContext.accessibleDescription")); 180 releaseVersion.setLabelFor(releaseVersionValue); 181 org.openide.awt.Mnemonics.setLocalizedText(releaseVersion, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_MajorReleaseVersion")); gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.gridx = 0; 184 gridBagConstraints.gridy = 2; 185 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 186 gridBagConstraints.insets = new java.awt.Insets (24, 0, 0, 12); 187 add(releaseVersion, gridBagConstraints); 188 gridBagConstraints = new java.awt.GridBagConstraints (); 189 gridBagConstraints.gridx = 1; 190 gridBagConstraints.gridy = 2; 191 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 192 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 193 gridBagConstraints.weightx = 1.0; 194 gridBagConstraints.insets = new java.awt.Insets (24, 0, 0, 0); 195 add(releaseVersionValue, gridBagConstraints); 196 releaseVersionValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.releaseVersionValue.AccessibleContext.accessibleName")); releaseVersionValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.releaseVersionValue.AccessibleContext.accessibleDescription")); 199 versionGroup.add(specVer); 200 specVer.setSelected(true); 201 org.openide.awt.Mnemonics.setLocalizedText(specVer, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_SpecificationVersion")); specVer.addActionListener(new java.awt.event.ActionListener () { 203 public void actionPerformed(java.awt.event.ActionEvent evt) { 204 versionChanged(evt); 205 } 206 }); 207 gridBagConstraints = new java.awt.GridBagConstraints (); 208 gridBagConstraints.gridx = 0; 209 gridBagConstraints.gridy = 3; 210 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 211 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 212 add(specVer, gridBagConstraints); 213 specVer.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.specVer.AccessibleContext.accessibleDescription")); 215 gridBagConstraints = new java.awt.GridBagConstraints (); 216 gridBagConstraints.gridx = 1; 217 gridBagConstraints.gridy = 3; 218 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 219 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 220 add(specVerValue, gridBagConstraints); 221 specVerValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.specVerValue.AccessibleContext.accessibleName")); specVerValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.specVerValue.AccessibleContext.accessibleDescription")); 224 versionGroup.add(implVer); 225 org.openide.awt.Mnemonics.setLocalizedText(implVer, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_ImplementationVersion")); implVer.addActionListener(new java.awt.event.ActionListener () { 227 public void actionPerformed(java.awt.event.ActionEvent evt) { 228 versionChanged(evt); 229 } 230 }); 231 gridBagConstraints = new java.awt.GridBagConstraints (); 232 gridBagConstraints.gridx = 0; 233 gridBagConstraints.gridy = 4; 234 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 235 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 236 add(implVer, gridBagConstraints); 237 implVer.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.implVer.AccessibleContext.accessibleDescription")); 239 org.openide.awt.Mnemonics.setLocalizedText(includeInCP, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_IncludeAPIPackages")); gridBagConstraints = new java.awt.GridBagConstraints (); 241 gridBagConstraints.gridx = 0; 242 gridBagConstraints.gridy = 5; 243 gridBagConstraints.gridwidth = 2; 244 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 245 gridBagConstraints.insets = new java.awt.Insets (24, 0, 0, 0); 246 add(includeInCP, gridBagConstraints); 247 includeInCP.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.includeInCP.AccessibleContext.accessibleDescription")); 249 availablePkgSP.setViewportView(availablePkg); 250 availablePkg.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.availablePkg.AccessibleContext.accessibleName")); availablePkg.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.availablePkg.AccessibleContext.accessibleDescription")); 253 gridBagConstraints = new java.awt.GridBagConstraints (); 254 gridBagConstraints.gridx = 0; 255 gridBagConstraints.gridy = 6; 256 gridBagConstraints.gridwidth = 2; 257 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 258 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 259 gridBagConstraints.weighty = 1.0; 260 add(availablePkgSP, gridBagConstraints); 261 262 codeNameBaseValue.setEditable(false); 263 gridBagConstraints = new java.awt.GridBagConstraints (); 264 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 266 add(codeNameBaseValue, gridBagConstraints); 267 codeNameBaseValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.codeNameBaseValue.AccessibleContext.accessibleName")); codeNameBaseValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.codeNameBaseValue.AccessibleContext.accessibleDescription")); 270 jarLocationValue.setEditable(false); 271 gridBagConstraints = new java.awt.GridBagConstraints (); 272 gridBagConstraints.gridx = 1; 273 gridBagConstraints.gridy = 1; 274 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 275 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 276 gridBagConstraints.insets = new java.awt.Insets (2, 0, 0, 0); 277 add(jarLocationValue, gridBagConstraints); 278 jarLocationValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.jarLocationValue.AccessibleContext.accessibleName")); jarLocationValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.jarLocationValue.AccessibleContext.accessibleDescription")); 281 org.openide.awt.Mnemonics.setLocalizedText(showJavadocButton, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "CTL_ShowJavadoc")); showJavadocButton.addActionListener(new java.awt.event.ActionListener () { 283 public void actionPerformed(java.awt.event.ActionEvent evt) { 284 showJavadoc(evt); 285 } 286 }); 287 gridBagConstraints = new java.awt.GridBagConstraints (); 288 gridBagConstraints.gridx = 0; 289 gridBagConstraints.gridy = 7; 290 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 291 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 292 gridBagConstraints.insets = new java.awt.Insets (24, 0, 0, 0); 293 add(showJavadocButton, gridBagConstraints); 294 showJavadocButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.showJavadocButton.AccessibleContext.accessibleDescription")); } 297 private void showJavadoc(java.awt.event.ActionEvent evt) { HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc); 299 } 301 private void versionChanged(java.awt.event.ActionEvent evt) { refresh(); 303 if (implVer.isSelected()) { includeInCP.setSelected(true); 305 } 306 } 308 private javax.swing.JList availablePkg; 310 private javax.swing.JScrollPane availablePkgSP; 311 private javax.swing.JLabel codeNameBase; 312 private javax.swing.JTextField codeNameBaseValue; 313 private javax.swing.JRadioButton implVer; 314 private javax.swing.JCheckBox includeInCP; 315 private javax.swing.JLabel jarLocation; 316 private javax.swing.JTextField jarLocationValue; 317 private javax.swing.JLabel releaseVersion; 318 private javax.swing.JTextField releaseVersionValue; 319 private javax.swing.JButton showJavadocButton; 320 private javax.swing.JRadioButton specVer; 321 private javax.swing.JTextField specVerValue; 322 private javax.swing.ButtonGroup versionGroup; 323 325 } 326 | Popular Tags |