import java.beans.*; import java.awt.*; import java.util.*; public class DateGUIEditor extends PropertyEditorSupport implements PropertyChangeListener { // the GUI that this *custom* editor uses protected DateGUI dateGUI; //------------------------------------------------------------------- // DateGUIEditor constructor //------------------------------------------------------------------- public DateGUIEditor() { dateGUI = new DateGUI(); dateGUI.addPropertyChangeListener(this); } //------------------------------------------------------------------- // overridden PropertyEditor interface methods //------------------------------------------------------------------- public void setValue(Object value) { // when a tool hands us the value we should manage, pass it on to GUI dateGUI.setDate((Date) value); } public Object getValue() { // when a tool asks us what our current value is, ask the GUI return dateGUI.getDate(); } public boolean supportsCustomEditor() { // yes we do ! return true; } public Component getCustomEditor() { return dateGUI; } public boolean isPaintable() { return true; } //------------------------------------------------------------------- // paintValue() is called inside the tool's paint() method to repaint // a property sheet window containing property values. //------------------------------------------------------------------- public void paintValue(Graphics g, Rectangle clipRect) { String fullDate, compactDate; g.clipRect (clipRect.x,clipRect.y,clipRect.width,clipRect.height); g.translate(clipRect.x,clipRect.y); fullDate = dateGUI.getDate().toString(); compactDate = fullDate.substring(4,11) + fullDate.substring(fullDate.length()-4); g.drawString(compactDate,2,14); } //------------------------------------------------------------------- // PropertyChangeListener interface implementation // Here we (the editor) receive notifications from the DateGUI that // the date has changed, so we pass this fact on to our own listener(s). //------------------------------------------------------------------- public void propertyChange(PropertyChangeEvent evt) { firePropertyChange(); } } // End of Class DateGUIEditor