1 19 20 package org.netbeans.modules.looks; 21 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.EventObject ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Set ; 28 import org.netbeans.spi.looks.LookSelector; 29 30 36 public class SelectorEvent extends EventObject { 37 38 private SelectorImpl impl; 39 private HashMap oldCache; 40 41 44 public SelectorEvent( LookSelector source ) { 45 super( source ); 46 impl = Accessor.DEFAULT.getSelectorImpl( source ); 47 oldCache = impl.getCache(); 48 } 49 50 63 public boolean affectsObject( Object representedObject ) { 64 return true; 65 } 66 67 public Collection getAddedLooks( Object representedObject ) { 68 if ( oldCache == null ) { 69 return Collections.EMPTY_SET; 71 } 72 73 Object key = impl.getKey4Object( representedObject ); 74 75 Set diff[] = getDiff4Key( key ); 76 if ( diff == null ) { 77 return Collections.EMPTY_SET; 78 } 79 else { 80 return diff[0]; 81 } 82 83 } 84 85 public Collection getRemovedLooks( Object representedObject ) { 86 87 if ( oldCache == null ) { 88 return Collections.EMPTY_SET; 90 } 91 92 Object key = impl.getKey4Object( representedObject ); 93 94 Set diff[] = getDiff4Key( key ); 95 if ( diff == null ) { 96 return Collections.EMPTY_SET; 97 } 98 else { 99 return diff[1]; 100 } 101 102 } 103 104 106 109 private Set [] getDiff4Key( Object key ) { 110 Object o = oldCache.get( key ); 111 112 if ( key instanceof Set [] ) { 113 return (Set [])o; 115 } 116 else { 117 119 Set [] diff = new Set [2]; 120 121 SelectorImplFactory.CacheItem oldItem = (SelectorImplFactory.CacheItem)oldCache.get( key ); 122 Collection oldLooks = oldItem.getCachedLooks( false ); 123 Collection newLooks = Collections.list( impl.getLooks4Key( key ) ); 124 125 diff[0] = new HashSet ( newLooks ); 127 diff[0].removeAll( oldLooks ); 128 129 diff[1] = new HashSet ( oldLooks ); 131 diff[1].removeAll( newLooks ); 132 133 return diff; 134 } 135 136 } 137 138 139 } 140 | Popular Tags |