blob: 17efb0fafe5080628da4d7cc2b0f7d2dfd74c837 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package org.openslx.dozmod.util;
import java.text.ParseException;
import java.util.Calendar;
import javax.swing.JFormattedTextField.AbstractFormatter;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class DateLabelFormatter extends AbstractFormatter {
/**
* Version for serialization.
*/
private static final long serialVersionUID = -5278627382904881108L;
private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.yyyy");
@Override
public Object stringToValue(String text) throws ParseException {
try {
return formatter.parseDateTime(text);
} catch (Exception e) {
throw new ParseException(e.getMessage(), -1);
}
}
@Override
public String valueToString(Object value) throws ParseException {
if (value == null)
return "";
return formatter.print(((Calendar) value).getTimeInMillis());
}
}
|