SyncModesTreeNode.java :  » Ajax » ItsNat » org » itsnat » feashow » features » core » listeners » Java Open Source

Java Open Source » Ajax » ItsNat 
ItsNat » org » itsnat » feashow » features » core » listeners » SyncModesTreeNode.java
/*
 * This file is not part of the ItsNat framework.
 *
 * Original source code use and closed source derivatives are authorized
 * to third parties with no restriction or fee.
 * The original source code is owned by the author.
 *
 * This program is distributed AS IS in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Author: Jose Maria Arranz Santamaria
 * (C) Innowhere Software Services S.L., Spanish company, year 2007
 */

package org.itsnat.feashow.features.core.listeners;

import org.itsnat.core.ItsNatDocument;
import org.itsnat.core.SyncMode;
import org.itsnat.feashow.FeatureTreeNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;

public class SyncModesTreeNode extends FeatureTreeNode implements EventListener
{
    protected Element syncModeElem;
    protected Element asyncHoldModeElem;
    protected Element asyncModeElem;

    public SyncModesTreeNode()
    {
    }

    public void startExamplePanel()
    {
        ItsNatDocument itsNatDoc = getItsNatDocument();
        Document doc = itsNatDoc.getDocument();

        this.syncModeElem = doc.getElementById("syncModeId");
        this.asyncHoldModeElem = doc.getElementById("asyncHoldModeId");
        this.asyncModeElem = doc.getElementById("asyncModeId");

        itsNatDoc.addEventListener((EventTarget)syncModeElem,"click",this,false,SyncMode.SYNC);
        itsNatDoc.addEventListener((EventTarget)asyncHoldModeElem,"click",this,false,SyncMode.ASYNC_HOLD);
        itsNatDoc.addEventListener((EventTarget)asyncModeElem,"click",this,false,SyncMode.ASYNC);
    }

    public void endExamplePanel()
    {
        ItsNatDocument itsNatDoc = getItsNatDocument();
        itsNatDoc.removeEventListener((EventTarget)syncModeElem,"click",this,false);
        itsNatDoc.removeEventListener((EventTarget)asyncHoldModeElem,"click",this,false);
        itsNatDoc.removeEventListener((EventTarget)asyncModeElem,"click",this,false);

        this.syncModeElem = null;
        this.asyncHoldModeElem = null;
        this.asyncModeElem = null;
    }

    public void handleEvent(Event evt)
    {
        EventTarget currTarget = evt.getCurrentTarget();
        Thread currentThr = Thread.currentThread();
        try{ currentThr.sleep(1000); } catch(InterruptedException ex){ }

        String msg = "";
        if (currTarget == syncModeElem)
            msg = "SYNC";
        else if (currTarget == asyncHoldModeElem)
            msg = "ASYNC HOLD";
        else if (currTarget == asyncModeElem)
            msg = "ASYNC";

        log("Clicked : " + msg);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.