1 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 ; 27 import java.io.IOException ; 28 import java.util.MissingResourceException ; 29 import java.util.Set ; 30 import java.util.Iterator ; 31 import java.util.HashSet ; 32 import java.awt.*; 33 import java.beans.BeanInfo ; 34 import java.beans.IntrospectionException ; 35 36 public class Utils { 37 38 static String getString(String s) { 39 try { 40 return NbBundle.getBundle("org.netbeans.modules.masterfs.resources.Bundle", java.util.Locale.getDefault(), MasterFileSystem.class.getClassLoader()).getString(s); 42 } catch (MissingResourceException msx) { 43 return ""; 44 } 45 } 46 47 static String formatString(String excName, Object [] args) { 48 String 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 format, Object [] args) throws IOException { 56 throwIOException(new IOException (formatString(format, args))); 57 } 58 59 static void throwIOException(IOException exc2Fire) throws IOException { 60 throw exc2Fire; 61 } 62 63 static Image getRootIcon(int iconType, Object obj) { 64 try { 65 BeanInfo bI = Utilities.getBeanInfo(obj.getClass()); 66 Image img = bI.getIcon(iconType); 67 return img; 68 } catch (IntrospectionException iex) { 69 return null; 70 } 71 } 72 73 static Set transformSet (final Set files) { 74 final Set transformedSet = new HashSet (); 75 76 Iterator 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 f) { 89 String path; 90 try { 91 path = f.getCanonicalPath(); 92 } catch (IOException iex) { 93 path = f.getAbsolutePath(); 94 } 95 return new ResourcePath (path); 96 } 97 98 static Set transformToDelegates(java.util.Set foSet, boolean prefered) { 99 Set retVal = new HashSet (); 100 Iterator it = foSet.iterator(); 101 while (it.hasNext()) { 102 Object 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 |