KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > properties > ShortProperty


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

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