1 19 20 package org.netbeans.spi.looks; 21 22 import java.util.Enumeration ; 23 import java.util.TooManyListenersException ; 24 import javax.swing.event.ChangeEvent ; 25 import javax.swing.event.ChangeListener ; 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 37 public class DecoratorSelectorEventsTest extends NbTestCase { 38 39 41 private GoldenValue goldenValues[][]; 42 private static GoldenValue gvForTypes[] = GoldenValue.createGoldenValues(); 43 44 46 public DecoratorSelectorEventsTest(String testName) { 47 super(testName); 48 } 49 50 52 public void testEventFromDelegate() { 53 54 55 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 LookSelector decoratingSelector = Selectors.decorator( primarySelector, decoratingLook ); 63 64 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 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 83 private static class TestChangeableProvider implements ChangeableLookProvider { 84 85 private Look look; 86 87 private ChangeListener listener; 88 89 public TestChangeableProvider( Look look ) { 90 this.look = look; 91 } 92 93 public void addChangeListener(ChangeListener listener) throws TooManyListenersException { 94 if ( this.listener != null ) { 95 throw new TooManyListenersException (); 96 } 97 else { 98 this.listener = listener; 99 } 100 } 101 102 public Object getKeyForObject(Object representedObject) { 103 return this; 104 } 105 106 public Enumeration getLooksForKey(Object key) { 107 return Enumerations.singleton(look); 108 } 109 110 public void fireChange( Look look ) { 111 this.look = look; 112 listener.stateChanged( new ChangeEvent ( this ) ); 113 } 114 115 } 116 117 118 } 119 | Popular Tags |