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.window;
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 PropertyEditorsTestSheet {
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 PropertyEditorsTestSheet() {
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((Object) 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((Object) 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", java.lang.Character.class));
144: //
145: // // props.put(new TestProperty("char", char.class));
146: // TestProperty charProperty = new TestProperty("char", char.class);
147: // try {
148: // charProperty.setValue((Object)"a");
149: // props.put(charProperty);
150: // }catch(Exception exc){
151: // System.err.println("Exception during set value and add char property :"+exc.getMessage());
152: // }
153: //
154: // props.put(new TestProperty("Class", java.lang.Class.class));
155: props.put(new TestProperty("Color", java.awt.Color.class));
156: // props.put(new TestProperty("Dimension", java.awt.Dimension.class));
157: // props.put(new TestProperty("Double", java.lang.Double.class));
158: // props.put(new TestProperty("double", double.class));
159: // props.put(new TestProperty("File", java.io.File.class));
160: // props.put(new TestProperty("Filesystem", org.openide.filesystems.FileSystem.class));
161: // props.put(new TestProperty("Float", java.lang.Float.class));
162: // props.put(new TestProperty("float", float.class));
163: // props.put(new TestProperty("Font", java.awt.Font.class));
164: // props.put(new TestProperty("Html Browser", org.openide.awt.HtmlBrowser.Factory.class));
165: // props.put(new TestProperty("Indent Engine", org.openide.text.IndentEngine.class));
166: // props.put(new TestProperty("Insets", java.awt.Insets.class));
167: // props.put(new TestProperty("Integer", java.lang.Integer.class));
168: // props.put(new TestProperty("int", int.class));
169: // props.put(new TestProperty("Long", java.lang.Long.class));
170: // props.put(new TestProperty("long", long.class));
171: // props.put(new TestProperty("NbClassPath", org.openide.execution.NbClassPath.class));
172: // props.put(new TestProperty("NbProcessDescriptor", org.openide.execution.NbProcessDescriptor.class));
173: // props.put(new TestProperty("Object", java.lang.Object.class));
174: // props.put(new TestProperty("Point", java.awt.Point.class));
175: // props.put(new TestProperty("Properties", java.util.Properties.class));
176: // props.put(new TestProperty("Rectangle", java.awt.Rectangle.class));
177: // props.put(new TestProperty("Service Type", org.openide.ServiceType.class));
178: // props.put(new TestProperty("Short", java.lang.Short.class));
179: // props.put(new TestProperty("short", short.class));
180: props
181: .put(new TestProperty("String",
182: java.lang.String.class));
183: // props.put(new TestProperty("String []", java.lang.String[].class));
184: // props.put(new TestProperty("Table Model", javax.swing.table.TableModel.class));
185: // props.put(new TestProperty("URL", java.net.URL.class));
186:
187: return sheet;
188: }
189:
190: /**
191: * Method firing changes
192: * @param s
193: * @param o1
194: * @param o2
195: */
196: public void fireMethod(String s, Object o1, Object o2) {
197: firePropertyChange(s, o1, o2);
198: }
199: }
200:
201: /** Property definition */
202: public class TestProperty extends PropertySupport {
203: Object myValue;
204:
205: /**
206: * Create new property
207: * @param name
208: * @param classType
209: */
210: public TestProperty(String name, Class classType) {
211: super (name, classType, name, "", true, true);
212: }
213:
214: /**
215: * Get property value
216: * @return property value
217: */
218: public Object getValue() {
219: return myValue;
220: }
221:
222: /**
223: * Set property value
224: * @param value property value
225: * @throws IllegalArgumentException
226: * @throws IllegalAccessException
227: * @throws InvocationTargetException
228: */
229: public void setValue(Object value)
230: throws IllegalArgumentException,
231: IllegalAccessException, InvocationTargetException {
232: Object oldVal = myValue;
233: myValue = value;
234: tn.fireMethod(getName(), oldVal, myValue);
235: }
236: }
237:
238: }
|