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.buttons.toggle;
017:
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020: import java.awt.event.ItemEvent;
021: import java.awt.event.ItemListener;
022: import javax.swing.ButtonGroup;
023: import javax.swing.JToggleButton.ToggleButtonModel;
024: import org.itsnat.comp.ItsNatButtonGroup;
025: import org.itsnat.comp.ItsNatComponentManager;
026: import org.itsnat.comp.html.ItsNatHTMLInputRadio;
027: import org.itsnat.core.ItsNatDocument;
028: import org.itsnat.feashow.FeatureTreeNode;
029: import org.w3c.dom.events.Event;
030: import org.w3c.dom.events.EventListener;
031: import org.w3c.dom.events.EventTarget;
032:
033: public class InputRadioButtonTreeNode extends FeatureTreeNode implements
034: EventListener, ActionListener, ItemListener {
035: protected ItsNatHTMLInputRadio inputComp1;
036: protected ItsNatHTMLInputRadio inputComp2;
037:
038: public InputRadioButtonTreeNode() {
039: }
040:
041: public void startExamplePanel() {
042: ItsNatDocument itsNatDoc = getItsNatDocument();
043: ItsNatComponentManager componentMgr = itsNatDoc
044: .getItsNatComponentManager();
045:
046: this .inputComp1 = (ItsNatHTMLInputRadio) componentMgr
047: .createItsNatComponentById("inputId1");
048: inputComp1.addEventListener("click", this );
049:
050: this .inputComp2 = (ItsNatHTMLInputRadio) componentMgr
051: .createItsNatComponentById("inputId2");
052: inputComp2.addEventListener("click", this );
053:
054: ItsNatButtonGroup itsNatGrp1 = inputComp1
055: .getItsNatButtonGroup();
056: ItsNatButtonGroup itsNatGrp2 = inputComp2
057: .getItsNatButtonGroup();
058: if (((itsNatGrp1 == null) || (itsNatGrp2 == null))
059: || (itsNatGrp1.getButtonGroup() != itsNatGrp2
060: .getButtonGroup())) {
061: ButtonGroup group = new ButtonGroup();
062: ItsNatButtonGroup htmlGroup = componentMgr
063: .getItsNatButtonGroup(group);
064: htmlGroup.addButton(inputComp1);
065: htmlGroup.addButton(inputComp2);
066: }
067:
068: ToggleButtonModel dataModel1 = inputComp1
069: .getToggleButtonModel();
070: dataModel1.addActionListener(this );
071: dataModel1.addItemListener(this );
072:
073: ToggleButtonModel dataModel2 = inputComp2
074: .getToggleButtonModel();
075: dataModel2.addActionListener(this );
076: dataModel2.addItemListener(this );
077: }
078:
079: public void endExamplePanel() {
080: this .inputComp1.dispose();
081: this .inputComp1 = null;
082:
083: this .inputComp2.dispose();
084: this .inputComp2 = null;
085: }
086:
087: public void handleEvent(Event evt) {
088: EventTarget currentTarget = evt.getCurrentTarget();
089: String button;
090: if (currentTarget == inputComp1.getHTMLInputElement())
091: button = "button 1";
092: else
093: button = "button 2";
094:
095: log(evt.getCurrentTarget() + " " + evt.getType() + " " + button);
096: }
097:
098: public void actionPerformed(ActionEvent e) {
099: String button;
100: if (e.getSource() == inputComp1.getToggleButtonModel())
101: button = "button 1";
102: else
103: button = "button 2";
104:
105: log(e.getClass().toString() + " " + button);
106: }
107:
108: public void itemStateChanged(ItemEvent e) {
109: String fact;
110: int state = e.getStateChange();
111: if (state == ItemEvent.SELECTED)
112: fact = "selected";
113: else
114: fact = "deselected";
115:
116: if (e.getItem() == inputComp1.getToggleButtonModel())
117: fact += " 1";
118: else
119: fact += " 2";
120:
121: log(e.getClass().toString() + " " + fact);
122: }
123:
124: }
|