-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFeatureDescriptor.java
More file actions
398 lines (363 loc) · 12.4 KB
/
Copy pathFeatureDescriptor.java
File metadata and controls
398 lines (363 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
* Some portions of this file have been modified by Robert Hanson hansonr.at.stolaf.edu 2012-2017
* for use in SwingJS via transpilation into JavaScript using Java2Script.
*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jsjava.beans;
//import java.lang.ref.Reference;
//import java.lang.ref.SoftReference;
//import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
/**
* The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
* EventSetDescriptor, and MethodDescriptor, etc.
* <p>
* It supports some common information that can be set and retrieved for
* any of the introspection descriptors.
* <p>
* In addition it provides an extension mechanism so that arbitrary
* attribute/value pairs can be associated with a design feature.
*/
public class FeatureDescriptor {
private Class /*Reference<Class>*/ classRef;
/**
* Constructs a <code>FeatureDescriptor</code>.
*/
public FeatureDescriptor() {
}
/**
* Gets the programmatic name of this feature.
*
* @return The programmatic name of the property/method/event
*/
public String getName() {
return name;
}
/**
* Sets the programmatic name of this feature.
*
* @param name The programmatic name of the property/method/event
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the localized display name of this feature.
*
* @return The localized display name for the property/method/event.
* This defaults to the same as its programmatic name from getName.
*/
public String getDisplayName() {
if (displayName == null) {
return getName();
}
return displayName;
}
/**
* Sets the localized display name of this feature.
*
* @param displayName The localized display name for the
* property/method/event.
*/
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
/**
* The "expert" flag is used to distinguish between those features that are
* intended for expert users from those that are intended for normal users.
*
* @return True if this feature is intended for use by experts only.
*/
public boolean isExpert() {
return expert;
}
/**
* The "expert" flag is used to distinguish between features that are
* intended for expert users from those that are intended for normal users.
*
* @param expert True if this feature is intended for use by experts only.
*/
public void setExpert(boolean expert) {
this.expert = expert;
}
/**
* The "hidden" flag is used to identify features that are intended only
* for tool use, and which should not be exposed to humans.
*
* @return True if this feature should be hidden from human users.
*/
public boolean isHidden() {
return hidden;
}
/**
* The "hidden" flag is used to identify features that are intended only
* for tool use, and which should not be exposed to humans.
*
* @param hidden True if this feature should be hidden from human users.
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
* The "preferred" flag is used to identify features that are particularly
* important for presenting to humans.
*
* @return True if this feature should be preferentially shown to human users.
*/
public boolean isPreferred() {
return preferred;
}
/**
* The "preferred" flag is used to identify features that are particularly
* important for presenting to humans.
*
* @param preferred True if this feature should be preferentially shown
* to human users.
*/
public void setPreferred(boolean preferred) {
this.preferred = preferred;
}
/**
* Gets the short description of this feature.
*
* @return A localized short description associated with this
* property/method/event. This defaults to be the display name.
*/
public String getShortDescription() {
if (shortDescription == null) {
return getDisplayName();
}
return shortDescription;
}
/**
* You can associate a short descriptive string with a feature. Normally
* these descriptive strings should be less than about 40 characters.
* @param text A (localized) short description to be associated with
* this property/method/event.
*/
public void setShortDescription(String text) {
shortDescription = text;
}
/**
* Associate a named attribute with this feature.
*
* @param attributeName The locale-independent name of the attribute
* @param value The value.
*/
public void setValue(String attributeName, Object value) {
if (table == null) {
table = new java.util.Hashtable();
}
table.put(attributeName, value);
}
/**
* Retrieve a named attribute with this feature.
*
* @param attributeName The locale-independent name of the attribute
* @return The value of the attribute. May be null if
* the attribute is unknown.
*/
public Object getValue(String attributeName) {
if (table == null) {
return null;
}
return table.get(attributeName);
}
/**
* Gets an enumeration of the locale-independent names of this
* feature.
*
* @return An enumeration of the locale-independent names of any
* attributes that have been registered with setValue.
*/
public java.util.Enumeration<String> attributeNames() {
if (table == null) {
table = new java.util.Hashtable();
}
return table.keys();
}
/**
* Package-private constructor,
* Merge information from two FeatureDescriptors.
* The merged hidden and expert flags are formed by or-ing the values.
* In the event of other conflicts, the second argument (y) is
* given priority over the first argument (x).
*
* @param x The first (lower priority) MethodDescriptor
* @param y The second (higher priority) MethodDescriptor
*/
FeatureDescriptor(FeatureDescriptor x, FeatureDescriptor y) {
expert = x.expert | y.expert;
hidden = x.hidden | y.hidden;
preferred = x.preferred | y.preferred;
name = y.name;
shortDescription = x.shortDescription;
if (y.shortDescription != null) {
shortDescription = y.shortDescription;
}
displayName = x.displayName;
if (y.displayName != null) {
displayName = y.displayName;
}
classRef = x.classRef;
if (y.classRef != null) {
classRef = y.classRef;
}
addTable(x.table);
addTable(y.table);
}
/*
* Package-private dup constructor
* This must isolate the new object from any changes to the old object.
*/
FeatureDescriptor(FeatureDescriptor old) {
expert = old.expert;
hidden = old.hidden;
preferred = old.preferred;
name = old.name;
shortDescription = old.shortDescription;
displayName = old.displayName;
classRef = old.classRef;
addTable(old.table);
}
private void addTable(java.util.Hashtable t) {
if (t == null) {
return;
}
java.util.Enumeration keys = t.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
Object value = t.get(key);
setValue(key, value);
}
}
// Package private methods for recreating the weak/soft referent
void setClass0(Class cls) {
this.classRef = cls;//getWeakReference(cls);
}
Class getClass0() {
return (this.classRef != null)
? this.classRef//.get()
: null;
}
// /**
// * Create a Reference wrapper for the object.
// *
// * @param obj object that will be wrapped
// * @param soft true if a SoftReference should be created; otherwise Soft
// * @return a Reference or null if obj is null.
// */
// static Reference createReference(Object obj, boolean soft) {
// Reference ref = null;
// if (obj != null) {
// if (soft) {
// ref = new SoftReference(obj);
// } else {
// ref = new WeakReference(obj);
// }
// }
// return ref;
// }
// // Convenience method which creates a WeakReference.
// static Reference createReference(Object obj) {
// return createReference(obj, false);
// }
//
// /**
// * Returns an object from a Reference wrapper.
// *
// * @return the Object in a wrapper or null.
// */
// static Object getObject(Reference ref) {
// return (ref == null) ? null : (Object)ref.get();
// }
// /**
// * Creates a new soft reference that refers to the given object.
// *
// * @return a new soft reference or <code>null</code> if object is <code>null</code>
// *
// * @see SoftReference
// */
// static <T> Reference<T> getSoftReference(T object) {
// return (object != null)
// ? new SoftReference<T>(object)
// : null;
// }
//
// /**
// * Creates a new weak reference that refers to the given object.
// *
// * @return a new weak reference or <code>null</code> if object is <code>null</code>
// *
// * @see WeakReference
// */
// static <T> Reference<T> getWeakReference(T object) {
// return (object != null)
// ? new WeakReference<T>(object)
// : null;
// }
/**
* Resolves the return type of the method.
*
* @param base the class that contains the method in the hierarchy
* @param method the object that represents the method
* @return a class identifying the return type of the method
*
* @see Method#getGenericReturnType
* @see Method#getReturnType
*/
static Class getReturnType(Class base, Method method) {
return null; // SwingJS ??
// if (base == null) {
// base = method.getDeclaringClass();
// }
// return TypeResolver.erase(TypeResolver.resolveInClass(base, method.getGenericReturnType()));
}
/**
* Resolves the parameter types of the method.
*
* @param base the class that contains the method in the hierarchy
* @param method the object that represents the method
* @return an array of classes identifying the parameter types of the method
*
* @see Method#getGenericParameterTypes
* @see Method#getParameterTypes
*/
static Class[] getParameterTypes(Class base, Method method) {
return new Class[0];
// SwingJS for now.
// if (base == null) {
// base = method.getDeclaringClass();
// }
// return TypeResolver.erase(TypeResolver.resolveInClass(base, method.getGenericParameterTypes()));
}
private boolean expert;
private boolean hidden;
private boolean preferred;
private String shortDescription;
private String name;
private String displayName;
private java.util.Hashtable table;
}