1 19 24 package org.openide.explorer.propertysheet; 25 26 import java.awt.Toolkit ; 27 import java.beans.PropertyChangeEvent ; 28 import java.beans.PropertyChangeListener ; 29 import javax.swing.JTextField ; 30 import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor; 31 import org.openide.nodes.Node.Property; 32 33 import java.beans.PropertyEditor ; 34 35 import javax.swing.BorderFactory ; 36 import javax.swing.JComponent ; 37 38 45 final class InplaceEditorFactory { 46 private InplaceEditor checkbox = null; 47 private InplaceEditor text = null; 48 private InplaceEditor combo = null; 49 private InplaceEditor radio = null; 50 private ReusablePropertyEnv reusableEnv; 51 private boolean tableUI; 52 int radioButtonMax = -1; 53 private boolean useLabels = false; 54 private boolean useRadioBoolean = PropUtils.forceRadioButtons; 55 56 InplaceEditorFactory(boolean tableUI, ReusablePropertyEnv env) { 57 this.tableUI = tableUI; 58 this.reusableEnv = env; 59 60 Toolkit.getDefaultToolkit().addPropertyChangeListener( "win.xpstyle.themeActive", new PropertyChangeListener () { public void propertyChange(PropertyChangeEvent evt) { 63 checkbox = null; 64 text = null; 65 combo = null; 66 radio = null; 67 } 68 }); 69 70 } 71 72 74 void setRadioButtonMax(int i) { 75 radioButtonMax = i; 76 } 77 78 80 void setUseLabels(boolean val) { 81 useLabels = val; 82 } 83 84 void setUseRadioBoolean(boolean val) { 85 useRadioBoolean = val; 86 } 87 88 89 private InplaceEditor getRadioEditor(boolean newInstance) { 90 RadioInplaceEditor result; 91 92 if (newInstance) { 93 result = new RadioInplaceEditor(tableUI); 94 } else { 95 if (radio == null) { 96 radio = new RadioInplaceEditor(tableUI); 97 98 ((JComponent ) radio).setName( 100 "RadioEditor for " + getClass().getName() + "@" + System.identityHashCode(this) 101 ); } 103 104 result = (RadioInplaceEditor) radio; 105 } 106 107 result.setUseTitle(useLabels); 108 109 return result; 110 } 111 112 113 private InplaceEditor getComboBoxEditor(boolean newInstance) { 114 if (newInstance) { 115 return new ComboInplaceEditor(tableUI); 116 } 117 118 if (combo == null) { 119 combo = new ComboInplaceEditor(tableUI); 120 121 ((JComponent ) combo).setName( 123 "ComboInplaceEditor for " + getClass().getName() + "@" + System.identityHashCode(this) 124 ); } 126 127 return combo; 128 } 129 130 131 private InplaceEditor getStringEditor(boolean newInstance) { 132 if (newInstance) { 133 return new StringInplaceEditor(); 134 } 135 136 if (text == null) { 137 text = new StringInplaceEditor(); 138 139 ((JComponent ) text).setName( 141 "StringEditor for " + getClass().getName() + "@" + System.identityHashCode(this) 142 ); } 144 145 return text; 146 } 147 148 149 private InplaceEditor getCheckboxEditor(boolean newInstance) { 150 CheckboxInplaceEditor result; 151 152 if (newInstance) { 153 result = new CheckboxInplaceEditor(); 154 } else { 155 if (checkbox == null) { 156 checkbox = new CheckboxInplaceEditor(); 157 158 ((JComponent ) checkbox).setName( 160 "CheckboxEditor for " + getClass().getName() + "@" + System.identityHashCode(this) 161 ); } 163 164 result = (CheckboxInplaceEditor) checkbox; 165 } 166 167 result.setUseTitle(useLabels); 168 169 return (InplaceEditor) result; 170 } 171 172 190 public InplaceEditor getInplaceEditor(Property p, boolean newInstance) { 191 PropertyEnv env = new PropertyEnv(); 192 env.setBeans(reusableEnv.getBeans()); 193 194 return getInplaceEditor(p, env, newInstance); 195 } 196 197 InplaceEditor getInplaceEditor(Property p, PropertyEnv env, boolean newInstance) { 198 PropertyEditor ped = PropUtils.getPropertyEditor(p); 199 InplaceEditor result = (InplaceEditor) p.getValue("inplaceEditor"); env.setFeatureDescriptor(p); 201 env.setEditable(p.canWrite()); 202 203 if (ped instanceof ExPropertyEditor) { 204 ExPropertyEditor epe = (ExPropertyEditor) ped; 205 206 epe.attachEnv(env); 208 209 if (result == null) { 210 result = env.getInplaceEditor(); 211 } 212 } else if (ped instanceof EnhancedPropertyEditor) { 213 EnhancedPropertyEditor enh = (EnhancedPropertyEditor) ped; 215 216 if (enh.hasInPlaceCustomEditor()) { 217 result = new WrapperInplaceEditor(enh); 219 } 220 } 221 222 if (result == null) { 224 Class c = p.getValueType(); 225 226 if ((c == Boolean .class) || (c == Boolean.TYPE)) { 227 if (ped instanceof PropUtils.NoPropertyEditorEditor) { 228 result = getStringEditor(newInstance); 230 } else { 231 boolean useRadioButtons = useRadioBoolean || (p.getValue("stringValues") != null); result = useRadioButtons ? getRadioEditor(newInstance) : getCheckboxEditor(newInstance); 233 } 234 } else if (ped.getTags() != null) { 235 if (ped.getTags().length <= radioButtonMax) { 236 result = getRadioEditor(newInstance); 237 } else { 238 result = getComboBoxEditor(newInstance); 239 } 240 } else { 241 result = getStringEditor(newInstance); 242 } 243 } 244 245 if (!tableUI && Boolean.FALSE.equals(p.getValue("canEditAsText"))) { result.getComponent().setEnabled(false); 247 } 248 249 result.clear(); result.setPropertyModel(new NodePropertyModel(p, env.getBeans())); 251 result.connect(ped, env); 252 253 if (tableUI) { 255 if( result instanceof JTextField ) 256 result.getComponent().setBorder(BorderFactory.createEmptyBorder(0,3,0,0)); 257 else 258 result.getComponent().setBorder(BorderFactory.createEmptyBorder()); 259 } 260 261 return result; 262 } 263 } 264 | Popular Tags |