The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. 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, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations under |
| 15 | * the License. |
| 16 | */ |
| 17 | |
| 18 | package java.beans; |
| 19 | |
| 20 | import java.util.Collections; |
| 21 | import java.util.Enumeration; |
| 22 | import java.util.HashMap; |
| 23 | import java.util.LinkedList; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | /** |
| 27 | * Common base class for Descriptors. |
| 28 | */ |
| 29 | public class FeatureDescriptor { |
| 30 | |
| 31 | private Map<String, Object> values; |
| 32 | |
| 33 | boolean preferred, hidden, expert; |
| 34 | |
| 35 | String shortDescription; |
| 36 | |
| 37 | String name; |
| 38 | |
| 39 | String displayName; |
| 40 | |
| 41 | /** |
| 42 | * <p> |
| 43 | * Constructs an instance. |
| 44 | * </p> |
| 45 | */ |
| 46 | public FeatureDescriptor() { |
| 47 | this.values = new HashMap<String, Object>(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * <p> |
| 52 | * Sets the value for the named attribute. |
| 53 | * </p> |
| 54 | * |
| 55 | * @param attributeName |
| 56 | * The name of the attribute to set a value with. |
| 57 | * @param value |
| 58 | * The value to set. |
| 59 | */ |
| 60 | public void setValue(String attributeName, Object value) { |
| 61 | if (attributeName == null || value == null) { |
| 62 | throw new NullPointerException(); |
| 63 | } |
| 64 | values.put(attributeName, value); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * <p> |
| 69 | * Gets the value associated with the named attribute. |
| 70 | * </p> |
| 71 | * |
| 72 | * @param attributeName |
| 73 | * The name of the attribute to get a value for. |
| 74 | * @return The attribute's value. |
| 75 | */ |
| 76 | public Object getValue(String attributeName) { |
| 77 | Object result = null; |
| 78 | if (attributeName != null) { |
| 79 | result = values.get(attributeName); |
| 80 | } |
| 81 | return result; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * <p> |
| 86 | * Enumerates the attribute names. |
| 87 | * </p> |
| 88 | * |
| 89 | * @return An instance of {@link Enumeration}. |
| 90 | */ |
| 91 | public Enumeration<String> attributeNames() { |
| 92 | // Create a new list, so that the references are copied |
| 93 | return Collections.enumeration(new LinkedList<String>(values.keySet())); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * <p> |
| 98 | * Sets the short description. |
| 99 | * </p> |
| 100 | * |
| 101 | * @param text |
| 102 | * The description to set. |
| 103 | */ |
| 104 | public void setShortDescription(String text) { |
| 105 | this.shortDescription = text; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * <p> |
| 110 | * Sets the name. |
| 111 | * </p> |
| 112 | * |
| 113 | * @param name |
| 114 | * The name to set. |
| 115 | */ |
| 116 | public void setName(String name) { |
| 117 | this.name = name; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * <p> |
| 122 | * Sets the display name. |
| 123 | * </p> |
| 124 | * |
| 125 | * @param displayName |
| 126 | * The display name to set. |
| 127 | */ |
| 128 | public void setDisplayName(String displayName) { |
| 129 | this.displayName = displayName; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * <p> |
| 134 | * Gets the short description or {@link #getDisplayName()} if not set. |
| 135 | * </p> |
| 136 | * |
| 137 | * @return The description. |
| 138 | */ |
| 139 | public String getShortDescription() { |
| 140 | return shortDescription == null ? getDisplayName() : shortDescription; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * <p> |
| 145 | * Gets the name. |
| 146 | * </p> |
| 147 | * |
| 148 | * @return The name. |
| 149 | */ |
| 150 | public String getName() { |
| 151 | return name; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * <p> |
| 156 | * Gets the display name or {@link #getName()} if not set. |
| 157 | * </p> |
| 158 | * |
| 159 | * @return The display name. |
| 160 | */ |
| 161 | public String getDisplayName() { |
| 162 | return displayName == null ? getName() : displayName; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * <p> |
| 167 | * Sets the preferred indicator. |
| 168 | * </p> |
| 169 | * |
| 170 | * @param preferred |
| 171 | * <code>true</code> if preferred, <code>false</code> |
| 172 | * otherwise. |
| 173 | */ |
| 174 | public void setPreferred(boolean preferred) { |
| 175 | this.preferred = preferred; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * <p> |
| 180 | * Sets the hidden indicator. |
| 181 | * </p> |
| 182 | * |
| 183 | * @param hidden |
| 184 | * <code>true</code> if hidden, <code>false</code> otherwise. |
| 185 | */ |
| 186 | public void setHidden(boolean hidden) { |
| 187 | this.hidden = hidden; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * <p> |
| 192 | * Sets the expert indicator. |
| 193 | * </p> |
| 194 | * |
| 195 | * @param expert |
| 196 | * <code>true</code> if expert, <code>false</code> otherwise. |
| 197 | */ |
| 198 | public void setExpert(boolean expert) { |
| 199 | this.expert = expert; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * <p> |
| 204 | * Indicates if this feature is preferred. |
| 205 | * </p> |
| 206 | * |
| 207 | * @return <code>true</code> if preferred, <code>false</code> otherwise. |
| 208 | */ |
| 209 | public boolean isPreferred() { |
| 210 | return preferred; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * <p> |
| 215 | * Indicates if this feature is hidden. |
| 216 | * </p> |
| 217 | * |
| 218 | * @return <code>true</code> if hidden, <code>false</code> otherwise. |
| 219 | */ |
| 220 | public boolean isHidden() { |
| 221 | return hidden; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * <p> |
| 226 | * Indicates if this feature is an expert feature. |
| 227 | * </p> |
| 228 | * |
| 229 | * @return <code>true</code> if hidden, <code>false</code> otherwise. |
| 230 | */ |
| 231 | public boolean isExpert() { |
| 232 | return expert; |
| 233 | } |
| 234 | } |