Initial commit of newLISP.
[newlisp.git] / guiserver / java / Dispatcher.java
blob608027061a2f963431e8730b642dc86e2d93ed4b
1 //
2 // Dispatcher.java
3 // guiserver
4 //
5 // Created by Lutz Mueller on 5/14/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.lang.*;
26 import java.lang.reflect.Constructor;
27 import java.lang.reflect.Method;
28 import java.util.*;
29 import java.io.*;
30 import java.net.*;
31 import java.awt.*;
32 import javax.swing.*;
33 import javax.swing.event.*;
34 import javax.swing.text.*;
36 @SuppressWarnings("unchecked")
37 public class Dispatcher {
39 static String cmd;
40 static HashMap classes = new HashMap();
41 static HashMap methods = new HashMap();
43 public static void dispatch(String command)
45 StringTokenizer tokens = null;
46 String id = null;
47 gsObject gsobject = null;
48 Class cfoo;
49 Constructor constor;
50 Class[] defArgs = {StringTokenizer.class};
51 Method method;
52 String methodName;
54 if(guiserver.debug) System.out.println("-> " + command);
56 tokens = new StringTokenizer(command);
58 Object[] initArgs = {tokens};
59 cmd = tokens.nextToken();
61 // look for constructor methods
62 if((cfoo = (Class)classes.get(cmd)) != null)
64 try {
65 constor = cfoo.getConstructor(defArgs);
66 constor.newInstance(initArgs);
67 } catch (Exception ce) {
68 if(guiserver.debug)
69 System.out.println("Error: " + cmd + "=>" + ce);
70 else
72 ErrorDialog.show(command, "Could not create " + cmd);
73 //System.exit(1);
74 return;
78 return;
81 else // get target object
83 id = tokens.nextToken();
84 gsobject = (gsObject)gsObject.widgets.get(id);
85 //System.out.println("get target: " + id);
86 if(gsobject == null)
88 ErrorDialog.wrongApplication(cmd, id);
89 //System.exit(1);
90 return;
94 // get method for target and invoke it with arguments
95 try {
96 //System.out.println("invoke " + cmd + " on " + id);
97 methodName = (String)methods.get(cmd);
98 //System.out.println("methodName:" + methodName);
99 method = gsobject.getClass().getMethod(methodName, defArgs);
100 //System.out.println("method:" + method);
101 if(method != null)
103 method.invoke(gsobject, initArgs);
104 return;
106 } catch (Exception ce) {
107 if(guiserver.debug)
108 ce.printStackTrace();
109 else
111 ErrorDialog.show(command, "Could not invoke method " + cmd + " with " + id);
112 //System.exit(1);
113 return;
118 public static void init()
120 // GUI widget classes
121 classes.put("window", WindowWidget.class);
122 classes.put("frame", WindowFrame.class);
123 classes.put("dialog", DialogWidget.class);
124 classes.put("panel", PanelWidget.class);
125 classes.put("tabbed-pane", TabbedPaneWidget.class);
126 classes.put("split-pane", SplitPaneWidget.class);
127 classes.put("scroll-pane", ScrollPaneWidget.class);
128 classes.put("label", LabelWidget.class);
129 classes.put("image-label", ImageLabelWidget.class);
130 classes.put("set-grid-layout", LayoutGrid.class);
131 classes.put("set-flow-layout", LayoutFlow.class);
132 classes.put("set-border-layout", LayoutBorder.class);
133 classes.put("button", ButtonWidget.class);
134 classes.put("image-button", ImageButtonWidget.class);
135 classes.put("toggle-button", ToggleButtonWidget.class);
136 classes.put("check-box", CheckBoxWidget.class);
137 classes.put("radio-button", RadioButtonWidget.class);
138 classes.put("combo-box", ComboBoxWidget.class);
139 classes.put("slider", SliderWidget.class);
140 classes.put("progress-bar", ProgressBarWidget.class);
141 classes.put("list-box", ListBoxWidget.class);
142 classes.put("text-field", TextFieldWidget.class);
143 classes.put("text-area", TextAreaWidget.class);
144 classes.put("menu-item", MenuItemWidget.class);
145 classes.put("menu-item-check", MenuItemCheckWidget.class);
146 classes.put("menu", MenuWidget.class);
147 classes.put("menu-popup", PopupMenuWidget.class);
148 classes.put("menu-bar", MenuBarWidget.class);
149 classes.put("tool-bar", ToolbarWidget.class);
150 classes.put("text-pane", TextPaneWidget.class);
152 // 2D Graphics classes
153 classes.put("canvas", CanvasWidget.class);
155 // GUI methods
156 methods.put("add-list-item","addListItem");
157 methods.put("add-separator","addSeparator");
158 methods.put("add-to","addTo");
159 methods.put("append-text","appendText");
160 methods.put("clear-list","clearList");
161 methods.put("clear-text","clearText");
162 methods.put("confirm-dialog","confirmDialog");
163 methods.put("color-dialog","ColorChooser");
164 methods.put("copy-text","copyText");
165 methods.put("cut-text","cutText");
166 methods.put("disable","Disable");
167 methods.put("dispose","dispose");
168 methods.put("enable","Enable");
169 methods.put("find-text", "findText");
170 methods.put("frame-closed", "frameCloseEvent");
171 methods.put("frame-moved", "frameMoveEvent");
172 methods.put("frame-resized", "frameResizeEvent");
173 methods.put("get-bounds", "getBounds");
174 methods.put("get-font-metrics", "getFontMetrics");
175 methods.put("get-selected-text", "getSelection");
176 methods.put("get-text","getText");
177 methods.put("get-text-position","getTextPosition");
178 methods.put("goto-text", "gotoText");
179 methods.put("insert-list-item","insertListItem");
180 methods.put("insert-tab","insertTab");
181 methods.put("insert-text", "insertText");
182 methods.put("layout", "layout");
183 methods.put("load-text", "loadText");
184 methods.put("open-file-dialog","OpenFileChooser");
185 methods.put("message-dialog","messageDialog");
186 methods.put("paste-text","pasteText");
187 methods.put("redo-text","redoText");
188 methods.put("remove-from", "removeFrom");
189 methods.put("remove-list-item","removeListItem");
190 methods.put("remove-tab","removeTab");
191 methods.put("request-focus","requestFocus");
192 methods.put("save-file-dialog","SaveFileChooser");
193 methods.put("save-text", "saveText");
194 methods.put("set-caret", "setCaret");
195 methods.put("select-text","selectText");
196 methods.put("set-accelerator","setAccelerator");
197 methods.put("set-background","setBackground");
198 methods.put("set-bevel-border","setBevelBorder");
199 methods.put("set-caret-color","setCaretColor");
200 methods.put("set-color","setBackground");
201 methods.put("set-cursor","setCursor");
202 methods.put("set-editable","setEditable");
203 methods.put("set-font","setFont");
204 methods.put("set-foreground","setForeground");
205 methods.put("set-icon","setIcon");
206 methods.put("select-list-item","selectListItem");
207 methods.put("set-pressed-icon","setPressedIcon");
208 methods.put("set-resizable","setResizable");
209 methods.put("set-selected","setSelected");
210 methods.put("set-selection-color","setSelectionColor");
211 methods.put("set-size","setPreferredSize");
212 methods.put("set-text","setText");
213 methods.put("set-tab-size","setTabSize");
214 methods.put("set-titled-border","setTitledBorder");
215 methods.put("set-tool-tip","setToolTip");
216 methods.put("set-value","setValue");
217 methods.put("set-visible","setVisible");
218 methods.put("set-syntax", "setSyntax");
219 methods.put("show-popup", "showPopup");
220 methods.put("undo-text","undoText");
221 methods.put("undo-enable", "undoEnable");
222 methods.put("run-shell", "runShell");
223 methods.put("eval-shell", "evalShell");
224 methods.put("destroy-shell", "destroyShell");
226 // methods for System object (guiserver)
227 methods.put("dispose-splash", "disposeSplash");
228 methods.put("get-fonts", "getFonts");
229 methods.put("get-screen", "getScreen");
230 methods.put("get-version", "getVersion");
231 methods.put("set-trace", "setTrace");
232 methods.put("set-look-and-feel", "setLookAndFeel");
233 methods.put("set-syntax-colors", "setSyntaxColors");
234 methods.put("play-sound", "playSound");
235 methods.put("set-utf8", "setUTF8");
237 // 2D Grapics
238 // All methods hace the current canvas as target
240 // methods for creating sjapes
241 // put in Vector in current canvas
242 methods.put("draw-arc", "drawArc");
243 methods.put("draw-circle", "drawCircle");
244 methods.put("draw-ellipse", "drawEllipse");
245 methods.put("draw-image", "drawImage");
246 methods.put("draw-line", "drawLine");
247 methods.put("draw-path", "drawPath");
248 methods.put("draw-polygon", "drawPolygon");
249 methods.put("draw-text", "drawText");
250 methods.put("draw-rect", "drawRectangle");
251 methods.put("draw-round-rect", "drawRoundRect");
252 methods.put("fill-arc", "fillArc");
253 methods.put("fill-circle", "fillCircle");
254 methods.put("fill-ellipse", "fillEllipse");
255 methods.put("fill-polygon", "fillPolygon");
256 methods.put("fill-rect", "fillRectangle");
257 methods.put("fill-round-rect", "fillRoundRect");
258 methods.put("set-anti-aliasing", "setAntiAliasing");
260 // general mouse and key events
261 methods.put("mouse-event","registerMouseEvent");
262 methods.put("key-event","registerKeyEvent");
264 // specialize events for canvas
265 methods.put("mouse-clicked","registerMouseClicked");
266 methods.put("mouse-pressed","registerMousePressed");
267 methods.put("mouse-released","registerMouseRelease");
268 methods.put("mouse-entered","registerMouseEntered");
269 methods.put("mouse-exited","registerMouseExited");
270 methods.put("mouse-dragged","registerMouseDragged");
271 methods.put("mouse-moved","registerMouseMoved");
272 methods.put("mouse-wheel", "registerMouseWheel");
274 // take canvas for global settings as target
275 methods.put("set-canvas", "g2Canvas");
276 methods.put("set-translation", "g2Translation");
277 methods.put("set-transform", "g2Transform");
278 methods.put("set-rotation", "g2Rotation");
279 methods.put("set-scale", "g2Scale");
280 methods.put("export", "g2Export");
281 methods.put("print", "g2Print");
282 methods.put("update", "g2Update");
284 // current canvas settings used in next shape
285 methods.put("set-stroke", "g2Stroke");
286 methods.put("set-paint", "g2Paint");
287 methods.put("set-composite", "g2Composite");
288 methods.put("set-clipping", "g2Clip");
290 // take tags for drawing shapes as target
291 methods.put("delete-tag", "deleteTaggedShape");
292 methods.put("move-tag", "moveTaggedShape");
293 methods.put("translate-tag", "translateTaggedShape");
294 methods.put("rotate-tag", "rotateTaggedShape");
295 methods.put("scale-tag", "scaleTaggedShape");
296 methods.put("shear-tag", "shearTaggedShape");
297 methods.put("hide-tag", "hideTaggedShape");
298 methods.put("show-tag", "showTaggedShape");
299 methods.put("delete-tag", "deleteTaggedShape");
300 methods.put("reorder-tags", "orderTaggedShapes");
301 methods.put("color-tag", "colorTaggedShape");
306 // eof //