KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > Utils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.masterfs;
21
22 import org.openide.filesystems.*;
23 import org.openide.util.NbBundle;
24 import org.openide.util.Utilities;
25
26 import java.io.File JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.MissingResourceException JavaDoc;
29 import java.util.Set JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.awt.*;
33 import java.beans.BeanInfo JavaDoc;
34 import java.beans.IntrospectionException JavaDoc;
35
36 public class Utils {
37
38     static String JavaDoc getString(String JavaDoc s) {
39         try {
40             return NbBundle.getBundle("org.netbeans.modules.masterfs.resources.Bundle", //NOI18N
41
java.util.Locale.getDefault(), MasterFileSystem.class.getClassLoader()).getString(s);
42         } catch (MissingResourceException JavaDoc msx) {
43             return "";
44         }
45     }
46
47     static String JavaDoc formatString(String JavaDoc excName, Object JavaDoc[] args) {
48         String JavaDoc format = getString(excName);
49         if (args == null)
50             return format;
51         else
52             return java.text.MessageFormat.format(format, args);
53     }
54
55     static void throwIOException(String JavaDoc format, Object JavaDoc[] args) throws IOException JavaDoc {
56         throwIOException(new IOException JavaDoc(formatString(format, args)));
57     }
58
59     static void throwIOException(IOException JavaDoc exc2Fire) throws IOException JavaDoc {
60         throw exc2Fire;
61     }
62
63     static Image getRootIcon(int iconType, Object JavaDoc obj) {
64         try {
65             BeanInfo JavaDoc bI = Utilities.getBeanInfo(obj.getClass());
66             Image img = bI.getIcon(iconType);
67             return img;
68         } catch (IntrospectionException JavaDoc iex) {
69             return null;
70         }
71     }
72
73     static Set JavaDoc transformSet (final Set JavaDoc files) {
74         final Set JavaDoc transformedSet = new HashSet JavaDoc ();
75         
76         Iterator JavaDoc it = files.iterator();
77         while (it.hasNext()) {
78             MasterFileObject mfo = (MasterFileObject)it.next();
79             FileObject fo = mfo.getDelegate().get(true);
80             if (fo != null) {
81                 transformedSet.add(fo);
82             }
83         }
84         return transformedSet;
85     }
86     
87
88     static ResourcePath getResource (File JavaDoc f) {
89         String JavaDoc path;
90         try {
91             path = f.getCanonicalPath();
92         } catch (IOException JavaDoc iex) {
93             path = f.getAbsolutePath();
94         }
95         return new ResourcePath (path);
96     }
97
98     static Set JavaDoc transformToDelegates(java.util.Set JavaDoc foSet, boolean prefered) {
99         Set JavaDoc retVal = new HashSet JavaDoc();
100         Iterator JavaDoc it = foSet.iterator();
101         while (it.hasNext()) {
102             Object JavaDoc obj = it.next();
103             if (obj instanceof MasterFileObject) {
104                 FileObject fo;
105                 if (prefered) {
106                     MasterFileObject hfo = (MasterFileObject) obj;
107                     fo = hfo.getDelegate().getPrefered();
108                 } else {
109                     MasterFileObject hfo = (MasterFileObject) obj;
110                     fo = hfo.getDelegate().get();
111                 }
112
113                 if (fo != null)
114                     retVal.add(fo);
115             }
116         }
117         return retVal;
118     }
119
120 }
121
Popular Tags