1 19 package gcc.properties; 20 21 public class BooleanProperty extends PropertyType 22 { 23 private boolean _defaultValue = false; 24 25 public BooleanProperty(Class componentClass, String propertyName) 26 { 27 super(componentClass, propertyName); 28 } 29 30 public BooleanProperty displayName(String displayName) 31 { 32 setDisplayName(displayName); 33 return this; 34 } 35 36 public BooleanProperty displayOnlyIf(PropertyType other, String value) 37 { 38 setDisplayOnlyIf(other, value); 39 return this; 40 } 41 42 public BooleanProperty description(String description) 43 { 44 setDescription(description); 45 return this; 46 } 47 48 public BooleanProperty consoleHelp(String consoleHelp) 49 { 50 setConsoleHelp(consoleHelp); 51 return this; 52 } 53 54 public BooleanProperty sortOrder(int sortOrder) 55 { 56 setSortOrder(sortOrder); 57 return this; 58 } 59 60 public BooleanProperty defaultValue(boolean defaultValue) 61 { 62 _defaultValue = defaultValue; 63 return this; 64 } 65 66 public boolean getDefaultValue() 67 { 68 return _defaultValue; 69 } 70 71 public String getDefaultValueAsString() 72 { 73 return String.valueOf(_defaultValue); 74 } 75 76 public boolean getBoolean() 77 { 78 return getBoolean(null, getComponentProperties()); 79 } 80 81 public boolean getBoolean(String instanceName, PropertyMap props) 82 { 83 boolean b; 84 boolean ok = true; 85 String value = props.getProperty(_propertyName, String.valueOf(_defaultValue)); 86 value = value.toLowerCase(); 87 if (value.equals("true")) 88 { 89 b = true; 90 } 91 else if (value.equals("false")) 92 { 93 b = false; 94 } 95 else 96 { 97 ok = false; 98 b = false; 99 } 100 if (! ok) 101 { 102 badPropertyValue(instanceName, value, expectedTrueOrFalse()); 103 } 104 logPropertyValue(instanceName, value, b == _defaultValue); 105 return b; 106 } 107 } 108 | Popular Tags |