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.ItemEvent;
019: import java.awt.event.ItemListener;
020: import javax.swing.ButtonModel;
021: import javax.swing.JToggleButton.ToggleButtonModel;
022: import javax.swing.event.ChangeEvent;
023: import javax.swing.event.ChangeListener;
024: import org.itsnat.comp.ItsNatComponentManager;
025: import org.itsnat.comp.free.ItsNatFreeCheckBox;
026: import org.itsnat.core.ItsNatDocument;
027: import org.itsnat.feashow.FeatureTreeNode;
028: import org.w3c.dom.Element;
029: import org.w3c.dom.events.Event;
030: import org.w3c.dom.events.EventListener;
031:
032: public class FreeCheckBoxTreeNode extends FeatureTreeNode implements
033: EventListener, ChangeListener, ItemListener {
034: protected ItsNatFreeCheckBox buttonComp;
035: protected boolean selected;
036:
037: public FreeCheckBoxTreeNode() {
038: }
039:
040: public void startExamplePanel() {
041: this .selected = false;
042:
043: ItsNatDocument itsNatDoc = getItsNatDocument();
044: ItsNatComponentManager componentMgr = itsNatDoc
045: .getItsNatComponentManager();
046:
047: this .buttonComp = (ItsNatFreeCheckBox) componentMgr
048: .createItsNatComponentById("buttonId", "freeCheckBox",
049: null);
050: buttonComp.addEventListener("click", this );
051:
052: ToggleButtonModel dataModel = buttonComp.getToggleButtonModel();
053: dataModel.addChangeListener(this );
054: dataModel.addItemListener(this );
055: }
056:
057: public void endExamplePanel() {
058: this .buttonComp.dispose();
059: this .buttonComp = null;
060: }
061:
062: public void handleEvent(Event evt) {
063: log(evt.getCurrentTarget() + " " + evt.getType());
064: }
065:
066: public void stateChanged(ChangeEvent e) {
067: // This event is generated when ButtonModel is changed (armed, pressed etc).
068: // the selection state change is detected only
069: ButtonModel model = (ButtonModel) e.getSource();
070:
071: String fact = "";
072: if (model.isSelected() && !selected) {
073: selected = true;
074: fact = "selected ";
075: } else if (!model.isSelected() && selected) {
076: selected = false;
077: fact = "deselected ";
078: }
079:
080: if (!fact.equals("")) {
081: log(e.getClass().toString() + " " + fact + " ");
082: }
083: }
084:
085: public void itemStateChanged(ItemEvent e) {
086: String fact;
087: int state = e.getStateChange();
088: if (state == ItemEvent.SELECTED)
089: fact = "selected";
090: else
091: fact = "deselected";
092:
093: log(e.getClass().toString() + " " + fact + " ");
094:
095: updateDecoration();
096: }
097:
098: public void updateDecoration() {
099: Element buttonElem = buttonComp.getElement();
100: ToggleButtonModel model = buttonComp.getToggleButtonModel();
101: if (model.isSelected())
102: buttonElem.setAttribute("style",
103: "background: rgb(253,147,173);"); // weak red
104: else
105: buttonElem.removeAttribute("style");
106: }
107:
108: }
|