|
|
* | * |
* @author teras | * @author teras |
*/ | */ |
public class TimeFormatter extends MaskFormatter { |
|
private static Pattern pat; |
|
|
|
static { |
|
pat = Pattern.compile("(\\d+):(\\d+):(\\d+),(\\d\\d\\d)\\d*"); |
|
} |
|
|
|
public TimeFormatter () throws ParseException { |
|
super("##:##:##,###"); |
|
} |
|
|
|
public Object stringToValue(String text) throws ParseException { |
|
Matcher m = pat.matcher(text); |
|
if ( !m.matches()) { |
|
throw new ParseException("",0); |
|
} |
|
Time res = new Time(m.group(1), m.group(2), m.group(3), m.group(4)); |
|
return res; |
|
} |
|
|
|
public String valueToString(Object value) { |
|
return value.toString(); |
|
} |
|
} |
|
|
|
|
|
class TimeFormatterFactory extends JFormattedTextField.AbstractFormatterFactory { | class TimeFormatterFactory extends JFormattedTextField.AbstractFormatterFactory { |
| |
public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) { | public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) { |