1 19 24 package org.openide.explorer.propertysheet; 25 26 import org.openide.util.*; 27 28 import java.awt.Component ; 29 import java.awt.Graphics ; 30 import java.awt.Rectangle ; 31 import java.awt.event.*; 32 33 import java.beans.*; 34 35 import java.util.ArrayList ; 36 import java.util.List ; 37 38 import javax.swing.*; 39 40 41 46 final class Boolean3WayEditor implements ExPropertyEditor, InplaceEditor.Factory { 47 Boolean v = null; 48 49 50 private transient List <PropertyChangeListener> propertyChangeListenerList; 51 private Boolean3Inplace renderer = null; 52 53 public Boolean3WayEditor() { 54 } 55 56 public String getAsText() { 57 if (v == null) { 58 return NbBundle.getMessage(Boolean3WayEditor.class, "CTL_Different_Values"); 59 } else if (Boolean.TRUE.equals(v)) { 60 return Boolean.TRUE.toString(); } else { 62 return Boolean.FALSE.toString(); } 64 } 65 66 public java.awt.Component getCustomEditor() { 67 return null; 68 } 69 70 public String getJavaInitializationString() { 71 if (v == null) { 72 return "null"; } else if (Boolean.TRUE.equals(v)) { 74 return "Boolean.TRUE"; } else { 76 return "Boolean.FALSE"; } 78 } 79 80 public String [] getTags() { 81 return null; 82 } 83 84 public Object getValue() { 85 return v; 86 } 87 88 public boolean isPaintable() { 89 return true; 90 } 91 92 public void paintValue(Graphics gfx, Rectangle box) { 93 if (renderer == null) { 94 renderer = new Boolean3Inplace(); 95 } 96 97 renderer.setSize(box.width, box.height); 98 renderer.doLayout(); 99 100 Graphics g = gfx.create(box.x, box.y, box.width, box.height); 101 renderer.setOpaque(false); 102 renderer.paint(g); 103 g.dispose(); 104 } 105 106 public void setAsText(String text) { 107 if (Boolean.TRUE.toString().compareToIgnoreCase(text) == 0) { 108 setValue(Boolean.TRUE); 109 } else { 110 setValue(Boolean.FALSE); 111 } 112 } 113 114 public void setValue(Object value) { 115 if (v != value) { 116 v = (Boolean ) value; 117 firePropertyChange(); 118 } 119 } 120 121 public boolean supportsCustomEditor() { 122 return false; 123 } 124 125 public void attachEnv(PropertyEnv env) { 126 env.registerInplaceEditorFactory(this); 127 } 128 129 133 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { 134 if (propertyChangeListenerList == null) { 135 propertyChangeListenerList = new java.util.ArrayList <PropertyChangeListener>(); 136 } 137 138 propertyChangeListenerList.add(listener); 139 } 140 141 145 public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { 146 if (propertyChangeListenerList != null) { 147 propertyChangeListenerList.remove(listener); 148 } 149 } 150 151 156 private void firePropertyChange() { 157 List list; 158 159 synchronized (this) { 160 if (propertyChangeListenerList == null) { 161 return; 162 } 163 164 list = (List ) ((ArrayList ) propertyChangeListenerList).clone(); 165 } 166 167 PropertyChangeEvent event = new PropertyChangeEvent(this, null, null, null); 168 169 for (int i = 0; i < list.size(); i++) { 170 ((PropertyChangeListener) list.get(i)).propertyChange(event); 171 } 172 } 173 174 178 public InplaceEditor getInplaceEditor() { 179 return new Boolean3Inplace(); 180 } 181 182 class Boolean3Inplace extends JCheckBox implements InplaceEditor { 183 private PropertyModel propertyModel = null; 184 185 Boolean3Inplace() { 186 setModel(new ButtonModel3Way()); 187 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 188 } 189 190 public String getText() { 191 return PropUtils.noCheckboxCaption ? "" : NbBundle.getMessage( 192 Boolean3WayEditor.class, "CTL_Different_Values" 193 ); } 195 196 public void clear() { 197 propertyModel = null; 198 } 199 200 public void connect(PropertyEditor pe, PropertyEnv env) { 201 } 203 204 public javax.swing.JComponent getComponent() { 205 return this; 206 } 207 208 public javax.swing.KeyStroke [] getKeyStrokes() { 209 return null; 210 } 211 212 public PropertyEditor getPropertyEditor() { 213 return Boolean3WayEditor.this; 214 } 215 216 public Object getValue() { 217 return Boolean3WayEditor.this.getValue(); 218 } 219 220 public void reset() { 221 } 223 224 public void setValue(Object o) { 225 } 227 228 public boolean supportsTextEntry() { 229 return false; 230 } 231 232 public void setPropertyModel(PropertyModel pm) { 233 propertyModel = pm; 234 } 235 236 public PropertyModel getPropertyModel() { 237 return propertyModel; 238 } 239 240 public boolean isKnownComponent(Component c) { 241 return false; 242 } 243 } 244 245 private class ButtonModel3Way extends DefaultButtonModel { 246 public boolean isPressed() { 247 return Boolean3WayEditor.this.v == null; 248 } 249 250 public boolean isArmed() { 251 return true; 252 } 253 254 public boolean isSelected() { 255 if (v == null) { 256 return true; 257 } 258 259 return super.isSelected(); 260 } 261 } 262 } 263 | Popular Tags |