1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import java.awt.Dimension ; 22 import java.text.ParsePosition ; 23 import org.objectweb.jac.aspects.gui.FieldEditor; 24 import org.objectweb.jac.aspects.gui.Format; 25 import org.objectweb.jac.core.rtti.FieldItem; 26 import org.objectweb.jac.util.WrappedThrowableException; 27 28 public abstract class FormatEditor extends TextFieldEditor 29 implements FieldEditor 30 { 31 32 protected Format format; 33 34 36 37 public FormatEditor(Object substance, FieldItem field) { 38 super(substance,field); 39 textField = new JTextField(10); 40 textField.addFocusListener(this); 41 add(textField); 42 initFormat(field); 43 } 44 45 protected abstract void initFormat(FieldItem field); 46 47 public void setField(FieldItem field) { 48 super.setField(field); 49 initFormat(field); 50 } 51 52 public Object getValue() { 53 try { 54 if (textField.getText().equals("")) { 55 return null; 56 } else { 57 return parse(textField.getText()); 58 } 59 } catch (Exception e) { 60 throw new WrappedThrowableException(e); 61 } 62 } 63 64 protected Object parse(String s) { 65 ParsePosition pos = new ParsePosition (0); 66 return format.parse(s,pos); 67 } 68 69 public void setValue(Object value) { 70 super.setValue(value); 71 if( value != null ) 72 textField.setText(format.format(value)); 73 } 74 } 75 | Popular Tags |