01: /*
02: * ActionListener.java
03: *
04: * Copyright (C) 2003 Peter Graves
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: */
20:
21: package org.armedbear.lisp.java.awt;
22:
23: import org.armedbear.lisp.JHandler;
24: import java.awt.event.ActionEvent;
25: import java.awt.Button;
26: import java.awt.List;
27: import java.awt.MenuItem;
28: import java.awt.TextField;
29: import javax.swing.AbstractButton;
30: import javax.swing.JTextField;
31:
32: public class ActionListener implements java.awt.event.ActionListener {
33: public void actionPerformed(ActionEvent actionevent) {
34: String as[] = { actionevent.paramString(),
35: actionevent.getActionCommand() };
36: int ai[] = { actionevent.getModifiers() };
37: long al[] = { actionevent.getWhen() }; // not yet used
38: JHandler.callLisp("ACTIONPERFORMED", handle, as, ai);
39: }
40:
41: //AWT
42:
43: public static synchronized void addTo(Button button) {
44: ActionListener actionlistener = new ActionListener();
45: actionlistener.handle = button;
46: button.addActionListener(actionlistener);
47: }
48:
49: public static synchronized void addTo(List list) {
50: ActionListener actionlistener = new ActionListener();
51: actionlistener.handle = list;
52: list.addActionListener(actionlistener);
53: }
54:
55: public static synchronized void addTo(MenuItem menuitem) {
56: ActionListener actionlistener = new ActionListener();
57: actionlistener.handle = menuitem;
58: menuitem.addActionListener(actionlistener);
59: }
60:
61: public static synchronized void addTo(TextField textfield) {
62: ActionListener actionlistener = new ActionListener();
63: actionlistener.handle = textfield;
64: textfield.addActionListener(actionlistener);
65: }
66:
67: //Swing
68:
69: //takes care of JButton, JMenuItem, JToggleButton etc.
70: public static synchronized void addTo(AbstractButton ab) {
71: ActionListener actionlistener = new ActionListener();
72: actionlistener.handle = ab;
73: ab.addActionListener(actionlistener);
74: }
75:
76: public static synchronized void addTo(JTextField textfield) {
77: ActionListener actionlistener = new ActionListener();
78: actionlistener.handle = textfield;
79: textfield.addActionListener(actionlistener);
80: }
81:
82: private Object handle;
83: }
|