1 19 20 package org.openide.explorer.propertysheet.editors; 21 22 import java.awt.*; 23 import java.beans.*; 24 import java.util.Locale ; 25 26 import org.openide.ErrorManager; 27 import org.openide.src.Type; 28 import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor; 29 import org.openide.explorer.propertysheet.ExPropertyEditor; 30 import org.openide.explorer.propertysheet.PropertyEnv; 31 import org.openide.util.NbBundle; 32 33 34 38 public class TypeEditor extends PropertyEditorSupport 39 implements EnhancedPropertyEditor, ExPropertyEditor { 40 41 44 private static final String [] LVALUE_TYPES = { 45 "boolean", "int", "char", "byte", "short", "long", "float", "double", "Object", "String" }; 48 49 52 private static final String [] RVALUE_TYPES = { 53 "void", "boolean", "int", "char", "byte", "short", "long", "float", "double", "Object", "String" }; 56 57 58 static final long serialVersionUID = 1423443523462351952L; 59 60 private boolean acceptsVoid; 61 62 63 public TypeEditor () { 64 } 65 66 72 public String getAsText () { 73 Object val = getValue(); 74 return (val == null) ? "" : val.toString(); } 76 77 81 public void setAsText (String string) throws IllegalArgumentException { 82 Type t; 83 84 try { 85 t = Type.parse(string); 86 } catch (IllegalArgumentException ex) { 87 ErrorManager.getDefault().annotate(ex, 88 ErrorManager.USER, null, 89 getString("MSG_InvalidTypeDecl"), null, null); 91 throw ex; 92 } 93 if (!acceptsVoid && t == Type.VOID) { 94 IllegalArgumentException ex = new IllegalArgumentException ("Void not allowed"); ErrorManager.getDefault().annotate(ex, 96 ErrorManager.USER, null, 97 getString("MSG_VoidTypeNotPermitted"), null, null); 99 throw ex; 100 } 101 setValue(t); 102 } 103 104 107 public void setValue(Object v) { 108 109 if ( v == null || v instanceof Type ) 110 super.setValue(v); 111 else 112 throw new IllegalArgumentException (); 113 } 114 115 119 public String getJavaInitializationString () { 120 return getAsText(); 121 } 122 123 126 public String [] getTags () { 127 return acceptsVoid ? RVALUE_TYPES : LVALUE_TYPES; 128 } 129 130 134 public Component getInPlaceCustomEditor () { 135 return null; 136 } 137 138 142 public boolean hasInPlaceCustomEditor () { 143 return false; 144 } 145 146 150 public boolean supportsEditingTaggedValues () { 151 return true; 152 } 153 154 158 public void attachEnv(PropertyEnv env) { 159 FeatureDescriptor desc = env.getFeatureDescriptor(); 160 Object o; 161 162 o = desc.getValue("acceptVoidType"); if (o instanceof Boolean ) { 164 acceptsVoid = ((Boolean )o).booleanValue(); 165 } else { 166 acceptsVoid = true; 167 } 168 } 169 170 private static String getString(String key) { 171 return NbBundle.getBundle("org.openide.explorer.propertysheet.editors.Bundle2", Locale.getDefault(), TypeEditor.class.getClassLoader()).getString(key); 172 } 173 174 } 175 | Popular Tags |