source: trunk/gcc/libjava/javax/swing/JOptionPane.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.1 KB
Line 
1/* JOptionPane.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.swing;
39
40import java.awt.*;
41import javax.swing.plaf.*;
42import javax.accessibility.AccessibleContext;
43import javax.accessibility.AccessibleRole;
44import javax.accessibility.AccessibleState;
45import javax.accessibility.AccessibleStateSet;
46
47public class JOptionPane extends JComponent
48{
49 public static final int DEFAULT_OPTION = 0;
50 public static final int YES_NO_OPTION = 1;
51 public static final int YES_NO_CANCEL_OPTION = 2;
52 public static final int OK_CANCEL_OPTION = 3;
53 public static final int YES_OPTION = 4;
54 public static final int NO_OPTION = 5;
55 public static final int CANCEL_OPTION = 6;
56 public static final int OK_OPTION = 7;
57 public static final int CLOSED_OPTION = 8;
58
59 public static final int ERROR_MESSAGE = 0;
60 public static final int INFORMATION_MESSAGE = 1;
61 public static final int WARNING_MESSAGE = 2;
62 public static final int QUESTION_MESSAGE = 3;
63 public static final int PLAIN_MESSAGE = 4;
64
65 final static String VALUE_PROPERTY = "value_prop";
66 final static String INPUT_VALUE_PROPERTY = "input_value_prop";
67
68 final static String UNINITIALIZED_VALUE = "uninit";
69
70 // Ronald: shouldnt by public ?
71 public Object msg;
72 public int mtype;
73 public int otype;
74 public Icon icon;
75 public Object []args;
76 public Object init;
77
78 public JDialog dialog;
79
80 /*****************************************************************************
81 *
82 *
83 * joptionpanels
84 *
85 *
86 ***********************************/
87
88 JOptionPane()
89 {
90 this("mess");
91 }
92
93 JOptionPane(Object m)
94 {
95 this(m, PLAIN_MESSAGE);
96 }
97
98 JOptionPane(Object m,
99 int mtype)
100 {
101 this(m, mtype, DEFAULT_OPTION);
102 }
103
104 JOptionPane(Object m,
105 int mtype,
106 int otype)
107 {
108 this(m, mtype, otype, null);
109 }
110
111 JOptionPane(Object m,
112 int mtype,
113 int otype,
114 Icon icon)
115 {
116 this(m, mtype, otype, icon, null);
117 }
118
119 JOptionPane(Object m,
120 int mtype,
121 int otype,
122 Icon icon,
123 Object []args)
124 {
125 this(m, mtype, otype, icon, args, null);
126 }
127
128 JOptionPane(Object msg,
129 int mtype,
130 int otype,
131 Icon icon,
132 Object []args,
133 Object init)
134 {
135 // this(m, mtype, otype, icon, args, init);
136 this.msg = msg;
137 this.mtype = mtype;
138 this.otype = otype;
139 this.icon = icon;
140 this.args = args;
141 this.init = init;
142
143 updateUI();
144 }
145
146
147 /*****************************************************************************
148 *
149 *
150 *
151 *
152 *
153 ***********************************/
154
155 Object val;
156 public void setValue(Object v)
157 { val = v; }
158 public Object getValue()
159 { return val; }
160
161 public String getUIClassID()
162 { return "JOptionPane"; }
163
164
165 public void setUI(OptionPaneUI ui) {
166 super.setUI(ui);
167 }
168
169 public OptionPaneUI getUI() {
170 return (OptionPaneUI)ui;
171 }
172
173 public void updateUI() {
174 setUI((OptionPaneUI)UIManager.getUI(this));
175 }
176
177
178 public AccessibleContext getAccessibleContext()
179 {
180 return null;
181 }
182
183 protected String paramString()
184 {
185 return "JOptionPane";
186 }
187
188 public static void showMessageDialog(Component frame,
189 String msg,
190 String title,
191 int bla)
192 {
193 DoShowOptionDialog(frame,
194 msg,
195 title,
196 bla,
197 0,
198 null,
199 null,
200 null);
201 }
202
203 public static void showMessageDialog(Component frame,
204 String msg,
205 String title,
206 int bla,
207 Icon icon)
208 {
209 DoShowOptionDialog(frame,
210 msg,
211 title,
212 bla,
213 0,
214 icon,
215 null,
216 null);
217 }
218
219 public static void showMessageDialog(Component frame,
220 String msg)
221 {
222 showMessageDialog(frame,
223 msg,
224 null);
225 }
226
227
228 public static void showMessageDialog(Component frame,
229 String msg,
230 Icon icon)
231 {
232 //System.out.println("++++++++++++++++++creating message dialog:"+msg + ", frame="+frame);
233 DoShowOptionDialog(frame,
234 msg,
235 "Message",
236 DEFAULT_OPTION,
237 PLAIN_MESSAGE,
238 icon,
239 null,
240 null);
241 }
242
243 public static int showConfirmDialog(JFrame frame,
244 String yes,
245 String no,
246 int bla)
247 {
248 return 0;
249 }
250
251 public static String showInputDialog(JFrame frame,
252 String msg,
253 String title,
254 int opt_type,
255 int msg_type,
256 Icon icon,
257 Object[] opts,
258 Object init)
259 {
260 return (String) DoShowOptionDialog(frame,
261 msg,
262 title,
263 opt_type,
264 msg_type,
265 icon,
266 opts,
267 init);
268 }
269
270 public static Object showInputDialog(JFrame frame,
271 String msg,
272 String title,
273 int opt_type,
274 Icon icon,
275 Object[] opts,
276 Object init)
277 {
278 return DoShowOptionDialog(frame,
279 msg,
280 title,
281 opt_type,
282 0, //msg_type,
283 icon,
284 opts,
285 init);
286 }
287
288
289 // everybody comes here eventually
290 public static int showOptionDialog(Component frame,
291 String msg,
292 String title,
293 int opt_type,
294 int msg_type,
295 Icon icon,
296 Object[] opts,
297 Object init)
298 {
299 Integer a = (Integer) DoShowOptionDialog(frame,
300 msg,
301 title,
302 opt_type,
303 msg_type,
304 icon,
305 opts,
306 init);
307 if (a == null)
308 return -1;
309 return a.intValue();
310 }
311
312 public static Object DoShowOptionDialog(Component frame,
313 String msg,
314 String title,
315 int opt_type,
316 int msg_type,
317 Icon icon,
318 Object[] opts,
319 Object init)
320 {
321
322 JOptionPane p = new JOptionPane(msg,
323 msg_type,
324 opt_type,
325 icon,
326 opts,
327 init);
328 System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " + p.msg);
329
330
331 JDialog a;
332
333 if (frame == null)
334 {
335 a = new JDialog((Frame)frame,
336 title,
337 true);
338 }
339 else if (frame instanceof Dialog)
340 {
341 a = new JDialog((Dialog) frame,
342 title,
343 true);
344 }
345 else if (frame instanceof Frame)
346 {
347 a = new JDialog((Frame) frame,
348 title,
349 true);
350 }
351 else
352 {
353 System.out.println("HUUUUHHH, not a frame or dialog !");
354
355 a = new JDialog((Frame)null,
356 title,
357 true);
358 }
359
360 p.dialog = a;
361
362 a.getContentPane().setLayout(new BorderLayout());
363 a.getContentPane().add(p,
364 BorderLayout.CENTER);
365 // package the deal
366 a.pack();
367
368 a.setVisible(true);
369
370 Object s = p.getValue();
371
372 System.out.println("RESULT FROM DIALOG = " + s);
373
374 if (s == null)
375 return null;
376
377 return s;
378 }
379
380}
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
Note: See TracBrowser for help on using the repository browser.