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.ItsNatHTMLAnchor;
024: import org.itsnat.comp.html.ItsNatHTMLInputHidden;
025: import org.itsnat.core.ItsNatDocument;
026: import org.itsnat.feashow.FeatureTreeNode;
027: import org.w3c.dom.events.Event;
028: import org.w3c.dom.events.EventListener;
029:
030: public class InputHiddenTreeNode extends FeatureTreeNode implements
031: EventListener, DocumentListener {
032: protected ItsNatHTMLInputHidden inputComp;
033: protected ItsNatHTMLAnchor linkComp;
034:
035: public InputHiddenTreeNode() {
036: }
037:
038: public void startExamplePanel() {
039: ItsNatDocument itsNatDoc = getItsNatDocument();
040: ItsNatComponentManager componentMgr = itsNatDoc
041: .getItsNatComponentManager();
042:
043: this .inputComp = (ItsNatHTMLInputHidden) componentMgr
044: .createItsNatComponentById("inputId");
045: inputComp.setText("Initial Hidden Value");
046:
047: PlainDocument dataModel = (PlainDocument) inputComp
048: .getDocument();
049: dataModel.addDocumentListener(this );
050:
051: this .linkComp = (ItsNatHTMLAnchor) componentMgr
052: .createItsNatComponentById("linkId");
053: linkComp.addEventListener("click", this );
054: }
055:
056: public void endExamplePanel() {
057: this .inputComp.dispose();
058: this .inputComp = null;
059:
060: this .linkComp.dispose();
061: this .linkComp = null;
062: }
063:
064: public void handleEvent(Event evt) {
065: log(evt.getCurrentTarget() + " " + evt.getType());
066:
067: ItsNatDocument itsNatDoc = getItsNatDocument();
068: String code = "";
069: code += "var input = document.getElementById('inputId');\n";
070: code += "alert('Old hidden value: ' + input.value);\n";
071: itsNatDoc.addCodeToSend(code);
072:
073: inputComp.setText("A New Hidden Value");
074:
075: itsNatDoc
076: .addCodeToSend("alert('New hidden value: ' + input.value);\n");
077: }
078:
079: public void insertUpdate(DocumentEvent e) {
080: javax.swing.text.Document docModel = e.getDocument();
081: int offset = e.getOffset();
082: int len = e.getLength();
083:
084: try {
085: log(e.getClass() + " inserted, pos " + offset + "," + len
086: + " chars,\"" + docModel.getText(offset, len)
087: + "\"");
088: } catch (BadLocationException ex) {
089: throw new RuntimeException(ex);
090: }
091: }
092:
093: public void removeUpdate(DocumentEvent e) {
094: // javax.swing.text.Document docModel = e.getDocument();
095: int offset = e.getOffset();
096: int len = e.getLength();
097:
098: log(e.getClass() + " removed, pos " + offset + "," + len
099: + " chars");
100: }
101:
102: public void changedUpdate(DocumentEvent e) {
103: // A PlainDocument has no attributes
104: }
105: }
|