KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > propertyeditors > PropertiesTest


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 package gui.propertyeditors;
20
21 import org.openide.nodes.AbstractNode;
22 import org.openide.nodes.Children;
23 import org.openide.nodes.Node;
24 import org.openide.nodes.NodeOperation;
25 import org.openide.nodes.PropertySupport;
26 import org.openide.nodes.Sheet;
27
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29
30 /**
31  * This test class tests the main functionality of the property sheet,
32  * property editors and property customizers customizable by IDE.
33  *
34  * @author mmirilovic@netbeans.org
35  */

36 public class PropertiesTest {
37
38     /** Node with all customizable properties */
39     private TNode tn;
40     
41     /** Create new instance of the TNode and show property sheet */
42     public PropertiesTest() {
43         // Create new TNode
44
tn = new TNode();
45         
46         // Display Node
47
//NodeOperation.getDefault().getNodeOperation().explore(tn);
48

49         // Display Properties of a Node
50
NodeOperation.getDefault().showProperties(tn);
51        //NodeOperation no = (NodeOperation)org.openide.util.Lookup.getDefault().lookup(NodeOperation.class);
52
//no.showProperties(tn);
53

54         // Wait 3s for showing properties sheet
55
try {
56             Thread.currentThread().sleep(3000);
57         }catch(Exception JavaDoc exc){
58             System.err.println("Exception during sleep after showing properties sheet :" + exc.getMessage());
59         }
60     }
61     
62     /** Definition of the node with all customizable properties */
63     public class TNode extends AbstractNode {
64         
65         /** Create new instance of the node */
66         public TNode() {
67             super(Children.LEAF);
68             setName("TestNode"); // or, super.setName if needed
69
setDisplayName("TestNode");
70         }
71         
72         /**
73          * Clone existing node
74          * @return cloned node
75          */

76         public Node cloneNode() {
77             return new TNode();
78         }
79         
80         /**
81          * Create a property sheet - that shows node with all customizable properties.
82          * @return property sheet
83          */

84         protected Sheet createSheet() {
85             Sheet sheet = super.createSheet();
86             // Make sure there is a "Properties" set:
87
Sheet.Set props = sheet.get(Sheet.PROPERTIES);
88             if (props == null) {
89                 props = Sheet.createPropertiesSet();
90                 sheet.put(props);
91             }
92             
93             // props.put(new TestProperty("Boolean", java.lang.Boolean.class));
94
TestProperty booleanObjectProperty = new TestProperty("Boolean", java.lang.Boolean JavaDoc.class);
95             try {
96                 booleanObjectProperty.setValue(Boolean.TRUE);
97                 props.put(booleanObjectProperty);
98             }
99             catch (Exception JavaDoc exc) {
100                 System.err.println("Exception during set value and add Boolean property :" +
101                                    exc.getMessage());
102             }
103             
104             // props.put(new TestProperty("boolean", boolean.class));
105
TestProperty booleanProperty = new TestProperty("boolean", boolean.class);
106             try {
107                 booleanProperty.setValue(Boolean.TRUE);
108                 props.put(booleanProperty);
109             }
110             catch (Exception JavaDoc exc) {
111                 System.err.println("Exception during set value and add boolean property :" +
112                                    exc.getMessage());
113             }
114             
115             props.put(new TestProperty("Byte", java.lang.Byte JavaDoc.class));
116             props.put(new TestProperty("byte", byte.class));
117             props.put(new TestProperty("Character", java.lang.Character JavaDoc.class));
118             
119             // props.put(new TestProperty("char", char.class));
120
TestProperty charProperty = new TestProperty("char", char.class);
121             try {
122                 charProperty.setValue("a");
123                 props.put(charProperty);
124             }
125             catch (Exception JavaDoc exc) {
126                 System.err.println("Exception during set value and add char property :" +
127                                    exc.getMessage());
128             }
129             
130             props.put(new TestProperty("Class", java.lang.Class JavaDoc.class));
131             props.put(new TestProperty("Color", java.awt.Color JavaDoc.class));
132             props.put(new TestProperty("Dimension", java.awt.Dimension JavaDoc.class));
133             props.put(new TestProperty("Double", java.lang.Double JavaDoc.class));
134             props.put(new TestProperty("double", double.class));
135             props.put(new TestProperty("File", java.io.File JavaDoc.class));
136             props.put(new TestProperty("Float", java.lang.Float JavaDoc.class));
137             props.put(new TestProperty("float", float.class));
138             props.put(new TestProperty("Font", java.awt.Font JavaDoc.class));
139             props.put(new TestProperty("Html Browser", org.openide.awt.HtmlBrowser.Factory.class));
140             props.put(new TestProperty("Indent Engine", org.openide.text.IndentEngine.class));
141             props.put(new TestProperty("Insets", java.awt.Insets JavaDoc.class));
142             props.put(new TestProperty("Integer", java.lang.Integer JavaDoc.class));
143             props.put(new TestProperty("int", int.class));
144             props.put(new TestProperty("Long", java.lang.Long JavaDoc.class));
145             props.put(new TestProperty("long", long.class));
146 // props.put(new TestProperty("NbClassPath", org.openide.execution.NbClassPath.class));
147
// props.put(new TestProperty("NbProcessDescriptor", org.openide.execution.NbProcessDescriptor.class));
148
props.put(new TestProperty("Object", java.lang.Object JavaDoc.class));
149             props.put(new TestProperty("Point", java.awt.Point JavaDoc.class));
150             props.put(new TestProperty("property_Properties", java.util.Properties JavaDoc.class));
151             props.put(new TestProperty("Rectangle", java.awt.Rectangle JavaDoc.class));
152             props.put(new TestProperty("Service Type", org.openide.ServiceType.class));
153             props.put(new TestProperty("Short", java.lang.Short JavaDoc.class));
154             props.put(new TestProperty("short", short.class));
155             props.put(new TestProperty("String", java.lang.String JavaDoc.class));
156             props.put(new TestProperty("String []", java.lang.String JavaDoc[].class));
157             props.put(new TestProperty("URL", java.net.URL JavaDoc.class));
158
159             return sheet;
160         }
161         
162         /**
163          * Method firing changes
164          * @param s
165          * @param o1
166          * @param o2
167          */

168         public void fireMethod(String JavaDoc s, Object JavaDoc o1, Object JavaDoc o2) {
169             firePropertyChange(s,o1,o2);
170         }
171     }
172     
173     /** Property definition */
174     public class TestProperty extends PropertySupport {
175         Object JavaDoc myValue;
176         
177         /**
178          * Create new property
179          * @param name
180          * @param classType
181          */

182         public TestProperty(String JavaDoc name, Class JavaDoc classType) {
183             super(name, classType, name, "", true, true);
184         }
185         
186         /**
187          * Get property value
188          * @return property value
189          */

190         public Object JavaDoc getValue() {
191             return myValue;
192         }
193         
194         /**
195          * Set property value
196          * @param value property value
197          * @throws IllegalArgumentException
198          * @throws IllegalAccessException
199          * @throws InvocationTargetException
200          */

201         public void setValue(Object JavaDoc value) throws IllegalArgumentException JavaDoc,IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
202             Object JavaDoc oldVal = myValue;
203             myValue = value;
204             tn.fireMethod(getName(), oldVal, myValue);
205         }
206     }
207     
208     
209     /**
210      * Main method for trying it within IDE.
211      * @param args
212      */

213     public static void main(String JavaDoc args[]) {
214         new PropertiesTest();
215     }
216     
217 }
Popular Tags