KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Collections JavaDoc;
23 import org.netbeans.spi.looks.Look;
24 import org.netbeans.spi.looks.LookSelector;
25 import org.netbeans.spi.looks.Selectors;
26 import org.openide.util.Lookup;
27
28 /** Used from Looks.childrenSelectorProvider (...)
29  *
30  * @author Petr Hrebejk
31  */

32 public final class ChildrenSelectorProvider extends org.netbeans.spi.looks.ProxyLook {
33
34     private Look look;
35     private LookSelector lookSelector;
36
37     /** Creates a new instance of ChildrenSelectorProvider */
38     public ChildrenSelectorProvider( String JavaDoc name, Look look, LookSelector lookSelector) {
39         super ( name, Selectors.singleton (look));
40         this.look = look;
41         this.lookSelector = lookSelector;
42     }
43
44     public String JavaDoc getDisplayName() {
45         return look.getDisplayName();
46     }
47
48
49     /** Adds the LookSelector in front of items produced by the look.
50      */

51     public java.util.Collection JavaDoc getLookupItems( Object JavaDoc representedObject, Lookup oldEnv ) {
52         java.util.Collection JavaDoc res = super.getLookupItems(representedObject, oldEnv );
53         if ( res == null ) {
54             return Collections.singleton( new Item() );
55         }
56         java.util.ArrayList JavaDoc r = new java.util.ArrayList JavaDoc (res.size () + 1);
57         r.add (new Item ());
58         r.addAll (res);
59         return r;
60     }
61
62     private final class Item extends org.openide.util.Lookup.Item {
63
64         public String JavaDoc getDisplayName() {
65             return getId ();
66         }
67
68         public String JavaDoc getId() {
69             return getType ().getName ();
70         }
71
72         public Object JavaDoc getInstance() {
73             return ChildrenSelectorProvider.this.lookSelector;
74         }
75
76         public Class JavaDoc getType() {
77             return LookSelector.class;
78         }
79
80         public boolean equals (Object JavaDoc o) {
81             if (o instanceof Item) {
82                 Item i = (Item)o;
83                 return getInstance () == i.getInstance ();
84             }
85             return false;
86         }
87     }
88 }
89
Popular Tags