1 19 24 25 package org.netbeans.beaninfo.editors; 26 import java.beans.*; 27 import org.openide.explorer.propertysheet.ExPropertyEditor; 28 import org.openide.util.NbBundle; 29 41 public class BoolEditor extends ExPropertyEditorSupport { 42 String [] stringValues = null; 43 44 public BoolEditor() { 45 } 46 47 protected void attachEnvImpl(org.openide.explorer.propertysheet.PropertyEnv env) { 48 stringValues = (String []) env.getFeatureDescriptor().getValue( 49 "stringValues"); } 51 52 53 protected void validateEnv(org.openide.explorer.propertysheet.PropertyEnv env) { 54 if (stringValues != null) { 55 if (stringValues.length != 2) { 56 throw new EnvException( 57 "String value hint for boolean editor must contain exactly 2 " 58 + "items. The supplied value contains " + stringValues.length + 59 " items: " + arrToStr(stringValues)); 60 } 61 } 62 } 63 64 private String getStringRep(boolean val) { 65 if (stringValues != null) { 66 return stringValues [val ? 0 : 1]; 67 } 68 String result; 69 if (val) { 70 result = NbBundle.getMessage(BoolEditor.class, "TRUE"); } else { 72 result = NbBundle.getMessage(BoolEditor.class, "FALSE"); } 74 return result; 75 } 76 77 79 private Boolean stringVal(String val) { 80 String valToTest = val.trim().toUpperCase(); 81 String test = getStringRep(true).toUpperCase(); 82 if (test.equals(valToTest)) return Boolean.TRUE; 83 test = getStringRep(false).toUpperCase(); 84 if (test.equals(valToTest)) return Boolean.FALSE; 85 return null; 86 } 87 88 public String getJavaInitializationString() { 89 Boolean val = (Boolean ) getValue(); 90 if (val == null) return "null"; return Boolean.TRUE.equals(getValue()) ? "true" : "false"; } 93 94 public String [] getTags() { 95 return new String [] { 96 getStringRep(true), getStringRep(false) 97 }; 98 } 99 100 public String getAsText() { 101 Boolean val = (Boolean ) getValue(); 102 if (val == null) return NbBundle.getMessage(BoolEditor.class, "NULL"); 103 return getStringRep(Boolean.TRUE.equals(getValue())); 104 } 105 106 public void setAsText(String txt) { 107 Boolean val = stringVal(txt); 108 boolean newVal = val == null ? false : val.booleanValue(); 109 setValue(newVal ? Boolean.TRUE : Boolean.FALSE); 110 } 111 } 112 | Popular Tags |