Source Code Cross Referenced for ThemeVolumeCustomizer.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » project » jsf » libraries » provider » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.project.jsf.libraries.provider 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.visualweb.project.jsf.libraries.provider;
043:
044:        import java.awt.Color;
045:        import java.awt.Component;
046:        import java.beans.Customizer;
047:        import java.io.File;
048:        import java.net.URL;
049:        import java.net.MalformedURLException;
050:        import java.util.Collection;
051:        import java.util.Arrays;
052:        import java.awt.*;
053:        import javax.swing.*;
054:        import javax.swing.DefaultListCellRenderer;
055:        import javax.swing.event.*;
056:        import org.openide.ErrorManager;
057:        import org.openide.filesystems.FileUtil;
058:        import org.openide.util.NbBundle;
059:        import org.netbeans.spi.project.libraries.LibraryImplementation;
060:
061:        import javax.swing.filechooser.FileFilter;
062:        import org.netbeans.spi.project.libraries.LibraryStorageArea;
063:        import org.netbeans.spi.project.libraries.support.LibrariesSupport;
064:        import org.openide.filesystems.FileObject;
065:
066:        /**
067:         *
068:         * @author  tom
069:         */
070:        public class ThemeVolumeCustomizer extends javax.swing.JPanel implements 
071:                Customizer {
072:
073:            private String volumeType;
074:            private LibraryImplementation impl;
075:            private VolumeContentModel model;
076:            private LibraryStorageArea area;
077:
078:            /**
079:             * Creates new form ThemeVolumeCustomizer
080:             */
081:            ThemeVolumeCustomizer(String volumeType) {
082:                this .volumeType = volumeType;
083:                initComponents();
084:                postInitComponents();
085:                this .setName(NbBundle.getMessage(ThemeVolumeCustomizer.class,
086:                        "TXT_" + volumeType));
087:            }
088:
089:            public void addNotify() {
090:                super .addNotify();
091:                this .addButton.requestFocus();
092:            }
093:
094:            public void setEnabled(boolean enabled) {
095:                super .setEnabled(enabled);
096:                this .addButton.setEnabled(enabled);
097:                if (this .addURLButton != null) {
098:                    this .addURLButton.setEnabled(enabled);
099:                }
100:                int[] indices = content.getSelectedIndices();
101:                this .removeButton.setEnabled(enabled && indices.length > 0);
102:                this .downButton.setEnabled(enabled && indices.length > 0
103:                        && indices[indices.length - 1] < model.getSize() - 1);
104:                this .upButton.setEnabled(enabled && indices.length > 0
105:                        && indices[0] > 0);
106:            }
107:
108:            private void postInitComponents() {
109:                this .content.setCellRenderer(new ContentRenderer());
110:                this .upButton.setEnabled(false);
111:                this .downButton.setEnabled(false);
112:                this .removeButton.setEnabled(false);
113:                if (this .volumeType
114:                        .equals(ThemeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) { //NOI18N
115:                    this .addButton.setText(NbBundle.getMessage(
116:                            ThemeVolumeCustomizer.class, "CTL_AddClassPath"));
117:                    this .addButton.setMnemonic(NbBundle.getMessage(
118:                            ThemeVolumeCustomizer.class, "MNE_AddClassPath")
119:                            .charAt(0));
120:                    this .message.setText(NbBundle
121:                            .getMessage(ThemeVolumeCustomizer.class,
122:                                    "CTL_ContentClassPath"));
123:                    this .message.setDisplayedMnemonic(NbBundle
124:                            .getMessage(ThemeVolumeCustomizer.class,
125:                                    "MNE_ContentClassPath").charAt(0));
126:                    this .addButton.getAccessibleContext()
127:                            .setAccessibleDescription(
128:                                    NbBundle.getMessage(
129:                                            ThemeVolumeCustomizer.class,
130:                                            "AD_AddClassPath"));
131:                    this .message.getAccessibleContext()
132:                            .setAccessibleDescription(
133:                                    NbBundle.getMessage(
134:                                            ThemeVolumeCustomizer.class,
135:                                            "AD_ContentClassPath"));
136:                } else if (this .volumeType
137:                        .equals(ThemeLibraryTypeProvider.VOLUME_TYPE_JAVADOC)) { //NOI18N
138:                    this .addButton.setText(NbBundle.getMessage(
139:                            ThemeVolumeCustomizer.class, "CTL_AddJavadoc"));
140:                    this .addButton.setMnemonic(NbBundle.getMessage(
141:                            ThemeVolumeCustomizer.class, "MNE_AddJavadoc")
142:                            .charAt(0));
143:                    this .message.setText(NbBundle.getMessage(
144:                            ThemeVolumeCustomizer.class, "CTL_ContentJavadoc"));
145:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
146:                            ThemeVolumeCustomizer.class, "MNE_ContentJavadoc")
147:                            .charAt(0));
148:                    this .addButton.getAccessibleContext()
149:                            .setAccessibleDescription(
150:                                    NbBundle.getMessage(
151:                                            ThemeVolumeCustomizer.class,
152:                                            "AD_AddJavadoc"));
153:                    this .message.getAccessibleContext()
154:                            .setAccessibleDescription(
155:                                    NbBundle.getMessage(
156:                                            ThemeVolumeCustomizer.class,
157:                                            "AD_ContentJavadoc"));
158:                    //            this.addURLButton = new JButton ();
159:                    //            this.addURLButton.setText(NbBundle.getMessage (ThemeVolumeCustomizer.class,"CTL_AddJavadocURL"));
160:                    //            this.addURLButton.setMnemonic(NbBundle.getMessage (ThemeVolumeCustomizer.class,"MNE_AddJavadocURL").charAt(0));
161:                    //            this.addURLButton.addActionListener (new ActionListener () {
162:                    //                public void actionPerformed(ActionEvent e) {
163:                    //                    addURLResource ();
164:                    //                }
165:                    //            });
166:                    //            GridBagConstraints c = new GridBagConstraints();
167:                    //            c.gridx = 1;
168:                    //            c.gridy = 2;
169:                    //            c.gridwidth = GridBagConstraints.REMAINDER;
170:                    //            c.gridheight = 1;
171:                    //            c.fill = GridBagConstraints.HORIZONTAL;
172:                    //            c.anchor = GridBagConstraints.NORTHWEST;
173:                    //            c.insets = new Insets (0,6,5,6);
174:                    //            ((GridBagLayout)this.getLayout()).setConstraints(this.addURLButton,c);
175:                    //            this.add (this.addURLButton);
176:                } else if (this .volumeType
177:                        .equals(ThemeLibraryTypeProvider.VOLUME_TYPE_SRC)) { //NOI18N
178:                    this .addButton.setText(NbBundle.getMessage(
179:                            ThemeVolumeCustomizer.class, "CTL_AddSources"));
180:                    this .addButton.setMnemonic(NbBundle.getMessage(
181:                            ThemeVolumeCustomizer.class, "MNE_AddSources")
182:                            .charAt(0));
183:                    this .message.setText(NbBundle.getMessage(
184:                            ThemeVolumeCustomizer.class, "CTL_ContentSources"));
185:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
186:                            ThemeVolumeCustomizer.class, "MNE_ContentSources")
187:                            .charAt(0));
188:                    this .addButton.getAccessibleContext()
189:                            .setAccessibleDescription(
190:                                    NbBundle.getMessage(
191:                                            ThemeVolumeCustomizer.class,
192:                                            "AD_AddSources"));
193:                    this .message.getAccessibleContext()
194:                            .setAccessibleDescription(
195:                                    NbBundle.getMessage(
196:                                            ThemeVolumeCustomizer.class,
197:                                            "AD_ContentSources"));
198:                } else if (this .volumeType
199:                        .equals(ThemeLibraryTypeProvider.VOLUME_TYPE_RUNTIME)) { //NOI18N
200:                    this .addButton.setText(NbBundle.getMessage(
201:                            ThemeVolumeCustomizer.class, "CTL_AddSources"));
202:                    this .addButton.setMnemonic(NbBundle.getMessage(
203:                            ThemeVolumeCustomizer.class, "MNE_AddSources")
204:                            .charAt(0));
205:                    this .message.setText(NbBundle.getMessage(
206:                            ThemeVolumeCustomizer.class, "CTL_ContentSources"));
207:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
208:                            ThemeVolumeCustomizer.class, "MNE_ContentSources")
209:                            .charAt(0));
210:                    this .addButton.getAccessibleContext()
211:                            .setAccessibleDescription(
212:                                    NbBundle.getMessage(
213:                                            ThemeVolumeCustomizer.class,
214:                                            "AD_AddSources"));
215:                    this .message.getAccessibleContext()
216:                            .setAccessibleDescription(
217:                                    NbBundle.getMessage(
218:                                            ThemeVolumeCustomizer.class,
219:                                            "AD_ContentSources"));
220:                }
221:                this .content
222:                        .addListSelectionListener(new ListSelectionListener() {
223:                            public void valueChanged(ListSelectionEvent e) {
224:                                if (e.getValueIsAdjusting())
225:                                    return;
226:                                int[] indices = content.getSelectedIndices();
227:                                removeButton.setEnabled(indices.length > 0);
228:                                downButton.setEnabled(indices.length > 0
229:                                        && indices[indices.length - 1] < model
230:                                                .getSize() - 1);
231:                                upButton.setEnabled(indices.length > 0
232:                                        && indices[0] > 0);
233:                            }
234:                        });
235:            }
236:
237:            /** This method is called from within the constructor to
238:             * initialize the form.
239:             * WARNING: Do NOT modify this code. The content of this method is
240:             * always regenerated by the Form Editor.
241:             */
242:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
243:            private void initComponents() {
244:                java.awt.GridBagConstraints gridBagConstraints;
245:
246:                message = new javax.swing.JLabel();
247:                jScrollPane1 = new javax.swing.JScrollPane();
248:                content = new javax.swing.JList();
249:                addButton = new javax.swing.JButton();
250:                removeButton = new javax.swing.JButton();
251:                upButton = new javax.swing.JButton();
252:                downButton = new javax.swing.JButton();
253:
254:                setLayout(new java.awt.GridBagLayout());
255:
256:                getAccessibleContext().setAccessibleDescription(null);
257:                message.setLabelFor(content);
258:                org.openide.awt.Mnemonics.setLocalizedText(message,
259:                        org.openide.util.NbBundle.getBundle(
260:                                ThemeVolumeCustomizer.class).getString(
261:                                "CTL_RemoveContent"));
262:                gridBagConstraints = new java.awt.GridBagConstraints();
263:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
264:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
266:                gridBagConstraints.weightx = 1.0;
267:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 2, 6);
268:                add(message, gridBagConstraints);
269:
270:                jScrollPane1.setViewportView(content);
271:
272:                gridBagConstraints = new java.awt.GridBagConstraints();
273:                gridBagConstraints.gridx = 0;
274:                gridBagConstraints.gridy = 1;
275:                gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
276:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
277:                gridBagConstraints.weightx = 1.0;
278:                gridBagConstraints.weighty = 1.0;
279:                gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 6);
280:                add(jScrollPane1, gridBagConstraints);
281:
282:                org.openide.awt.Mnemonics.setLocalizedText(addButton,
283:                        org.openide.util.NbBundle.getBundle(
284:                                ThemeVolumeCustomizer.class).getString(
285:                                "CTL_AddContent"));
286:                addButton
287:                        .addActionListener(new java.awt.event.ActionListener() {
288:                            public void actionPerformed(
289:                                    java.awt.event.ActionEvent evt) {
290:                                addResource(evt);
291:                            }
292:                        });
293:
294:                gridBagConstraints = new java.awt.GridBagConstraints();
295:                gridBagConstraints.gridx = 1;
296:                gridBagConstraints.gridy = 1;
297:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
298:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
299:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
300:                gridBagConstraints.insets = new java.awt.Insets(3, 6, 5, 6);
301:                add(addButton, gridBagConstraints);
302:                addButton.getAccessibleContext().setAccessibleDescription(null);
303:
304:                org.openide.awt.Mnemonics.setLocalizedText(removeButton,
305:                        org.openide.util.NbBundle.getBundle(
306:                                ThemeVolumeCustomizer.class).getString(
307:                                "CTL_RemoveContent"));
308:                removeButton
309:                        .addActionListener(new java.awt.event.ActionListener() {
310:                            public void actionPerformed(
311:                                    java.awt.event.ActionEvent evt) {
312:                                removeResource(evt);
313:                            }
314:                        });
315:
316:                gridBagConstraints = new java.awt.GridBagConstraints();
317:                gridBagConstraints.gridx = 1;
318:                gridBagConstraints.gridy = 3;
319:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
320:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
321:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
322:                gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 6);
323:                add(removeButton, gridBagConstraints);
324:                removeButton.getAccessibleContext().setAccessibleDescription(
325:                        null);
326:
327:                org.openide.awt.Mnemonics.setLocalizedText(upButton,
328:                        org.openide.util.NbBundle.getBundle(
329:                                ThemeVolumeCustomizer.class).getString(
330:                                "CTL_UpContent"));
331:                upButton.addActionListener(new java.awt.event.ActionListener() {
332:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
333:                        upResource(evt);
334:                    }
335:                });
336:
337:                gridBagConstraints = new java.awt.GridBagConstraints();
338:                gridBagConstraints.gridx = 1;
339:                gridBagConstraints.gridy = 4;
340:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
341:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
342:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
343:                gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 6);
344:                add(upButton, gridBagConstraints);
345:                upButton.getAccessibleContext().setAccessibleDescription(null);
346:
347:                org.openide.awt.Mnemonics.setLocalizedText(downButton,
348:                        org.openide.util.NbBundle.getBundle(
349:                                ThemeVolumeCustomizer.class).getString(
350:                                "CTL_DownContent"));
351:                downButton
352:                        .addActionListener(new java.awt.event.ActionListener() {
353:                            public void actionPerformed(
354:                                    java.awt.event.ActionEvent evt) {
355:                                downResource(evt);
356:                            }
357:                        });
358:
359:                gridBagConstraints = new java.awt.GridBagConstraints();
360:                gridBagConstraints.gridx = 1;
361:                gridBagConstraints.gridy = 5;
362:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
363:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
364:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
365:                gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6);
366:                add(downButton, gridBagConstraints);
367:                downButton.getAccessibleContext()
368:                        .setAccessibleDescription(null);
369:
370:            }
371:
372:            // </editor-fold>//GEN-END:initComponents
373:
374:            private void downResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downResource
375:                int[] indices = this .content.getSelectedIndices();
376:                if (indices.length == 0 || indices[0] < 0
377:                        || indices[indices.length - 1] >= model.getSize() - 1) {
378:                    return;
379:                }
380:                this .model.moveDown(indices);
381:                for (int i = 0; i < indices.length; i++) {
382:                    indices[i] = indices[i] + 1;
383:                }
384:                this .content.setSelectedIndices(indices);
385:            }//GEN-LAST:event_downResource
386:
387:            private void upResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upResource
388:                int[] indices = this .content.getSelectedIndices();
389:                if (indices.length == 0 || indices[0] <= 0) {
390:                    return;
391:                }
392:                this .model.moveUp(indices);
393:                for (int i = 0; i < indices.length; i++) {
394:                    indices[i] = indices[i] - 1;
395:                }
396:                this .content.setSelectedIndices(indices);
397:            }//GEN-LAST:event_upResource
398:
399:            private void removeResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeResource
400:                int[] indices = this .content.getSelectedIndices();
401:                if (indices.length == 0) {
402:                    return;
403:                }
404:                this .model.removeResources(indices);
405:                if (indices[indices.length - 1] - indices.length + 1 < this .model
406:                        .getSize()) {
407:                    this .content.setSelectedIndex(indices[indices.length - 1]
408:                            - indices.length + 1);
409:                } else if (indices[0] >= 1) {
410:                    this .content.setSelectedIndex(indices[0] - 1);
411:                }
412:            }//GEN-LAST:event_removeResource
413:
414:            private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
415:                // TODO add your handling code here:
416:                JFileChooser chooser = new JFileChooser();
417:                FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
418:                chooser.setAcceptAllFileFilterUsed(false);
419:                if (this .volumeType
420:                        .equalsIgnoreCase(ThemeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) { //NOI18N
421:                    chooser.setMultiSelectionEnabled(true);
422:                    chooser.setDialogTitle(NbBundle.getMessage(
423:                            ThemeVolumeCustomizer.class, "TXT_OpenClasses"));
424:                    chooser
425:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
426:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
427:                            .getMessage(ThemeVolumeCustomizer.class,
428:                                    "TXT_Classpath"), new String[] { "ZIP",
429:                            "JAR" })); //NOI18N
430:                    chooser.setApproveButtonText(NbBundle.getMessage(
431:                            ThemeVolumeCustomizer.class, "CTL_SelectCP"));
432:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
433:                            ThemeVolumeCustomizer.class, "MNE_SelectCP")
434:                            .charAt(0));
435:                } else if (this .volumeType
436:                        .equalsIgnoreCase(ThemeLibraryTypeProvider.VOLUME_TYPE_JAVADOC)) { //NOI18N
437:                    chooser.setDialogTitle(NbBundle.getMessage(
438:                            ThemeVolumeCustomizer.class, "TXT_OpenJavadoc"));
439:                    chooser
440:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
441:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
442:                            .getMessage(ThemeVolumeCustomizer.class,
443:                                    "TXT_Javadoc"),
444:                            new String[] { "ZIP", "JAR" })); //NOI18N
445:                    chooser.setApproveButtonText(NbBundle.getMessage(
446:                            ThemeVolumeCustomizer.class, "CTL_SelectJD"));
447:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
448:                            ThemeVolumeCustomizer.class, "MNE_SelectJD")
449:                            .charAt(0));
450:                } else if (this .volumeType
451:                        .equalsIgnoreCase(ThemeLibraryTypeProvider.VOLUME_TYPE_SRC)) { //NOI18N
452:                    chooser.setDialogTitle(NbBundle.getMessage(
453:                            ThemeVolumeCustomizer.class, "TXT_OpenSources"));
454:                    chooser
455:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
456:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
457:                            .getMessage(ThemeVolumeCustomizer.class,
458:                                    "TXT_Sources"),
459:                            new String[] { "ZIP", "JAR" })); //NOI18N
460:                    chooser.setApproveButtonText(NbBundle.getMessage(
461:                            ThemeVolumeCustomizer.class, "CTL_SelectSRC"));
462:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
463:                            ThemeVolumeCustomizer.class, "MNE_SelectSRC")
464:                            .charAt(0));
465:                } else if (this .volumeType
466:                        .equalsIgnoreCase(ThemeLibraryTypeProvider.VOLUME_TYPE_RUNTIME)) { //NOI18N
467:                    chooser.setDialogTitle(NbBundle.getMessage(
468:                            ThemeVolumeCustomizer.class, "TXT_OpenSources"));
469:                    chooser
470:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
471:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
472:                            .getMessage(ThemeVolumeCustomizer.class,
473:                                    "TXT_Sources"),
474:                            new String[] { "ZIP", "JAR" })); //NOI18N
475:                    chooser.setApproveButtonText(NbBundle.getMessage(
476:                            ThemeVolumeCustomizer.class, "CTL_SelectSRC"));
477:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
478:                            ThemeVolumeCustomizer.class, "MNE_SelectSRC")
479:                            .charAt(0));
480:                }
481:                if (lastFolder != null) {
482:                    chooser.setCurrentDirectory(lastFolder);
483:                }
484:                if (chooser.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
485:                    try {
486:                        lastFolder = chooser.getCurrentDirectory();
487:                        if (chooser.isMultiSelectionEnabled()) {
488:                            addFiles(chooser.getSelectedFiles());
489:                        } else {
490:                            addFiles(new File[] { chooser.getSelectedFile() });
491:                        }
492:                    } catch (MalformedURLException mue) {
493:                        ErrorManager.getDefault().notify(mue);
494:                    }
495:                }
496:            }//GEN-LAST:event_addResource
497:
498:            //    private void addURLResource () {
499:            //        DialogDescriptor.InputLine input = new DialogDescriptor.InputLine (
500:            //                NbBundle.getMessage(ThemeVolumeCustomizer.class,"CTL_AddJavadocURLMessage"),
501:            //                NbBundle.getMessage(ThemeVolumeCustomizer.class,"CTL_AddJavadocURLTitle"));
502:            //        if (DialogDisplayer.getDefault().notify(input) == DialogDescriptor.OK_OPTION) {
503:            //            try {
504:            //                String value = input.getInputText();
505:            //                URL url = new URL (value);
506:            //                this.model.addResource(url);
507:            //                this.content.setSelectedIndex(this.model.getSize()-1);
508:            //            } catch (MalformedURLException mue) {
509:            //                DialogDescriptor.Message message = new DialogDescriptor.Message (
510:            //                        NbBundle.getMessage(ThemeVolumeCustomizer.class,"CTL_InvalidURLFormat"),
511:            //                        DialogDescriptor.ERROR_MESSAGE
512:            //                );
513:            //                DialogDisplayer.getDefault().notify(message);
514:            //            }
515:            //        }
516:            //    }
517:
518:            private void addFiles(File[] files) throws MalformedURLException {
519:                int firstIndex = this .model.getSize();
520:                for (int i = 0; i < files.length; i++) {
521:                    File f = files[i];
522:                    //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
523:                    // E.g. for /foo/src it returns /foo/src/src
524:                    // Try to convert it back by removing last invalid name component
525:                    if (!f.exists()) {
526:                        File parent = f.getParentFile();
527:                        if (parent != null
528:                                && f.getName().equals(parent.getName())
529:                                && parent.exists()) {
530:                            f = parent;
531:                        }
532:                    }
533:                    URL url = f.toURI().toURL();
534:                    this .model.addResource(url);
535:                }
536:                int lastIndex = this .model.getSize() - 1;
537:                if (firstIndex <= lastIndex) {
538:                    int[] toSelect = new int[lastIndex - firstIndex + 1];
539:                    for (int i = 0; i < toSelect.length; i++) {
540:                        toSelect[i] = firstIndex + i;
541:                    }
542:                    this .content.setSelectedIndices(toSelect);
543:                }
544:            }
545:
546:            public void setObject(Object bean) {
547:                if (bean instanceof  LibraryStorageArea) {
548:                    this .area = (LibraryStorageArea) bean;
549:                } else {
550:                    this .area = null;
551:                }
552:                if (bean instanceof  LibraryImplementation) {
553:                    this .impl = (LibraryImplementation) bean;
554:                    this .model = new VolumeContentModel(this .impl, area,
555:                            this .volumeType);
556:                    this .content.setModel(model);
557:                    if (this .model.getSize() > 0) {
558:                        this .content.setSelectedIndex(0);
559:                    }
560:                } else {
561:                    throw new IllegalArgumentException();
562:                }
563:            }
564:
565:            private static class SimpleFileFilter extends FileFilter {
566:
567:                private String description;
568:                private Collection extensions;
569:
570:                public SimpleFileFilter(String description, String[] extensions) {
571:                    this .description = description;
572:                    this .extensions = Arrays.asList(extensions);
573:                }
574:
575:                public boolean accept(File f) {
576:                    if (f.isDirectory())
577:                        return true;
578:                    String name = f.getName();
579:                    int index = name.lastIndexOf('.'); //NOI18N
580:                    if (index <= 0 || index == name.length() - 1)
581:                        return false;
582:                    String extension = name.substring(index + 1).toUpperCase();
583:                    return this .extensions.contains(extension);
584:                }
585:
586:                public String getDescription() {
587:                    return this .description;
588:                }
589:            }
590:
591:            private static File lastFolder = null;
592:
593:            // Variables declaration - do not modify//GEN-BEGIN:variables
594:            private javax.swing.JButton addButton;
595:            private javax.swing.JList content;
596:            private javax.swing.JButton downButton;
597:            private javax.swing.JScrollPane jScrollPane1;
598:            private javax.swing.JLabel message;
599:            private javax.swing.JButton removeButton;
600:            private javax.swing.JButton upButton;
601:            // End of variables declaration//GEN-END:variables
602:            private JButton addURLButton;
603:
604:            private static class ContentRenderer extends
605:                    DefaultListCellRenderer {
606:
607:                public Component getListCellRendererComponent(JList list,
608:                        Object value, int index, boolean isSelected,
609:                        boolean cellHasFocus) {
610:                    String displayName = null;
611:                    Color color = null;
612:                    String toolTip = null;
613:
614:                    if (value instanceof  URL) {
615:                        URL url = (URL) value;
616:                        displayName = url.toExternalForm();
617:                        if ("jar".equals(url.getProtocol())) { //NOI18N
618:                            url = FileUtil.getArchiveFile(url);
619:                        }
620:                        VolumeContentModel model = (VolumeContentModel) list
621:                                .getModel();
622:                        LibraryStorageArea area = model.getArea();
623:                        FileObject fo = LibrariesSupport
624:                                .resolveLibraryEntryFileObject(
625:                                        area != null ? area.getLocation()
626:                                                : null, url);
627:                        if (fo == null) {
628:                            color = new Color(164, 0, 0);
629:                            toolTip = NbBundle.getMessage(
630:                                    ThemeVolumeCustomizer.class,
631:                                    "TXT_BrokenFile");
632:                        }
633:                    }
634:                    Component c = super .getListCellRendererComponent(list,
635:                            displayName, index, isSelected, cellHasFocus);
636:                    if (c instanceof  JComponent) {
637:                        if (color != null) {
638:                            ((JComponent) c).setForeground(color);
639:                        }
640:                        if (toolTip != null) {
641:                            ((JComponent) c).setToolTipText(toolTip);
642:                        }
643:                    }
644:                    return c;
645:                }
646:
647:            }
648:
649:        }
ww_w__.__j__a__v_a___2__s__.___co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.