1 package net.suberic.util.gui.propedit; 2 import net.suberic.util.*; 3 import javax.swing.*; 4 import java.awt.Dimension ; 5 import java.util.HashSet ; 6 import java.util.List ; 7 import java.util.LinkedList ; 8 import java.util.logging.Logger ; 9 import java.util.Set ; 10 11 14 public abstract class SwingPropertyEditor extends JPanel implements PropertyEditorUI { 15 protected boolean debug = false; 17 18 protected Set disableMaskSet = new HashSet (); 20 21 protected String property; 23 24 protected String editorTemplate; 26 27 protected String propertyBase; 29 30 protected String originalValue; 32 33 protected PropertyEditorManager manager; 35 36 protected static Logger sLogger = Logger.getLogger("editors.debug"); 38 39 44 public SwingPropertyEditor() { 45 super(); 46 this.setLayout(new java.awt.GridBagLayout ()); 47 } 48 49 60 public SwingPropertyEditor(String propertyName, String template, String baseProperty, PropertyEditorManager newManager) { 61 configureEditor(propertyName, template, baseProperty, newManager); 62 } 63 64 72 public SwingPropertyEditor(String propertyName, PropertyEditorManager newManager) { 73 configureEditor(propertyName, propertyName, newManager); 74 } 75 76 84 public void configureEditor(String propertyName, PropertyEditorManager newManager) { 85 configureEditor(propertyName, propertyName, newManager); 86 } 87 88 97 public void configureEditor(String propertyName, String template, PropertyEditorManager manager) { 98 configureEditor(propertyName, template, propertyName, manager); 99 } 100 101 104 public void configureBasic(String propertyName, String template, String propertyBaseName, PropertyEditorManager newManager) { 105 manager=newManager; 106 propertyBase=propertyBaseName; 107 editorTemplate = template; 108 115 property = propertyName; 116 addDefaultListeners(); 117 originalValue = manager.getProperty(property, manager.getProperty(editorTemplate, "")); 118 manager.registerPropertyEditor(property, this); 119 firePropertyInitializedEvent(originalValue); 120 121 } 122 123 126 public void addDisableMask(Object key) { 127 disableMaskSet.add(key); 128 updateEditorEnabled(); 129 } 130 131 134 public void removeDisableMask(Object key) { 135 disableMaskSet.remove(key); 136 updateEditorEnabled(); 137 } 138 139 142 public boolean isEditorEnabled() { 143 return disableMaskSet.isEmpty(); 144 } 145 146 149 protected abstract void updateEditorEnabled(); 150 151 154 public PropertyEditorManager getManager() { 155 return manager; 156 } 157 158 161 public void addPropertyEditorListener(PropertyEditorListener pel) { 162 manager.addPropertyEditorListener(getProperty(), pel); 163 } 164 165 168 public void removePropertyEditorListener(PropertyEditorListener pel) { 169 manager.removePropertyEditorListener(getProperty(), pel); 170 } 171 172 173 178 public void firePropertyChangingEvent(String newValue) throws PropertyValueVetoException { 179 manager.firePropertyChangingEvent(this, newValue); 180 } 181 182 185 public void firePropertyChangedEvent(String newValue) { 186 manager.firePropertyChangedEvent(this, newValue); 187 } 188 189 192 public void firePropertyCommittingEvent(String newValue) throws PropertyValueVetoException { 193 manager.firePropertyCommittingEvent(this, newValue); 194 } 195 196 199 public void firePropertyInitializedEvent(String newValue) { 200 manager.firePropertyInitializedEvent(this, newValue); 201 } 202 203 206 public abstract PropertyEditorPane getPropertyEditorPane(); 207 208 211 protected PropertyEditorPane getPropertyEditorPane(java.awt.Component component) { 212 try { 213 Class pepClass = Class.forName("net.suberic.util.gui.propedit.PropertyEditorPane"); 214 if (pepClass != null) { 215 PropertyEditorPane pep = (PropertyEditorPane) SwingUtilities.getAncestorOfClass(pepClass, component); 216 return pep; 217 } 218 } catch (Exception e) { 219 } 220 221 return null; 222 } 223 224 227 public void addDefaultListeners() { 228 List propertyListenerList = manager.getPropertyAsList(editorTemplate + "._listeners", ""); 229 java.util.Iterator it = propertyListenerList.iterator(); 230 while (it.hasNext()) { 231 String current = (String )it.next(); 232 PropertyEditorListener pel = manager.createListener(current, property, propertyBase, editorTemplate); 233 if (pel != null) { 234 addPropertyEditorListener(pel); 235 } 236 } 237 } 238 239 242 public String getProperty() { 243 return property; 244 } 245 246 249 public void setOriginalValue(String pOriginalValue) { 250 originalValue = pOriginalValue; 251 } 252 253 256 public String getEditorTemplate() { 257 return editorTemplate; 258 } 259 260 263 public String getHelpID() { 264 return getEditorTemplate(); 265 } 266 267 271 public Logger getLogger() { 272 return sLogger; 273 } 274 275 278 public void remove() { 279 manager.removePropertyEditorListeners(getProperty()); 280 } 281 282 285 public boolean acceptDefaultFocus() { 286 return false; 287 } 288 } 289 | Popular Tags |