Revision 270 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/spinner/DateTextFieldFormatter.java

View differences:

DateTextFieldFormatter.java
10 10

  
11 11
public class DateTextFieldFormatter extends AbstractFormatter {
12 12

  
13
	private DateFormat df;
14
	private int dynType;
15
	private Locale loc;
13
    private DateFormat df;
14
    private int dynType;
15
    private Locale loc;
16 16

  
17
	public DateTextFieldFormatter(int dynType, Locale loc) {
18
		super();
19
		this.dynType = dynType;
20
		this.loc = loc;
21
	}
22
	private DateFormat getDateFormat(){
23
		if (df==null){
24
			df = new DateFormatter(loc).getDynFieldDateFormatter(dynType);
25
		}
26
		return df;
27
	}
17
    public DateTextFieldFormatter(int dynType, Locale loc) {
18
        super();
19
        this.dynType = dynType;
20
        this.loc = loc;
21
    }
28 22

  
29
	@Override
30
	public Object stringToValue(String text) throws ParseException {
31
		if ((text==null)||(text.equals("")))
32
			return null;
33
		return getDateFormat().parse(text);
34
	}
23
    private DateFormat getDateFormat() {
24
        if (df == null) {
25
            df = new DateFormatter(loc).getDynFieldDateFormatter(dynType);
26
        }
27
        return df;
28
    }
35 29

  
36
	@Override
37
	public String valueToString(Object value) throws ParseException {
38
		if (value == null)
39
			return "";
40
		return getDateFormat().format(value);
41
	}
30
    @Override
31
    public Object stringToValue(String text) throws ParseException {
32
        if ((text == null) || (text.equals("")))
33
            return null;
34
        return getDateFormat().parse(text);
35
    }
42 36

  
37
    @Override
38
    public String valueToString(Object value) throws ParseException {
39
        if (value == null)
40
            return "";
41
        return getDateFormat().format(value);
42
    }
43

  
43 44
}

Also available in: Unified diff