1 19 package gcc.properties; 20 21 public class IntProperty extends PropertyType 22 { 23 private int _defaultValue = 0; 24 25 private int _minimumValue = 0; 26 27 private int _maximumValue = Integer.MAX_VALUE; 28 29 public IntProperty(Class componentClass, String propertyName) 30 { 31 super(componentClass, propertyName); 32 } 33 34 public IntProperty displayName(String displayName) 35 { 36 setDisplayName(displayName); 37 return this; 38 } 39 40 public IntProperty displayOnlyIf(PropertyType other, String value) 41 { 42 setDisplayOnlyIf(other, value); 43 return this; 44 } 45 46 public IntProperty description(String description) 47 { 48 setDescription(description); 49 return this; 50 } 51 52 public IntProperty consoleHelp(String consoleHelp) 53 { 54 setConsoleHelp(consoleHelp); 55 return this; 56 } 57 58 public IntProperty sortOrder(int sortOrder) 59 { 60 setSortOrder(sortOrder); 61 return this; 62 } 63 64 public IntProperty defaultValue(int defaultValue) 65 { 66 _defaultValue = defaultValue; 67 return this; 68 } 69 70 public IntProperty minimumValue(int minimumValue) 71 { 72 _minimumValue = minimumValue; 73 return this; 74 } 75 76 public IntProperty maximumValue(int maximumValue) 77 { 78 _maximumValue = maximumValue; 79 return this; 80 } 81 82 public int getDefaultValue() 83 { 84 return _defaultValue; 85 } 86 87 public String getDefaultValueAsString() 88 { 89 return String.valueOf(_defaultValue); 90 } 91 92 public int getMinimumValue() 93 { 94 return _minimumValue; 95 } 96 97 public int getMaximumValue() 98 { 99 return _maximumValue; 100 } 101 102 public int getInt() 103 { 104 return getInt(null, getComponentProperties()); 105 } 106 107 public int getInt(String instanceName, PropertyMap props) 108 { 109 int n; 110 boolean ok = true; 111 String value = props.getProperty(_propertyName, String.valueOf(_defaultValue)); 112 try 113 { 114 n = Integer.parseInt(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 |