source: other-projects/trunk/gs3-release-maker/tasks/sshtaskdef/src/mindbright/ssh/SSHMiscDialogs.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 11.1 KB
Line 
1/******************************************************************************
2 *
3 * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
4 * www.mindbright.se, [email protected]
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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 *****************************************************************************
17 * $Author: mats $
18 * $Date: 2000/04/07 07:14:55 $
19 * $Name: rel1-2-1 $
20 *****************************************************************************/
21package mindbright.ssh;
22
23import java.awt.*;
24import java.awt.event.*;
25
26import mindbright.util.AWTConvenience;
27
28public final class SSHMiscDialogs {
29
30 private static Dialog alertDialog = null;
31 private static Label alertLabel;
32 private static Button okAlertBut;
33 public static void alert(String title, String message, Frame parent) {
34
35 if(alertDialog == null) {
36 alertDialog = new Dialog(parent, title, true);
37
38 GridBagLayout grid = new GridBagLayout();
39 GridBagConstraints gridc = new GridBagConstraints();
40
41 alertDialog.setLayout(grid);
42
43 gridc.fill = GridBagConstraints.HORIZONTAL;
44 gridc.weightx = 1.0;
45 gridc.weighty = 1.0;
46 gridc.gridwidth = GridBagConstraints.REMAINDER;
47 gridc.anchor = GridBagConstraints.CENTER;
48 gridc.insets = new Insets(8, 4, 4, 8);
49
50 gridc.gridy = 0;
51 alertLabel = new Label();
52 grid.setConstraints(alertLabel, gridc);
53 alertDialog.add(alertLabel);
54
55 okAlertBut = new Button("OK");
56 okAlertBut.addActionListener(new AWTConvenience.CloseAction(alertDialog));
57 gridc.fill = GridBagConstraints.NONE;
58 gridc.gridy = 1;
59 grid.setConstraints(okAlertBut, gridc);
60 alertDialog.add(okAlertBut);
61
62 alertDialog.addWindowListener(new AWTConvenience.CloseAdapter(okAlertBut));
63
64 AWTConvenience.setBackgroundOfChildren(alertDialog);
65
66 alertDialog.setResizable(true);
67 }
68
69 alertDialog.setTitle(title);
70
71 alertDialog.remove(alertLabel);
72 alertLabel.setText(message);
73 alertDialog.add(alertLabel);
74 alertDialog.pack();
75
76 AWTConvenience.placeDialog(alertDialog);
77 okAlertBut.requestFocus();
78 alertDialog.setVisible(true);
79 }
80
81 private static Dialog passwordDialog = null;
82 private static Label pwdMsgLabel;
83 private static String pwdAnswer;
84 private static TextField pwdPassword;
85 public static String password(String title, String message, Frame parent) {
86
87 if(passwordDialog == null) {
88 passwordDialog = new Dialog(parent, title, true);
89
90 GridBagLayout grid = new GridBagLayout();
91 GridBagConstraints gridc = new GridBagConstraints();
92 ActionListener al;
93 passwordDialog.setLayout(grid);
94 Label lbl;
95
96 gridc.fill = GridBagConstraints.HORIZONTAL;
97 gridc.gridwidth = GridBagConstraints.REMAINDER;
98 gridc.anchor = GridBagConstraints.CENTER;
99 gridc.insets = new Insets(8, 4, 4, 8);
100
101 gridc.gridy = 0;
102 pwdMsgLabel = new Label();
103 grid.setConstraints(pwdMsgLabel, gridc);
104 passwordDialog.add(pwdMsgLabel);
105
106 gridc.gridy = 1;
107 gridc.gridwidth = 1;
108 gridc.anchor = GridBagConstraints.WEST;
109 lbl = new Label("Password:");
110 grid.setConstraints(lbl, gridc);
111 passwordDialog.add(lbl);
112
113 pwdPassword = new TextField();
114 gridc.gridwidth = GridBagConstraints.REMAINDER;
115 grid.setConstraints(pwdPassword, gridc);
116 pwdPassword.setEchoChar('*');
117 passwordDialog.add(pwdPassword);
118
119 Panel bp = new Panel(new FlowLayout());
120
121 Button okBut, cancBut;
122 bp.add(okBut = new Button("OK"));
123
124 okBut.addActionListener(al = new ActionListener() {
125 public void actionPerformed(ActionEvent e) {
126 if(e.getActionCommand().equals("OK")) {
127 pwdAnswer = pwdPassword.getText();
128 } else {
129 pwdAnswer = null;
130 }
131 passwordDialog.setVisible(false);
132 }
133 });
134
135 bp.add(cancBut = new Button("Cancel"));
136 cancBut.addActionListener(al);
137
138 gridc.gridy = 2;
139 gridc.gridwidth = GridBagConstraints.REMAINDER;
140 grid.setConstraints(bp, gridc);
141 passwordDialog.add(bp);
142
143 passwordDialog.addWindowListener(new AWTConvenience.CloseAdapter(cancBut));
144
145 AWTConvenience.setKeyListenerOfChildren(passwordDialog,
146 new AWTConvenience.OKCancelAdapter(okBut, cancBut),
147 null);
148
149 AWTConvenience.setBackgroundOfChildren(passwordDialog);
150
151 passwordDialog.setResizable(true);
152 }
153
154 passwordDialog.setTitle(title);
155
156 passwordDialog.remove(pwdMsgLabel);
157 pwdMsgLabel.setText(message);
158 pwdPassword.setText("");
159 passwordDialog.add(pwdMsgLabel);
160 passwordDialog.pack();
161
162 AWTConvenience.placeDialog(passwordDialog);
163
164 passwordDialog.setVisible(true);
165
166 return pwdAnswer;
167 }
168
169 private static Dialog setPasswordDialog = null;
170 private static Label setPwdMsgLabel;
171 private static String setPwdAnswer;
172 private static TextField setPwdText, setPwdText2;
173 public static String setPassword(String title, String message, Frame parent) {
174
175 if(setPasswordDialog == null) {
176 setPasswordDialog = new Dialog(parent, title, true);
177
178 GridBagLayout grid = new GridBagLayout();
179 GridBagConstraints gridc = new GridBagConstraints();
180 ActionListener al;
181 setPasswordDialog.setLayout(grid);
182 Label lbl;
183
184 gridc.fill = GridBagConstraints.HORIZONTAL;
185 gridc.gridwidth = GridBagConstraints.REMAINDER;
186 gridc.anchor = GridBagConstraints.CENTER;
187 gridc.insets = new Insets(8, 4, 4, 8);
188
189 gridc.gridy = 0;
190 setPwdMsgLabel = new Label();
191 grid.setConstraints(setPwdMsgLabel, gridc);
192 setPasswordDialog.add(setPwdMsgLabel);
193
194 gridc.gridy = 1;
195 gridc.gridwidth = 1;
196 gridc.anchor = GridBagConstraints.WEST;
197 lbl = new Label("Password:");
198 grid.setConstraints(lbl, gridc);
199 setPasswordDialog.add(lbl);
200
201 setPwdText = new TextField("", 12);
202 grid.setConstraints(setPwdText, gridc);
203 setPwdText.setEchoChar('*');
204 setPasswordDialog.add(setPwdText);
205
206 gridc.gridy = 2;
207 lbl = new Label("Password again:");
208 grid.setConstraints(lbl, gridc);
209 setPasswordDialog.add(lbl);
210
211 setPwdText2 = new TextField("", 12);
212 grid.setConstraints(setPwdText2, gridc);
213 setPwdText2.setEchoChar('*');
214 setPasswordDialog.add(setPwdText2);
215
216 Panel bp = new Panel(new FlowLayout());
217
218 Button okBut, cancBut;
219 bp.add(okBut = new Button("OK"));
220
221 okBut.addActionListener(al = new ActionListener() {
222 public void actionPerformed(ActionEvent e) {
223 if(e.getActionCommand().equals("OK")) {
224 setPwdAnswer = setPwdText.getText();
225 if(!setPwdAnswer.equals(setPwdText2.getText())) {
226 setPwdText.setText("");
227 setPwdText2.setText("");
228 return;
229 }
230 } else {
231 setPwdAnswer = null;
232 }
233 setPasswordDialog.setVisible(false);
234 }
235 });
236
237 bp.add(cancBut = new Button("Cancel"));
238 cancBut.addActionListener(al);
239
240 gridc.gridy = 3;
241 gridc.gridwidth = GridBagConstraints.REMAINDER;
242 grid.setConstraints(bp, gridc);
243 setPasswordDialog.add(bp);
244
245 setPasswordDialog.addWindowListener(new AWTConvenience.CloseAdapter(cancBut));
246
247 AWTConvenience.setKeyListenerOfChildren(setPasswordDialog,
248 new AWTConvenience.OKCancelAdapter(okBut, cancBut),
249 null);
250
251 AWTConvenience.setBackgroundOfChildren(setPasswordDialog);
252
253 setPasswordDialog.setResizable(true);
254 }
255
256 setPasswordDialog.setTitle(title);
257
258 setPasswordDialog.remove(setPwdMsgLabel);
259 setPwdMsgLabel.setText(message);
260 setPwdText.setText("");
261 setPwdText2.setText("");
262 setPasswordDialog.add(setPwdMsgLabel);
263 setPasswordDialog.pack();
264
265 AWTConvenience.placeDialog(setPasswordDialog);
266
267 setPasswordDialog.setVisible(true);
268
269 return setPwdAnswer;
270 }
271
272 private static Dialog confirmDialog = null;
273 private static Label confirmLabel;
274 private static boolean confirmRet;
275 private static Button yesBut, noBut;
276 public static boolean confirm(String title, String message, boolean defAnswer,
277 Frame parent) {
278
279 if(confirmDialog == null) {
280 confirmDialog = new Dialog(parent, title, true);
281
282 GridBagLayout grid = new GridBagLayout();
283 GridBagConstraints gridc = new GridBagConstraints();
284 ActionListener al;
285 confirmDialog.setLayout(grid);
286
287 gridc.fill = GridBagConstraints.HORIZONTAL;
288 gridc.gridwidth = GridBagConstraints.REMAINDER;
289 gridc.anchor = GridBagConstraints.CENTER;
290 gridc.insets = new Insets(8, 4, 4, 8);
291
292 gridc.gridy = 0;
293 confirmLabel = new Label();
294 grid.setConstraints(confirmLabel, gridc);
295 confirmDialog.add(confirmLabel);
296
297 Panel bp = new Panel(new FlowLayout());
298
299 bp.add(yesBut = new Button("Yes"));
300
301 yesBut.addActionListener(al = new ActionListener() {
302 public void actionPerformed(ActionEvent e) {
303 if(e.getActionCommand().equals("Yes"))
304 confirmRet = true;
305 else
306 confirmRet = false;
307 confirmDialog.setVisible(false);
308 }
309 });
310
311 bp.add(noBut = new Button("No"));
312 noBut.addActionListener(al);
313
314 gridc.gridy = 1;
315 gridc.gridwidth = GridBagConstraints.REMAINDER;
316 grid.setConstraints(bp, gridc);
317 confirmDialog.add(bp);
318
319 confirmDialog.addWindowListener(new AWTConvenience.CloseAdapter(noBut));
320
321 AWTConvenience.setBackgroundOfChildren(confirmDialog);
322
323 confirmDialog.setResizable(true);
324 }
325
326 confirmDialog.remove(confirmLabel);
327 confirmLabel.setText(message);
328 confirmDialog.add(confirmLabel);
329 confirmDialog.pack();
330
331 AWTConvenience.placeDialog(confirmDialog);
332
333 if(defAnswer)
334 yesBut.requestFocus();
335 else
336 noBut.requestFocus();
337
338 confirmDialog.setVisible(true);
339
340 return confirmRet;
341 }
342
343 public static void notice(String title, String text, int rows, int cols,
344 boolean scrollbar, Frame parent) {
345 Dialog textDialog = null;
346 TextArea textArea;
347 Button okTextBut;
348
349 textDialog = new Dialog(parent, title, true);
350
351 GridBagLayout grid = new GridBagLayout();
352 GridBagConstraints gridc = new GridBagConstraints();
353
354 textDialog.setLayout(grid);
355
356 gridc.fill = GridBagConstraints.NONE;
357 gridc.gridwidth = GridBagConstraints.REMAINDER;
358 gridc.anchor = GridBagConstraints.CENTER;
359 gridc.insets = new Insets(4, 4, 4, 4);
360
361 textArea = new TextArea(text, rows, cols,
362 scrollbar ? TextArea.SCROLLBARS_VERTICAL_ONLY : TextArea.SCROLLBARS_NONE);
363 grid.setConstraints(textArea, gridc);
364 textDialog.add(textArea);
365 textArea.setEditable(false);
366
367 okTextBut = new Button("OK");
368 okTextBut.addActionListener(new AWTConvenience.CloseAction(textDialog));
369 gridc.fill = GridBagConstraints.NONE;
370 grid.setConstraints(okTextBut, gridc);
371 textDialog.add(okTextBut);
372
373 textDialog.addWindowListener(new AWTConvenience.CloseAdapter(okTextBut));
374
375 AWTConvenience.setBackgroundOfChildren(textDialog);
376
377 textDialog.setResizable(true);
378 textDialog.pack();
379
380 AWTConvenience.placeDialog(textDialog);
381 okTextBut.requestFocus();
382 textDialog.setVisible(true);
383 }
384
385}
Note: See TracBrowser for help on using the repository browser.