KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > properties > BooleanProperty


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 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