KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > library > 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.j2ee.persistence.wizard.library;
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.netbeans.spi.project.libraries.support.LibrariesSupport;
39 import org.openide.DialogDisplayer;
40 import org.openide.ErrorManager;
41 import org.openide.NotifyDescriptor;
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  * This class is copy from j2seplatform
50  *
51  * @author tom
52  */

53 public class J2SEVolumeCustomizer extends javax.swing.JPanel JavaDoc implements Customizer JavaDoc {
54     
55     private String JavaDoc volumeType;
56     private LibraryImplementation impl;
57     private VolumeContentModel model;
58
59     /** Creates new form J2SEVolumeCustomizer */
60     J2SEVolumeCustomizer (String JavaDoc volumeType) {
61         this.volumeType = volumeType;
62         initComponents();
63         postInitComponents ();
64         this.setName (NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_"+volumeType));
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(PersistenceLibrarySupport.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(PersistenceLibrarySupport.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(PersistenceLibrarySupport.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(null);
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(null);
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(null);
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(null);
253
254     }// </editor-fold>//GEN-END:initComponents
255

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

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

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

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

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

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