source: branches/1.1.x/examples/gui/awt/ItemListener.java

Last change on this file was 12731, checked in by Mark Evenson, 14 years ago

Move unused GUI code to examples hierarchy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/*
2 * ItemListener.java
3 *
4 * Copyright (C) 2003-2005 Peter Graves
5 * $Id: ItemListener.java 12731 2010-05-25 12:42:15Z mevenson $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22package awt;
23
24import java.awt.Checkbox;
25import java.awt.CheckboxMenuItem;
26import java.awt.Choice;
27import java.awt.ItemSelectable;
28import java.awt.List;
29import java.awt.event.ItemEvent;
30import javax.swing.AbstractButton;
31import javax.swing.ButtonModel;
32import javax.swing.DefaultButtonModel;
33import javax.swing.JComboBox;
34import org.armedbear.lisp.JHandler;
35
36public class ItemListener implements java.awt.event.ItemListener
37{
38    public void itemStateChanged(ItemEvent itemevent)
39    {
40        String as[] = { itemevent.paramString(), itemevent.getItem().toString() };
41        int ai[] = { itemevent.getStateChange() != ItemEvent.SELECTED ? 0 : 1 };
42        JHandler.callLisp("ITEMSTATECHANGED", handle, as, ai);
43    }
44
45    public static synchronized void addTo(Checkbox checkbox)
46    {
47        ItemListener itemlistener = new ItemListener();
48        itemlistener.handle = checkbox;
49        checkbox.addItemListener(itemlistener);
50    }
51
52    public static synchronized void addTo(CheckboxMenuItem checkboxmenuitem)
53    {
54        ItemListener itemlistener = new ItemListener();
55        itemlistener.handle = checkboxmenuitem;
56        checkboxmenuitem.addItemListener(itemlistener);
57    }
58
59    public static synchronized void addTo(Choice choice)
60    {
61        ItemListener itemlistener = new ItemListener();
62        itemlistener.handle = choice;
63        choice.addItemListener(itemlistener);
64    }
65
66    public static synchronized void addTo(ItemSelectable itemselectable)
67    {
68        ItemListener itemlistener = new ItemListener();
69        itemlistener.handle = itemselectable;
70        itemselectable.addItemListener(itemlistener);
71    }
72
73    public static synchronized void addTo(List list)
74    {
75        ItemListener itemlistener = new ItemListener();
76        itemlistener.handle = list;
77        list.addItemListener(itemlistener);
78    }
79
80    //Swing
81
82    public static synchronized void addTo(AbstractButton abstractbutton)
83    {
84        ItemListener itemlistener = new ItemListener();
85        itemlistener.handle = abstractbutton;
86        abstractbutton.addItemListener(itemlistener);
87    }
88
89    public static synchronized void addTo(ButtonModel buttonmodel)
90    {
91        ItemListener itemlistener = new ItemListener();
92        itemlistener.handle = buttonmodel;
93        buttonmodel.addItemListener(itemlistener);
94    }
95
96    public static synchronized void addTo(DefaultButtonModel defaultbuttonmodel)
97    {
98        ItemListener itemlistener = new ItemListener();
99        itemlistener.handle = defaultbuttonmodel;
100        defaultbuttonmodel.addItemListener(itemlistener);
101    }
102
103    public static synchronized void addTo(JComboBox jcombobox)
104    {
105        ItemListener itemlistener = new ItemListener();
106        itemlistener.handle = jcombobox;
107        jcombobox.addItemListener(itemlistener);
108    }
109
110    private Object handle;
111}
Note: See TracBrowser for help on using the repository browser.