1 19 20 package org.netbeans.modules.form.beaninfo.swing; 21 22 import java.awt.Image ; 23 import java.beans.*; 24 import java.util.ResourceBundle ; 25 import org.openide.util.NbBundle; 26 import org.openide.util.Utilities; 27 28 33 abstract class BISupport extends SimpleBeanInfo { 34 35 private PropertyDescriptor[] pds; 36 private String icon; 37 private Class beanClass; 38 39 protected BISupport(String iconBaseName, Class beanClass) { 40 icon = iconBaseName; 41 this.beanClass = beanClass; 42 } 43 44 public BeanDescriptor getBeanDescriptor() { 45 return new BeanDescriptor(beanClass); 46 } 47 48 public synchronized PropertyDescriptor[] getPropertyDescriptors() { 49 if (pds == null) { 50 try { 51 pds = createPropertyDescriptors(); 52 } catch (IntrospectionException e) { 53 pds = super.getPropertyDescriptors(); 54 } 55 } 56 return pds; 57 } 58 59 60 public Image getIcon(int type) { 61 if (type == ICON_COLOR_32x32 || type == ICON_MONO_32x32) 62 return Utilities.loadImage("org/netbeans/modules/form/beaninfo/swing/" + icon + "32.gif"); else 64 return Utilities.loadImage("org/netbeans/modules/form/beaninfo/swing/" + icon + ".gif"); } 66 67 protected PropertyDescriptor[] createPropertyDescriptors() throws IntrospectionException { 68 return new PropertyDescriptor[0]; 69 } 70 71 protected String getString(String key) { 72 return NbBundle.getMessage(BISupport.class, key); 73 } 74 75 protected PropertyDescriptor createRW( Class beanClass, String name) 76 throws IntrospectionException { 77 String title = Character.toUpperCase(name.charAt(0)) + name.substring(1); 78 79 PropertyDescriptor pd = new PropertyDescriptor(name, beanClass, 80 "get" + title, "set" + title ); 82 setProps(pd, beanClass, title); 83 return pd; 84 } 85 86 protected PropertyDescriptor createRO( Class beanClass, String name) 87 throws IntrospectionException { 88 String title = Character.toUpperCase(name.charAt(0)) + name.substring(1); 89 90 PropertyDescriptor pd = new PropertyDescriptor(name, beanClass, 91 "get" + title, null); 93 setProps(pd, beanClass, title); 94 return pd; 95 } 96 97 private void setProps( PropertyDescriptor pd, Class beanClass, String title ) { 98 String className = beanClass.getName(); 99 int dotIdx = className.lastIndexOf('.'); 100 className = dotIdx > 0 ? className.substring(dotIdx+1) : className; 101 pd.setDisplayName(getString("PROP_" + className + '.' + title)); pd.setShortDescription(getString("HINT_" + className + '.' + title)); } 104 105 106 107 static class TaggedPropertyEditor extends PropertyEditorSupport { 108 private String [] tags; 109 private int[] values; 110 private String [] javaInitStrings; 111 private String [] tagKeys; 112 113 protected TaggedPropertyEditor( int[] values, String [] javaInitStrings, String [] tagKeys ) { 114 this.values = values; 115 this.javaInitStrings = javaInitStrings; 116 this.tagKeys = tagKeys; 117 } 118 119 public String [] getTags() { 120 if (tags == null) createTags(); 121 return tags; 122 } 123 124 public String getAsText() { 125 Object valObj = getValue(); 126 if (valObj instanceof Integer ) { 127 if (tags == null) createTags(); 128 129 int value = ((Integer )valObj).intValue(); 130 for (int i = 0; i < values.length; i++) 131 if (value == values[i]) 132 return tags[i]; 133 } 134 return null; 135 } 136 137 public void setAsText(String str) { 138 if (tags == null) createTags(); 139 140 int value = -1; 141 142 for (int i = 0; i < tags.length; i++) { 143 if (str.equals(tags[i])) { 144 value = values[i]; 145 break; 146 } 147 } 148 149 if (value != -1) 150 setValue(new Integer (value)); 151 } 152 153 public String getJavaInitializationString() { 154 Object valObj = getValue(); 155 if (valObj instanceof Integer ) { 156 int value = ((Integer )valObj).intValue(); 157 for (int i = 0; i < values.length; i++) 158 if (value == values[i]) 159 return javaInitStrings[i]; 160 } 161 return "???"; } 163 164 private void createTags() { 165 tags = new String [tagKeys.length]; 166 ResourceBundle bundle = NbBundle.getBundle(BISupport.class); 167 for (int i=0; i<tagKeys.length; i++) { 168 tags[i] = bundle.getString(tagKeys[i]); 169 } 170 } 171 } 172 } 173 | Popular Tags |