1 19 20 package org.netbeans.spi.looks; 21 22 import java.io.IOException ; 23 import org.openide.filesystems.FileObject; 24 import org.netbeans.modules.looks.SelectorImplFactory; 25 26 33 public abstract class Selectors { 34 35 36 private Selectors() {} 37 38 private static final String DECORATING_LOOK = "decoratingLook"; private static final String CONTEXT = Looks.CONTEXT; 41 private static final String LOOK_SELECTOR = Looks.LOOK_SELECTOR; 42 private static final String DEFAULT_CONTEXT = "Looks/Types/"; 47 48 private static LookSelector DEFAULT_SELECTOR; 49 50 52 54 static final LookSelector namespaceTypes(FileObject fo) throws IOException { 55 String contextPrefix = Looks.readStringAttribute (fo, CONTEXT); 56 if (contextPrefix == null) 57 contextPrefix = DEFAULT_CONTEXT; 58 59 org.netbeans.modules.looks.RegistryBridge rb = 60 org.netbeans.modules.looks.RegistryBridge.getDefault( fo ); 61 62 return new LookSelector( SelectorImplFactory.namespaceTypes( rb, contextPrefix ) ); 63 } 64 65 67 static final LookSelector decorator(FileObject fo) throws IOException { 68 return createDecoratorSelector (fo); 69 } 70 71 73 79 public static synchronized final LookSelector selector( LookProvider provider ) { 80 return new LookSelector( SelectorImplFactory.provider( provider ) ); 81 } 82 83 89 public static synchronized final LookSelector selector( ChangeableLookProvider provider ) { 90 return new LookSelector( SelectorImplFactory.changeableProvider( provider ) ); 91 } 92 93 99 public static final LookSelector singleton( Look delegate ) { 100 return new LookSelector( SelectorImplFactory.singleton( delegate ) ); 101 } 102 103 109 public static final LookSelector array( Look delegates[] ) { 110 return new LookSelector( SelectorImplFactory.array( delegates ) ); 111 } 112 113 120 public static final LookSelector first( LookSelector delegate ) { 121 return new LookSelector( SelectorImplFactory.first( delegate ) ); 122 } 123 124 139 public static synchronized final LookSelector defaultTypes() { 140 if (DEFAULT_SELECTOR == null) { 141 DEFAULT_SELECTOR = new LookSelector( SelectorImplFactory.namespaceTypes( DEFAULT_CONTEXT ) ); 142 } 143 return DEFAULT_SELECTOR; 144 } 145 146 165 public static final LookSelector namespaceTypes( String contextPrefix ) { 166 return new LookSelector( SelectorImplFactory.namespaceTypes( contextPrefix ) ); 167 } 168 169 183 208 public static final LookSelector decorator( LookSelector lookSelector, Look decoratingLook ) { 209 return new LookSelector( SelectorImplFactory.decorator( lookSelector, decoratingLook, true, true ) ); 210 } 211 212 217 218 223 public static final LookSelector composite( LookSelector[] selectors ) { 224 return new LookSelector( SelectorImplFactory.composite( selectors, true ) ); 225 } 226 227 229 230 static synchronized final LookSelector selector( org.netbeans.modules.looks.NamespaceLookProvider provider, String prefix ) { 231 return new LookSelector( SelectorImplFactory.namespaceProvider( provider, prefix ) ); 232 } 233 234 235 236 238 private static LookSelector createDecoratorSelector(FileObject fo) throws IOException { 239 Look decorator = Looks.readLookAttribute (fo, DECORATING_LOOK); 240 LookSelector selector = readLookSelectorAttribute (fo, LOOK_SELECTOR); 241 242 256 return new LookSelector( SelectorImplFactory.decorator( selector, decorator, true, true ) ); 257 } 258 259 private static LookSelector readLookSelectorAttribute (FileObject fo, String attribute) throws IOException { 260 return (LookSelector)Looks.readLookOrSelectorAttribute (fo, attribute, false); 261 } 262 } 263 | Popular Tags |