1 19 package gcc.properties; 20 21 public class ByteProperty extends PropertyType 22 { 23 private byte _defaultValue = 0; 24 25 private byte _minimumValue = 0; 26 27 private byte _maximumValue = Byte.MAX_VALUE; 28 29 public ByteProperty(Class componentClass, String propertyName) 30 { 31 super(componentClass, propertyName); 32 } 33 34 public ByteProperty displayName(String displayName) 35 { 36 setDisplayName(displayName); 37 return this; 38 } 39 40 public ByteProperty displayOnlyIf(PropertyType other, String value) 41 { 42 setDisplayOnlyIf(other, value); 43 return this; 44 } 45 46 public ByteProperty description(String description) 47 { 48 setDescription(description); 49 return this; 50 } 51 52 public ByteProperty consoleHelp(String consoleHelp) 53 { 54 setConsoleHelp(consoleHelp); 55 return this; 56 } 57 58 public ByteProperty sortOrder(int sortOrder) 59 { 60 setSortOrder(sortOrder); 61 return this; 62 } 63 64 public ByteProperty defaultValue(byte defaultValue) 65 { 66 _defaultValue = defaultValue; 67 return this; 68 } 69 70 public ByteProperty minimumValue(byte minimumValue) 71 { 72 _minimumValue = minimumValue; 73 return this; 74 } 75 76 public ByteProperty maximumValue(byte maximumValue) 77 { 78 _maximumValue = maximumValue; 79 return this; 80 } 81 82 public byte getDefaultValue() 83 { 84 return _defaultValue; 85 } 86 87 public String getDefaultValueAsString() 88 { 89 return String.valueOf(_defaultValue); 90 } 91 92 public byte getMinimumValue() 93 { 94 return _minimumValue; 95 } 96 97 public byte getMaximumValue() 98 { 99 return _maximumValue; 100 } 101 102 public byte getByte() 103 { 104 return getByte(null, getComponentProperties()); 105 } 106 107 public byte getByte(String instanceName, PropertyMap props) 108 { 109 byte n; 110 boolean ok = true; 111 String value = props.getProperty(_propertyName, String.valueOf(_defaultValue)); 112 try 113 { 114 n = Byte.parseByte(value); 115 } 116 catch (NumberFormatException ex) 117 { 118 ok = false; 119 n = 0; 120 } 121 if (n < _minimumValue || n > _maximumValue) 122 { 123 ok = false; 124 } 125 if (! ok) 126 { 127 badPropertyValue(instanceName, value, expectedNumberInRange(_minimumValue, _maximumValue)); 128 } 129 logPropertyValue(instanceName, value, n == _defaultValue); 130 return n; 131 } 132 } 133 | Popular Tags |