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.ItsNatHTMLInputFile;
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 InputFileTreeNode extends FeatureTreeNode implements
29: EventListener, DocumentListener {
30: protected ItsNatHTMLInputFile inputComp;
31:
32: public InputFileTreeNode() {
33: }
34:
35: public void startExamplePanel() {
36: ItsNatDocument itsNatDoc = getItsNatDocument();
37: ItsNatComponentManager componentMgr = itsNatDoc
38: .getItsNatComponentManager();
39:
40: this .inputComp = (ItsNatHTMLInputFile) componentMgr
41: .createItsNatComponentById("inputId");
42:
43: // The HTML input file element value attribute/property can not be changed with JavaScript:
44: // is ignored in MSIE and throws an error with FireFox
45: // inputComp.setText("Change this text and lost the focus");
46:
47: inputComp.addEventListener("change", this );
48: PlainDocument dataModel = (PlainDocument) inputComp
49: .getDocument();
50: dataModel.addDocumentListener(this );
51:
52: inputComp.focus();
53: // inputComp.select(); No text to select (empty by default)
54: }
55:
56: public void endExamplePanel() {
57: this .inputComp.dispose();
58: this .inputComp = null;
59: }
60:
61: public void handleEvent(Event evt) {
62: log(evt.getCurrentTarget() + " " + evt.getType());
63: }
64:
65: public void insertUpdate(DocumentEvent e) {
66: javax.swing.text.Document docModel = e.getDocument();
67: int offset = e.getOffset();
68: int len = e.getLength();
69:
70: try {
71: log(e.getClass() + " inserted, pos " + offset + "," + len
72: + " chars,\"" + docModel.getText(offset, len)
73: + "\"");
74: } catch (BadLocationException ex) {
75: throw new RuntimeException(ex);
76: }
77: }
78:
79: public void removeUpdate(DocumentEvent e) {
80: // javax.swing.text.Document docModel = e.getDocument();
81: int offset = e.getOffset();
82: int len = e.getLength();
83:
84: log(e.getClass() + " removed, pos " + offset + "," + len
85: + " chars");
86: }
87:
88: public void changedUpdate(DocumentEvent e) {
89: // A PlainDocument has no attributes
90: }
91: }
|