01: /*
02: * This file is not part of the ItsNat framework.
03: *
04: * Original source code use and closed source derivatives are authorized
05: * to third parties with no restriction or fee.
06: * The original source code is owned by the author.
07: *
08: * This program is distributed AS IS in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * Author: Jose Maria Arranz Santamaria
13: * (C) Innowhere Software Services S.L., Spanish company, year 2007
14: */
15:
16: package org.itsnat.feashow.features.components.text.fields;
17:
18: import java.beans.PropertyChangeEvent;
19: import java.beans.PropertyChangeListener;
20: import java.beans.PropertyVetoException;
21: import java.beans.VetoableChangeListener;
22: import java.text.DateFormat;
23: import java.util.Date;
24: import java.util.Locale;
25: import org.itsnat.comp.ItsNatComponentManager;
26: import org.itsnat.comp.ItsNatFormattedTextField.ItsNatFormatter;
27: import org.itsnat.comp.ItsNatFormatterFactoryDefault;
28: import org.itsnat.comp.html.ItsNatHTMLInputTextFormatted;
29: import org.itsnat.core.ItsNatDocument;
30: import org.itsnat.feashow.FeatureTreeNode;
31:
32: public class InputTextFormattedWithFactoryTreeNode extends
33: FeatureTreeNode implements PropertyChangeListener,
34: VetoableChangeListener {
35: protected ItsNatHTMLInputTextFormatted inputComp;
36:
37: public InputTextFormattedWithFactoryTreeNode() {
38: }
39:
40: public void startExamplePanel() {
41: ItsNatDocument itsNatDoc = getItsNatDocument();
42: ItsNatComponentManager componentMgr = itsNatDoc
43: .getItsNatComponentManager();
44:
45: this .inputComp = (ItsNatHTMLInputTextFormatted) componentMgr
46: .createItsNatComponentById("inputId",
47: "formattedTextField", null);
48:
49: ItsNatFormatterFactoryDefault factory = (ItsNatFormatterFactoryDefault) inputComp
50: .createDefaultItsNatFormatterFactory();
51:
52: ItsNatFormatter dispFormatter = inputComp
53: .createItsNatFormatter(DateFormat.getDateInstance(
54: DateFormat.LONG, Locale.US));
55: factory.setDisplayFormatter(dispFormatter);
56: ItsNatFormatter editFormatter = inputComp
57: .createItsNatFormatter(DateFormat.getDateInstance(
58: DateFormat.SHORT, Locale.US));
59: factory.setEditFormatter(editFormatter);
60:
61: inputComp.setItsNatFormatterFactory(factory);
62:
63: try {
64: inputComp.setValue(new Date());
65: } catch (PropertyVetoException ex) {
66: throw new RuntimeException(ex);
67: }
68:
69: inputComp.addPropertyChangeListener("value", this );
70:
71: inputComp.addVetoableChangeListener(this );
72: }
73:
74: public void endExamplePanel() {
75: this .inputComp.dispose();
76: this .inputComp = null;
77: }
78:
79: public void propertyChange(PropertyChangeEvent evt) {
80: Date value = (Date) evt.getNewValue();
81:
82: log("Value changed to: " + value + " ");
83: }
84:
85: public void vetoableChange(PropertyChangeEvent evt)
86: throws PropertyVetoException {
87: Date newDate = (Date) evt.getNewValue();
88: if (newDate.compareTo(new Date()) > 0)
89: throw new PropertyVetoException(
90: "Future date is not allowed", evt);
91: }
92: }
|