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.components.buttons.toggle;
17:
18: import java.awt.event.ActionEvent;
19: import java.awt.event.ActionListener;
20: import java.awt.event.ItemEvent;
21: import java.awt.event.ItemListener;
22: import javax.swing.ButtonModel;
23: import javax.swing.JToggleButton.ToggleButtonModel;
24: import javax.swing.event.ChangeEvent;
25: import javax.swing.event.ChangeListener;
26: import org.itsnat.comp.ItsNatComponentManager;
27: import org.itsnat.comp.html.ItsNatHTMLInputCheckBox;
28: import org.itsnat.core.ItsNatDocument;
29: import org.itsnat.feashow.FeatureTreeNode;
30: import org.w3c.dom.events.Event;
31: import org.w3c.dom.events.EventListener;
32:
33: public class InputCheckBoxTreeNode extends FeatureTreeNode implements
34: EventListener, ChangeListener, ItemListener {
35: protected ItsNatHTMLInputCheckBox inputComp;
36: protected boolean selected;
37:
38: public InputCheckBoxTreeNode() {
39: }
40:
41: public void startExamplePanel() {
42: this .selected = false;
43:
44: ItsNatDocument itsNatDoc = getItsNatDocument();
45: ItsNatComponentManager componentMgr = itsNatDoc
46: .getItsNatComponentManager();
47:
48: this .inputComp = (ItsNatHTMLInputCheckBox) componentMgr
49: .createItsNatComponentById("inputId");
50: inputComp.addEventListener("click", this );
51:
52: ToggleButtonModel dataModel = inputComp.getToggleButtonModel();
53: dataModel.addChangeListener(this );
54: dataModel.addItemListener(this );
55: }
56:
57: public void endExamplePanel() {
58: this .inputComp.dispose();
59: this .inputComp = null;
60: }
61:
62: public void handleEvent(Event evt) {
63: log(evt.getCurrentTarget() + " " + evt.getType());
64: }
65:
66: public void stateChanged(ChangeEvent e) {
67: // This event is generated when ButtonModel is changed (armed, pressed etc).
68: // the selection state change is detected only
69: ButtonModel model = (ButtonModel) e.getSource();
70:
71: String fact = "";
72: if (model.isSelected() && !selected) {
73: selected = true;
74: fact = "selected ";
75: } else if (!model.isSelected() && selected) {
76: selected = false;
77: fact = "deselected ";
78: }
79:
80: if (!fact.equals("")) {
81: log(e.getClass().toString() + " " + fact + " ");
82: }
83: }
84:
85: public void itemStateChanged(ItemEvent e) {
86: String fact;
87: int state = e.getStateChange();
88: if (state == ItemEvent.SELECTED)
89: fact = "selected";
90: else
91: fact = "deselected";
92:
93: log(e.getClass().toString() + " " + fact);
94: }
95:
96: }
|