1 7 8 package java.beans; 9 10 import java.lang.ref.Reference ; 11 import java.lang.ref.WeakReference ; 12 import java.lang.ref.SoftReference ; 13 14 24 25 public class FeatureDescriptor { 26 27 private Reference classRef; 28 29 32 public FeatureDescriptor() { 33 } 34 35 40 public String getName() { 41 return name; 42 } 43 44 49 public void setName(String name) { 50 this.name = name; 51 } 52 53 59 public String getDisplayName() { 60 if (displayName == null) { 61 return getName(); 62 } 63 return displayName; 64 } 65 66 72 public void setDisplayName(String displayName) { 73 this.displayName = displayName; 74 } 75 76 82 public boolean isExpert() { 83 return expert; 84 } 85 86 92 public void setExpert(boolean expert) { 93 this.expert = expert; 94 } 95 96 102 public boolean isHidden() { 103 return hidden; 104 } 105 106 112 public void setHidden(boolean hidden) { 113 this.hidden = hidden; 114 } 115 116 122 public boolean isPreferred() { 123 return preferred; 124 } 125 126 133 public void setPreferred(boolean preferred) { 134 this.preferred = preferred; 135 } 136 137 143 public String getShortDescription() { 144 if (shortDescription == null) { 145 return getDisplayName(); 146 } 147 return shortDescription; 148 } 149 150 156 public void setShortDescription(String text) { 157 shortDescription = text; 158 } 159 160 166 public void setValue(String attributeName, Object value) { 167 if (table == null) { 168 table = new java.util.Hashtable (); 169 } 170 table.put(attributeName, value); 171 } 172 173 180 public Object getValue(String attributeName) { 181 if (table == null) { 182 return null; 183 } 184 return table.get(attributeName); 185 } 186 187 194 public java.util.Enumeration <String > attributeNames() { 195 if (table == null) { 196 table = new java.util.Hashtable (); 197 } 198 return table.keys(); 199 } 200 201 211 FeatureDescriptor(FeatureDescriptor x, FeatureDescriptor y) { 212 expert = x.expert | y.expert; 213 hidden = x.hidden | y.hidden; 214 preferred = x.preferred | y.preferred; 215 name = y.name; 216 shortDescription = x.shortDescription; 217 if (y.shortDescription != null) { 218 shortDescription = y.shortDescription; 219 } 220 displayName = x.displayName; 221 if (y.displayName != null) { 222 displayName = y.displayName; 223 } 224 classRef = x.classRef; 225 if (y.classRef != null) { 226 classRef = y.classRef; 227 } 228 addTable(x.table); 229 addTable(y.table); 230 } 231 232 236 FeatureDescriptor(FeatureDescriptor old) { 237 expert = old.expert; 238 hidden = old.hidden; 239 preferred = old.preferred; 240 name = old.name; 241 shortDescription = old.shortDescription; 242 displayName = old.displayName; 243 classRef = old.classRef; 244 245 addTable(old.table); 246 } 247 248 private void addTable(java.util.Hashtable t) { 249 if (t == null) { 250 return; 251 } 252 java.util.Enumeration keys = t.keys(); 253 while (keys.hasMoreElements()) { 254 String key = (String )keys.nextElement(); 255 Object value = t.get(key); 256 setValue(key, value); 257 } 258 } 259 260 262 void setClass0(Class cls) { 263 classRef = createReference(cls); 264 } 265 266 Class getClass0() { 267 return (Class )getObject(classRef); 268 } 269 270 277 static Reference createReference(Object obj, boolean soft) { 278 Reference ref = null; 279 if (obj != null) { 280 if (soft) { 281 ref = new SoftReference (obj); 282 } else { 283 ref = new WeakReference (obj); 284 } 285 } 286 return ref; 287 } 288 289 static Reference createReference(Object obj) { 291 return createReference(obj, false); 292 } 293 294 299 static Object getObject(Reference ref) { 300 return (ref == null) ? null : (Object )ref.get(); 301 } 302 303 static String capitalize(String s) { 304 return NameGenerator.capitalize(s); 305 } 306 307 private boolean expert; 308 private boolean hidden; 309 private boolean preferred; 310 private String shortDescription; 311 private String name; 312 private String displayName; 313 private java.util.Hashtable table; 314 } 315 | Popular Tags |