1 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 ; 29 30 36 public class PropertiesTest { 37 38 39 private TNode tn; 40 41 42 public PropertiesTest() { 43 tn = new TNode(); 45 46 49 NodeOperation.getDefault().showProperties(tn); 51 54 try { 56 Thread.currentThread().sleep(3000); 57 }catch(Exception exc){ 58 System.err.println("Exception during sleep after showing properties sheet :" + exc.getMessage()); 59 } 60 } 61 62 63 public class TNode extends AbstractNode { 64 65 66 public TNode() { 67 super(Children.LEAF); 68 setName("TestNode"); setDisplayName("TestNode"); 70 } 71 72 76 public Node cloneNode() { 77 return new TNode(); 78 } 79 80 84 protected Sheet createSheet() { 85 Sheet sheet = super.createSheet(); 86 Sheet.Set props = sheet.get(Sheet.PROPERTIES); 88 if (props == null) { 89 props = Sheet.createPropertiesSet(); 90 sheet.put(props); 91 } 92 93 TestProperty booleanObjectProperty = new TestProperty("Boolean", java.lang.Boolean .class); 95 try { 96 booleanObjectProperty.setValue(Boolean.TRUE); 97 props.put(booleanObjectProperty); 98 } 99 catch (Exception exc) { 100 System.err.println("Exception during set value and add Boolean property :" + 101 exc.getMessage()); 102 } 103 104 TestProperty booleanProperty = new TestProperty("boolean", boolean.class); 106 try { 107 booleanProperty.setValue(Boolean.TRUE); 108 props.put(booleanProperty); 109 } 110 catch (Exception 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 .class)); 116 props.put(new TestProperty("byte", byte.class)); 117 props.put(new TestProperty("Character", java.lang.Character .class)); 118 119 TestProperty charProperty = new TestProperty("char", char.class); 121 try { 122 charProperty.setValue("a"); 123 props.put(charProperty); 124 } 125 catch (Exception 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 .class)); 131 props.put(new TestProperty("Color", java.awt.Color .class)); 132 props.put(new TestProperty("Dimension", java.awt.Dimension .class)); 133 props.put(new TestProperty("Double", java.lang.Double .class)); 134 props.put(new TestProperty("double", double.class)); 135 props.put(new TestProperty("File", java.io.File .class)); 136 props.put(new TestProperty("Float", java.lang.Float .class)); 137 props.put(new TestProperty("float", float.class)); 138 props.put(new TestProperty("Font", java.awt.Font .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 .class)); 142 props.put(new TestProperty("Integer", java.lang.Integer .class)); 143 props.put(new TestProperty("int", int.class)); 144 props.put(new TestProperty("Long", java.lang.Long .class)); 145 props.put(new TestProperty("long", long.class)); 146 props.put(new TestProperty("Object", java.lang.Object .class)); 149 props.put(new TestProperty("Point", java.awt.Point .class)); 150 props.put(new TestProperty("property_Properties", java.util.Properties .class)); 151 props.put(new TestProperty("Rectangle", java.awt.Rectangle .class)); 152 props.put(new TestProperty("Service Type", org.openide.ServiceType.class)); 153 props.put(new TestProperty("Short", java.lang.Short .class)); 154 props.put(new TestProperty("short", short.class)); 155 props.put(new TestProperty("String", java.lang.String .class)); 156 props.put(new TestProperty("String []", java.lang.String [].class)); 157 props.put(new TestProperty("URL", java.net.URL .class)); 158 159 return sheet; 160 } 161 162 168 public void fireMethod(String s, Object o1, Object o2) { 169 firePropertyChange(s,o1,o2); 170 } 171 } 172 173 174 public class TestProperty extends PropertySupport { 175 Object myValue; 176 177 182 public TestProperty(String name, Class classType) { 183 super(name, classType, name, "", true, true); 184 } 185 186 190 public Object getValue() { 191 return myValue; 192 } 193 194 201 public void setValue(Object value) throws IllegalArgumentException ,IllegalAccessException , InvocationTargetException { 202 Object oldVal = myValue; 203 myValue = value; 204 tn.fireMethod(getName(), oldVal, myValue); 205 } 206 } 207 208 209 213 public static void main(String args[]) { 214 new PropertiesTest(); 215 } 216 217 } | Popular Tags |