KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > format > support > AbstractFormatterFactory


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.binding.format.support;
17
18 import java.util.Locale JavaDoc;
19
20 import org.springframework.binding.format.Formatter;
21 import org.springframework.binding.format.FormatterFactory;
22 import org.springframework.binding.format.Style;
23 import org.springframework.context.i18n.LocaleContext;
24 import org.springframework.context.i18n.SimpleLocaleContext;
25
26 /**
27  * Base class for formatter factories.
28  *
29  * @author Keith Donald
30  */

31 public abstract class AbstractFormatterFactory implements FormatterFactory {
32
33     private LocaleContext localeContext = new SimpleLocaleContext(Locale.getDefault());
34
35     private Style defaultDateStyle = Style.MEDIUM;
36
37     private Style defaultTimeStyle = Style.MEDIUM;
38
39     public void setLocaleContext(LocaleContext localeContext) {
40         this.localeContext = localeContext;
41     }
42
43     public void setDefaultDateStyle(Style defaultDateStyle) {
44         this.defaultDateStyle = defaultDateStyle;
45     }
46
47     public void setDefaultTimeStyle(Style defaultTimeStyle) {
48         this.defaultTimeStyle = defaultTimeStyle;
49     }
50
51     protected Style getDefaultDateStyle() {
52         return defaultDateStyle;
53     }
54
55     protected Style getDefaultTimeStyle() {
56         return defaultTimeStyle;
57     }
58
59     protected Locale JavaDoc getLocale() {
60         return localeContext.getLocale();
61     }
62
63     public Formatter getDateFormatter() {
64         return getDateFormatter(getDefaultDateStyle());
65     }
66
67     public Formatter getDateTimeFormatter() {
68         return getDateTimeFormatter(getDefaultDateStyle(), getDefaultTimeStyle());
69     }
70
71     public Formatter getTimeFormatter() {
72         return getTimeFormatter(getDefaultTimeStyle());
73     }
74 }
Popular Tags