001: /*
002: * This file is not part of the ItsNat framework.
003: *
004: * Original source code use and closed source derivatives are authorized
005: * to third parties with no restriction or fee.
006: * The original source code is owned by the author.
007: *
008: * This program is distributed AS IS in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
011: *
012: * Author: Jose Maria Arranz Santamaria
013: * (C) Innowhere Software Services S.L., Spanish company, year 2007
014: */
015:
016: package org.itsnat.feashow.features.components.text.fields;
017:
018: import javax.swing.event.DocumentEvent;
019: import javax.swing.event.DocumentListener;
020: import javax.swing.text.BadLocationException;
021: import javax.swing.text.PlainDocument;
022: import org.itsnat.comp.ItsNatComponentManager;
023: import org.itsnat.comp.html.ItsNatHTMLInputText;
024: import org.itsnat.core.ItsNatDocument;
025: import org.itsnat.core.event.KeyEvent;
026: import org.itsnat.feashow.FeatureTreeNode;
027: import org.w3c.dom.events.Event;
028: import org.w3c.dom.events.EventListener;
029:
030: public class InputTextKeyUpDownTreeNode extends FeatureTreeNode
031: implements EventListener, DocumentListener {
032: protected ItsNatHTMLInputText inputComp;
033:
034: public InputTextKeyUpDownTreeNode() {
035: }
036:
037: public void startExamplePanel() {
038: ItsNatDocument itsNatDoc = getItsNatDocument();
039: ItsNatComponentManager componentMgr = itsNatDoc
040: .getItsNatComponentManager();
041:
042: this .inputComp = (ItsNatHTMLInputText) componentMgr
043: .createItsNatComponentById("inputId");
044: inputComp.setText("Write any text, use SHIFT/ALT/CTRL too");
045:
046: inputComp.addEventListener("change", this );
047: inputComp.addEventListener("keyup", this );
048: inputComp.addEventListener("keydown", this );
049:
050: PlainDocument dataModel = (PlainDocument) inputComp
051: .getDocument();
052: dataModel.addDocumentListener(this );
053:
054: inputComp.focus();
055: inputComp.select();
056: }
057:
058: public void endExamplePanel() {
059: this .inputComp.dispose();
060: this .inputComp = null;
061: }
062:
063: public void handleEvent(Event evt) {
064: String type = evt.getType();
065: if (type.equals("change"))
066: log(evt.getClass() + " " + type);
067: else {
068: KeyEvent keyEvt = (KeyEvent) evt;
069: String msg = "";
070: msg += evt.getClass() + " " + type + " ";
071: msg += ", char code: " + keyEvt.getCharCode();
072: msg += ", key code: " + keyEvt.getKeyCode() + " ";
073: if (keyEvt.getShiftKey())
074: msg += " SHIFT";
075: if (keyEvt.getCtrlKey())
076: msg += " CTRL";
077: if (keyEvt.getAltKey())
078: msg += " ALT";
079:
080: msg += " text: " + inputComp.getText();
081:
082: log(msg);
083: }
084: }
085:
086: public void insertUpdate(DocumentEvent e) {
087: javax.swing.text.Document docModel = e.getDocument();
088: int offset = e.getOffset();
089: int len = e.getLength();
090:
091: try {
092: log(e.getClass() + " inserted, pos " + offset + "," + len
093: + " chars,\"" + docModel.getText(offset, len)
094: + "\"");
095: } catch (BadLocationException ex) {
096: throw new RuntimeException(ex);
097: }
098: }
099:
100: public void removeUpdate(DocumentEvent e) {
101: // javax.swing.text.Document docModel = e.getDocument();
102: int offset = e.getOffset();
103: int len = e.getLength();
104:
105: log(e.getClass() + " removed, pos " + offset + "," + len
106: + " chars");
107: }
108:
109: public void changedUpdate(DocumentEvent e) {
110: // A PlainDocument has no attributes
111: }
112: }
|