alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.spi.looks;

import java.io.IOException;

import org.openide.filesystems.FileObject;

import org.netbeans.modules.looks.SelectorImplFactory;

/** Static factory class providing useful look selectors. For looks which
 * can be constructed using module layer
 * XMLFileSystems, a sample of such XML definition is given
 * in their Javadoc.
 *
 * @author  Petr Hrebejk
 */
public abstract class Selectors {
    
    /** no instances */
    private Selectors() {}

    // Names of attributes
    private static final String DECORATING_LOOK = "decoratingLook"; // NOI18N
    private static final String CONTEXT = Looks.CONTEXT;
    private static final String LOOK_SELECTOR = Looks.LOOK_SELECTOR;
    // Default values
    private static final String DEFAULT_CONTEXT = "Looks/Types/"; // NOI18N
    // private static final String AS_LAST = "asLast"; // NOI18N
    // private static final String EXCLUDABLE = "excludable"; // NOI18N

    /* The only default selector in the system */
    private static LookSelector DEFAULT_SELECTOR;
    
    // Metheods to be used from XML layers -------------------------------------

    /** A method to be used from XML layers
     */
    static final LookSelector namespaceTypes(FileObject fo) throws IOException {
        String contextPrefix = Looks.readStringAttribute (fo, CONTEXT);
        if (contextPrefix == null)
            contextPrefix = DEFAULT_CONTEXT;

        org.netbeans.modules.looks.RegistryBridge rb = 
            org.netbeans.modules.looks.RegistryBridge.getDefault( fo );
        
        return new LookSelector( SelectorImplFactory.namespaceTypes( rb, contextPrefix ) ); 
    }

    /** A method to be used from XML layers
     */
    static final LookSelector decorator(FileObject fo) throws IOException {
        return createDecoratorSelector (fo);
    }

    // Methods to be used from code --------------------------------------------

    /** Creates a LookSelector based on LookProvider which will never change
     * it's content.
     * @see LookProvider
     * @param provider The concrete implementation of finding the Looks
     * @return LookSelector based on given LookProvider
     */
    public static synchronized final LookSelector selector( LookProvider provider ) {
        return new LookSelector( SelectorImplFactory.provider( provider ) );
    }

    /** Creates a LookSelector which may change it's content.
     * @see ChangeableLookProvider
     * @param provider The concrete implementation of finding the Looks and
     *        firing changes of the LookSelector content
     * @return LookSelector based on given LookProvider
     */
    public static synchronized final LookSelector selector( ChangeableLookProvider provider ) {
        return new LookSelector( SelectorImplFactory.changeableProvider( provider ) );
    }

    /** Utility method, creates a LookSelector which will allways return
     *  the look put into this method as a parameter.
     *
     * @param delegate The Look to be returned from the selector.
     * @return LookSelector returning Enumeration which contains given look.
     */
    public static final LookSelector singleton( Look delegate ) {
        return new LookSelector( SelectorImplFactory.singleton( delegate ) );
    }

    /** Utility method, creates a LookSelector which will allways return
     *  the looks put into this method as a parameter.
     *
     * @param delegates Array of Looks to be returned from the selector.
     * @return LookSelector returning Enumeration which contains given looks.
     */
    public static final LookSelector array( Look delegates[] ) {
        return new LookSelector( SelectorImplFactory.array( delegates ) );
    }

    /** Utility method, creates a LookSelector which selects the first only Look from another
     * LookSelector which it delegates to.
     *
     * @param delegate LookSelector from which the first Look only will be returned
     * @return LookSelector returning Enumeration which contains the first Look selected by
     * delegate selector for given represented object
     */
    public static final LookSelector first( LookSelector delegate ) {
        return new LookSelector( SelectorImplFactory.first( delegate ) );
    }

    /** NamespaceSelector which searches for a look in default namespace
     * "Looks/Types/".
     *
     * 

* To create this namespace selector from an XML layer type: *

     * <file name="NameOfYourNamaspaceSelector.instance" >
     *   <attr name="instanceClass" stringvalue="org.netbeans.spi.looks.LookSelector" />
     *   <attr name="instanceCreate" methodvalue="org.netbeans.spi.looks.Selectors.defaultTypes" />
     * </file>
     * 
* @see #namespaceTypes(String) * @return default namespace selector searching for looks in "Looks/Types" * on system filesystem. */ public static synchronized final LookSelector defaultTypes() { if (DEFAULT_SELECTOR == null) { DEFAULT_SELECTOR = new LookSelector( SelectorImplFactory.namespaceTypes( DEFAULT_CONTEXT ) ); } return DEFAULT_SELECTOR; } /** Searches for a look in namespace given name of context to search. Name * of the look should correspond with a type (class, superclass, interface) * of the represented object. * *

* To create this namespace selector from an XML layer type: *

     * <file name="NameOfYourNamaspaceSelector.instance" >
     *   <attr name="instanceClass" stringvalue="org.netbeans.spi.looks.LookSelector" />
     *   <attr name="instanceCreate" methodvalue="org.netbeans.spi.looks.Selectors.namespaceTypes" />
     *   <!--Optionally! The context prefix for the namespace. The default prefix is "Looks/Types/".-->
     *   <attr name="context" stringvalue="Looks/Selectors/MyTypes/" />
     * </file>
     * 
* * @param contextPrefix the Context to be searched * @return LookSelector searching the given Context by type of the * represented object. */ public static final LookSelector namespaceTypes( String contextPrefix ) { return new LookSelector( SelectorImplFactory.namespaceTypes( contextPrefix ) ); } // * <!--Optionally! The additionally features are append at last. The default value is false.--$gt; // * <attr name="asLast" boolvalue="true" /> // * @param asLast If true the decoratingLook will be the second look in the // * resulting composite looks. If true the decorating look will // * occupy the first place. // * @param excludable If set to true the decoration will stop on next // * change of LookSelector in the nodes hierarchy. // The excludable parameter determines // * whether decorating should stop on next change of selector in the node // * hierarchy. I.e. if the excludable parameter is set to true // * then the decoration will stop as soon as some node in the nodes hierarchy // * will heave some other LookSelector set. If parameter is set to false // * then the decoration will be effective throughout the complete node hierarchy. /** Decorates looks found by given selector, with a decorating look. * Works exactly as the decorator. Resulting looks are composite * looks made from the look found by the selector and the decorating look. * *

* To create this decorator selector from an XML layer type: *

     * <file name="NameOfYourDecoratorSelector.instance" >
     *   <attr name="instanceClass" stringvalue="org.netbeans.spi.looks.LookSelector" />
     *   <attr name="instanceCreate" methodvalue="org.netbeans.spi.looks.Selectors.decorator" />
     *   <!--The path to declaration of look selector searches for the looks.-->
     *   <attr name="lookSelector" stringvalue="Looks/Selectors/MyTypes/" />
     *   <!--The path to declaration of decorating look.-->
     *   <attr name="decoratingLook" stringvalue="Looks/MyLayer/MyLooks/FooLook" />
     *   <!--Optionally! The additionally features are append at last. The default value is false.-->
     * </file>
     * 
* * @param lookSelector Selector used for searching for Looks for given represented * object * @param decoratingLook Look which will decorate all the subnodes. * @return LookSelector which adds the decorating look to every look provided * in the parameter selector. * */ public static final LookSelector decorator( LookSelector lookSelector, Look decoratingLook ) { return new LookSelector( SelectorImplFactory.decorator( lookSelector, decoratingLook, true, true ) ); } /* public static final LookSelector decorator( LookSelector selector, Look decoratingLook, boolean asLast, boolean excludable ) { return new org.netbeans.modules.looks.DecoratorSelector( selector, decoratingLook, asLast, excludable ); } */ /** Creates composite selector which merges all selectors given as * parameter and removed duplicities. * @param selectors Array of selctors to be merged. * @return Selector which merges the selectors */ public static final LookSelector composite( LookSelector[] selectors ) { return new LookSelector( SelectorImplFactory.composite( selectors, true ) ); } // Usefull look selectors may be published later --------------------------- static synchronized final LookSelector selector( org.netbeans.modules.looks.NamespaceLookProvider provider, String prefix ) { return new LookSelector( SelectorImplFactory.namespaceProvider( provider, prefix ) ); } // Private methods --------------------------------------------------------- private static LookSelector createDecoratorSelector(FileObject fo) throws IOException { Look decorator = Looks.readLookAttribute (fo, DECORATING_LOOK); LookSelector selector = readLookSelectorAttribute (fo, LOOK_SELECTOR); // proccess parameters // 1. read asLast, default value is false // 2. read excludable, default value is excludable /* Boolean helpBool = null; helpBool = readBooleanAttribute (fo, AS_LAST); boolean asLast = helpBool != null && helpBool.booleanValue () ? true : false; helpBool = readBooleanAttribute (fo, EXCLUDABLE); boolean excludable = helpBool != null && helpBool.booleanValue () ? true : false; return new org.netbeans.modules.looks.DecoratorSelector (selector, decorator, asLast, excludable ); */ return new LookSelector( SelectorImplFactory.decorator( selector, decorator, true, true ) ); } private static LookSelector readLookSelectorAttribute (FileObject fo, String attribute) throws IOException { return (LookSelector)Looks.readLookOrSelectorAttribute (fo, attribute, false); } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.