jdk/src/share/classes/java/beans/SimpleBeanInfo.java
Print this page
@@ -100,10 +100,30 @@
/**
* Claim there are no icons available. You can override
* this if you want to provide icons for your bean.
*/
public java.awt.Image getIcon(int iconKind) {
+ BeanDescriptor descriptor = getBeanDescriptor();
+ if (descriptor != null) {
+ Class<?> type = descriptor.getBeanClass();
+ if ((type != null) && (null != type.getAnnotation(JavaBean.class))) {
+ String name = type.getName();
+ int index = name.lastIndexOf('.');
+ if (name.substring(0, index).equals("javax.swing")) {
+ switch (iconKind) {
+ case ICON_COLOR_32x32:
+ return loadImage(name.substring(index + 1), "Color32.gif");
+ case ICON_COLOR_16x16:
+ return loadImage(name.substring(index + 1), "Color16.gif");
+ case ICON_MONO_32x32:
+ return loadImage(name.substring(index + 1), "Mono32.gif");
+ case ICON_MONO_16x16:
+ return loadImage(name.substring(index + 1), "Mono16.gif");
+ }
+ }
+ }
+ }
return null;
}
/**
* This is a utility method to help in loading icon images.
@@ -143,6 +163,10 @@
} catch (Exception ex) {
return null;
}
}
+ private java.awt.Image loadImage(String name, String postfix) {
+ java.awt.Image image = loadImage("/javax/swing/beaninfo/images/" + name + postfix);
+ return (image != null) ? image : loadImage("/javax/swing/beaninfo/images/JComponent" + postfix);
+ }
}