|
Lines 34-65
Link Here
|
| 34 |
* |
34 |
* |
| 35 |
* @author teras |
35 |
* @author teras |
| 36 |
*/ |
36 |
*/ |
| 37 |
public class TimeFormatter extends MaskFormatter { |
|
|
| 38 |
private static Pattern pat; |
| 39 |
|
| 40 |
static { |
| 41 |
pat = Pattern.compile("(\\d+):(\\d+):(\\d+),(\\d\\d\\d)\\d*"); |
| 42 |
} |
| 43 |
|
| 44 |
public TimeFormatter () throws ParseException { |
| 45 |
super("##:##:##,###"); |
| 46 |
} |
| 47 |
|
| 48 |
public Object stringToValue(String text) throws ParseException { |
| 49 |
Matcher m = pat.matcher(text); |
| 50 |
if ( !m.matches()) { |
| 51 |
throw new ParseException("",0); |
| 52 |
} |
| 53 |
Time res = new Time(m.group(1), m.group(2), m.group(3), m.group(4)); |
| 54 |
return res; |
| 55 |
} |
| 56 |
|
| 57 |
public String valueToString(Object value) { |
| 58 |
return value.toString(); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
class TimeFormatterFactory extends JFormattedTextField.AbstractFormatterFactory { |
37 |
class TimeFormatterFactory extends JFormattedTextField.AbstractFormatterFactory { |
| 64 |
|
38 |
|
| 65 |
public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) { |
39 |
public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) { |