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: package org.itsnat.feashow.features.components.text.fields;
16:
17: import javax.swing.event.DocumentEvent;
18: import javax.swing.event.DocumentListener;
19: import javax.swing.text.BadLocationException;
20: import javax.swing.text.PlainDocument;
21: import org.itsnat.comp.ItsNatComponentManager;
22: import org.itsnat.comp.html.ItsNatHTMLInputText;
23: import org.itsnat.core.ItsNatDocument;
24: import org.itsnat.feashow.FeatureTreeNode;
25: import org.w3c.dom.events.Event;
26: import org.w3c.dom.events.EventListener;
27:
28: public class InputTextTreeNode extends FeatureTreeNode implements
29: EventListener, DocumentListener {
30: protected ItsNatHTMLInputText inputComp;
31:
32: public InputTextTreeNode() {
33: }
34:
35: public void startExamplePanel() {
36: ItsNatDocument itsNatDoc = getItsNatDocument();
37: ItsNatComponentManager componentMgr = itsNatDoc
38: .getItsNatComponentManager();
39:
40: this .inputComp = (ItsNatHTMLInputText) componentMgr
41: .createItsNatComponentById("inputId");
42: inputComp.setText("Change this text and lost the focus");
43:
44: inputComp.addEventListener("change", this );
45:
46: PlainDocument dataModel = (PlainDocument) inputComp
47: .getDocument();
48: dataModel.addDocumentListener(this );
49:
50: inputComp.focus();
51: inputComp.select();
52: }
53:
54: public void endExamplePanel() {
55: this .inputComp.dispose();
56: this .inputComp = null;
57: }
58:
59: public void handleEvent(Event evt) {
60: log(evt.getCurrentTarget() + " " + evt.getType() + " "
61: + inputComp.getHTMLInputElement().getValue());
62: }
63:
64: public void insertUpdate(DocumentEvent e) {
65: javax.swing.text.Document docModel = e.getDocument();
66: int offset = e.getOffset();
67: int len = e.getLength();
68:
69: try {
70: log(e.getClass() + " inserted, pos " + offset + "," + len
71: + " chars,\"" + docModel.getText(offset, len)
72: + "\"");
73: } catch (BadLocationException ex) {
74: throw new RuntimeException(ex);
75: }
76: }
77:
78: public void removeUpdate(DocumentEvent e) {
79: // javax.swing.text.Document docModel = e.getDocument();
80: int offset = e.getOffset();
81: int len = e.getLength();
82:
83: log(e.getClass() + " removed, pos " + offset + "," + len
84: + " chars");
85: }
86:
87: public void changedUpdate(DocumentEvent e) {
88: // A PlainDocument has no attributes
89: }
90: }
|