View Javadoc
1 package xdoclet.gui.swing; 2 3 import org.apache.commons.logging.LogFactory; 4 5 import javax.swing.JTextField; 6 import javax.swing.event.DocumentListener; 7 import javax.swing.event.DocumentEvent; 8 9 import java.beans.*; 10 11 /*** 12 * Support for a PropertyEditor that uses text. 13 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a> 14 * @version $Revision: 1.6 $ 15 */ 16 class PropertyText extends JTextField implements DocumentListener, PropertyChangeListener { 17 private final PropertyEditor _propertyEditor; 18 private final PropertyDescriptor _propertyDescriptor; 19 private final Object _bean; 20 21 PropertyText(PropertyEditor propertyEditor, PropertyDescriptor propertyDescriptor, Object bean ) { 22 super(); 23 _propertyEditor = propertyEditor; 24 _propertyDescriptor = propertyDescriptor; 25 _bean = bean; 26 27 setText(_propertyEditor.getValue() != null ? _propertyEditor.getAsText() : ""); 28 29 getDocument().addDocumentListener(this); 30 _propertyEditor.addPropertyChangeListener(this); 31 updateEditor(); 32 } 33 34 protected void updateEditor() { 35 try { 36 _propertyEditor.setAsText(getText()); 37 } catch (IllegalArgumentException e) { 38 LogFactory.getLog(PropertyText.class).error("Couldn't set new value", e); 39 } 40 } 41 42 public void propertyChange(PropertyChangeEvent evt) { 43 // Set the new value 44 try { 45 // Get the source. Should be "our" Property editor. 46 // The event will always contain null as the newValue :-( 47 PropertyEditor propertyEditor = (PropertyEditor) evt.getSource(); 48 String newValue = propertyEditor.getAsText(); 49 _propertyDescriptor.getWriteMethod().invoke( _bean, new Object[] {newValue} ); 50 } catch (Exception e) { 51 LogFactory.getLog(PropertyText.class).error("Couldn't set new value", e); 52 throw new IllegalStateException(e.getMessage()); 53 } 54 } 55 56 public void insertUpdate(DocumentEvent e) { 57 updateEditor(); 58 } 59 60 public void removeUpdate(DocumentEvent e) { 61 updateEditor(); 62 } 63 64 public void changedUpdate(DocumentEvent e) { 65 updateEditor(); 66 } 67 }

This page was automatically generated by Maven