1 19 20 package org.netbeans.modules.apisupport.project.ui.platform; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.Locale ; 25 import javax.swing.JFileChooser ; 26 import javax.swing.JPanel ; 27 import javax.swing.filechooser.FileFilter ; 28 import org.netbeans.modules.apisupport.project.Util; 29 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings; 30 import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizerSources.ListListener; 31 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.NbBundle; 34 35 40 final class NbPlatformCustomizerJavadoc extends JPanel { 41 42 private NbPlatform plaf; 43 private PlatformComponentFactory.NbPlatformJavadocRootsModel model; 44 private final ListListener listListener; 45 46 47 NbPlatformCustomizerJavadoc() { 48 initComponents(); 49 initAccessibility(); 50 this.listListener = new ListListener() { 51 void listChanged() { 52 updateEnabled(); 53 } 54 }; 55 updateEnabled(); 56 } 57 58 public void addNotify() { 59 super.addNotify(); 60 javadocList.addListSelectionListener(listListener); 61 javadocList.getModel().addListDataListener(listListener); 62 } 63 64 public void removeNotify() { 65 javadocList.removeListSelectionListener(listListener); 66 javadocList.getModel().removeListDataListener(listListener); 67 super.removeNotify(); 68 } 69 70 private void updateEnabled() { 71 removeButton.setEnabled(javadocList.getModel().getSize() > 0 && javadocList.getSelectedIndex() != -1); 73 moveUpButton.setEnabled(javadocList.getSelectionModel().getMinSelectionIndex() > 0); 74 moveDownButton.setEnabled(plaf != null && 75 javadocList.getSelectionModel().getMaxSelectionIndex() < plaf.getJavadocRoots().length - 1); 76 } 77 78 void setPlatform(NbPlatform plaf) { 79 this.plaf = plaf; 80 this.model = new PlatformComponentFactory.NbPlatformJavadocRootsModel(plaf); 81 javadocList.setModel(model); 82 } 83 84 89 private void initComponents() { 91 java.awt.GridBagConstraints gridBagConstraints; 92 93 javadocLabel = new javax.swing.JLabel (); 94 javadocSP = new javax.swing.JScrollPane (); 95 javadocList = new javax.swing.JList (); 96 buttonPanel = new javax.swing.JPanel (); 97 addFolderButton = new javax.swing.JButton (); 98 removeButton = new javax.swing.JButton (); 99 moveUpButton = new javax.swing.JButton (); 100 moveDownButton = new javax.swing.JButton (); 101 102 setLayout(new java.awt.GridBagLayout ()); 103 104 setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 12, 12)); 105 javadocLabel.setLabelFor(javadocList); 106 org.openide.awt.Mnemonics.setLocalizedText(javadocLabel, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "LBL_PlatformJavadoc")); 107 gridBagConstraints = new java.awt.GridBagConstraints (); 108 gridBagConstraints.gridx = 0; 109 gridBagConstraints.gridy = 0; 110 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 111 add(javadocLabel, gridBagConstraints); 112 113 javadocList.setCellRenderer(PlatformComponentFactory.getURLListRenderer()); 114 javadocSP.setViewportView(javadocList); 115 116 gridBagConstraints = new java.awt.GridBagConstraints (); 117 gridBagConstraints.gridx = 0; 118 gridBagConstraints.gridy = 1; 119 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 120 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 121 gridBagConstraints.weightx = 1.0; 122 gridBagConstraints.weighty = 1.0; 123 add(javadocSP, gridBagConstraints); 124 125 buttonPanel.setLayout(new java.awt.GridBagLayout ()); 126 127 buttonPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 12, 0, 0)); 128 org.openide.awt.Mnemonics.setLocalizedText(addFolderButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_AddZipOrFolder")); 129 addFolderButton.addActionListener(new java.awt.event.ActionListener () { 130 public void actionPerformed(java.awt.event.ActionEvent evt) { 131 addZipFolder(evt); 132 } 133 }); 134 135 gridBagConstraints = new java.awt.GridBagConstraints (); 136 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 137 buttonPanel.add(addFolderButton, gridBagConstraints); 138 139 org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_Remove")); 140 removeButton.addActionListener(new java.awt.event.ActionListener () { 141 public void actionPerformed(java.awt.event.ActionEvent evt) { 142 removeFolder(evt); 143 } 144 }); 145 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridx = 0; 148 gridBagConstraints.gridy = 1; 149 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 150 gridBagConstraints.insets = new java.awt.Insets (12, 0, 12, 0); 151 buttonPanel.add(removeButton, gridBagConstraints); 152 153 org.openide.awt.Mnemonics.setLocalizedText(moveUpButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_MoveUp")); 154 moveUpButton.addActionListener(new java.awt.event.ActionListener () { 155 public void actionPerformed(java.awt.event.ActionEvent evt) { 156 moveUp(evt); 157 } 158 }); 159 160 gridBagConstraints = new java.awt.GridBagConstraints (); 161 gridBagConstraints.gridx = 0; 162 gridBagConstraints.gridy = 2; 163 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 164 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 0); 165 buttonPanel.add(moveUpButton, gridBagConstraints); 166 167 org.openide.awt.Mnemonics.setLocalizedText(moveDownButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, "CTL_MoveDown")); 168 moveDownButton.addActionListener(new java.awt.event.ActionListener () { 169 public void actionPerformed(java.awt.event.ActionEvent evt) { 170 moveDown(evt); 171 } 172 }); 173 174 gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 0; 176 gridBagConstraints.gridy = 3; 177 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 178 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 179 gridBagConstraints.weighty = 1.0; 180 buttonPanel.add(moveDownButton, gridBagConstraints); 181 182 gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.gridx = 1; 184 gridBagConstraints.gridy = 1; 185 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 186 add(buttonPanel, gridBagConstraints); 187 188 } 190 private void moveDown(java.awt.event.ActionEvent evt) { int[] selIndices = javadocList.getSelectedIndices(); 192 model.moveJavadocRootsDown(selIndices); 193 for (int i = 0; i < selIndices.length; i++) { 194 selIndices[i] = ++selIndices[i]; 195 } 196 javadocList.setSelectedIndices(selIndices); 197 } 199 private void moveUp(java.awt.event.ActionEvent evt) { int[] selIndices = javadocList.getSelectedIndices(); 201 model.moveJavadocRootsUp(selIndices); 202 for (int i = 0; i < selIndices.length; i++) { 203 selIndices[i] = --selIndices[i]; 204 } 205 javadocList.setSelectedIndices(selIndices); 206 } 208 private void removeFolder(java.awt.event.ActionEvent evt) { Object [] selVals = javadocList.getSelectedValues(); 210 int toSelect = javadocList.getSelectedIndex() - 1; 211 URL [] selURLs = new URL [selVals.length]; 212 System.arraycopy(selVals, 0, selURLs, 0, selVals.length); 213 model.removeJavadocRoots(selURLs); 214 javadocList.setSelectedIndex(toSelect); 215 } 217 private void addZipFolder(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (ModuleUISettings.getDefault().getLastUsedNbPlatformLocation()); 219 chooser.setAcceptAllFileFilterUsed(false); 220 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 221 chooser.setFileFilter(new FileFilter () { 222 public boolean accept(File f) { 223 return f.isDirectory() || 224 f.getName().toLowerCase(Locale.US).endsWith(".jar") || f.getName().toLowerCase(Locale.US).endsWith(".zip"); } 227 public String getDescription() { 228 return getMessage("CTL_JavadocTab"); 229 } 230 }); 231 int ret = chooser.showOpenDialog(this); 232 if (ret == JFileChooser.APPROVE_OPTION) { 233 File javadocRoot = FileUtil.normalizeFile(chooser.getSelectedFile()); 234 ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(javadocRoot.getParentFile().getAbsolutePath()); 235 URL newUrl = Util.urlForDirOrJar(javadocRoot); 236 model.addJavadocRoot(newUrl); 237 javadocList.setSelectedValue(newUrl, true); 238 } 239 } 241 242 private javax.swing.JButton addFolderButton; 244 private javax.swing.JPanel buttonPanel; 245 private javax.swing.JLabel javadocLabel; 246 private javax.swing.JList javadocList; 247 private javax.swing.JScrollPane javadocSP; 248 private javax.swing.JButton moveDownButton; 249 private javax.swing.JButton moveUpButton; 250 private javax.swing.JButton removeButton; 251 253 private void initAccessibility() { 254 addFolderButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_addFolderButton")); 255 javadocList.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_javadocList")); 256 moveDownButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_moveDownButton")); 257 moveUpButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_moveUpButton")); 258 removeButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_removeButton")); 259 } 260 261 private String getMessage(String key) { 262 return NbBundle.getMessage(NbPlatformCustomizerJavadoc.class, key); 263 } 264 265 } 266 | Popular Tags |