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; @SuppressWarnings("serial") public class DateLabelFormatter extends AbstractFormatter { 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()); } }