Initial commit of newLISP.
[newlisp.git] / guiserver / java / DialogWidget.java
blob13378fc129185c31aee4c5ad683fa8a26de1ffc7
1 //
2 // DialogWidget.java
3 // guiserver
4 //
5 // Created by Lutz Mueller on 5/23/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.color.*;
27 import java.awt.event.*;
28 import javax.swing.*;
29 import java.util.*;
31 // DO NOT USE, when set modal inhibits Dispather from processing incoming messages
32 // this makes it imposible to serve newLISP requests from the Dialog, if modal
34 @SuppressWarnings("unchecked")
36 public class DialogWidget extends gsObject {
38 JDialog jdialog;
39 JFrame jfowner;
40 String dialogCloseAction = null;
41 String dialogMoveAction = null;
42 String dialogResizeAction = null;
44 public DialogWidget(StringTokenizer params)
46 id = params.nextToken();
47 String owner = params.nextToken();
48 String message = Base64Coder.decodeString(params.nextToken());
49 boolean ismodal = false;
51 jfowner = ((WindowFrame)gsObject.widgets.get(owner)).jframe;
53 //String closeButtonId = params.nextToken();
54 //ButtonWidget closeButton = (ButtonWidget)gsObject.widgets.get(closeButtonId);
56 int x = jfowner.getX() + 100;
57 int y = jfowner.getY() + 100;
58 int width = Integer.parseInt(params.nextToken());
59 int height = Integer.parseInt(params.nextToken());
61 jdialog = new JDialog(jfowner, message, false);
62 //closeButton.jdialog = jdialog;
64 jdialog.setBounds(x, y, width, height);
66 container = jdialog.getContentPane();
68 if(params.hasMoreTokens())
70 if(params.nextToken().equals("true"))
71 jdialog.setVisible(true);
73 else jdialog.setVisible(false);
75 if(params.hasMoreTokens())
77 if(params.nextToken().equals("true"))
78 jfowner.setEnabled(false);
81 WindowAdapter listener = new WindowAdapter() {
82 public void windowClosing(WindowEvent w)
84 //System.out.println("Closing dialog");
85 jfowner.setEnabled(true);
86 jdialog.dispose();
87 if(dialogCloseAction != null)
89 guiserver.out.println("(" + dialogCloseAction + "\"" + id + "\")");
90 guiserver.out.flush();
95 jdialog.addWindowListener(listener);
97 ComponentAdapter componentListener = new ComponentAdapter() {
98 public void componentResized(ComponentEvent re)
100 if(dialogResizeAction != null)
102 guiserver.out.println("(" + dialogResizeAction + "\"" + id + "\"" +
103 jdialog.getWidth() + " " + jdialog.getHeight() +")");
104 guiserver.out.flush();
108 public void componentMoved(ComponentEvent me)
110 if(dialogMoveAction != null)
112 guiserver.out.println("(" + dialogMoveAction + "\"" + id + "\"" +
113 jdialog.getLocationOnScreen().x + " " + jdialog.getLocationOnScreen().y +")");
114 guiserver.out.flush();
119 jdialog.addComponentListener(componentListener);
121 gsObject.widgets.put(id, this);
123 jdialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
127 public void setText(StringTokenizer tokens)
129 String text = Base64Coder.decodeString(tokens.nextToken());
130 jdialog.setTitle(text);
134 public void getText(StringTokenizer tokens)
136 String action = tokens.nextToken();
137 String text = jdialog.getTitle();
138 if(text.length() == 0)
139 guiserver.out.println("(" + action + " \"" + id + "\")");
140 else
141 guiserver.out.println("(" + action + " \"" + id + "\" [text]" + Base64Coder.encodeString(text) + "[/text])");
142 guiserver.out.flush();
146 public void clearText(StringTokenizer tokens)
148 jdialog.setTitle("");
152 public void setVisible(StringTokenizer tokens)
154 if(tokens.nextToken().equals("true"))
155 jdialog.setVisible(true);
156 else
157 jdialog.setVisible(false);
160 public void setResizable(StringTokenizer tokens)
162 if(tokens.nextToken().equals("true"))
163 jdialog.setResizable(true);
164 else
165 jdialog.setResizable(false);
168 public void dispose(StringTokenizer tokens)
170 jfowner.setEnabled(true);
171 jdialog.dispose();
174 public void setBackground(StringTokenizer tokens)
176 Float red = Float.parseFloat(tokens.nextToken());
177 Float green = Float.parseFloat(tokens.nextToken());
178 Float blue = Float.parseFloat(tokens.nextToken());
179 if(tokens.hasMoreTokens())
181 Float alpha = Float.parseFloat(tokens.nextToken());
182 jdialog.setBackground(new Color(red, green, blue, alpha));
184 else
185 jdialog.setBackground(new Color(red, green, blue));
188 public void setFont(StringTokenizer tokens)
190 ErrorDialog.wrongApplication(Dispatcher.cmd, id);
193 public void setToolTip(StringTokenizer tokens)
195 ErrorDialog.wrongApplication(Dispatcher.cmd, id);
198 public void getBounds(StringTokenizer tokens)
200 int x, y, width, height;
202 x = jdialog.getLocationOnScreen().x;
203 y = jdialog.getLocationOnScreen().y;
205 width = jdialog.getWidth();
206 height = jdialog.getHeight();
208 guiserver.out.println("( set 'gs:bounds '(" + x + " " + y + " " + width + " " + height + "))\n");
209 guiserver.out.flush();
213 public void frameCloseEvent(StringTokenizer tokens)
215 dialogCloseAction = tokens.nextToken();
218 public void frameResizeEvent(StringTokenizer tokens)
220 dialogResizeAction = tokens.nextToken();
223 public void frameMoveEvent(StringTokenizer tokens)
225 dialogMoveAction = tokens.nextToken();
231 // eof //