1 19 20 package org.netbeans.spi.looks; 21 22 import java.util.Arrays ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.ArrayList ; 26 import java.awt.Image ; 27 import java.awt.image.BufferedImage ; 28 import java.awt.datatransfer.Transferable ; 29 import java.awt.datatransfer.StringSelection ; 30 31 import javax.swing.JPanel ; 32 33 34 import org.openide.nodes.*; 35 import org.openide.util.HelpCtx; 36 import org.openide.util.Lookup; 37 import org.openide.util.actions.SystemAction; 38 import org.openide.util.actions.CallableSystemAction; 39 import org.openide.util.datatransfer.NewType; 40 import org.openide.util.datatransfer.PasteType; 41 42 import org.netbeans.spi.looks.ProxyLook; 43 import org.netbeans.api.nodes2looks.LookNodeValuesTest; 44 45 48 public class GoldenValue { 49 50 long key; 51 Object result; 52 53 public GoldenValue(long key, Object result) { 54 this.key = key; 55 this.result = result; 56 } 57 58 public static boolean isOK( long key, Object result, GoldenValue[] items) { 59 for( int i = 0; i < items.length; i++ ) { 60 if ( key == items[i].key ) { 61 if ( result == items[i].result ) { 62 return true; 63 } 64 else if ( result == null ) { 65 return false; 66 } 67 else if ( result.equals( items[i].result ) ){ 68 return true; 69 } 70 else if ( key == ProxyLook.GET_LOOKUP_ITEMS ) { 71 return compareLookupItems( (Collection )result, (Collection )items[i].result ); 72 } 73 else if ( result.getClass().isArray() && 74 items[i].result.getClass().isArray() && 75 Arrays.equals( (Object [])result, (Object [])items[i].result ) ) { 76 return true; 77 } 78 else { 79 return false; 80 } 81 } 82 } 83 84 return false; 85 } 86 87 public static Object get( long key, GoldenValue[] items) { 88 for( int i = 0; i < items.length; i++ ) { 89 if ( key == items[i].key ) { 90 return items[i].result; 91 } 92 } 93 94 return null; 95 } 96 97 99 private static boolean compareLookupItems( Collection c1, Collection c2 ) { 100 if ( c1.size() != c2.size() ) { 101 return false; 102 } 103 104 Iterator it1 = c1.iterator(); 105 Iterator it2 = c2.iterator(); 106 107 while( it1.hasNext() ) { 108 Lookup.Item li1 = (Lookup.Item)it1.next(); 109 Lookup.Item li2 = (Lookup.Item)it2.next(); 110 111 if ( !li1.getDisplayName().equals( li2.getDisplayName() ) ) { 112 return false; 113 } 114 115 if ( !li1.getId().equals( li2.getId() ) ) { 116 return false; 117 } 118 119 if ( !li1.getInstance().equals( li2.getInstance() ) ) { 120 return false; 121 } 122 123 if ( !li1.getType().equals( li2.getType() ) ) { 124 return false; 125 } 126 127 } 128 129 return true; 130 } 131 132 public static GoldenValue[] createGoldenValues() { 134 135 return new GoldenValue[] { 136 new GoldenValue( ProxyLook.GET_DISPLAY_NAME, 137 "DisplayName" ), 138 139 new GoldenValue( ProxyLook.GET_NAME, 140 "Name" ), 141 142 new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, 143 "ShortDescription" ), 144 145 new GoldenValue( ProxyLook.GET_ICON, 146 new BufferedImage ( 16, 16, BufferedImage.TYPE_INT_RGB ) ), 147 148 new GoldenValue( ProxyLook.GET_OPENED_ICON, 149 new BufferedImage ( 16, 16, BufferedImage.TYPE_INT_RGB ) ), 150 151 new GoldenValue( ProxyLook.GET_HELP_CTX, 152 new HelpCtx( LookNodeValuesTest.class ) ), 153 154 new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, 155 Arrays.asList( new String [] { 156 "Child 1", 157 "Child 2" 158 }) ), 159 160 new GoldenValue( ProxyLook.GET_NEW_TYPES, 161 new NewType[] { 162 new NewType() { 163 public void create() { } 164 }, 165 166 new NewType() { 167 public void create() { } 168 } 169 } ), 170 171 new GoldenValue( ProxyLook.GET_ACTIONS, 172 new SystemAction[] { 173 (SystemAction)org.openide.util.SharedClassObject.findObject( TestingAction1.class ), 174 (SystemAction)org.openide.util.SharedClassObject.findObject( TestingAction2.class ) 175 } ), 176 177 new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, 178 new SystemAction[] { 179 (SystemAction)org.openide.util.SharedClassObject.findObject( TestingAction3.class ), 180 (SystemAction)org.openide.util.SharedClassObject.findObject( TestingAction4.class ) 181 } ), 182 183 new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, 184 SystemAction.get( TestingAction5.class ) ), 185 186 new GoldenValue( ProxyLook.GET_PROPERTY_SETS, 187 new Node.PropertySet[] { 188 new Sheet.Set(), 189 new Sheet.Set() 190 }), 191 192 new GoldenValue( ProxyLook.GET_CUSTOMIZER, 193 new JPanel () ), 194 195 new GoldenValue( ProxyLook.HAS_CUSTOMIZER, 196 Boolean.TRUE ), 197 198 new GoldenValue( ProxyLook.CAN_RENAME, 199 Boolean.TRUE ), 200 201 new GoldenValue( ProxyLook.CAN_DESTROY, 202 Boolean.TRUE ), 203 204 new GoldenValue( ProxyLook.CAN_COPY, 205 Boolean.TRUE ), 206 207 new GoldenValue( ProxyLook.CAN_CUT, 208 Boolean.TRUE ), 209 210 new GoldenValue( ProxyLook.GET_PASTE_TYPES, 211 new PasteType[] { 212 new PasteType() { 213 public Transferable paste() { return null; } 214 }, 215 216 new PasteType() { 217 public Transferable paste() { return null; } 218 } 219 }), 220 221 new GoldenValue( ProxyLook.GET_DROP_TYPE, 222 new PasteType() { 223 public Transferable paste() { return null; } 224 }), 225 226 new GoldenValue( ProxyLook.CLIPBOARD_COPY, 227 new StringSelection ( "ClipboardCopy" ) ), 228 229 new GoldenValue( ProxyLook.CLIPBOARD_CUT, 230 new StringSelection ( "ClipboardCut" ) ), 231 232 new GoldenValue( ProxyLook.DRAG, 233 new StringSelection ( "Drag" ) ), 234 235 new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, 236 createGoldenLookupItems() ) 237 238 239 }; 240 } 241 242 public static Collection createGoldenLookupItems() { 243 244 ArrayList lookupItems = new ArrayList (); 245 246 lookupItems.add( 247 new TestLookupItem( 248 new org.openide.cookies.SaveCookie() { 249 public void save() {} 250 251 public String toString() { 252 return "Tetst SaveCookie"; 253 } 254 } 255 ) 256 ); 257 258 lookupItems.add( 259 new TestLookupItem( 260 new org.openide.cookies.CloseCookie() { 261 public boolean close() { return false; } 262 263 public String toString() { 264 return "Tetst CloseCookie"; 265 } 266 } 267 ) 268 ); 269 270 lookupItems.add( new TestLookupItem( "HoHo" ) ); 271 272 return lookupItems; 273 } 274 275 277 public static class TestingAction extends CallableSystemAction { 278 279 public HelpCtx getHelpCtx() { 280 return null; 281 } 282 283 public String getName() { 284 return this.getClass().getName(); 285 } 286 287 public void performAction() { 288 } 289 290 } 291 292 public static class TestingAction1 extends TestingAction { 293 } 294 295 public static class TestingAction2 extends TestingAction { 296 } 297 298 public static class TestingAction3 extends TestingAction { 299 } 300 301 public static class TestingAction4 extends TestingAction { 302 } 303 304 public static class TestingAction5 extends TestingAction { 305 } 306 307 public static class TestingAction6 extends TestingAction { 308 } 309 310 public static class TestLookupItem extends Lookup.Item { 311 312 private String id; 313 private Object instance; 314 315 public TestLookupItem( Object instance ) { 316 this( instance, null ); 317 } 318 319 public TestLookupItem( Object instance, String id ) { 320 this.id = id; 321 this.instance = instance; 322 } 323 324 public String getDisplayName() { 325 return getId(); 326 } 327 328 public String getId() { 329 return id == null ? instance.toString() : id; 330 } 331 332 public Object getInstance() { 333 return instance; 334 } 335 336 public Class getType() { 337 return instance.getClass(); 338 } 339 340 public boolean equals( Object object ) { 341 if ( object instanceof Lookup.Item ) { 342 return instance == ((Lookup.Item)object).getInstance(); 343 } 344 return false; 345 } 346 347 public int hashCode() { 348 return instance.hashCode(); 349 } 350 351 } 352 353 } 354 | Popular Tags |