01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.comp;
15:
16: import java.text.Format;
17: import java.util.Date;
18: import org.itsnat.comp.ItsNatFormattedTextField;
19: import org.itsnat.comp.ItsNatFormattedTextField.ItsNatFormatter;
20: import org.itsnat.comp.ItsNatFormatterFactoryDefault;
21:
22: /**
23: *
24: * @author jmarranz
25: */
26: public class ItsNatFormatterFactoryDefaultImpl implements
27: ItsNatFormatterFactoryDefault {
28: protected ItsNatFormatter defaultFormat;
29: protected ItsNatFormatter displayFormat;
30: protected ItsNatFormatter editFormat;
31: protected ItsNatFormatter nullFormat;
32:
33: /**
34: * Creates a new instance of ItsNatFormatterFactoryDefaultImpl
35: */
36: public ItsNatFormatterFactoryDefaultImpl() {
37: }
38:
39: public void setDefaultFormatter(ItsNatFormatter atf) {
40: defaultFormat = atf;
41: }
42:
43: public ItsNatFormatter getDefaultFormatter() {
44: return defaultFormat;
45: }
46:
47: public void setDisplayFormatter(ItsNatFormatter atf) {
48: displayFormat = atf;
49: }
50:
51: public ItsNatFormatter getDisplayFormatter() {
52: return displayFormat;
53: }
54:
55: public void setEditFormatter(ItsNatFormatter atf) {
56: editFormat = atf;
57: }
58:
59: public ItsNatFormatter getEditFormatter() {
60: return editFormat;
61: }
62:
63: public void setNullFormatter(ItsNatFormatter atf) {
64: nullFormat = atf;
65: }
66:
67: public ItsNatFormatter getNullFormatter() {
68: return nullFormat;
69: }
70:
71: public ItsNatFormatter getItsNatFormatter(
72: ItsNatFormattedTextField comp) {
73: ItsNatFormatter formatter = null;
74:
75: if (comp == null)
76: return null;
77:
78: Object value = comp.getValue();
79:
80: if (value == null)
81: formatter = getNullFormatter();
82:
83: if (formatter == null) {
84: if (comp.hasFocus())
85: formatter = getEditFormatter();
86: else
87: formatter = getDisplayFormatter();
88:
89: if (formatter == null) {
90: formatter = getDefaultFormatter();
91: }
92: }
93:
94: return formatter; // Puede ser null
95: }
96:
97: }
|