001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package gui.propertyeditors;
042:
043: import org.openide.nodes.AbstractNode;
044: import org.openide.nodes.Children;
045: import org.openide.nodes.Node;
046: import org.openide.nodes.NodeOperation;
047: import org.openide.nodes.PropertySupport;
048: import org.openide.nodes.Sheet;
049:
050: import java.lang.reflect.InvocationTargetException;
051:
052: /**
053: * This test class tests the main functionality of the property sheet,
054: * property editors and property customizers customizable by IDE.
055: *
056: * @author mmirilovic@netbeans.org
057: */
058: public class PropertiesTest {
059:
060: /** Node with all customizable properties */
061: private TNode tn;
062:
063: /** Create new instance of the TNode and show property sheet */
064: public PropertiesTest() {
065: // Create new TNode
066: tn = new TNode();
067:
068: // Display Node
069: //NodeOperation.getDefault().getNodeOperation().explore(tn);
070:
071: // Display Properties of a Node
072: NodeOperation.getDefault().showProperties(tn);
073: //NodeOperation no = (NodeOperation)org.openide.util.Lookup.getDefault().lookup(NodeOperation.class);
074: //no.showProperties(tn);
075:
076: // Wait 3s for showing properties sheet
077: try {
078: Thread.currentThread().sleep(3000);
079: } catch (Exception exc) {
080: System.err
081: .println("Exception during sleep after showing properties sheet :"
082: + exc.getMessage());
083: }
084: }
085:
086: /** Definition of the node with all customizable properties */
087: public class TNode extends AbstractNode {
088:
089: /** Create new instance of the node */
090: public TNode() {
091: super (Children.LEAF);
092: setName("TestNode"); // or, super.setName if needed
093: setDisplayName("TestNode");
094: }
095:
096: /**
097: * Clone existing node
098: * @return cloned node
099: */
100: public Node cloneNode() {
101: return new TNode();
102: }
103:
104: /**
105: * Create a property sheet - that shows node with all customizable properties.
106: * @return property sheet
107: */
108: protected Sheet createSheet() {
109: Sheet sheet = super .createSheet();
110: // Make sure there is a "Properties" set:
111: Sheet.Set props = sheet.get(Sheet.PROPERTIES);
112: if (props == null) {
113: props = Sheet.createPropertiesSet();
114: sheet.put(props);
115: }
116:
117: // props.put(new TestProperty("Boolean", java.lang.Boolean.class));
118: TestProperty booleanObjectProperty = new TestProperty(
119: "Boolean", java.lang.Boolean.class);
120: try {
121: booleanObjectProperty.setValue(Boolean.TRUE);
122: props.put(booleanObjectProperty);
123: } catch (Exception exc) {
124: System.err
125: .println("Exception during set value and add Boolean property :"
126: + exc.getMessage());
127: }
128:
129: // props.put(new TestProperty("boolean", boolean.class));
130: TestProperty booleanProperty = new TestProperty("boolean",
131: boolean.class);
132: try {
133: booleanProperty.setValue(Boolean.TRUE);
134: props.put(booleanProperty);
135: } catch (Exception exc) {
136: System.err
137: .println("Exception during set value and add boolean property :"
138: + exc.getMessage());
139: }
140:
141: props.put(new TestProperty("Byte", java.lang.Byte.class));
142: props.put(new TestProperty("byte", byte.class));
143: props.put(new TestProperty("Character",
144: java.lang.Character.class));
145:
146: // props.put(new TestProperty("char", char.class));
147: TestProperty charProperty = new TestProperty("char",
148: char.class);
149: try {
150: charProperty.setValue("a");
151: props.put(charProperty);
152: } catch (Exception exc) {
153: System.err
154: .println("Exception during set value and add char property :"
155: + exc.getMessage());
156: }
157:
158: props.put(new TestProperty("Class", java.lang.Class.class));
159: props.put(new TestProperty("Color", java.awt.Color.class));
160: props.put(new TestProperty("Dimension",
161: java.awt.Dimension.class));
162: props
163: .put(new TestProperty("Double",
164: java.lang.Double.class));
165: props.put(new TestProperty("double", double.class));
166: props.put(new TestProperty("File", java.io.File.class));
167: props.put(new TestProperty("Float", java.lang.Float.class));
168: props.put(new TestProperty("float", float.class));
169: props.put(new TestProperty("Font", java.awt.Font.class));
170: props.put(new TestProperty("Html Browser",
171: org.openide.awt.HtmlBrowser.Factory.class));
172: props.put(new TestProperty("Indent Engine",
173: org.openide.text.IndentEngine.class));
174: props
175: .put(new TestProperty("Insets",
176: java.awt.Insets.class));
177: props.put(new TestProperty("Integer",
178: java.lang.Integer.class));
179: props.put(new TestProperty("int", int.class));
180: props.put(new TestProperty("Long", java.lang.Long.class));
181: props.put(new TestProperty("long", long.class));
182: // props.put(new TestProperty("NbClassPath", org.openide.execution.NbClassPath.class));
183: // props.put(new TestProperty("NbProcessDescriptor", org.openide.execution.NbProcessDescriptor.class));
184: props
185: .put(new TestProperty("Object",
186: java.lang.Object.class));
187: props.put(new TestProperty("Point", java.awt.Point.class));
188: props.put(new TestProperty("property_Properties",
189: java.util.Properties.class));
190: props.put(new TestProperty("Rectangle",
191: java.awt.Rectangle.class));
192: props.put(new TestProperty("Service Type",
193: org.openide.ServiceType.class));
194: props.put(new TestProperty("Short", java.lang.Short.class));
195: props.put(new TestProperty("short", short.class));
196: props
197: .put(new TestProperty("String",
198: java.lang.String.class));
199: props.put(new TestProperty("String []",
200: java.lang.String[].class));
201: props.put(new TestProperty("URL", java.net.URL.class));
202:
203: return sheet;
204: }
205:
206: /**
207: * Method firing changes
208: * @param s
209: * @param o1
210: * @param o2
211: */
212: public void fireMethod(String s, Object o1, Object o2) {
213: firePropertyChange(s, o1, o2);
214: }
215: }
216:
217: /** Property definition */
218: public class TestProperty extends PropertySupport {
219: Object myValue;
220:
221: /**
222: * Create new property
223: * @param name
224: * @param classType
225: */
226: public TestProperty(String name, Class classType) {
227: super (name, classType, name, "", true, true);
228: }
229:
230: /**
231: * Get property value
232: * @return property value
233: */
234: public Object getValue() {
235: return myValue;
236: }
237:
238: /**
239: * Set property value
240: * @param value property value
241: * @throws IllegalArgumentException
242: * @throws IllegalAccessException
243: * @throws InvocationTargetException
244: */
245: public void setValue(Object value)
246: throws IllegalArgumentException,
247: IllegalAccessException, InvocationTargetException {
248: Object oldVal = myValue;
249: myValue = value;
250: tn.fireMethod(getName(), oldVal, myValue);
251: }
252: }
253:
254: /**
255: * Main method for trying it within IDE.
256: * @param args
257: */
258: public static void main(String args[]) {
259: new PropertiesTest();
260: }
261:
262: }
|