KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > looks > DecoratorSelectorEventsTest


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.spi.looks;
21
22 import java.util.Enumeration JavaDoc;
23 import java.util.TooManyListenersException JavaDoc;
24 import javax.swing.event.ChangeEvent JavaDoc;
25 import javax.swing.event.ChangeListener JavaDoc;
26 import org.netbeans.junit.NbTest;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.junit.NbTestSuite;
29 import org.netbeans.spi.looks.ChangeableLookProvider;
30 import org.netbeans.spi.looks.GoldenValue;
31 import org.netbeans.spi.looks.Look;
32 import org.openide.util.Enumerations;
33
34 /** Tests whether all vales returned from a Node are identical with
35  * the values server by associated look
36  */

37 public class DecoratorSelectorEventsTest extends NbTestCase {
38
39     // Golden values for the three looks which will be composed
40

41     private GoldenValue goldenValues[][];
42     private static GoldenValue gvForTypes[] = GoldenValue.createGoldenValues();
43     
44     // Methods of testCase -----------------------------------------------------
45

46     public DecoratorSelectorEventsTest(String JavaDoc testName) {
47         super(testName);
48     }
49     
50     // Test methods ------------------------------------------------------------
51

52     public void testEventFromDelegate() {
53         
54         
55         // Create all necessary looks
56
Look primaryLook = new SampleLook( "CL1" );
57         Look decoratingLook = new SampleLook( "CL2" );
58         Look replacementLook = new SampleLook( "CL3" );
59         TestChangeableProvider provider = new TestChangeableProvider( primaryLook );
60         LookSelector primarySelector = Selectors.selector( provider );
61         // Create selector which decorates
62
LookSelector decoratingSelector = Selectors.decorator( primarySelector, decoratingLook );
63         
64         // Add listeners
65
NamespaceSelectorEventsTest.TestLookSelectorListener tlsl1 =
66             new NamespaceSelectorEventsTest.TestLookSelectorListener();
67         NamespaceSelectorEventsTest.TestLookSelectorListener tlsl2 =
68             new NamespaceSelectorEventsTest.TestLookSelectorListener();
69         org.netbeans.modules.looks.Accessor.DEFAULT.addSelectorListener( primarySelector, tlsl1 );
70         org.netbeans.modules.looks.Accessor.DEFAULT.addSelectorListener( decoratingSelector, tlsl2 );
71         
72         // Fire the change and test
73
provider.fireChange( replacementLook );
74         
75         assertEquals( "One event in primarySelector", 1, tlsl1.events.size() );
76         assertEquals( "One event in decoratorSelector", 1, tlsl2.events.size() );
77         
78         
79     }
80     
81     // Private classes ---------------------------------------------------------
82

83     private static class TestChangeableProvider implements ChangeableLookProvider {
84         
85         private Look look;
86         
87         private ChangeListener JavaDoc listener;
88         
89         public TestChangeableProvider( Look look ) {
90             this.look = look;
91         }
92         
93         public void addChangeListener(ChangeListener JavaDoc listener) throws TooManyListenersException JavaDoc {
94             if ( this.listener != null ) {
95                 throw new TooManyListenersException JavaDoc();
96             }
97             else {
98                 this.listener = listener;
99             }
100         }
101         
102         public Object JavaDoc getKeyForObject(Object JavaDoc representedObject) {
103             return this;
104         }
105         
106         public Enumeration JavaDoc getLooksForKey(Object JavaDoc key) {
107             return Enumerations.singleton(look);
108         }
109         
110         public void fireChange( Look look ) {
111             this.look = look;
112             listener.stateChanged( new ChangeEvent JavaDoc( this ) );
113         }
114         
115     }
116     
117     
118 }
119
Popular Tags