1 19 20 package org.netbeans.spi.looks; 21 22 import java.lang.reflect.Array ; 23 import java.util.*; 24 25 import org.openide.nodes.*; 26 import org.netbeans.junit.*; 27 28 import org.netbeans.spi.looks.*; 29 import org.netbeans.api.nodes2looks.LookNodeValuesTest; 30 31 34 public class CompositeLookValuesTest extends TestBaseValues { 35 36 38 private GoldenValue goldenValues[][]; 39 private static GoldenValue gvForTypes[] = GoldenValue.createGoldenValues(); 40 41 43 public CompositeLookValuesTest(java.lang.String testName) { 44 super(testName); 45 } 46 47 public static void main(java.lang.String [] args) { 48 junit.textui.TestRunner.run(suite()); 49 } 50 51 public static NbTest suite() { 52 NbTestSuite suite = new NbTestSuite( CompositeLookValuesTest.class ); 53 return suite; 54 } 55 56 protected void setUp() throws Exception { 57 58 goldenValues = new GoldenValue[][] { 59 createGoldenValues( 1 ), 60 createGoldenValues( 2 ), 61 createGoldenValues( 3 ) 62 }; 63 64 GoldenValue[] resultValues = mergeGoldenValues( goldenValues ); 65 66 Look look1 = new SampleLook( "CL1", goldenValues[0] ); 67 Look look2 = new SampleLook( "CL2", goldenValues[1] ); 68 Look look3 = new SampleLook( "CL3", goldenValues[2] ); 69 Look compositeLook = Looks.composite( "Composite", new Look[] { look1, look2, look3 } ); 70 71 75 setTarget( compositeLook, new SampleRepObject(), 3 ); 76 setGoldenValues( resultValues ); 77 78 super.setUp(); 79 } 80 81 protected void tearDown() throws Exception { 82 super.tearDown(); 83 } 84 85 86 88 94 95 97 public static GoldenValue[] createGoldenValues( int index ) { 98 99 GoldenValue goldenValues[] = null; 100 101 switch ( index ) { 102 case 1: 103 goldenValues = new GoldenValue[] { 104 105 new GoldenValue( ProxyLook.GET_DISPLAY_NAME, 106 "DisplayName_1" ), 107 108 new GoldenValue( ProxyLook.GET_NAME, null ), 109 110 new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, "ShortDescription_1" ), 111 112 new GoldenValue( ProxyLook.GET_ICON, 113 new java.awt.image.BufferedImage ( 16, 16, java.awt.image.BufferedImage.TYPE_INT_RGB ) ), 114 115 new GoldenValue( ProxyLook.GET_OPENED_ICON, null ), 116 117 new GoldenValue( ProxyLook.GET_HELP_CTX, null ), 118 119 new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, 120 Arrays.asList( new String [] { 121 "Child 1", 122 "Child 2" 123 } ) ), 124 125 new GoldenValue( ProxyLook.GET_NEW_TYPES, 126 new org.openide.util.datatransfer.NewType[] { 127 new org.openide.util.datatransfer.NewType() { 128 public void create() { } 129 }, 130 131 new org.openide.util.datatransfer.NewType() { 132 public void create() { } 133 } 134 } ), 135 136 new GoldenValue( ProxyLook.GET_ACTIONS, null ), 137 138 139 new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, 140 new org.openide.util.actions.SystemAction[] { 141 (org.openide.util.actions.SystemAction)org.openide.util.SharedClassObject.findObject( GoldenValue.TestingAction3.class ) 142 } ), 143 144 new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, 145 org.openide.util.actions.SystemAction.get( GoldenValue.TestingAction5.class ) ), 146 147 new GoldenValue( ProxyLook.GET_PROPERTY_SETS, 148 new Node.PropertySet[] { 149 new Sheet.Set(), 150 new Sheet.Set() 151 }), 152 153 new GoldenValue( ProxyLook.GET_CUSTOMIZER, 154 null ), 155 156 new GoldenValue( ProxyLook.HAS_CUSTOMIZER, 157 Boolean.FALSE ), 158 159 new GoldenValue( ProxyLook.CAN_RENAME, 160 Boolean.TRUE ), 161 162 new GoldenValue( ProxyLook.CAN_DESTROY, 163 Boolean.FALSE ), 164 165 new GoldenValue( ProxyLook.CAN_COPY, 166 Boolean.FALSE ), 167 168 new GoldenValue( ProxyLook.CAN_CUT, 169 Boolean.TRUE ), 170 171 new GoldenValue( ProxyLook.GET_PASTE_TYPES, null ), 172 173 new GoldenValue( ProxyLook.GET_DROP_TYPE, null ), 174 175 new GoldenValue( ProxyLook.CLIPBOARD_COPY, null ), 176 177 new GoldenValue( ProxyLook.CLIPBOARD_CUT, 178 new java.awt.datatransfer.StringSelection ( "ClipboardCut" ) ), 179 180 new GoldenValue( ProxyLook.DRAG, null ), 181 182 new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, createGoldenLookupItems( index ) ) 183 184 }; 185 186 Node.PropertySet[] sets = (Node.PropertySet[])GoldenValue.get( ProxyLook.GET_PROPERTY_SETS, goldenValues ); 188 sets[0].setName( "Set_1" ); 189 sets[1].setName( "Set_2" ); 190 191 break; 192 case 2: 193 goldenValues = new GoldenValue[] { 194 new GoldenValue( ProxyLook.GET_DISPLAY_NAME, null ), 195 196 new GoldenValue( ProxyLook.GET_NAME, 197 "Name 2" ), 198 199 new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, null ), 200 201 new GoldenValue( ProxyLook.GET_ICON, null ), 202 203 new GoldenValue( ProxyLook.GET_OPENED_ICON, 204 new java.awt.image.BufferedImage ( 16, 16, java.awt.image.BufferedImage.TYPE_INT_RGB ) ), 205 206 new GoldenValue( ProxyLook.GET_HELP_CTX, null ), 207 208 new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, 209 Arrays.asList( new String [] { 210 "Child 3", 211 "Child 4" 212 } ) ), 213 214 new GoldenValue( ProxyLook.GET_NEW_TYPES, null ), 215 216 new GoldenValue( ProxyLook.GET_ACTIONS, 217 new org.openide.util.actions.SystemAction[] { 218 (org.openide.util.actions.SystemAction)org.openide.util.SharedClassObject.findObject( GoldenValue.TestingAction1.class ) 219 } ), 220 221 new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, 222 new org.openide.util.actions.SystemAction[] { 223 (org.openide.util.actions.SystemAction)org.openide.util.SharedClassObject.findObject( GoldenValue.TestingAction4.class ) 224 } ), 225 226 new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, null ), 227 228 new GoldenValue( ProxyLook.GET_PROPERTY_SETS, 229 new Node.PropertySet[] { 230 new Sheet.Set(), 231 new Sheet.Set() 232 }), 233 234 new GoldenValue( ProxyLook.GET_CUSTOMIZER, 235 new javax.swing.JPanel () ), 236 237 new GoldenValue( ProxyLook.HAS_CUSTOMIZER, 238 Boolean.FALSE ), 239 240 new GoldenValue( ProxyLook.CAN_RENAME, 241 Boolean.FALSE ), 242 243 new GoldenValue( ProxyLook.CAN_DESTROY, 244 Boolean.TRUE ), 245 246 new GoldenValue( ProxyLook.CAN_COPY, 247 Boolean.FALSE ), 248 249 new GoldenValue( ProxyLook.CAN_CUT, 250 Boolean.FALSE ), 251 252 new GoldenValue( ProxyLook.GET_PASTE_TYPES, 253 new org.openide.util.datatransfer.PasteType[] { 254 new org.openide.util.datatransfer.PasteType() { 255 public java.awt.datatransfer.Transferable paste() { return null; } 256 }, 257 258 new org.openide.util.datatransfer.PasteType() { 259 public java.awt.datatransfer.Transferable paste() { return null; } 260 } 261 }), 262 263 new GoldenValue( ProxyLook.GET_DROP_TYPE, 264 new org.openide.util.datatransfer.PasteType() { 265 public java.awt.datatransfer.Transferable paste() { return null; } 266 }), 267 268 new GoldenValue( ProxyLook.CLIPBOARD_COPY, null ), 269 270 new GoldenValue( ProxyLook.CLIPBOARD_CUT, null ), 271 272 new GoldenValue( ProxyLook.DRAG, 273 new java.awt.datatransfer.StringSelection ( "Drag" ) ), 274 275 new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, createGoldenLookupItems( index ) ) 276 }; 277 278 sets = (Node.PropertySet[])GoldenValue.get( ProxyLook.GET_PROPERTY_SETS, goldenValues ); 280 sets[0].setName( "Set_3" ); 281 sets[1].setName( "Set_4" ); 282 break; 283 default: 284 goldenValues = new GoldenValue[] { 285 new GoldenValue( ProxyLook.GET_DISPLAY_NAME, null ), 286 287 new GoldenValue( ProxyLook.GET_NAME, null ), 288 289 new GoldenValue( ProxyLook.GET_SHORT_DESCRIPTION, 290 "ShortDescription_3" ), 291 292 new GoldenValue( ProxyLook.GET_ICON, null ), 293 294 new GoldenValue( ProxyLook.GET_OPENED_ICON, null ), 295 296 new GoldenValue( ProxyLook.GET_HELP_CTX, 297 new org.openide.util.HelpCtx( LookNodeValuesTest.class ) ), 298 299 new GoldenValue( ProxyLook.GET_CHILD_OBJECTS, null ), 300 301 new GoldenValue( ProxyLook.GET_NEW_TYPES, 302 new org.openide.util.datatransfer.NewType[] { 303 new org.openide.util.datatransfer.NewType() { 304 public void create() { } 305 }, 306 307 new org.openide.util.datatransfer.NewType() { 308 public void create() { } 309 } 310 } ), 311 312 new GoldenValue( ProxyLook.GET_ACTIONS, 313 new org.openide.util.actions.SystemAction[] { 314 (org.openide.util.actions.SystemAction)org.openide.util.SharedClassObject.findObject( GoldenValue.TestingAction2.class ) 315 } ), 316 317 new GoldenValue( ProxyLook.GET_CONTEXT_ACTIONS, null ), 318 319 new GoldenValue( ProxyLook.GET_DEFAULT_ACTION, null ), 320 321 new GoldenValue( ProxyLook.GET_PROPERTY_SETS, null ), 322 323 new GoldenValue( ProxyLook.GET_CUSTOMIZER, null ), 324 325 new GoldenValue( ProxyLook.HAS_CUSTOMIZER, 326 Boolean.TRUE ), 327 328 new GoldenValue( ProxyLook.CAN_RENAME, 329 Boolean.FALSE ), 330 331 new GoldenValue( ProxyLook.CAN_DESTROY, 332 Boolean.FALSE ), 333 334 new GoldenValue( ProxyLook.CAN_COPY, 335 Boolean.TRUE ), 336 337 new GoldenValue( ProxyLook.CAN_CUT, 338 Boolean.FALSE ), 339 340 new GoldenValue( ProxyLook.GET_PASTE_TYPES, 341 new org.openide.util.datatransfer.PasteType[] { 342 new org.openide.util.datatransfer.PasteType() { 343 public java.awt.datatransfer.Transferable paste() { return null; } 344 }, 345 346 new org.openide.util.datatransfer.PasteType() { 347 public java.awt.datatransfer.Transferable paste() { return null; } 348 } 349 }), 350 351 new GoldenValue( ProxyLook.GET_DROP_TYPE, 352 new org.openide.util.datatransfer.PasteType() { 353 public java.awt.datatransfer.Transferable paste() { return null; } 354 }), 355 356 new GoldenValue( ProxyLook.CLIPBOARD_COPY, 357 new java.awt.datatransfer.StringSelection ( "ClipboardCopy" ) ), 358 359 new GoldenValue( ProxyLook.CLIPBOARD_CUT, 360 new java.awt.datatransfer.StringSelection ( "ClipboardCut" ) ), 361 362 new GoldenValue( ProxyLook.DRAG, 363 new java.awt.datatransfer.StringSelection ( "Drag" ) ), 364 365 new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, createGoldenLookupItems( index ) ) 366 }; 367 break; 368 } 369 return goldenValues; 370 } 371 372 374 public static Collection createGoldenLookupItems( int index ) { 375 376 ArrayList ic; 377 378 switch ( index ) { 379 case 1: 380 ic = new ArrayList(); 381 ic.add( 382 new GoldenValue.TestLookupItem( 383 new org.openide.cookies.SaveCookie() { 384 public void save() {} 385 } 386 ) 387 ); 388 ic.add( new GoldenValue.TestLookupItem( new javax.swing.JPanel () ) ); 389 return ic; 390 case 2: 391 ic = new ArrayList(); 392 ic.add( 393 new GoldenValue.TestLookupItem( 394 new org.openide.cookies.CloseCookie() { 395 public boolean close() { return false; } 396 } 397 ) 398 ); 399 ic.add( new GoldenValue.TestLookupItem( "HoHo" ) ); 400 return ic; 401 default: 402 return null; 403 } 404 } 405 406 407 410 public static GoldenValue[] mergeGoldenValues( GoldenValue gv[][] ) { 411 412 GoldenValue result[] = new GoldenValue[ gv[0].length ]; 413 414 for( int i = 0; i < gv[0].length; i++ ) { 415 416 Class clazz = GoldenValue.get( gv[0][i].key, gvForTypes ).getClass(); 417 boolean isArray = clazz.isArray(); 418 419 420 if ( List.class.isAssignableFrom( clazz ) ) { ArrayList list = new ArrayList(); 422 for( int j = 0; j < gv.length; j++ ) { 423 List gvList = (List)GoldenValue.get( gv[0][i].key, gv[j] ); 424 425 if ( gvList != null ) { 426 list.addAll( gvList ); 427 } 428 } 429 430 result[i] = new GoldenValue( gv[0][i].key, list ); 431 432 } 433 else if ( isArray ) { 434 ArrayList list = new ArrayList(); 436 for( int j = 0; j < gv.length; j++ ) { 437 Object gvArray[] = (Object [])GoldenValue.get( gv[0][i].key, gv[j] ); 438 439 if ( gvArray != null ) { 440 list.addAll( Arrays.asList(gvArray) ); 441 } 442 } 443 444 result[i] = new GoldenValue( gv[0][i].key, 445 list.toArray( (Object [])Array.newInstance( clazz.getComponentType(), 0 ) ) ); 446 447 } 448 else { Object resultValue = null; 450 for( int j = 0; j < gv.length; j++ ) { 451 Object goldenValue = GoldenValue.get( gv[0][i].key, gv[j] ); 452 453 if ( goldenValue instanceof Boolean ) { 454 if ( Boolean.TRUE.equals( goldenValue ) ) { 455 resultValue = Boolean.TRUE; 456 break; 457 } 458 else { 459 resultValue = Boolean.FALSE; 460 } 461 } 462 else if ( goldenValue != null ) { 463 resultValue = goldenValue; 464 break; 465 } 466 } 467 468 result[i] = new GoldenValue( gv[0][i].key, resultValue ); 469 470 } 471 } 472 473 474 return result; 475 } 476 477 } 478 479 480 | Popular Tags |