Initial commit of newLISP.
[newlisp.git] / guiserver / java / MenuItemWidget.java
blob67ceec36f00a11fc18f3c696a6500ead352207d0
1 //
2 // MenuItemWidget.java
3 // guiserver
4 //
5 // Created by Lutz Mueller on 5/21/07.
6 //
7 //
8 // Copyright (C) 2007 Lutz Mueller
9 //
10 // This program is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import java.awt.*;
26 import java.awt.event.*;
27 import javax.swing.*;
28 import java.util.*;
30 public class MenuItemWidget extends aButton {
32 JMenuItem menuitem;
34 @SuppressWarnings("unchecked")
35 public MenuItemWidget(StringTokenizer params)
37 menuitem = new JMenuItem();
38 jcomponent = menuitem;
39 component = menuitem;
40 container = menuitem;
41 abutton = menuitem;
43 id = params.nextToken();
44 action = params.nextToken();
46 menuitem.setText(Base64Coder.decodeString(params.nextToken()));
48 gsObject.widgets.put(id, this);
50 ActionListener listener = new ActionListener() {
51 public void actionPerformed(ActionEvent e)
53 if(action != null)
55 guiserver.out.println("("+ action + " \"" + id + "\")");
56 guiserver.out.flush();
61 menuitem.addActionListener(listener);
64 public void setAccelerator(StringTokenizer tokens)
66 String keystroke = Base64Coder.decodeString(tokens.nextToken());
68 //System.out.println("setting accelerator: " + keystroke);
70 menuitem.setAccelerator(KeyStroke.getKeyStroke(keystroke));
72 // Syntax:
73 // <modifiers>* (<typedID> | <pressedReleasedID>)
74 // modifiers := shift | control | ctrl | meta | alt | button1 | button2 | button3
75 // typedID := typed <typedKey>
76 // typedKey := string of length 1 giving Unicode character.
77 // pressedReleasedID := (pressed | released) key
78 // key := KeyEvent key code name, i.e. the name following "VK_".
80 // Examples:
81 // "INSERT"
82 // "control DELETE"
83 // "alt shift X"
84 // "alt shift released X"
85 // "typed a"
87 // note that alt on MacOS X is the option key
88 // for letters use uppercase, keys care added in menu item display automatically
94 // eof //