Source Code Cross Referenced for VisualClassPathItem.java in  » IDE-Netbeans » mobility » org » netbeans » modules » mobility » project » ui » 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.mobility.project.ui.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.mobility.project.ui.customizer;
043:
044:        import java.io.File;
045:        import java.net.URI;
046:        import java.awt.*;
047:        import javax.swing.Icon;
048:        import javax.swing.ImageIcon;
049:        import org.netbeans.api.project.ant.AntArtifact;
050:        import org.netbeans.api.project.libraries.Library;
051:        import org.openide.filesystems.FileUtil;
052:        import org.openide.util.Utilities;
053:
054:        /** Represents classpath items of various types. Can be used in the model
055:         * of classpath editing controls.
056:         *
057:         * @author  phrebejk
058:         */
059:        public final class VisualClassPathItem {
060:
061:            // Types of the classpath elements
062:            public static final int TYPE_JAR = 0;
063:            public static final int TYPE_LIBRARY = 1;
064:            public static final int TYPE_ARTIFACT = 2;
065:            public static final int TYPE_CLASSPATH = 3;
066:            public static final int TYPE_FOLDER = 4;
067:
068:            final private static String RESOURCE_ICON_JAR = "org/netbeans/modules/project/support/customizer/resources/jar.gif"; //NOI18N
069:            final private static String RESOURCE_ICON_FOLDER = "org/netbeans/modules/project/support/customizer/resources/folder.gif"; //NOI18N
070:            final private static String RESOURCE_ICON_LIBRARY = "org/netbeans/modules/project/support/customizer/resources/libraries.gif"; //NOI18N
071:            final private static String RESOURCE_ICON_ARTIFACT = "org/netbeans/modules/project/support/customizer/resources/projectDependencies.gif"; //NOI18N
072:            final private static String RESOURCE_ICON_CLASSPATH = "org/netbeans/modules/project/support/customizer/resources/project.gif"; //NOI18N
073:            final private static String RESOURCE_ICON_BROKEN = "org/netbeans/modules/project/support/customizer/resources/brokenProjectBadge.gif"; //NOI18N
074:
075:            private static Icon ICON_JAR;
076:            private static Icon ICON_LIBRARY;
077:            private static Icon ICON_ARTIFACT;
078:            private static Icon ICON_CLASSPATH;
079:            private static Icon ICON_FOLDER;
080:            private static Icon ICON_BROKEN_JAR;
081:            private static Icon ICON_BROKEN_LIBRARY;
082:            private static Icon ICON_BROKEN_ARTIFACT;
083:            private static Icon ICON_BROKEN_CLASSPATH;
084:            private static Icon ICON_BROKEN_FOLDER;
085:
086:            static {
087:                Image i;
088:                Image broken = Utilities.loadImage(RESOURCE_ICON_BROKEN);
089:
090:                i = Utilities.loadImage(RESOURCE_ICON_JAR);
091:                ICON_JAR = new ImageIcon(i);
092:                ICON_BROKEN_JAR = new ImageIcon(Utilities.mergeImages(i,
093:                        broken, 8, 0));
094:
095:                i = Utilities.loadImage(RESOURCE_ICON_LIBRARY);
096:                ICON_LIBRARY = new ImageIcon(i);
097:                ICON_BROKEN_LIBRARY = new ImageIcon(Utilities.mergeImages(i,
098:                        broken, 8, 0));
099:
100:                i = Utilities.loadImage(RESOURCE_ICON_ARTIFACT);
101:                ICON_ARTIFACT = new ImageIcon(i);
102:                ICON_BROKEN_ARTIFACT = new ImageIcon(Utilities.mergeImages(i,
103:                        broken, 8, 0));
104:
105:                i = Utilities.loadImage(RESOURCE_ICON_CLASSPATH);
106:                ICON_CLASSPATH = new ImageIcon(i);
107:                ICON_BROKEN_CLASSPATH = new ImageIcon(Utilities.mergeImages(i,
108:                        broken, 8, 0));
109:
110:                i = Utilities.loadImage(RESOURCE_ICON_FOLDER);
111:                ICON_FOLDER = new ImageIcon(i);
112:                ICON_BROKEN_FOLDER = new ImageIcon(Utilities.mergeImages(i,
113:                        broken, 8, 0));
114:            }
115:
116:            private int type;
117:            private Object cpElement;
118:            private String display;
119:            private String rawText;
120:            private URI uri;
121:            private boolean extra = false;
122:
123:            public static VisualClassPathItem create(final Library library) {
124:                if (library == null) {
125:                    throw new IllegalArgumentException(
126:                            "library must not be null"); // NOI18N
127:                }
128:                final String libraryName = library.getName();
129:                return new VisualClassPathItem(library, TYPE_LIBRARY, "${libs."
130:                        + libraryName + ".classpath}", library.getDisplayName()); //NOI18N
131:
132:            }
133:
134:            public static VisualClassPathItem create(
135:                    final AntArtifact artifact, final URI artifactURI) {
136:                if (artifactURI == null) {
137:                    throw new IllegalArgumentException(
138:                            "artifactURI must not be null"); // NOI18N
139:                }
140:                if (artifact == null) {
141:                    throw new IllegalArgumentException(
142:                            "artifact must not be null"); // NOI18N
143:                }
144:                String location;
145:                try {
146:                    location = FileUtil.normalizeFile(
147:                            new File(artifact.getScriptLocation()
148:                                    .getParentFile().toURI().resolve(
149:                                            artifactURI))).getPath();
150:                } catch (Exception e) {
151:                    location = artifactURI.getPath();
152:                }
153:                return new VisualClassPathItem(artifact, artifactURI,
154:                        TYPE_ARTIFACT, null, location);
155:            }
156:
157:            public static VisualClassPathItem create(final File file) {
158:                if (file == null) {
159:                    throw new IllegalArgumentException("file must not be null"); // NOI18N
160:                }
161:                return new VisualClassPathItem(file,
162:                        isJar(file.getName()) ? TYPE_JAR : TYPE_FOLDER, null,
163:                        file.getPath());
164:            }
165:
166:            private static boolean isJar(String s) {
167:                if (s == null)
168:                    return false;
169:                s = s.toLowerCase();
170:                return s.endsWith(".jar") || s.endsWith(".zip"); //NOI18N
171:            }
172:
173:            public void setExtra(boolean extra) {
174:                this .extra = extra;
175:            }
176:
177:            public boolean isExtra() {
178:                return extra;
179:            }
180:
181:            public VisualClassPathItem(AntArtifact cpElement, URI uri,
182:                    int type, String rawText, String display) {
183:                this (cpElement, type, rawText, display);
184:                this .uri = uri;
185:            }
186:
187:            public VisualClassPathItem(Object cpElement, int type,
188:                    String rawText, String display) {
189:                this .cpElement = cpElement;
190:                this .type = type;
191:                this .display = display;
192:                this .rawText = rawText;
193:            }
194:
195:            public Object getElement() {
196:                return cpElement;
197:            }
198:
199:            public URI getURI() {
200:                return uri;
201:            }
202:
203:            public int getType() {
204:                return type;
205:            }
206:
207:            public String getDisplayName() {
208:                return display;
209:            }
210:
211:            public String getRawText() {
212:                return rawText;
213:            }
214:
215:            public boolean canDelete() {
216:                return getType() != TYPE_CLASSPATH;
217:            }
218:
219:            public Icon getIcon() {
220:
221:                switch (getType()) {
222:                case TYPE_JAR:
223:                    return getElement() != null ? ICON_JAR : ICON_BROKEN_JAR;
224:                case TYPE_FOLDER:
225:                    return getElement() != null ? ICON_FOLDER
226:                            : ICON_BROKEN_FOLDER;
227:                case TYPE_LIBRARY:
228:                    return getElement() != null ? ICON_LIBRARY
229:                            : ICON_BROKEN_LIBRARY;
230:                case TYPE_ARTIFACT:
231:                    return getElement() != null ? ICON_ARTIFACT
232:                            : ICON_BROKEN_ARTIFACT;
233:                case TYPE_CLASSPATH:
234:                    return getElement() != null ? ICON_CLASSPATH
235:                            : ICON_BROKEN_CLASSPATH;
236:                default:
237:                    return null;
238:                }
239:
240:            }
241:
242:            public String toString() {
243:                return getDisplayName();
244:            }
245:
246:            public int hashCode() {
247:
248:                int hash = getType();
249:
250:                switch (getType()) {
251:                case TYPE_ARTIFACT:
252:                    final AntArtifact aa = (AntArtifact) getElement();
253:                    if (aa == null) {
254:                        if (rawText != null)
255:                            hash += rawText.hashCode();
256:                        break;
257:                    }
258:
259:                    hash += aa.getType().hashCode();
260:                    hash += aa.getScriptLocation().hashCode();
261:                    hash += uri.hashCode();
262:                    break;
263:                default:
264:                    final Object element = getElement();
265:                    if (element != null)
266:                        hash += element.hashCode();
267:                    break;
268:                }
269:
270:                return hash;
271:            }
272:
273:            public boolean equals(final Object object) {
274:                //fix for 98455 - obvious case is missing
275:                if (this  == object)
276:                    return true;
277:
278:                if (!(object instanceof  VisualClassPathItem)) {
279:                    return false;
280:                }
281:                final VisualClassPathItem vcpi = (VisualClassPathItem) object;
282:
283:                if (getType() != vcpi.getType()) {
284:                    return false;
285:                }
286:
287:                switch (getType()) {
288:                case TYPE_ARTIFACT:
289:                    final AntArtifact aa1 = (AntArtifact) getElement();
290:                    final AntArtifact aa2 = (AntArtifact) vcpi.getElement();
291:                    if (aa1 == null || aa2 == null) {
292:                        if (getRawText() != null && vcpi.getRawText() != null)
293:                            if (getRawText().equals(vcpi.getRawText()))
294:                                return true;
295:                        return false;
296:                    }
297:
298:                    if (aa1.getType() != aa2.getType()) {
299:                        return false;
300:                    }
301:
302:                    if (!aa1.getScriptLocation()
303:                            .equals(aa2.getScriptLocation())) {
304:                        return false;
305:                    }
306:
307:                    if (!getURI().equals(vcpi.getURI())) {
308:                        return false;
309:                    }
310:
311:                    return true;
312:                default:
313:                    final Object element = getElement();
314:                    final Object cElement = vcpi.getElement();
315:                    //Special case when the library is missing but we want compare values
316:                    if (cElement == null && element == null
317:                            && vcpi.getRawText().equals(getRawText()))
318:                        return true;
319:                    //And another special case when library was removed from manager
320:                    if (element == null && cElement instanceof  Library
321:                            && toString().equals(vcpi.toString())
322:                            && vcpi.getRawText().equals(getRawText()))
323:                        return true;
324:
325:                    if (element == null)
326:                        return false;
327:
328:                    return element.equals(vcpi.getElement());
329:                }
330:
331:            }
332:
333:        }
w_ww___.__j___a_va__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.