1 19 20 package org.netbeans.modules.form; 21 22 import java.awt.*; 23 import javax.swing.*; 24 import javax.accessibility.*; 25 import java.beans.PropertyEditor ; 26 27 import org.openide.nodes.Node; 28 import org.openide.util.NbBundle; 29 30 35 36 public class RADMenuItemComponent extends RADComponent { 37 38 private MetaAccessibleContext accessibilityData; 39 private FormProperty[] accessibilityProperties; 40 41 42 private int type; 43 44 45 static final int T_MENUBAR = 0x01110; 46 static final int T_MENUITEM = 0x00011; 47 static final int T_CHECKBOXMENUITEM = 0x00012; 48 static final int T_MENU = 0x00113; 49 static final int T_POPUPMENU = 0x01114; 50 51 static final int T_JPOPUPMENU = 0x01125; 52 static final int T_JMENUBAR = 0x01126; 53 static final int T_JMENUITEM = 0x00027; 54 static final int T_JCHECKBOXMENUITEM = 0x00028; 55 static final int T_JMENU = 0x00129; 56 static final int T_JRADIOBUTTONMENUITEM = 0x0002A; 57 58 static final int T_SEPARATOR = 0x1001B; 59 static final int T_JSEPARATOR = 0x1002C; 60 61 62 static final int MASK_AWT = 0x00010; 63 static final int MASK_SWING = 0x00020; 64 static final int MASK_CONTAINER = 0x00100; 65 static final int MASK_ROOT = 0x01000; 66 static final int MASK_SEPARATOR = 0x10000; 67 68 69 public Object initInstance(Class beanClass) throws Exception { 70 type = recognizeType(beanClass); 71 return super.initInstance(beanClass); 72 } 73 74 protected org.openide.nodes.Node.Property[] createSyntheticProperties() { 75 if (type == T_SEPARATOR) 77 return RADComponent.NO_PROPERTIES; 78 else 79 return super.createSyntheticProperties(); 80 } 81 82 int getMenuItemType() { 83 return type; 84 } 85 86 89 static int recognizeType(Class cl) { 90 if (JSeparator.class.isAssignableFrom(cl)) 91 return T_JSEPARATOR; 92 if (org.netbeans.modules.form.Separator.class.isAssignableFrom(cl)) 93 return T_SEPARATOR; 94 if (PopupMenu.class.isAssignableFrom(cl)) 95 return T_POPUPMENU; 96 if (Menu.class.isAssignableFrom(cl)) 97 return T_MENU; 98 if (CheckboxMenuItem.class.isAssignableFrom(cl)) 99 return T_CHECKBOXMENUITEM; 100 if (MenuItem.class.isAssignableFrom(cl)) 101 return T_MENUITEM; 102 if (MenuBar.class.isAssignableFrom(cl)) 103 return T_MENUBAR; 104 if (JRadioButtonMenuItem.class.isAssignableFrom(cl)) 105 return T_JRADIOBUTTONMENUITEM; 106 if (JMenu.class.isAssignableFrom(cl)) 107 return T_JMENU; 108 if (JCheckBoxMenuItem.class.isAssignableFrom(cl)) 109 return T_JCHECKBOXMENUITEM; 110 if (JMenuItem.class.isAssignableFrom(cl)) 111 return T_JMENUITEM; 112 if (JMenuBar.class.isAssignableFrom(cl)) 113 return T_JMENUBAR; 114 if (JPopupMenu.class.isAssignableFrom(cl)) 115 return T_JPOPUPMENU; 116 117 throw new IllegalArgumentException ("Cannot create RADMenuItemComponent for class: "+cl.getName()); } 119 120 public Object cloneBeanInstance(java.util.Collection relativeProperties) { 121 if (type == T_SEPARATOR) 122 return null; return super.cloneBeanInstance(relativeProperties); 124 } 125 126 129 132 protected void createPropertySets(java.util.List propSets) { 133 super.createPropertySets(propSets); 134 135 if (accessibilityProperties == null) 136 createAccessibilityProperties(); 137 138 if (accessibilityProperties.length > 0) 139 propSets.add(new Node.PropertySet( 140 "accessibility", FormUtils.getBundleString("CTL_AccessibilityTab"), FormUtils.getBundleString("CTL_AccessibilityTabHint")) { 144 public Node.Property[] getProperties() { 145 return getAccessibilityProperties(); 146 } 147 }); 148 } 149 150 public Node.Property getPropertyByName(String name, 151 Class propertyType, 152 boolean fromAll) 153 { 154 if (fromAll && accessibilityProperties == null) 155 createAccessibilityProperties(); 156 return super.getPropertyByName(name, propertyType, fromAll); 157 } 158 159 protected void clearProperties() { 160 super.clearProperties(); 161 accessibilityData = null; 162 accessibilityProperties = null; 163 } 164 165 public FormProperty[] getAccessibilityProperties() { 166 if (accessibilityProperties == null) 167 createAccessibilityProperties(); 168 return accessibilityProperties; 169 } 170 171 private void createAccessibilityProperties() { 172 Object comp = getBeanInstance(); 173 if (comp instanceof Accessible 174 && ((Accessible)comp).getAccessibleContext() != null) 175 { 176 if (accessibilityData == null) 177 accessibilityData = new MetaAccessibleContext(); 178 accessibilityProperties = accessibilityData.getProperties(); 179 180 for (int i=0; i < accessibilityProperties.length; i++) { 181 FormProperty prop = accessibilityProperties[i]; 182 setPropertyListener(prop); 183 prop.setPropertyContext( 184 new RADProperty.RADPropertyContext(this)); 185 nameToProperty.put(prop.getName(), prop); 186 } 187 } 188 else { 189 accessibilityData = null; 190 accessibilityProperties = NO_PROPERTIES; 191 } 192 } 193 194 private class MetaAccessibleContext { 195 private Object accName = BeanSupport.NO_VALUE; 196 private Object accDescription = BeanSupport.NO_VALUE; 197 private Object accParent = BeanSupport.NO_VALUE; 198 199 private FormProperty[] properties; 200 201 FormProperty[] getProperties() { 202 if (properties == null) { 203 properties = new FormProperty[] { 204 new FormProperty( 205 "AccessibleContext.accessibleName", String .class, 207 FormUtils.getBundleString("PROP_AccessibleName"), FormUtils.getBundleString("PROP_AccessibleName")) { 210 public Object getTargetValue() { 211 return accName != BeanSupport.NO_VALUE ? 212 accName : getDefaultValue(); 213 } 214 public void setTargetValue(Object value) { 215 accName = (String ) value; 216 } 217 public boolean supportsDefaultValue () { 218 return true; 219 } 220 public Object getDefaultValue() { 221 return getAccessibleContext().getAccessibleName(); 222 } 223 public void restoreDefaultValue() 224 throws IllegalAccessException , 225 java.lang.reflect.InvocationTargetException 226 { 227 super.restoreDefaultValue(); 228 accName = BeanSupport.NO_VALUE; 229 } 230 String getPartialSetterCode(String javaInitStr) { 231 return "getAccessibleContext().setAccessibleName(" + javaInitStr + ")"; } 234 }, 235 236 new FormProperty( 237 "AccessibleContext.accessibleDescription", String .class, 239 FormUtils.getBundleString("PROP_AccessibleDescription"), FormUtils.getBundleString("PROP_AccessibleDescription")) { 242 public Object getTargetValue() { 243 return accDescription != BeanSupport.NO_VALUE ? 244 accDescription : getDefaultValue(); 245 } 246 public void setTargetValue(Object value) { 247 accDescription = (String ) value; 248 } 249 public boolean supportsDefaultValue () { 250 return true; 251 } 252 public Object getDefaultValue() { 253 return getAccessibleContext().getAccessibleDescription(); 254 } 255 public void restoreDefaultValue() 256 throws IllegalAccessException , 257 java.lang.reflect.InvocationTargetException 258 { 259 super.restoreDefaultValue(); 260 accDescription = BeanSupport.NO_VALUE; 261 } 262 String getPartialSetterCode(String javaInitStr) { 263 return 264 "getAccessibleContext().setAccessibleDescription(" + javaInitStr + ")"; } 267 }, 268 269 new FormProperty( 270 "AccessibleContext.accessibleParent", Accessible.class, 272 FormUtils.getBundleString("PROP_AccessibleParent"), FormUtils.getBundleString("PROP_AccessibleParent")) { 275 public Object getTargetValue() { 276 return accParent != BeanSupport.NO_VALUE ? 277 accParent : getDefaultValue(); 278 } 279 public void setTargetValue(Object value) { 280 accParent = value; 281 } 282 public boolean supportsDefaultValue () { 283 return true; 284 } 285 public Object getDefaultValue() { 286 Object acP = getAccessibleContext() 287 .getAccessibleParent(); 288 if (acP != null) { 289 RADComponent metacont = getParentComponent(); 290 if (metacont != null 291 && metacont.getBeanInstance() == acP) 292 return metacont; 293 } 294 return acP; 295 } 296 public void restoreDefaultValue() 297 throws IllegalAccessException , 298 java.lang.reflect.InvocationTargetException 299 { 300 super.restoreDefaultValue(); 301 accParent = BeanSupport.NO_VALUE; 302 } 303 public PropertyEditor getExpliciteEditor() { 304 return new AccessibleParentEditor(); 305 } 306 String getPartialSetterCode(String javaInitStr) { 307 return javaInitStr == null ? null : 308 "getAccessibleContext().setAccessibleParent(" + javaInitStr + ")"; } 311 } 312 }; 313 } 314 return properties; 315 } 316 317 private AccessibleContext getAccessibleContext() { 318 return ((Accessible)getBeanInstance()).getAccessibleContext(); 319 } 320 } 321 322 public static class AccessibleParentEditor extends ComponentChooserEditor { 323 public AccessibleParentEditor() { 324 super(); 325 setBeanTypes(new Class [] { Accessible.class }); 326 } 327 328 public String getDisplayName() { 329 return NbBundle.getBundle(getClass()).getString("CTL_AccessibleParentEditor_DisplayName"); } 331 } 332 } 333 | Popular Tags |