KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > looks > FilterLook


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.looks;
21
22 import org.netbeans.spi.looks.Look;
23 import org.netbeans.spi.looks.ProxyLook;
24 import org.netbeans.spi.looks.Selectors;
25 import org.openide.util.NbBundle;
26
27 /**
28  * This is base class for delegating to other looks or nodes. All methods
29  * delegate to the delegate, unless they are masked.
30  * <P>
31  * All the methods contain simple deleagation to the {@link org.netbeans.spi.looks.Look}
32  * passed as parameter into the constructor, if the mask contains flag
33  * for the method.<P>
34  * Use the methods: {@link #setLookMask}, {@link #lookMask}, {@link #lookMask},
35  * {@link #lookUnmask} for work with the mask.<BR>
36  * The default state is to delegate all methods (i.e. the mask is set to
37  * {@link #ALL_METHODS}.)
38  *
39  * @author Petr Hrebejk
40  */

41 public class FilterLook extends ProxyLook {
42     /** Contains current mask of the node */
43     private long mask;
44     
45     /** Contains the Look to delegate to. Array of one member */
46     private Look delegate;
47         
48     /** Creates new filter and delegates all methods to the provided delegate
49      * @param delegate The Look to delegate to.
50      */

51     public FilterLook ( String JavaDoc name, Look delegate) {
52         this (name, delegate, ALL_METHODS);
53     }
54     
55     /** Creates new filter look and sets its filtering
56      * @param delegate look to delegate to
57      * @param mask the mask to use (one of method contants)
58      */

59     public FilterLook ( String JavaDoc name, Look delegate, long mask) {
60         super( name, Selectors.singleton( delegate ) );
61         this.delegate = delegate;
62         this.mask = mask;
63     }
64
65     /** Display name of the look. Composed from the name of the delegate.
66      */

67     public String JavaDoc getDisplayName () {
68         return NbBundle.getMessage (FilterLook.class, "LAB_Filter", delegate.getDisplayName ());
69     }
70     
71     /** A method that checks whether given method should be delegated to
72      * the look provided in constructor or not.
73      * <P>
74      * The default implementation ignores the context and just checks
75      * the mask which can be modified by <link>lookMask</link>, <link>lookUnmask</link>
76      * methods.
77      * <P>
78      * Subclasses might override
79      * this method with implementation that bases its decision on different criteria.
80      *
81      * @param method one of the constants defined here that identifies the method
82      * we want to delegate to
83      * @param substitute the substitute that the method will be called with or
84      * null if we are in notification of changes and we have no substitute
85      * @return either the delegate look or null
86      */

87     protected final boolean delegateTo (long method, Look look, Object JavaDoc representedObject) {
88         return ( mask & method ) != 0;
89     }
90     
91     // Methods of look itself -------------------------------------------------
92

93     /** Sets mask for this look. Only methods contained in the mask
94      * will be delegated. Other methods will return neutral values.
95      * @param mask The mask to be set.
96      */

97     protected final void setLookMask( long mask ) {
98         this.mask = mask;
99     }
100     
101     /** Returns the current mask for this filter look.
102      * @return Current mask.
103      */

104     protected final long getLookMask( ) {
105         return mask;
106     }
107     
108     /** Masks given methods. Removes given methods from given mask.
109      * The masked methods will be no longer delegated.
110      * @param methods Logical <CODE>OR</CODE> of methods which have to be masked.
111      * @return Current mask.
112      */

113     protected final long lookMask( long methods ) {
114         mask |= methods;
115         return mask;
116     }
117      
118     /** Unmasks given methods. Adds given methods from given mask.
119      * The masked methods will start to be delegated.
120      * @param methods Logical <CODE>OR</CODE> of methods which have to be unmasked.
121      * @return Current mask.
122      */

123     protected final long lookUnmask( long methods ) {
124         mask &= ~methods;
125         return mask;
126     }
127     
128         
129 }
130
Popular Tags