Source Code Cross Referenced for LibrariesChooser.java in  » IDE-Netbeans » mobility » org » netbeans » modules » project » support » customizer » 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 » mobility » org.netbeans.modules.project.support.customizer 
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.project.support.customizer;
043:
044:        import org.netbeans.api.project.libraries.Library;
045:        import org.netbeans.api.project.libraries.LibraryManager;
046:        import org.netbeans.api.project.libraries.LibrariesCustomizer;
047:        import org.openide.util.WeakListeners;
048:
049:        import java.util.Comparator;
050:        import java.util.Arrays;
051:        import javax.swing.*;
052:        import java.awt.*;
053:        import java.beans.PropertyChangeListener;
054:        import java.beans.PropertyChangeEvent;
055:        import java.util.ArrayList;
056:        import org.openide.util.NbBundle;
057:
058:        /**
059:         *
060:         * @author  tz97951
061:         */
062:        public class LibrariesChooser extends javax.swing.JPanel {
063:
064:            /** Creates new form LibrariesChooser */
065:            public LibrariesChooser(String libraryType) {
066:                initComponents();
067:                initAccessibility();
068:                jList1.setPrototypeCellValue("0123456789012345678901234"); //NOI18N
069:                jList1.setModel(new LibrariesListModel(libraryType));
070:                jList1.setCellRenderer(new LibraryRenderer());
071:            }
072:
073:            public Library[] getSelectedLibraries() {
074:                final Object[] selected = this .jList1.getSelectedValues();
075:                final Library[] libraries = new Library[selected.length];
076:                System.arraycopy(selected, 0, libraries, 0, selected.length);
077:                return libraries;
078:            }
079:
080:            /** This method is called from within the constructor to
081:             * initialize the form.
082:             * WARNING: Do NOT modify this code. The content of this method is
083:             * always regenerated by the Form Editor.
084:             */
085:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
086:            private void initComponents() {
087:                java.awt.GridBagConstraints gridBagConstraints;
088:
089:                jLabel1 = new javax.swing.JLabel();
090:                jScrollPane1 = new javax.swing.JScrollPane();
091:                jList1 = new javax.swing.JList();
092:                edit = new javax.swing.JButton();
093:
094:                setLayout(new java.awt.GridBagLayout());
095:
096:                jLabel1.setLabelFor(jList1);
097:                org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle
098:                        .getMessage(LibrariesChooser.class,
099:                                "LAB_LIbCh_InstalledLibraries")); // NOI18N
100:                gridBagConstraints = new java.awt.GridBagConstraints();
101:                gridBagConstraints.gridx = 0;
102:                gridBagConstraints.gridy = 0;
103:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
104:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
106:                gridBagConstraints.weightx = 1.0;
107:                gridBagConstraints.insets = new java.awt.Insets(12, 12, 6, 12);
108:                add(jLabel1, gridBagConstraints);
109:                jLabel1.getAccessibleContext().setAccessibleName(
110:                        org.openide.util.NbBundle.getMessage(
111:                                LibrariesChooser.class,
112:                                "ACCESSIBLE_NAME_jLabel1")); // NOI18N
113:                jLabel1.getAccessibleContext().setAccessibleDescription(
114:                        org.openide.util.NbBundle.getMessage(
115:                                LibrariesChooser.class,
116:                                "ACCESSIBLE_DESCRIPTION_jLabel1")); // NOI18N
117:
118:                jScrollPane1.setViewportView(jList1);
119:
120:                gridBagConstraints = new java.awt.GridBagConstraints();
121:                gridBagConstraints.gridx = 0;
122:                gridBagConstraints.gridy = 1;
123:                gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
124:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
125:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
126:                gridBagConstraints.weightx = 1.0;
127:                gridBagConstraints.weighty = 1.0;
128:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 12, 12);
129:                add(jScrollPane1, gridBagConstraints);
130:
131:                org.openide.awt.Mnemonics.setLocalizedText(edit, NbBundle
132:                        .getMessage(LibrariesChooser.class, "LBL_LibCh_Edit")); // NOI18N
133:                edit.addActionListener(new java.awt.event.ActionListener() {
134:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
135:                        editLibraries(evt);
136:                    }
137:                });
138:                gridBagConstraints = new java.awt.GridBagConstraints();
139:                gridBagConstraints.gridx = 1;
140:                gridBagConstraints.gridy = 1;
141:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142:                gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
143:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
144:                gridBagConstraints.insets = new java.awt.Insets(6, 0, 12, 12);
145:                add(edit, gridBagConstraints);
146:                edit.getAccessibleContext()
147:                        .setAccessibleName(
148:                                org.openide.util.NbBundle.getMessage(
149:                                        LibrariesChooser.class,
150:                                        "ACCESSIBLE_NAME_edit")); // NOI18N
151:                edit.getAccessibleContext().setAccessibleDescription(
152:                        org.openide.util.NbBundle.getMessage(
153:                                LibrariesChooser.class,
154:                                "ACCESSIBLE_DESCRIPTION_edit")); // NOI18N
155:            }// </editor-fold>//GEN-END:initComponents
156:
157:            private void initAccessibility() {
158:                //getAccessibleContext().setAccessibleName();
159:                //getAccessibleContext().setAccessibleDescription();
160:            }
161:
162:            private void editLibraries(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editLibraries
163:                LibrariesCustomizer.showCustomizer((Library) this .jList1
164:                        .getSelectedValue());
165:            }//GEN-LAST:event_editLibraries
166:
167:            // Variables declaration - do not modify//GEN-BEGIN:variables
168:            private javax.swing.JButton edit;
169:            private javax.swing.JLabel jLabel1;
170:            private javax.swing.JList jList1;
171:            private javax.swing.JScrollPane jScrollPane1;
172:
173:            // End of variables declaration//GEN-END:variables
174:
175:            private final class LibrariesListModel extends AbstractListModel
176:                    implements  PropertyChangeListener {
177:
178:                private Library[] cache;
179:                private final String libraryType;
180:
181:                public LibrariesListModel(String libraryType) {
182:                    this .libraryType = libraryType;
183:                    LibraryManager manager = LibraryManager.getDefault();
184:                    manager.addPropertyChangeListener(WeakListeners.create(
185:                            PropertyChangeListener.class, this , manager));
186:                }
187:
188:                public synchronized int getSize() {
189:                    if (this .cache == null) {
190:                        this .cache = this .getLibraries();
191:                    }
192:                    return this .cache.length;
193:                }
194:
195:                public synchronized Object getElementAt(final int index) {
196:                    if (this .cache == null) {
197:                        this .cache = this .getLibraries();
198:                    }
199:                    if (index >= 0 && index < this .cache.length) {
200:                        return this .cache[index];
201:                    }
202:                    return null;
203:                }
204:
205:                public synchronized void propertyChange(
206:                        @SuppressWarnings("unused")
207:                        final PropertyChangeEvent evt) {
208:                    this .cache = null;
209:                }
210:
211:                private Library[] getLibraries() {
212:                    Library[] libs = LibraryManager.getDefault().getLibraries();
213:                    final ArrayList<Library> filtered = new ArrayList<Library>();
214:                    for (int i = 0; libs != null && i < libs.length; i++) {
215:                        if (libraryType == null
216:                                || libraryType.equals(libs[i].getType())) {
217:                            filtered.add(libs[i]);
218:                        }
219:                    }
220:                    libs = filtered.toArray(new Library[filtered.size()]);
221:                    Arrays.sort(libs, new Comparator<Library>() {
222:                        public int compare(Library o1, Library o2) {
223:                            final String name1 = o1.getDisplayName();
224:                            final String name2 = o2.getDisplayName();
225:                            return name1.compareToIgnoreCase(name2);
226:                        }
227:                    });
228:                    return libs;
229:                }
230:            }
231:
232:            private static final class LibraryRenderer extends
233:                    DefaultListCellRenderer {
234:
235:                private LibraryRenderer() {
236:                    //Just to avoid creation of accessor class
237:                }
238:
239:                public Component getListCellRendererComponent(final JList list,
240:                        final Object value, final int index,
241:                        final boolean isSelected, final boolean cellHasFocus) {
242:                    String displayName;
243:                    if (value instanceof  Library) {
244:                        displayName = ((Library) value).getDisplayName();
245:                    } else if (value instanceof  String) {
246:                        displayName = (String) value;
247:                    } else {
248:                        displayName = value.toString();
249:                    }
250:                    return super.getListCellRendererComponent(list,
251:                            displayName, index, isSelected, cellHasFocus);
252:                }
253:            }
254:
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.