001: /*
002: * ItemListener.java
003: *
004: * Copyright (C) 2003 Peter Graves
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020:
021: package org.armedbear.lisp.java.awt;
022:
023: import org.armedbear.lisp.JHandler;
024: import java.awt.event.ItemEvent;
025: import java.awt.Checkbox;
026: import java.awt.CheckboxMenuItem;
027: import java.awt.Choice;
028: import java.awt.ItemSelectable;
029: import java.awt.List;
030: import javax.swing.AbstractButton;
031: import javax.swing.ButtonModel;
032: import javax.swing.DefaultButtonModel;
033: import javax.swing.JComboBox;
034:
035: public class ItemListener implements java.awt.event.ItemListener {
036:
037: public void itemStateChanged(ItemEvent itemevent) {
038: String as[] = { itemevent.paramString(),
039: itemevent.getItem().toString() };
040: int ai[] = { itemevent.getStateChange() != itemevent.SELECTED ? 0
041: : 1 };
042: JHandler.callLisp("ITEMSTATECHANGED", handle, as, ai);
043: }
044:
045: public static synchronized void addTo(Checkbox checkbox) {
046: ItemListener itemlistener = new ItemListener();
047: itemlistener.handle = checkbox;
048: checkbox.addItemListener(itemlistener);
049: }
050:
051: public static synchronized void addTo(
052: CheckboxMenuItem checkboxmenuitem) {
053: ItemListener itemlistener = new ItemListener();
054: itemlistener.handle = checkboxmenuitem;
055: checkboxmenuitem.addItemListener(itemlistener);
056: }
057:
058: public static synchronized void addTo(Choice choice) {
059: ItemListener itemlistener = new ItemListener();
060: itemlistener.handle = choice;
061: choice.addItemListener(itemlistener);
062: }
063:
064: public static synchronized void addTo(ItemSelectable itemselectable) {
065: ItemListener itemlistener = new ItemListener();
066: itemlistener.handle = itemselectable;
067: itemselectable.addItemListener(itemlistener);
068: }
069:
070: public static synchronized void addTo(List list) {
071: ItemListener itemlistener = new ItemListener();
072: itemlistener.handle = list;
073: list.addItemListener(itemlistener);
074: }
075:
076: //Swing
077:
078: public static synchronized void addTo(AbstractButton abstractbutton) {
079: ItemListener itemlistener = new ItemListener();
080: itemlistener.handle = abstractbutton;
081: abstractbutton.addItemListener(itemlistener);
082: }
083:
084: public static synchronized void addTo(ButtonModel buttonmodel) {
085: ItemListener itemlistener = new ItemListener();
086: itemlistener.handle = buttonmodel;
087: buttonmodel.addItemListener(itemlistener);
088: }
089:
090: public static synchronized void addTo(
091: DefaultButtonModel defaultbuttonmodel) {
092: ItemListener itemlistener = new ItemListener();
093: itemlistener.handle = defaultbuttonmodel;
094: defaultbuttonmodel.addItemListener(itemlistener);
095: }
096:
097: public static synchronized void addTo(JComboBox jcombobox) {
098: ItemListener itemlistener = new ItemListener();
099: itemlistener.handle = jcombobox;
100: jcombobox.addItemListener(itemlistener);
101: }
102:
103: private Object handle;
104: }
|