Source Code Cross Referenced for ClasspathPanel.java in  » IDE-Netbeans » java » org » netbeans » modules » java » freeform » ui » 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 » java » org.netbeans.modules.java.freeform.ui 
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-2006 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.java.freeform.ui;
043:
044:        import java.awt.Component;
045:        import java.awt.event.ItemEvent;
046:        import java.io.File;
047:        import java.net.MalformedURLException;
048:        import java.text.Collator;
049:        import java.util.ArrayList;
050:        import java.util.Arrays;
051:        import java.util.Collection;
052:        import java.util.Comparator;
053:        import java.util.Iterator;
054:        import java.util.List;
055:        import java.util.SortedSet;
056:        import java.util.TreeSet;
057:        import javax.swing.DefaultComboBoxModel;
058:        import javax.swing.DefaultListCellRenderer;
059:        import javax.swing.DefaultListModel;
060:        import javax.swing.JFileChooser;
061:        import javax.swing.JList;
062:        import javax.swing.filechooser.FileFilter;
063:        import javax.swing.plaf.UIResource;
064:        import org.netbeans.api.java.platform.JavaPlatform;
065:        import org.netbeans.api.java.platform.JavaPlatformManager;
066:        import org.netbeans.api.java.platform.PlatformsCustomizer;
067:        import org.netbeans.modules.ant.freeform.spi.support.Util;
068:        import org.netbeans.modules.java.freeform.JavaProjectGenerator;
069:        import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration;
070:        import org.netbeans.spi.project.support.ant.PropertyEvaluator;
071:        import org.netbeans.spi.project.support.ant.PropertyUtils;
072:        import org.openide.ErrorManager;
073:        import org.openide.filesystems.FileUtil;
074:        import org.openide.util.HelpCtx;
075:        import org.openide.util.NbBundle;
076:
077:        /**
078:         * @author David Konecny, Jesse Glick
079:         */
080:        public class ClasspathPanel extends javax.swing.JPanel implements 
081:                HelpCtx.Provider {
082:
083:            private DefaultListModel listModel;
084:            private File lastChosenFile = null;
085:            private boolean isSeparateClasspath = true;
086:            private List<ProjectModel.CompilationUnitKey> compUnitsKeys;
087:            private boolean ignoreEvent;
088:            private ProjectModel model;
089:            private final JdkConfiguration jdkConf;
090:
091:            /**
092:             * Create new panel in wizard mode.
093:             */
094:            public ClasspathPanel() {
095:                jdkConf = null;
096:                basicInit();
097:                javaPlatformPanel.setVisible(false);
098:            }
099:
100:            /**
101:             * Create new panel in project properties mode.
102:             */
103:            ClasspathPanel(JdkConfiguration jdkConf) {
104:                this .jdkConf = jdkConf;
105:                basicInit();
106:                jTextArea1.setText(NbBundle.getMessage(ClasspathPanel.class,
107:                        "LBL_ClasspathPanel_Explanation"));
108:                javaPlatformIntro.setBackground(getBackground());
109:                javaPlatformIntro.setDisabledTextColor(jLabel2.getForeground());
110:                refreshJavaPlatforms();
111:                javaPlatform.setRenderer(new JavaPlatformRenderer());
112:            }
113:
114:            private void basicInit() {
115:                initComponents();
116:                jTextArea1.setBackground(getBackground());
117:                jTextArea1.setDisabledTextColor(jLabel2.getForeground());
118:                listModel = new DefaultListModel();
119:                classpath.setModel(listModel);
120:            }
121:
122:            private void refreshJavaPlatforms() {
123:                SortedSet<JavaPlatform> platforms = new TreeSet<JavaPlatform>(
124:                        new Comparator<JavaPlatform>() {
125:                            Collator COLL = Collator.getInstance();
126:
127:                            public int compare(JavaPlatform p1, JavaPlatform p2) {
128:                                int res = COLL.compare(p1.getDisplayName(), p2
129:                                        .getDisplayName());
130:                                if (res != 0) {
131:                                    return res;
132:                                } else {
133:                                    return System.identityHashCode(p1)
134:                                            - System.identityHashCode(p2);
135:                                }
136:                            }
137:                        });
138:                platforms.addAll(Arrays.asList(JavaPlatformManager.getDefault()
139:                        .getInstalledPlatforms()));
140:                javaPlatform.setModel(new DefaultComboBoxModel(platforms
141:                        .toArray(new JavaPlatform[platforms.size()])));
142:                JavaPlatform pf = jdkConf.getSelectedPlatform();
143:                if (pf == null) {
144:                    pf = JavaPlatformManager.getDefault().getDefaultPlatform();
145:                }
146:                javaPlatform.setSelectedItem(pf);
147:            }
148:
149:            public HelpCtx getHelpCtx() {
150:                return new HelpCtx(ClasspathPanel.class);
151:            }
152:
153:            void updateControls() {
154:                sourceFolder.removeAllItems();
155:                compUnitsKeys = model.createCompilationUnitKeys();
156:                isSeparateClasspath = !ProjectModel
157:                        .isSingleCompilationUnit(compUnitsKeys);
158:                List<String> names = createComboContent(compUnitsKeys, model
159:                        .getEvaluator(), model.getNBProjectFolder());
160:                for (String nm : names) {
161:                    sourceFolder.addItem(nm);
162:                }
163:                if (names.size() > 0) {
164:                    ignoreEvent = true;
165:                    sourceFolder.setSelectedIndex(0);
166:                    ignoreEvent = false;
167:                }
168:                loadClasspath();
169:
170:                // enable/disable "Separate Classpath" checkbox
171:                boolean sepClasspath = model.canHaveSeparateClasspath();
172:                separateClasspath.setEnabled(sepClasspath);
173:                if (sepClasspath) {
174:                    // in case there are separate comp units for sources and tests
175:                    // then disable "Separate Classpath" checkbox because at the
176:                    // moment it is not possible to create single compilation unit for them
177:                    if (isSeparateClasspath
178:                            && !model.canCreateSingleCompilationUnit()) {
179:                        separateClasspath.setEnabled(false);
180:                    }
181:                }
182:                jLabel2.setEnabled(sepClasspath && isSeparateClasspath);
183:                sourceFolder.setEnabled(sepClasspath && isSeparateClasspath);
184:                // set initial value of the checkbox
185:                ignoreEvent = true;
186:                separateClasspath.setSelected(isSeparateClasspath);
187:                ignoreEvent = false;
188:
189:                // disable classpath panel and Add Classpath button if there is 
190:                // no compilation unit ot be configured
191:                addClasspath.setEnabled(compUnitsKeys.size() > 0);
192:                classpath.setEnabled(compUnitsKeys.size() > 0);
193:            }
194:
195:            static List<String> createComboContent(
196:                    List<ProjectModel.CompilationUnitKey> compilationUnitKeys,
197:                    PropertyEvaluator evaluator, File nbProjectFolder) {
198:                List<String> l = new ArrayList<String>();
199:                for (ProjectModel.CompilationUnitKey cul : compilationUnitKeys) {
200:                    String name;
201:                    if (cul.locations.size() == 1) {
202:                        if (cul.label != null) {
203:                            name = cul.label
204:                                    + " ["
205:                                    + SourceFoldersPanel
206:                                            .getLocationDisplayName(evaluator,
207:                                                    nbProjectFolder,
208:                                                    cul.locations.get(0)) + "]"; // NOI18N
209:                        } else {
210:                            name = convertListToString(cul.locations);
211:                        }
212:                    } else {
213:                        name = convertListToString(cul.locations);
214:                    }
215:                    l.add(name);
216:                }
217:                return l;
218:            }
219:
220:            private static String convertListToString(List<String> l) {
221:                StringBuffer sb = new StringBuffer();
222:                Iterator<String> it = l.iterator();
223:                while (it.hasNext()) {
224:                    String s = it.next();
225:                    sb.append(s);
226:                    if (it.hasNext()) {
227:                        sb.append(File.pathSeparatorChar + " "); // NOI18N
228:                    }
229:                }
230:                return sb.toString();
231:            }
232:
233:            /** This method is called from within the constructor to
234:             * initialize the form.
235:             * WARNING: Do NOT modify this code. The content of this method is
236:             * always regenerated by the Form Editor.
237:             */
238:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
239:            private void initComponents() {
240:                java.awt.GridBagConstraints gridBagConstraints;
241:
242:                jLabel3 = new javax.swing.JLabel();
243:                addClasspath = new javax.swing.JButton();
244:                removeClasspath = new javax.swing.JButton();
245:                jScrollPane1 = new javax.swing.JScrollPane();
246:                classpath = new javax.swing.JList();
247:                jPanel1 = new javax.swing.JPanel();
248:                sourceFolder = new javax.swing.JComboBox();
249:                jLabel2 = new javax.swing.JLabel();
250:                moveUp = new javax.swing.JButton();
251:                moveDown = new javax.swing.JButton();
252:                jTextArea1 = new javax.swing.JTextArea();
253:                separateClasspath = new javax.swing.JCheckBox();
254:                javaPlatformPanel = new javax.swing.JPanel();
255:                javaPlatformIntro = new javax.swing.JTextArea();
256:                javaPlatformLabel = new javax.swing.JLabel();
257:                javaPlatform = new javax.swing.JComboBox();
258:                javaPlatformButton = new javax.swing.JButton();
259:                jPanel2 = new javax.swing.JPanel();
260:                jLabel1 = new javax.swing.JLabel();
261:                jTextArea2 = new javax.swing.JTextArea();
262:
263:                setPreferredSize(new java.awt.Dimension(275, 202));
264:                setLayout(new java.awt.GridBagLayout());
265:
266:                jLabel3.setLabelFor(classpath);
267:                org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
268:                        org.openide.util.NbBundle.getMessage(
269:                                ClasspathPanel.class,
270:                                "LBL_ClasspathPanel_jLabel3")); // NOI18N
271:                gridBagConstraints = new java.awt.GridBagConstraints();
272:                gridBagConstraints.gridx = 0;
273:                gridBagConstraints.gridy = 3;
274:                gridBagConstraints.gridwidth = 2;
275:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
276:                gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
277:                add(jLabel3, gridBagConstraints);
278:                jLabel3.getAccessibleContext().setAccessibleDescription(
279:                        org.openide.util.NbBundle.getMessage(
280:                                ClasspathPanel.class,
281:                                "ACSD_ClasspathPanel_jLabel3")); // NOI18N
282:
283:                org.openide.awt.Mnemonics.setLocalizedText(addClasspath,
284:                        org.openide.util.NbBundle.getMessage(
285:                                ClasspathPanel.class,
286:                                "BTN_ClasspathPanel_addClasspath")); // NOI18N
287:                addClasspath
288:                        .addActionListener(new java.awt.event.ActionListener() {
289:                            public void actionPerformed(
290:                                    java.awt.event.ActionEvent evt) {
291:                                addClasspathActionPerformed(evt);
292:                            }
293:                        });
294:                gridBagConstraints = new java.awt.GridBagConstraints();
295:                gridBagConstraints.gridx = 1;
296:                gridBagConstraints.gridy = 4;
297:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
298:                gridBagConstraints.insets = new java.awt.Insets(0, 8, 6, 0);
299:                add(addClasspath, gridBagConstraints);
300:                addClasspath.getAccessibleContext().setAccessibleDescription(
301:                        org.openide.util.NbBundle.getMessage(
302:                                ClasspathPanel.class,
303:                                "ACSD_ClasspathPanel_addClasspath")); // NOI18N
304:
305:                org.openide.awt.Mnemonics.setLocalizedText(removeClasspath,
306:                        org.openide.util.NbBundle.getMessage(
307:                                ClasspathPanel.class,
308:                                "BTN_ClasspathPanel_removeClasspath")); // NOI18N
309:                removeClasspath
310:                        .addActionListener(new java.awt.event.ActionListener() {
311:                            public void actionPerformed(
312:                                    java.awt.event.ActionEvent evt) {
313:                                removeClasspathActionPerformed(evt);
314:                            }
315:                        });
316:                gridBagConstraints = new java.awt.GridBagConstraints();
317:                gridBagConstraints.gridx = 1;
318:                gridBagConstraints.gridy = 5;
319:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
320:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
321:                gridBagConstraints.insets = new java.awt.Insets(0, 8, 6, 0);
322:                add(removeClasspath, gridBagConstraints);
323:                removeClasspath.getAccessibleContext()
324:                        .setAccessibleDescription(
325:                                org.openide.util.NbBundle.getMessage(
326:                                        ClasspathPanel.class,
327:                                        "ACSD_ClasspathPanel_removeClasspath")); // NOI18N
328:
329:                classpath
330:                        .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
331:                            public void valueChanged(
332:                                    javax.swing.event.ListSelectionEvent evt) {
333:                                classpathValueChanged(evt);
334:                            }
335:                        });
336:                jScrollPane1.setViewportView(classpath);
337:                classpath.getAccessibleContext().setAccessibleDescription(
338:                        org.openide.util.NbBundle.getMessage(
339:                                ClasspathPanel.class,
340:                                "ACSD_ClasspathPanel_classpath")); // NOI18N
341:
342:                gridBagConstraints = new java.awt.GridBagConstraints();
343:                gridBagConstraints.gridx = 0;
344:                gridBagConstraints.gridy = 4;
345:                gridBagConstraints.gridheight = 4;
346:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
347:                gridBagConstraints.weightx = 1.0;
348:                gridBagConstraints.weighty = 1.0;
349:                add(jScrollPane1, gridBagConstraints);
350:
351:                jPanel1.setLayout(new java.awt.GridBagLayout());
352:
353:                sourceFolder.addItemListener(new java.awt.event.ItemListener() {
354:                    public void itemStateChanged(java.awt.event.ItemEvent evt) {
355:                        sourceFolderItemStateChanged(evt);
356:                    }
357:                });
358:                gridBagConstraints = new java.awt.GridBagConstraints();
359:                gridBagConstraints.gridx = 1;
360:                gridBagConstraints.gridy = 0;
361:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
362:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
363:                gridBagConstraints.weightx = 1.0;
364:                gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
365:                jPanel1.add(sourceFolder, gridBagConstraints);
366:
367:                jLabel2.setLabelFor(sourceFolder);
368:                org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
369:                        org.openide.util.NbBundle.getMessage(
370:                                ClasspathPanel.class,
371:                                "LBL_ClasspathPanel_jLabel2")); // NOI18N
372:                gridBagConstraints = new java.awt.GridBagConstraints();
373:                gridBagConstraints.gridx = 0;
374:                gridBagConstraints.gridy = 0;
375:                jPanel1.add(jLabel2, gridBagConstraints);
376:                jLabel2.getAccessibleContext().setAccessibleDescription(
377:                        org.openide.util.NbBundle.getMessage(
378:                                ClasspathPanel.class,
379:                                "ACSD_ClasspathPanel_jLabel2")); // NOI18N
380:
381:                gridBagConstraints = new java.awt.GridBagConstraints();
382:                gridBagConstraints.gridx = 0;
383:                gridBagConstraints.gridy = 2;
384:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
385:                gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
386:                add(jPanel1, gridBagConstraints);
387:
388:                org.openide.awt.Mnemonics.setLocalizedText(moveUp,
389:                        org.openide.util.NbBundle.getMessage(
390:                                ClasspathPanel.class,
391:                                "LBL_ClasspathPanel_Move_Up")); // NOI18N
392:                moveUp.addActionListener(new java.awt.event.ActionListener() {
393:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
394:                        moveUpActionPerformed(evt);
395:                    }
396:                });
397:                gridBagConstraints = new java.awt.GridBagConstraints();
398:                gridBagConstraints.gridx = 1;
399:                gridBagConstraints.gridy = 6;
400:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
401:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
402:                gridBagConstraints.insets = new java.awt.Insets(0, 8, 6, 0);
403:                add(moveUp, gridBagConstraints);
404:                java.util.ResourceBundle bundle = java.util.ResourceBundle
405:                        .getBundle("org/netbeans/modules/java/freeform/ui/Bundle"); // NOI18N
406:                moveUp.getAccessibleContext().setAccessibleDescription(
407:                        bundle.getString("AD_ClasspathPanel_noveUp")); // NOI18N
408:
409:                org.openide.awt.Mnemonics.setLocalizedText(moveDown,
410:                        org.openide.util.NbBundle.getMessage(
411:                                ClasspathPanel.class,
412:                                "LBL_ClasspathPanel_Move_Down")); // NOI18N
413:                moveDown.addActionListener(new java.awt.event.ActionListener() {
414:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
415:                        moveDownActionPerformed(evt);
416:                    }
417:                });
418:                gridBagConstraints = new java.awt.GridBagConstraints();
419:                gridBagConstraints.gridx = 1;
420:                gridBagConstraints.gridy = 7;
421:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
422:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
423:                gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
424:                add(moveDown, gridBagConstraints);
425:                moveDown.getAccessibleContext().setAccessibleDescription(
426:                        bundle.getString("AD_ClasspathPanel_moveDown")); // NOI18N
427:
428:                jTextArea1.setEditable(false);
429:                jTextArea1.setLineWrap(true);
430:                jTextArea1.setText(org.openide.util.NbBundle.getMessage(
431:                        ClasspathPanel.class, "MSG_ClasspathPanel_jTextArea")); // NOI18N
432:                jTextArea1.setWrapStyleWord(true);
433:                jTextArea1.setEnabled(false);
434:                gridBagConstraints = new java.awt.GridBagConstraints();
435:                gridBagConstraints.gridx = 0;
436:                gridBagConstraints.gridy = 0;
437:                gridBagConstraints.gridwidth = 2;
438:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
439:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
440:                add(jTextArea1, gridBagConstraints);
441:                jTextArea1.getAccessibleContext().setAccessibleName(
442:                        org.openide.util.NbBundle.getMessage(
443:                                ClasspathPanel.class,
444:                                "ACSN_ClasspathPanel_jTextArea")); // NOI18N
445:                jTextArea1.getAccessibleContext().setAccessibleDescription(
446:                        org.openide.util.NbBundle.getMessage(
447:                                ClasspathPanel.class,
448:                                "ACSD_ClasspathPanel_jTextArea")); // NOI18N
449:
450:                separateClasspath.setSelected(true);
451:                org.openide.awt.Mnemonics.setLocalizedText(separateClasspath,
452:                        org.openide.util.NbBundle.getMessage(
453:                                ClasspathPanel.class,
454:                                "LBL_ClasspathPanel_sepatateClasspath")); // NOI18N
455:                separateClasspath.setMargin(new java.awt.Insets(0, 0, 0, 0));
456:                separateClasspath
457:                        .addActionListener(new java.awt.event.ActionListener() {
458:                            public void actionPerformed(
459:                                    java.awt.event.ActionEvent evt) {
460:                                separateClasspathActionPerformed(evt);
461:                            }
462:                        });
463:                gridBagConstraints = new java.awt.GridBagConstraints();
464:                gridBagConstraints.gridx = 0;
465:                gridBagConstraints.gridy = 1;
466:                gridBagConstraints.gridwidth = 2;
467:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
468:                gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
469:                add(separateClasspath, gridBagConstraints);
470:                separateClasspath
471:                        .getAccessibleContext()
472:                        .setAccessibleDescription(
473:                                bundle
474:                                        .getString("AD_ClasspathPanel_separateClasspath")); // NOI18N
475:
476:                javaPlatformPanel.setLayout(new java.awt.GridBagLayout());
477:
478:                javaPlatformIntro.setEditable(false);
479:                javaPlatformIntro.setLineWrap(true);
480:                javaPlatformIntro.setText(org.openide.util.NbBundle.getMessage(
481:                        ClasspathPanel.class,
482:                        "ClasspathPanel.javaPlatformIntro")); // NOI18N
483:                javaPlatformIntro.setWrapStyleWord(true);
484:                javaPlatformIntro.setEnabled(false);
485:                gridBagConstraints = new java.awt.GridBagConstraints();
486:                gridBagConstraints.gridx = 0;
487:                gridBagConstraints.gridy = 0;
488:                gridBagConstraints.gridwidth = 3;
489:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
490:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
491:                javaPlatformPanel.add(javaPlatformIntro, gridBagConstraints);
492:                javaPlatformIntro.getAccessibleContext().setAccessibleName(
493:                        org.openide.util.NbBundle.getMessage(
494:                                ClasspathPanel.class,
495:                                "ACSN_ClasspathPanel_PlatformIntro")); // NOI18N
496:                javaPlatformIntro.getAccessibleContext()
497:                        .setAccessibleDescription(
498:                                org.openide.util.NbBundle.getMessage(
499:                                        ClasspathPanel.class,
500:                                        "ACSD_ClasspathPanel_PlatformIntro")); // NOI18N
501:
502:                javaPlatformLabel.setLabelFor(javaPlatform);
503:                org.openide.awt.Mnemonics.setLocalizedText(javaPlatformLabel,
504:                        org.openide.util.NbBundle.getMessage(
505:                                ClasspathPanel.class,
506:                                "ClasspathPanel.javaPlatformLabel")); // NOI18N
507:                gridBagConstraints = new java.awt.GridBagConstraints();
508:                gridBagConstraints.gridx = 0;
509:                gridBagConstraints.gridy = 1;
510:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
511:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
512:                javaPlatformPanel.add(javaPlatformLabel, gridBagConstraints);
513:                gridBagConstraints = new java.awt.GridBagConstraints();
514:                gridBagConstraints.gridx = 1;
515:                gridBagConstraints.gridy = 1;
516:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
517:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
518:                gridBagConstraints.weightx = 1.0;
519:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
520:                javaPlatformPanel.add(javaPlatform, gridBagConstraints);
521:
522:                org.openide.awt.Mnemonics.setLocalizedText(javaPlatformButton,
523:                        org.openide.util.NbBundle.getMessage(
524:                                ClasspathPanel.class,
525:                                "ClasspathPanel.javaPlatformButton")); // NOI18N
526:                javaPlatformButton
527:                        .addActionListener(new java.awt.event.ActionListener() {
528:                            public void actionPerformed(
529:                                    java.awt.event.ActionEvent evt) {
530:                                javaPlatformButtonActionPerformed(evt);
531:                            }
532:                        });
533:                gridBagConstraints = new java.awt.GridBagConstraints();
534:                gridBagConstraints.gridx = 2;
535:                gridBagConstraints.gridy = 1;
536:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
537:                javaPlatformPanel.add(javaPlatformButton, gridBagConstraints);
538:
539:                gridBagConstraints = new java.awt.GridBagConstraints();
540:                gridBagConstraints.gridx = 0;
541:                gridBagConstraints.gridy = 8;
542:                gridBagConstraints.gridwidth = 2;
543:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
544:                gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
545:                add(javaPlatformPanel, gridBagConstraints);
546:
547:                jPanel2.setBorder(javax.swing.BorderFactory
548:                        .createLineBorder(javax.swing.UIManager.getDefaults()
549:                                .getColor("Label.disabledForeground")));
550:                jPanel2.setLayout(new java.awt.GridBagLayout());
551:
552:                jLabel1
553:                        .setIcon(new javax.swing.ImageIcon(
554:                                getClass()
555:                                        .getResource(
556:                                                "/org/netbeans/modules/java/freeform/resources/alert_32.png"))); // NOI18N
557:                gridBagConstraints = new java.awt.GridBagConstraints();
558:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
559:                gridBagConstraints.insets = new java.awt.Insets(8, 8, 8, 0);
560:                jPanel2.add(jLabel1, gridBagConstraints);
561:
562:                jTextArea2.setBackground(javax.swing.UIManager.getDefaults()
563:                        .getColor("Panel.background"));
564:                jTextArea2.setEditable(false);
565:                jTextArea2.setLineWrap(true);
566:                jTextArea2.setText(org.openide.util.NbBundle.getMessage(
567:                        ClasspathPanel.class, "Freeform_Warning_Message")); // NOI18N
568:                jTextArea2.setWrapStyleWord(true);
569:                gridBagConstraints = new java.awt.GridBagConstraints();
570:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
571:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
572:                gridBagConstraints.weightx = 1.0;
573:                gridBagConstraints.insets = new java.awt.Insets(4, 10, 4, 4);
574:                jPanel2.add(jTextArea2, gridBagConstraints);
575:                jTextArea2.getAccessibleContext().setAccessibleName(
576:                        org.openide.util.NbBundle.getMessage(
577:                                ClasspathPanel.class,
578:                                "ACSN_Freeform_Warning_Message")); // NOI18N
579:                jTextArea2.getAccessibleContext().setAccessibleDescription(
580:                        org.openide.util.NbBundle.getMessage(
581:                                ClasspathPanel.class,
582:                                "ACSD_Freeform_Warning_Message")); // NOI18N
583:
584:                gridBagConstraints = new java.awt.GridBagConstraints();
585:                gridBagConstraints.gridx = 0;
586:                gridBagConstraints.gridy = 9;
587:                gridBagConstraints.gridwidth = 2;
588:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
589:                gridBagConstraints.weightx = 1.0;
590:                gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
591:                add(jPanel2, gridBagConstraints);
592:            }// </editor-fold>//GEN-END:initComponents
593:
594:            private void javaPlatformButtonActionPerformed(
595:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javaPlatformButtonActionPerformed
596:                PlatformsCustomizer.showCustomizer(jdkConf
597:                        .getSelectedPlatform());
598:                refreshJavaPlatforms();
599:            }//GEN-LAST:event_javaPlatformButtonActionPerformed
600:
601:            private void classpathValueChanged(
602:                    javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_classpathValueChanged
603:                updateButtons();
604:            }//GEN-LAST:event_classpathValueChanged
605:
606:            private void separateClasspathActionPerformed(
607:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_separateClasspathActionPerformed
608:                if (ignoreEvent) {
609:                    return;
610:                }
611:                applyChanges();
612:                isSeparateClasspath = separateClasspath.isSelected();
613:                model.updateCompilationUnits(isSeparateClasspath);
614:                updateControls();
615:            }//GEN-LAST:event_separateClasspathActionPerformed
616:
617:            private void moveDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownActionPerformed
618:                int indices[] = classpath.getSelectedIndices();
619:                if (indices.length == 0
620:                        || indices[indices.length - 1] == listModel.getSize() - 1) {
621:                    return;
622:                }
623:                for (int i = 0; i < indices.length; i++) {
624:                    int index = indices[i];
625:                    Object o = listModel.remove(index);
626:                    index++;
627:                    listModel.add(index, o);
628:                    indices[i] = index;
629:                }
630:                classpath.setSelectedIndices(indices);
631:                applyChanges();
632:                updateButtons();
633:            }//GEN-LAST:event_moveDownActionPerformed
634:
635:            private void moveUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpActionPerformed
636:                int indices[] = classpath.getSelectedIndices();
637:                if (indices.length == 0 || indices[0] == 0) {
638:                    return;
639:                }
640:                for (int i = 0; i < indices.length; i++) {
641:                    int index = indices[i];
642:                    Object o = listModel.remove(index);
643:                    index--;
644:                    listModel.add(index, o);
645:                    indices[i] = index;
646:                }
647:                classpath.setSelectedIndices(indices);
648:                applyChanges();
649:                updateButtons();
650:            }//GEN-LAST:event_moveUpActionPerformed
651:
652:            private void sourceFolderItemStateChanged(
653:                    java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sourceFolderItemStateChanged
654:                if (ignoreEvent) {
655:                    return;
656:                }
657:                if (evt.getStateChange() == ItemEvent.DESELECTED) {
658:                    int index = findIndex(evt.getItem());
659:                    // if index == -1 then item was removed and will not be saved
660:                    if (index != -1) {
661:                        saveClasspath(index);
662:                    }
663:                } else {
664:                    loadClasspath();
665:                }
666:                updateButtons();
667:            }//GEN-LAST:event_sourceFolderItemStateChanged
668:
669:            private int findIndex(Object o) {
670:                for (int i = 0; i < sourceFolder.getModel().getSize(); i++) {
671:                    if (sourceFolder.getModel().getElementAt(i).equals(o)) {
672:                        return i;
673:                    }
674:                }
675:                return -1;
676:            }
677:
678:            /** Source package combo is changing - take classpath from the listbox and
679:             * store it in compilaiton unit identified by the index.*/
680:            private void saveClasspath(int index) {
681:                ProjectModel.CompilationUnitKey key = compUnitsKeys.get(index);
682:                JavaProjectGenerator.JavaCompilationUnit cu = model
683:                        .getCompilationUnit(key, model
684:                                .isTestSourceFolder(index));
685:                updateCompilationUnitCompileClasspath(cu);
686:            }
687:
688:            /** Source package has changed - find current source package and read its classpath and
689:             * update classpath listbox with it.*/
690:            private void loadClasspath() {
691:                int index;
692:                if (isSeparateClasspath) {
693:                    index = sourceFolder.getSelectedIndex();
694:                    if (index == -1) {
695:                        return;
696:                    }
697:                } else {
698:                    index = 0;
699:                }
700:                ProjectModel.CompilationUnitKey key = compUnitsKeys.get(index);
701:                JavaProjectGenerator.JavaCompilationUnit cu = model
702:                        .getCompilationUnit(key, model
703:                                .isTestSourceFolder(index));
704:                updateJListClassPath(cu.classpath);
705:            }
706:
707:            /** Update compilation unit classpath list with the classpath specified
708:             * in classpath list box. */
709:            private void updateCompilationUnitCompileClasspath(
710:                    JavaProjectGenerator.JavaCompilationUnit cu) {
711:                List<JavaProjectGenerator.JavaCompilationUnit.CP> cps = cu.classpath;
712:                if (cps != null) {
713:                    Iterator<JavaProjectGenerator.JavaCompilationUnit.CP> it = cps
714:                            .iterator();
715:                    while (it.hasNext()) {
716:                        JavaProjectGenerator.JavaCompilationUnit.CP cp = it
717:                                .next();
718:                        if (cp.mode.equals(ProjectModel.CLASSPATH_MODE_COMPILE)) {
719:                            it.remove();
720:                            // there should be only one, but go on
721:                            // break;
722:                        }
723:                    }
724:                }
725:                if (classpath.getModel().getSize() == 0) {
726:                    return;
727:                }
728:                StringBuffer sb = new StringBuffer();
729:                for (int i = 0; i < classpath.getModel().getSize(); i++) {
730:                    File f = new File((String) classpath.getModel()
731:                            .getElementAt(i));
732:                    String path = Util.relativizeLocation(
733:                            model.getBaseFolder(), model.getNBProjectFolder(),
734:                            f);
735:                    sb.append(path);
736:                    if (i + 1 < classpath.getModel().getSize()) {
737:                        sb.append(File.pathSeparatorChar);
738:                    }
739:                }
740:                if (sb.length() > 0) {
741:                    if (cps == null) {
742:                        cps = new ArrayList<JavaProjectGenerator.JavaCompilationUnit.CP>();
743:                        cu.classpath = cps;
744:                    }
745:                    JavaProjectGenerator.JavaCompilationUnit.CP cp = new JavaProjectGenerator.JavaCompilationUnit.CP();
746:                    cp.mode = ProjectModel.CLASSPATH_MODE_COMPILE;
747:                    cp.classpath = sb.toString();
748:                    cps.add(cp);
749:                }
750:            }
751:
752:            /** Reads "compile" mode classpath and updates panel's list box.*/
753:            private void updateJListClassPath(
754:                    List<JavaProjectGenerator.JavaCompilationUnit.CP> cps) {
755:                listModel.removeAllElements();
756:                if (cps == null) {
757:                    return;
758:                }
759:                for (JavaProjectGenerator.JavaCompilationUnit.CP cp : cps) {
760:                    if (cp.mode.equals(ProjectModel.CLASSPATH_MODE_COMPILE)) {
761:                        for (String path : PropertyUtils.tokenizePath(model
762:                                .getEvaluator().evaluate(cp.classpath))) {
763:                            path = PropertyUtils.resolveFile(
764:                                    model.getNBProjectFolder(), path)
765:                                    .getAbsolutePath();
766:                            if (path != null) {
767:                                listModel.addElement(path);
768:                            }
769:                        }
770:                    }
771:                }
772:                updateButtons();
773:            }
774:
775:            private void updateButtons() {
776:                int indices[] = classpath.getSelectedIndices();
777:                removeClasspath.setEnabled(listModel.getSize() > 0
778:                        && indices.length != 0);
779:                moveUp.setEnabled(indices.length > 0 && indices[0] != 0);
780:                moveDown
781:                        .setEnabled(indices.length > 0
782:                                && indices[indices.length - 1] != listModel
783:                                        .getSize() - 1);
784:            }
785:
786:            private void removeClasspathActionPerformed(
787:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeClasspathActionPerformed
788:                int entries[] = classpath.getSelectedIndices();
789:                for (int i = 0; i < entries.length; i++) {
790:                    listModel.remove(entries[i] - i);
791:                }
792:                applyChanges();
793:                updateButtons();
794:            }//GEN-LAST:event_removeClasspathActionPerformed
795:
796:            private void addClasspathActionPerformed(
797:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClasspathActionPerformed
798:                JFileChooser chooser = new JFileChooser();
799:                FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
800:                chooser
801:                        .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
802:                chooser.setMultiSelectionEnabled(true);
803:                if (lastChosenFile != null) {
804:                    chooser.setSelectedFile(lastChosenFile);
805:                } else {
806:                    File files[] = model.getBaseFolder().listFiles();
807:                    if (files != null && files.length > 0) {
808:                        chooser.setSelectedFile(files[0]);
809:                    } else {
810:                        chooser.setSelectedFile(model.getBaseFolder());
811:                    }
812:                }
813:                chooser.setDialogTitle(NbBundle.getMessage(
814:                        ClasspathPanel.class, "LBL_Browse_Classpath"));
815:
816:                //#65354: prevent adding a non-folder element on the classpath:
817:                FileFilter fileFilter = new SimpleFileFilter(NbBundle
818:                        .getMessage(ClasspathPanel.class,
819:                                "LBL_ZipJarFolderFilter"), // NOI18N
820:                        new String[] { "ZIP", "JAR" }); // NOI18N
821:                //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
822:                chooser.setAcceptAllFileFilterUsed(false);
823:                chooser.setFileFilter(fileFilter);
824:
825:                if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this )) {
826:                    for (File file : chooser.getSelectedFiles()) {
827:                        file = FileUtil.normalizeFile(file);
828:
829:                        //Check if the file is acceted by the FileFilter,
830:                        //user may enter the name of non displayed file into JFileChooser
831:                        if (!fileFilter.accept(file)) {
832:                            continue;
833:                        }
834:
835:                        listModel.addElement(file.getAbsolutePath());
836:                        lastChosenFile = file;
837:                    }
838:                    applyChanges();
839:                    updateButtons();
840:                }
841:            }//GEN-LAST:event_addClasspathActionPerformed
842:
843:            private void applyChanges() {
844:                if (isSeparateClasspath) {
845:                    if (sourceFolder.getSelectedIndex() != -1) {
846:                        saveClasspath(sourceFolder.getSelectedIndex());
847:                    }
848:                } else {
849:                    saveClasspath(0);
850:                }
851:            }
852:
853:            public void setModel(ProjectModel model) {
854:                this .model = model;
855:                updateControls();
856:            }
857:
858:            // Variables declaration - do not modify//GEN-BEGIN:variables
859:            private javax.swing.JButton addClasspath;
860:            private javax.swing.JList classpath;
861:            private javax.swing.JLabel jLabel1;
862:            private javax.swing.JLabel jLabel2;
863:            private javax.swing.JLabel jLabel3;
864:            private javax.swing.JPanel jPanel1;
865:            private javax.swing.JPanel jPanel2;
866:            private javax.swing.JScrollPane jScrollPane1;
867:            private javax.swing.JTextArea jTextArea1;
868:            private javax.swing.JTextArea jTextArea2;
869:            javax.swing.JComboBox javaPlatform;
870:            private javax.swing.JButton javaPlatformButton;
871:            private javax.swing.JTextArea javaPlatformIntro;
872:            private javax.swing.JLabel javaPlatformLabel;
873:            private javax.swing.JPanel javaPlatformPanel;
874:            private javax.swing.JButton moveDown;
875:            private javax.swing.JButton moveUp;
876:            private javax.swing.JButton removeClasspath;
877:            private javax.swing.JCheckBox separateClasspath;
878:            private javax.swing.JComboBox sourceFolder;
879:
880:            // End of variables declaration//GEN-END:variables
881:
882:            private static class SimpleFileFilter extends FileFilter {
883:
884:                private String description;
885:                private Collection extensions;
886:
887:                public SimpleFileFilter(String description, String[] extensions) {
888:                    this .description = description;
889:                    this .extensions = Arrays.asList(extensions);
890:                }
891:
892:                public boolean accept(File f) {
893:                    if (f.isDirectory())
894:                        return true;
895:                    try {
896:                        return FileUtil.isArchiveFile(f.toURI().toURL());
897:                    } catch (MalformedURLException mue) {
898:                        ErrorManager.getDefault().notify(mue);
899:                        return false;
900:                    }
901:                }
902:
903:                public String getDescription() {
904:                    return this .description;
905:                }
906:            }
907:
908:            private static final class JavaPlatformRenderer extends
909:                    DefaultListCellRenderer implements  UIResource {
910:
911:                public JavaPlatformRenderer() {
912:                    setOpaque(true);
913:                }
914:
915:                @Override
916:                public Component getListCellRendererComponent(JList list,
917:                        Object value, int index, boolean isSelected,
918:                        boolean cellHasFocus) {
919:                    setName("ComboBox.listRenderer");
920:                    setText(((JavaPlatform) value).getDisplayName());
921:                    setIcon(null);
922:                    if (isSelected) {
923:                        setBackground(list.getSelectionBackground());
924:                        setForeground(list.getSelectionForeground());
925:                    } else {
926:                        setBackground(list.getBackground());
927:                        setForeground(list.getForeground());
928:                    }
929:                    return this ;
930:                }
931:
932:                @Override
933:                public String getName() {
934:                    String name = super .getName();
935:                    return name == null ? "ComboBox.renderer" : name;
936:                }
937:
938:            }
939:
940:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.