Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java
41152 views
1
/*
2
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package java.beans;
27
28
import java.awt.Image;
29
import java.awt.Toolkit;
30
import java.awt.image.ImageProducer;
31
import java.net.URL;
32
import java.security.AccessController;
33
import java.security.PrivilegedAction;
34
35
/**
36
* This is a support class to make it easier for people to provide
37
* BeanInfo classes.
38
* <p>
39
* It defaults to providing "noop" information, and can be selectively
40
* overriden to provide more explicit information on chosen topics.
41
* When the introspector sees the "noop" values, it will apply low
42
* level introspection and design patterns to automatically analyze
43
* the target bean.
44
*
45
* @since 1.1
46
*/
47
public class SimpleBeanInfo implements BeanInfo {
48
49
/**
50
* Constructs a {@code SimpleBeanInfo}.
51
*/
52
public SimpleBeanInfo() {}
53
54
/**
55
* Deny knowledge about the class and customizer of the bean.
56
* You can override this if you wish to provide explicit info.
57
*/
58
@Override
59
public BeanDescriptor getBeanDescriptor() {
60
return null;
61
}
62
63
/**
64
* Deny knowledge of properties. You can override this
65
* if you wish to provide explicit property info.
66
*/
67
@Override
68
public PropertyDescriptor[] getPropertyDescriptors() {
69
return null;
70
}
71
72
/**
73
* Deny knowledge of a default property. You can override this
74
* if you wish to define a default property for the bean.
75
*/
76
@Override
77
public int getDefaultPropertyIndex() {
78
return -1;
79
}
80
81
/**
82
* Deny knowledge of event sets. You can override this
83
* if you wish to provide explicit event set info.
84
*/
85
@Override
86
public EventSetDescriptor[] getEventSetDescriptors() {
87
return null;
88
}
89
90
/**
91
* Deny knowledge of a default event. You can override this
92
* if you wish to define a default event for the bean.
93
*/
94
@Override
95
public int getDefaultEventIndex() {
96
return -1;
97
}
98
99
/**
100
* Deny knowledge of methods. You can override this
101
* if you wish to provide explicit method info.
102
*/
103
@Override
104
public MethodDescriptor[] getMethodDescriptors() {
105
return null;
106
}
107
108
/**
109
* Claim there are no other relevant BeanInfo objects. You
110
* may override this if you want to (for example) return a
111
* BeanInfo for a base class.
112
*/
113
@Override
114
public BeanInfo[] getAdditionalBeanInfo() {
115
return null;
116
}
117
118
/**
119
* Claim there are no icons available. You can override
120
* this if you want to provide icons for your bean.
121
*/
122
@Override
123
public Image getIcon(final int iconKind) {
124
final BeanDescriptor descriptor = getBeanDescriptor();
125
if (descriptor != null) {
126
final Class<?> type = descriptor.getBeanClass();
127
if (type != null && type.getClassLoader() == null
128
&& type.getAnnotation(JavaBean.class) != null) {
129
final String name = type.getName();
130
final int index = name.lastIndexOf('.');
131
if (name.substring(0, index).equals("javax.swing")) {
132
final String className = type.getSimpleName();
133
switch (iconKind) {
134
case ICON_COLOR_32x32:
135
return loadImage(className, "Color32.gif");
136
case ICON_COLOR_16x16:
137
return loadImage(className, "Color16.gif");
138
case ICON_MONO_32x32:
139
return loadImage(className, "Mono32.gif");
140
case ICON_MONO_16x16:
141
return loadImage(className, "Mono16.gif");
142
}
143
}
144
}
145
}
146
return null;
147
}
148
149
/**
150
* This is a utility method to help in loading standard icon images.
151
*
152
* @param resourceName A pathname relative to the directory holding the
153
* class file of the current class
154
* @return an image object. May be null if the load failed.
155
* @see java.beans.SimpleBeanInfo#loadImage(String)
156
*/
157
@SuppressWarnings("removal")
158
private Image loadStandardImage(final String resourceName) {
159
return AccessController.doPrivileged(
160
(PrivilegedAction<Image>) () -> loadImage(resourceName));
161
}
162
163
/**
164
* This is a utility method to help in loading standard icon images.
165
*
166
* @param resourceName A pathname relative to the directory holding the
167
* class file of the current class
168
* @param suffix A {@code String} containing a file suffix (<i>e.g.</i>,
169
* "Color32.gif" or "Mono32.gif")
170
* @return an image object. May be null if the load failed.
171
* @see java.beans.SimpleBeanInfo#loadImage(String)
172
*/
173
private Image loadImage(final String resourceName, final String suffix) {
174
final String prefix = "/javax/swing/beaninfo/images/";
175
final Image image = loadStandardImage(prefix + resourceName + suffix);
176
return image == null ? loadStandardImage(prefix + "JComponent" + suffix)
177
: image;
178
}
179
180
/**
181
* This is a utility method to help in loading icon images. It takes the
182
* name of a resource file associated with the current object's class file
183
* and loads an image object from that file. Typically images will be GIFs.
184
*
185
* @param resourceName A pathname relative to the directory holding the
186
* class file of the current class. For example, "wombat.gif".
187
* @return an image object or null if the resource is not found or the
188
* resource could not be loaded as an Image
189
*/
190
public Image loadImage(final String resourceName) {
191
try {
192
final URL url = getClass().getResource(resourceName);
193
if (url != null) {
194
final ImageProducer ip = (ImageProducer) url.getContent();
195
if (ip != null) {
196
return Toolkit.getDefaultToolkit().createImage(ip);
197
}
198
}
199
} catch (final Exception ignored) {
200
}
201
return null;
202
}
203
}
204
205