KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > nodes2looks > TestUtil


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.api.nodes2looks;
21
22 import java.net.URL JavaDoc;
23 import org.openide.nodes.Node;
24 import org.netbeans.spi.looks.Look;
25 import org.netbeans.spi.looks.LookSelector;
26 import org.openide.filesystems.FileSystem;
27 import org.openide.filesystems.XMLFileSystem;
28 import org.xml.sax.SAXException JavaDoc;
29
30
31 /** Usefull utility methods for Tests
32  *
33  * @author phrebejk
34  */

35 public class TestUtil {
36
37     /** Creates a new instance of TestUtil */
38     private TestUtil() {
39     }
40
41     public static Object JavaDoc getRepresentedObject( Node node ) {
42
43         if ( node instanceof LookNode ) {
44             return ((LookNode)node).getRepresentedObject();
45         }
46         else {
47             return null;
48         }
49         
50         /*
51         Lookup lookup = node.getLookup();
52         
53         if ( lookup == null ) {
54             return null;
55         }
56         
57         Look.NodeSubstitute subst = (Look.NodeSubstitute)lookup.lookup( Look.NodeSubstitute.class );
58         
59         if ( subst == null ) {
60             return null;
61         }
62         
63         return subst.getRepresentedObject();
64          */

65         
66     }
67     
68     /** [PENDING] This should be rewritten to LD, LS switcher later
69      */

70     public static void setLook( Node node, Look look ) {
71         
72         if ( node instanceof LookNode ) {
73             LookNode lookNode = (LookNode)node;
74             lookNode.setLook( look );
75         }
76         else {
77             throw new IllegalArgumentException JavaDoc( node + "does not support look switching (is not LookNode)" );
78         }
79         
80     }
81
82     /** [PENDING] This should be rewritten to LD, LS switcher later
83      */

84     public static Look getLook( Node node ) {
85         
86         if ( node instanceof LookNode ) {
87             LookNode lookNode = (LookNode)node;
88             return lookNode.getLook();
89         }
90         else {
91             throw new IllegalArgumentException JavaDoc( node + "does not support look switching (is not LookNode)" );
92         }
93         
94     }
95     
96     /** [PENDING] This should be rewritten to LD, LS switcher later
97      */

98     public static LookSelector getLookSelector( Node node ) {
99         
100         if ( node instanceof LookNode ) {
101             LookNode lookNode = (LookNode)node;
102             return lookNode.getLookSelector();
103         }
104         else {
105             throw new IllegalArgumentException JavaDoc( node + "does not support look switching (is not LookNode)" );
106         }
107         
108     }
109     
110     
111     /** Sets up the registry to use the default XML layer of Looks
112      */

113     public static void setUpRegistryToDefault() {
114         
115         URL JavaDoc url = org.netbeans.modules.looks.Accessor.class.getResource ("mf-layer.xml");
116
117         try {
118             FileSystem defaultFs = new XMLFileSystem( url );
119             org.netbeans.modules.looks.RegistryBridge.setDefault( defaultFs.getRoot() );
120         }
121         catch ( SAXException JavaDoc e ) {
122             IllegalStateException JavaDoc ex = new IllegalStateException JavaDoc( "Cant initialize defaut filesystem" );
123             ex.initCause( e );
124             throw ex;
125         }
126     }
127 }
128
Popular Tags