KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Array JavaDoc;
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 /** Tests whether all vales returned from a Node are identical with
32  * the values server by associated look
33  */

34 public class CompositeLookValuesTest extends TestBaseValues {
35
36     // Golden values for the three looks which will be composed
37

38     private GoldenValue goldenValues[][];
39     private static GoldenValue gvForTypes[] = GoldenValue.createGoldenValues();
40
41     // Methods of testCase -----------------------------------------------------
42

43     public CompositeLookValuesTest(java.lang.String JavaDoc testName) {
44         super(testName);
45     }
46
47     public static void main(java.lang.String JavaDoc[] 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 JavaDoc {
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         // LookSelector selector = new SampleSelector( look );
72
// SampleRepObject ro = new SampleRepObject( null );
73
// LookNode node = new LookNode( ro, composite, selector );
74

75         setTarget( compositeLook, new SampleRepObject(), 3 );
76         setGoldenValues( resultValues );
77
78         super.setUp();
79     }
80
81     protected void tearDown() throws Exception JavaDoc {
82         super.tearDown();
83     }
84
85
86     // Test methods ------------------------------------------------------------
87

88     ///////////////////////////////////////////////////////
89
// //
90
// Most methods are inherited from: TestBaseValues //
91
// //
92
///////////////////////////////////////////////////////
93

94
95     // Private methods ---------------------------------------------------------
96

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 JavaDoc( 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 JavaDoc[] {
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 JavaDoc( "ClipboardCut" ) ),
179
180                     new GoldenValue( ProxyLook.DRAG, null ),
181
182                     new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, createGoldenLookupItems( index ) )
183
184                 };
185
186                 // We need to patch PropertySets
187
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 JavaDoc( 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 JavaDoc[] {
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 JavaDoc() ),
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 JavaDoc paste() { return null; }
256                             },
257
258                             new org.openide.util.datatransfer.PasteType() {
259                                 public java.awt.datatransfer.Transferable JavaDoc 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 JavaDoc 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 JavaDoc( "Drag" ) ),
274
275                     new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, createGoldenLookupItems( index ) )
276                     };
277
278                 // We need to patch PropertySets
279
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 JavaDoc paste() { return null; }
344                             },
345
346                             new org.openide.util.datatransfer.PasteType() {
347                                 public java.awt.datatransfer.Transferable JavaDoc 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 JavaDoc paste() { return null; }
354                         }),
355
356                     new GoldenValue( ProxyLook.CLIPBOARD_COPY,
357                         new java.awt.datatransfer.StringSelection JavaDoc( "ClipboardCopy" ) ),
358
359                     new GoldenValue( ProxyLook.CLIPBOARD_CUT,
360                         new java.awt.datatransfer.StringSelection JavaDoc( "ClipboardCut" ) ),
361
362                     new GoldenValue( ProxyLook.DRAG,
363                         new java.awt.datatransfer.StringSelection JavaDoc( "Drag" ) ),
364
365                     new GoldenValue( ProxyLook.GET_LOOKUP_ITEMS, createGoldenLookupItems( index ) )
366                 };
367             break;
368         }
369         return goldenValues;
370     }
371
372     /** Creates lookup for testing
373      */

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 JavaDoc() ) );
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     /** Merges golden values together.
408      *
409      */

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 JavaDoc clazz = GoldenValue.get( gv[0][i].key, gvForTypes ).getClass();
417             boolean isArray = clazz.isArray();
418
419
420             if ( List.class.isAssignableFrom( clazz ) ) { // Merge lists
421
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                 // We need to merge the arrays
435
ArrayList list = new ArrayList();
436                 for( int j = 0; j < gv.length; j++ ) {
437                     Object JavaDoc gvArray[] = (Object JavaDoc[])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 JavaDoc[])Array.newInstance( clazz.getComponentType(), 0 ) ) );
446
447             }
448             else { // Well, single valued property we only need to find first
449
Object JavaDoc resultValue = null;
450                 for( int j = 0; j < gv.length; j++ ) {
451                     Object JavaDoc goldenValue = GoldenValue.get( gv[0][i].key, gv[j] );
452
453                     if ( goldenValue instanceof Boolean JavaDoc ) {
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