Initial commit of newLISP.
[newlisp.git] / guiserver / java / MenuItemCheckWidget.java
blobe63fc5f5f47966cc67025a708a9e18f57c047f45
1 //
2 // MenuItemCheckWidget.java
3 // guiserver
4 //
5 // Created by Lutz Mueller on 5/24/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 javax.swing.*;
27 import java.awt.event.*;
28 import java.util.*;
30 public class MenuItemCheckWidget extends gsObject{
32 JCheckBoxMenuItem cbmenuitem;
34 @SuppressWarnings("unchecked")
35 public MenuItemCheckWidget(StringTokenizer params)
37 cbmenuitem = new JCheckBoxMenuItem();
38 jcomponent = cbmenuitem;
39 component = cbmenuitem;
40 container = cbmenuitem;
42 id = params.nextToken();
43 action = params.nextToken();
45 if(params.hasMoreTokens())
47 String base64string = params.nextToken();
48 cbmenuitem.setText(Base64Coder.decodeString(base64string));
51 if(params.hasMoreTokens())
53 if(params.nextToken().equals("true"))
54 cbmenuitem.setSelected(true);
57 gsObject.widgets.put(id, this);
60 ActionListener listener = new ActionListener() {
61 public void actionPerformed(ActionEvent e)
63 if(action != null)
65 if(cbmenuitem.isSelected())
66 guiserver.out.println("("+ action + " \"" + id + "\" true)");
67 else
68 guiserver.out.println("("+ action + " \"" + id + "\" nil)");
70 guiserver.out.flush();
75 cbmenuitem.addActionListener(listener);
78 public void setText(StringTokenizer tokens)
80 String text = Base64Coder.decodeString(tokens.nextToken());
81 cbmenuitem.setText(text);
84 public void clearText(StringTokenizer tokens)
86 cbmenuitem.setText("");
89 public void setSelected(StringTokenizer tokens)
91 if(tokens.nextToken().equals("true"))
92 cbmenuitem.setSelected(true);
93 else
94 cbmenuitem.setSelected(false);
97 public void setIcon(StringTokenizer tokens)
99 String path = tokens.nextToken();
100 cbmenuitem.setIcon(guiserver.getIconFromPath(path, this.getClass()));
103 public void setAccelerator(StringTokenizer tokens)
105 String keystroke = Base64Coder.decodeString(tokens.nextToken());
107 //System.out.println("setting accelerator: " + keystroke);
109 cbmenuitem.setAccelerator(KeyStroke.getKeyStroke(keystroke));
111 // Syntax:
112 // <modifiers>* (<typedID> | <pressedReleasedID>)
113 // modifiers := shift | control | ctrl | meta | alt | button1 | button2 | button3
114 // typedID := typed <typedKey>
115 // typedKey := string of length 1 giving Unicode character.
116 // pressedReleasedID := (pressed | released) key
117 // key := KeyEvent key code name, i.e. the name following "VK_".
119 // Examples:
120 // "INSERT"
121 // "control DELETE"
122 // "alt shift X"
123 // "alt shift released X"
124 // "typed a"
126 // note that alt on MacOS X is the option key
127 // for letters use uppercase, keys care added in menu item display automatically
134 // eof //