1 19 20 package org.netbeans.modules.looks; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.Enumeration ; 27 import java.util.HashSet ; 28 import java.util.List ; 29 import org.netbeans.spi.looks.Look; 30 import org.openide.util.Enumerations; 31 32 36 public class TypesSearch { 37 38 40 private TypesSearch() {}; 41 42 47 public static Enumeration namesForClass (Class c) { 48 Enumeration en; 49 if (c != Object .class) { 50 en = Enumerations.queue(Enumerations.singleton(c), new Enumerations.Processor() { 51 public Object process(Object o, Collection coll) { 52 Class x = (Class ) o; 53 Class s = x.getSuperclass(); 54 coll.addAll(Arrays.asList(x.getInterfaces())); 55 if (s != null && s != Object .class) { 56 coll.add(s); 58 } 59 return o; 60 } 61 }); 62 } else { 63 en = Enumerations.empty(); 64 } 65 66 Enumeration alter = Enumerations.convert(en, new Enumerations.Processor() { 67 public Object process(Object clazz, Collection ignore) { 68 Class c = (Class ) clazz; 69 return c.getName().replace('.', '/'); 70 } 71 }); 72 73 return Enumerations.concat(alter, Enumerations.singleton("java/lang/Object")); } 75 76 82 static Enumeration findLooks( String prefix, Enumeration names, RegistryBridge rb ) { 83 ArrayList list = new ArrayList (); 84 findLook( prefix, names, list, null, rb ); 85 return Collections.enumeration( list ); 86 } 87 88 89 private static Look findLook (String prefix, Enumeration names, List looks, String preferredName, RegistryBridge registryBridge ) { 90 91 Collection checks = new HashSet (); 92 Look preferredLook = null; 93 94 while (names.hasMoreElements ()) { 95 String check = (String )names.nextElement (); 96 if (!checks.add(check)) 97 continue; 98 if (prefix != null) { 99 check = prefix + check; 100 } 101 102 Enumeration en = registryBridge.getObjects (check, Look.class); 103 while (en.hasMoreElements ()) { 104 Object o = en.nextElement (); 105 106 if (o != null) { 107 if ( preferredName != null && 108 preferredName.equals( ((Look)o).getName() ) ) { 109 preferredLook = (Look)o; 110 } 111 if (looks != null) { 112 looks.add (o); 114 } else { 115 return (Look)o; 117 } 118 } 119 } 120 } 121 return preferredLook == null ? 122 ( looks == null || looks.size() == 0 ? null : (Look)looks.get( 0 ) ) : 123 preferredLook; 124 } 125 126 } 127 | Popular Tags |