Package org.itsnat.feashow.features.comp.labels

Source Code of org.itsnat.feashow.features.comp.labels.LabelTreeNode

/*
* 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.
*
* (C) Innowhere Software a service of Jose Maria Arranz Santamaria, Spanish citizen.
*/

package org.itsnat.feashow.features.comp.labels;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import org.itsnat.comp.ItsNatComponent;
import org.itsnat.comp.ItsNatHTMLComponentManager;
import org.itsnat.comp.button.toggle.ItsNatHTMLInputCheckBox;
import org.itsnat.comp.label.ItsNatHTMLLabel;
import org.itsnat.comp.label.ItsNatLabelEditor;
import org.itsnat.comp.list.ItsNatHTMLSelectComboBox;
import org.itsnat.comp.text.ItsNatHTMLInputText;
import org.itsnat.comp.text.ItsNatHTMLInputTextFormatted;
import org.itsnat.comp.text.ItsNatHTMLTextArea;
import org.itsnat.core.html.ItsNatHTMLDocument;
import org.itsnat.feashow.FeatureTreeNode;
import org.w3c.dom.Element;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;

public class LabelTreeNode extends FeatureTreeNode implements EventListener,PropertyChangeListener
{
    protected ItsNatHTMLInputCheckBox useSingleClickComp;
    protected ItsNatHTMLLabel[] compList = new ItsNatHTMLLabel[5];

    public LabelTreeNode()
    {
    }

    public void startExamplePanel()
    {
        ItsNatHTMLDocument itsNatDoc = (ItsNatHTMLDocument)getItsNatDocument();
        ItsNatHTMLComponentManager compMgr = itsNatDoc.getItsNatHTMLComponentManager();

        this.useSingleClickComp = (ItsNatHTMLInputCheckBox)compMgr.createItsNatComponentById("useSingleClickId");
        useSingleClickComp.addEventListener("click",this);

        try
        {
            ItsNatHTMLLabel comp;

            comp = (ItsNatHTMLLabel)compMgr.createItsNatComponentById("labelId1");
            comp.setValue("Any Text");
            ItsNatHTMLInputText textInput = compMgr.createItsNatHTMLInputText(null,null);
            shared(0,comp,textInput);

            comp = (ItsNatHTMLLabel)compMgr.createItsNatComponentById("labelId2");
            comp.setValue(Boolean.TRUE);
            ItsNatHTMLInputCheckBox checkBox = compMgr.createItsNatHTMLInputCheckBox(null,null);
            checkBox.getElement().setAttribute("style","width:20px;height:20px;");
            shared(1,comp,checkBox);

            comp = (ItsNatHTMLLabel)compMgr.createItsNatComponentById("labelId3");
            comp.setValue(new Integer(3));
            ItsNatHTMLSelectComboBox comboBox = compMgr.createItsNatHTMLSelectComboBox(null,null);
            DefaultComboBoxModel model = (DefaultComboBoxModel)comboBox.getComboBoxModel();
            for(int i=0; i < 5; i++) model.addElement(new Integer(i));
            shared(2,comp,comboBox);

            comp = (ItsNatHTMLLabel)compMgr.createItsNatComponentById("labelId4");
            comp.setValue(new Date());
            ItsNatHTMLInputTextFormatted textInputFormatted = compMgr.createItsNatHTMLInputTextFormatted(null,null);
            shared(3,comp,textInputFormatted);

            comp = (ItsNatHTMLLabel)compMgr.createItsNatComponentById("labelId5");
            comp.setValue("Any \n Text");
            ItsNatHTMLTextArea textArea = compMgr.createItsNatHTMLTextArea(null,null);
            shared(4,comp,textArea);
        }
        catch(PropertyVetoException ex)
        {
            throw new RuntimeException(ex);
        }

    }

    public void endExamplePanel()
    {
        useSingleClickComp.dispose();
        this.useSingleClickComp = null;

        for(int i = 0; i < compList.length; i++)
        {
            compList[i].dispose();
            compList[i] = null;
        }
    }

    public void shared(int i, ItsNatHTMLLabel comp,ItsNatComponent editorComp)
    {
        ItsNatHTMLDocument itsNatDoc = (ItsNatHTMLDocument)getItsNatDocument();
        ItsNatHTMLComponentManager compMgr = itsNatDoc.getItsNatHTMLComponentManager();
        ItsNatLabelEditor editor = compMgr.createDefaultItsNatLabelEditor(editorComp);
        comp.setItsNatLabelEditor(editor);
        comp.addEventListener("click",this);
        comp.addPropertyChangeListener("value",this);
        compList[i] = comp;
    }

    public void handleEvent(Event evt)
    {
        log(evt);
        if (evt.getCurrentTarget() == useSingleClickComp.getElement())
        {
            boolean sel = useSingleClickComp.isSelected();
            String eventType = sel? "click" : "dblclick";
            for(int i = 0; i < compList.length; i++)
                compList[i].setEditorActivatorEvent(eventType);
        }
    }

    public void propertyChange(PropertyChangeEvent evt)
    {
        log(evt.getClass() + ", old: " + evt.getOldValue() + ", new: " + evt.getNewValue());
    }
}
TOP

Related Classes of org.itsnat.feashow.features.comp.labels.LabelTreeNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.