KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seplatform > libraries > J2SEVolumeCustomizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seplatform.libraries;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.beans.Customizer JavaDoc;
25 import java.io.File JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import javax.swing.DefaultListCellRenderer JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JComponent JavaDoc;
33 import javax.swing.JFileChooser JavaDoc;
34 import javax.swing.JList JavaDoc;
35 import javax.swing.event.ListSelectionEvent JavaDoc;
36 import javax.swing.event.ListSelectionListener JavaDoc;
37 import javax.swing.filechooser.FileFilter JavaDoc;
38 import org.openide.DialogDisplayer;
39 import org.openide.ErrorManager;
40 import org.openide.NotifyDescriptor;
41 import org.openide.NotifyDescriptor.Message;
42 import org.openide.filesystems.FileObject;
43 import org.openide.filesystems.FileUtil;
44 import org.openide.filesystems.URLMapper;
45 import org.openide.util.NbBundle;
46 import org.netbeans.spi.project.libraries.LibraryImplementation;
47
48 /**
49  *
50  * @author tom
51  */

52 public class J2SEVolumeCustomizer extends javax.swing.JPanel JavaDoc implements Customizer JavaDoc {
53     
54     private String JavaDoc volumeType;
55     private LibraryImplementation impl;
56     private VolumeContentModel model;
57
58     /** Creates new form J2SEVolumeCustomizer */
59     J2SEVolumeCustomizer (String JavaDoc volumeType) {
60         this.volumeType = volumeType;
61         initComponents();
62         postInitComponents ();
63         this.setName (NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_"+volumeType));
64     }
65
66
67     public void addNotify() {
68         super.addNotify();
69         this.addButton.requestFocus();
70     }
71
72     public void setEnabled(boolean enabled) {
73         super.setEnabled(enabled);
74         this.addButton.setEnabled(enabled);
75         if (this.addURLButton != null) {
76             this.addURLButton.setEnabled(enabled);
77         }
78         int[] indices = content.getSelectedIndices();
79         this.removeButton.setEnabled(enabled && indices.length > 0);
80         this.downButton.setEnabled(enabled && indices.length > 0 && indices[indices.length-1]<model.getSize()-1);
81         this.upButton.setEnabled(enabled && indices.length>0 && indices[0]>0);
82     }
83
84
85     private void postInitComponents () {
86         this.content.setCellRenderer(new ContentRenderer());
87         this.upButton.setEnabled (false);
88         this.downButton.setEnabled (false);
89         this.removeButton.setEnabled (false);
90         if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) {
91             this.addButton.setText (NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddClassPath"));
92             this.addButton.setMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_AddClassPath").charAt(0));
93             this.message.setText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_ContentClassPath"));
94             this.message.setDisplayedMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_ContentClassPath").charAt(0));
95             this.addButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEVolumeCustomizer.class,"AD_AddClassPath"));
96             this.message.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEVolumeCustomizer.class,"AD_ContentClassPath"));
97         }
98         else if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_JAVADOC)) {
99             this.addButton.setText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadoc"));
100             this.addButton.setMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_AddJavadoc").charAt(0));
101             this.message.setText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_ContentJavadoc"));
102             this.message.setDisplayedMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_ContentJavadoc").charAt(0));
103             this.addButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEVolumeCustomizer.class,"AD_AddJavadoc"));
104             this.message.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEVolumeCustomizer.class,"AD_ContentJavadoc"));
105 // this.addURLButton = new JButton ();
106
// this.addURLButton.setText(NbBundle.getMessage (J2SEVolumeCustomizer.class,"CTL_AddJavadocURL"));
107
// this.addURLButton.setMnemonic(NbBundle.getMessage (J2SEVolumeCustomizer.class,"MNE_AddJavadocURL").charAt(0));
108
// this.addURLButton.addActionListener (new ActionListener () {
109
// public void actionPerformed(ActionEvent e) {
110
// addURLResource ();
111
// }
112
// });
113
// GridBagConstraints c = new GridBagConstraints();
114
// c.gridx = 1;
115
// c.gridy = 2;
116
// c.gridwidth = GridBagConstraints.REMAINDER;
117
// c.gridheight = 1;
118
// c.fill = GridBagConstraints.HORIZONTAL;
119
// c.anchor = GridBagConstraints.NORTHWEST;
120
// c.insets = new Insets (0,6,5,6);
121
// ((GridBagLayout)this.getLayout()).setConstraints(this.addURLButton,c);
122
// this.add (this.addURLButton);
123
}
124         else if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_SRC)) {
125             this.addButton.setText (NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddSources"));
126             this.addButton.setMnemonic (NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_AddSources").charAt(0));
127             this.message.setText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_ContentSources"));
128             this.message.setDisplayedMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_ContentSources").charAt(0));
129             this.addButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEVolumeCustomizer.class,"AD_AddSources"));
130             this.message.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(J2SEVolumeCustomizer.class,"AD_ContentSources"));
131         }
132         this.content.addListSelectionListener(new ListSelectionListener JavaDoc () {
133             public void valueChanged(ListSelectionEvent JavaDoc e) {
134                 if (e.getValueIsAdjusting())
135                     return;
136                 int[] indices = content.getSelectedIndices();
137                 removeButton.setEnabled(indices.length > 0);
138                 downButton.setEnabled(indices.length > 0 && indices[indices.length-1]<model.getSize()-1);
139                 upButton.setEnabled(indices.length>0 && indices[0]>0);
140             }
141         });
142     }
143
144     /** This method is called from within the constructor to
145      * initialize the form.
146      * WARNING: Do NOT modify this code. The content of this method is
147      * always regenerated by the Form Editor.
148      */

149     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
150
private void initComponents() {
151         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
152
153         message = new javax.swing.JLabel JavaDoc();
154         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
155         content = new javax.swing.JList JavaDoc();
156         addButton = new javax.swing.JButton JavaDoc();
157         removeButton = new javax.swing.JButton JavaDoc();
158         upButton = new javax.swing.JButton JavaDoc();
159         downButton = new javax.swing.JButton JavaDoc();
160
161         setLayout(new java.awt.GridBagLayout JavaDoc());
162
163         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_J2SEVolumeCustomizer"));
164         message.setLabelFor(content);
165         org.openide.awt.Mnemonics.setLocalizedText(message, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_ContentMessage"));
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
170         gridBagConstraints.weightx = 1.0;
171         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 2, 6);
172         add(message, gridBagConstraints);
173
174         jScrollPane1.setViewportView(content);
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 0;
178         gridBagConstraints.gridy = 1;
179         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
180         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
181         gridBagConstraints.weightx = 1.0;
182         gridBagConstraints.weighty = 1.0;
183         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 6);
184         add(jScrollPane1, gridBagConstraints);
185
186         org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_AddContent"));
187         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
188             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
189                 addResource(evt);
190             }
191         });
192
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridx = 1;
195         gridBagConstraints.gridy = 1;
196         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
197         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
198         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 6);
200         add(addButton, gridBagConstraints);
201         addButton.getAccessibleContext().setAccessibleDescription(null);
202
203         org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_RemoveContent"));
204         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
205             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
206                 removeResource(evt);
207             }
208         });
209
210         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
211         gridBagConstraints.gridx = 1;
212         gridBagConstraints.gridy = 3;
213         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
214         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
216         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 6, 6);
217         add(removeButton, gridBagConstraints);
218         removeButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_RemoveContent"));
219
220         org.openide.awt.Mnemonics.setLocalizedText(upButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_UpContent"));
221         upButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
222             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
223                 upResource(evt);
224             }
225         });
226
227         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
228         gridBagConstraints.gridx = 1;
229         gridBagConstraints.gridy = 4;
230         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
231         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
232         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
233         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 0, 6);
234         add(upButton, gridBagConstraints);
235         upButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_UpContent"));
236
237         org.openide.awt.Mnemonics.setLocalizedText(downButton, org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("CTL_DownContent"));
238         downButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
239             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
240                 downResource(evt);
241             }
242         });
243
244         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
245         gridBagConstraints.gridx = 1;
246         gridBagConstraints.gridy = 5;
247         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
248         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
249         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
250         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 6, 6);
251         add(downButton, gridBagConstraints);
252         downButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(J2SEVolumeCustomizer.class).getString("AD_DownContent"));
253
254     }
255     // </editor-fold>//GEN-END:initComponents
256

257     private void downResource(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_downResource
258
int[] indices = this.content.getSelectedIndices();
259         if (indices.length == 0 || indices[0] < 0 || indices[indices.length-1]>=model.getSize()-1) {
260             return;
261         }
262         this.model.moveDown(indices);
263         for (int i=0; i< indices.length; i++) {
264             indices[i] = indices[i] + 1;
265         }
266         this.content.setSelectedIndices (indices);
267     }//GEN-LAST:event_downResource
268

269     private void upResource(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_upResource
270
int[] indices = this.content.getSelectedIndices();
271         if (indices.length == 0 || indices[0] <= 0) {
272             return;
273         }
274         this.model.moveUp(indices);
275         for (int i=0; i< indices.length; i++) {
276             indices[i] = indices[i] - 1;
277         }
278         this.content.setSelectedIndices(indices);
279     }//GEN-LAST:event_upResource
280

281     private void removeResource(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeResource
282
int[] indices =this.content.getSelectedIndices();
283         if (indices.length == 0) {
284             return;
285         }
286         this.model.removeResources(indices);
287         if (indices[indices.length-1]-indices.length+1 < this.model.getSize()) {
288             this.content.setSelectedIndex(indices[indices.length-1]-indices.length+1);
289         }
290         else if (indices[0] >= 1) {
291             this.content.setSelectedIndex (indices[0]-1);
292         }
293     }//GEN-LAST:event_removeResource
294

295     private void addResource(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addResource
296
// TODO add your handling code here:
297
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
298         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
299         chooser.setAcceptAllFileFilterUsed(false);
300         if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) {
301             chooser.setMultiSelectionEnabled (true);
302             chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenClasses"));
303             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
304             chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
305                     J2SEVolumeCustomizer.class,"TXT_Classpath"),new String JavaDoc[] {"ZIP","JAR"})); //NOI18N
306
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectCP"));
307             chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectCP").charAt(0));
308         }
309         else if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_JAVADOC)) {
310             chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenJavadoc"));
311             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
312             chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
313                     J2SEVolumeCustomizer.class,"TXT_Javadoc"),new String JavaDoc[] {"ZIP","JAR"})); //NOI18N
314
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectJD"));
315             chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectJD").charAt(0));
316         }
317         else if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_SRC)) {
318             chooser.setMultiSelectionEnabled (true);
319             chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenSources"));
320             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
321             chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
322                     J2SEVolumeCustomizer.class,"TXT_Sources"),new String JavaDoc[] {"ZIP","JAR"})); //NOI18N
323
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectSRC"));
324             chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectSRC").charAt(0));
325         }
326         if (lastFolder != null) {
327             chooser.setCurrentDirectory (lastFolder);
328         }
329         if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
330             try {
331                 lastFolder = chooser.getCurrentDirectory();
332                 if (chooser.isMultiSelectionEnabled()) {
333                     addFiles (chooser.getSelectedFiles());
334                 }
335                 else {
336                     final File JavaDoc selectedFile = chooser.getSelectedFile();
337                     addFiles (new File JavaDoc[] {selectedFile});
338                 }
339             } catch (MalformedURLException JavaDoc mue) {
340                 ErrorManager.getDefault().notify(mue);
341             }
342         }
343     }//GEN-LAST:event_addResource
344

345
346 // private void addURLResource () {
347
// DialogDescriptor.InputLine input = new DialogDescriptor.InputLine (
348
// NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadocURLMessage"),
349
// NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadocURLTitle"));
350
// if (DialogDisplayer.getDefault().notify(input) == DialogDescriptor.OK_OPTION) {
351
// try {
352
// String value = input.getInputText();
353
// URL url = new URL (value);
354
// this.model.addResource(url);
355
// this.content.setSelectedIndex(this.model.getSize()-1);
356
// } catch (MalformedURLException mue) {
357
// DialogDescriptor.Message message = new DialogDescriptor.Message (
358
// NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_InvalidURLFormat"),
359
// DialogDescriptor.ERROR_MESSAGE
360
// );
361
// DialogDisplayer.getDefault().notify(message);
362
// }
363
// }
364
// }
365

366
367     private void addFiles (File JavaDoc[] files) throws MalformedURLException JavaDoc {
368         int firstIndex = this.model.getSize();
369         for (int i = 0; i < files.length; i++) {
370             File JavaDoc f = files[i];
371             //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
372
// E.g. for /foo/src it returns /foo/src/src
373
// Try to convert it back by removing last invalid name component
374
if (!f.exists()) {
375                 File JavaDoc parent = f.getParentFile();
376                 if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
377                     f = parent;
378                 }
379             }
380             URL JavaDoc url = f.toURI().toURL();
381             if (FileUtil.isArchiveFile(url)) {
382                 url = FileUtil.getArchiveRoot(url);
383             }
384             else if (!url.toExternalForm().endsWith("/")){
385                 try {
386                     url = new URL JavaDoc (url.toExternalForm()+"/");
387                 } catch (MalformedURLException JavaDoc mue) {
388                     ErrorManager.getDefault().notify(mue);
389                 }
390             }
391             if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_JAVADOC)
392                 && !JavadocForBinaryQueryLibraryImpl.isValidLibraryJavadocRoot (url)) {
393                 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
394                     NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_InvalidJavadocRoot", f.getPath()),
395                     NotifyDescriptor.ERROR_MESSAGE));
396                 continue;
397             }
398             this.model.addResource(url);
399         }
400         int lastIndex = this.model.getSize()-1;
401         if (firstIndex<=lastIndex) {
402             int[] toSelect = new int[lastIndex-firstIndex+1];
403             for (int i = 0; i < toSelect.length; i++) {
404                 toSelect[i] = firstIndex+i;
405             }
406             this.content.setSelectedIndices(toSelect);
407         }
408     }
409     
410     public void setObject(Object JavaDoc bean) {
411         if (bean instanceof LibraryImplementation) {
412             this.impl = (LibraryImplementation) bean;
413             this.model = new VolumeContentModel(this.impl,this.volumeType);
414             this.content.setModel(model);
415             if (this.model.getSize()>0) {
416                 this.content.setSelectedIndex(0);
417             }
418         }
419         else {
420             throw new IllegalArgumentException JavaDoc();
421         }
422     }
423     
424     
425     private static class SimpleFileFilter extends FileFilter JavaDoc {
426         
427         private String JavaDoc description;
428         private Collection JavaDoc extensions;
429         
430         
431         public SimpleFileFilter(String JavaDoc description, String JavaDoc[] extensions) {
432             this.description = description;
433             this.extensions = Arrays.asList(extensions);
434         }
435         
436         public boolean accept(File JavaDoc f) {
437             if (f.isDirectory())
438                 return true;
439             String JavaDoc name = f.getName();
440             int index = name.lastIndexOf('.'); //NOI18N
441
if (index <= 0 || index==name.length()-1)
442                 return false;
443             String JavaDoc extension = name.substring(index+1).toUpperCase();
444             return this.extensions.contains(extension);
445         }
446         
447         public String JavaDoc getDescription() {
448             return this.description;
449         }
450     }
451     
452     
453     private static File JavaDoc lastFolder = null;
454     
455     
456     // Variables declaration - do not modify//GEN-BEGIN:variables
457
private javax.swing.JButton JavaDoc addButton;
458     private javax.swing.JList JavaDoc content;
459     private javax.swing.JButton JavaDoc downButton;
460     private javax.swing.JScrollPane JavaDoc jScrollPane1;
461     private javax.swing.JLabel JavaDoc message;
462     private javax.swing.JButton JavaDoc removeButton;
463     private javax.swing.JButton JavaDoc upButton;
464     // End of variables declaration//GEN-END:variables
465
private JButton JavaDoc addURLButton;
466     
467     private static class ContentRenderer extends DefaultListCellRenderer JavaDoc {
468                 
469         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
470             String JavaDoc displayName = null;
471             Color JavaDoc color = null;
472             String JavaDoc toolTip = null;
473             
474             if (value instanceof URL JavaDoc) {
475                 URL JavaDoc url = (URL JavaDoc) value;
476                 if ("jar".equals(url.getProtocol())) { //NOI18N
477
url = FileUtil.getArchiveFile (url);
478                 }
479                 FileObject fo = URLMapper.findFileObject (url);
480                 if (fo == null) {
481                     displayName = url.toExternalForm();
482                     color = new Color JavaDoc (164,0,0);
483                     toolTip = NbBundle.getMessage (J2SEVolumeCustomizer.class,"TXT_BrokenFile");
484                 }
485                 else {
486                     displayName = FileUtil.getFileDisplayName(fo);
487                 }
488             }
489             Component JavaDoc c = super.getListCellRendererComponent(list, displayName, index, isSelected, cellHasFocus);
490             if (c instanceof JComponent JavaDoc) {
491                 if (color != null) {
492                     ((JComponent JavaDoc)c).setForeground (color);
493                 }
494                 if (toolTip != null) {
495                     ((JComponent JavaDoc)c).setToolTipText (toolTip);
496                 }
497             }
498             return c;
499         }
500         
501     }
502
503 }
504
Popular Tags