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.core.listeners;
17:
18: import org.itsnat.core.ItsNatDocument;
19: import org.itsnat.core.SyncMode;
20: import org.itsnat.feashow.FeatureTreeNode;
21: import org.w3c.dom.Document;
22: import org.w3c.dom.Element;
23: import org.w3c.dom.events.Event;
24: import org.w3c.dom.events.EventListener;
25: import org.w3c.dom.events.EventTarget;
26:
27: public class SyncModesTreeNode extends FeatureTreeNode implements
28: EventListener {
29: protected Element syncModeElem;
30: protected Element asyncHoldModeElem;
31: protected Element asyncModeElem;
32:
33: public SyncModesTreeNode() {
34: }
35:
36: public void startExamplePanel() {
37: ItsNatDocument itsNatDoc = getItsNatDocument();
38: Document doc = itsNatDoc.getDocument();
39:
40: this .syncModeElem = doc.getElementById("syncModeId");
41: this .asyncHoldModeElem = doc.getElementById("asyncHoldModeId");
42: this .asyncModeElem = doc.getElementById("asyncModeId");
43:
44: itsNatDoc.addEventListener((EventTarget) syncModeElem, "click",
45: this , false, SyncMode.SYNC);
46: itsNatDoc.addEventListener((EventTarget) asyncHoldModeElem,
47: "click", this , false, SyncMode.ASYNC_HOLD);
48: itsNatDoc.addEventListener((EventTarget) asyncModeElem,
49: "click", this , false, SyncMode.ASYNC);
50: }
51:
52: public void endExamplePanel() {
53: ItsNatDocument itsNatDoc = getItsNatDocument();
54: itsNatDoc.removeEventListener((EventTarget) syncModeElem,
55: "click", this , false);
56: itsNatDoc.removeEventListener((EventTarget) asyncHoldModeElem,
57: "click", this , false);
58: itsNatDoc.removeEventListener((EventTarget) asyncModeElem,
59: "click", this , false);
60:
61: this .syncModeElem = null;
62: this .asyncHoldModeElem = null;
63: this .asyncModeElem = null;
64: }
65:
66: public void handleEvent(Event evt) {
67: EventTarget currTarget = evt.getCurrentTarget();
68: Thread currentThr = Thread.currentThread();
69: try {
70: currentThr.sleep(1000);
71: } catch (InterruptedException ex) {
72: }
73:
74: String msg = "";
75: if (currTarget == syncModeElem)
76: msg = "SYNC";
77: else if (currTarget == asyncHoldModeElem)
78: msg = "ASYNC HOLD";
79: else if (currTarget == asyncModeElem)
80: msg = "ASYNC";
81:
82: log("Clicked : " + msg);
83: }
84:
85: }
|