FSF GCC merge 02/23/03
[official-gcc.git] / libjava / javax / swing / JOptionPane.java
blob71904021a9e5c72fb884bd50997fb1689c12cafd
1 /* JOptionPane.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath 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, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing;
40 import java.awt.*;
41 import javax.swing.plaf.*;
42 import javax.accessibility.AccessibleContext;
43 import javax.accessibility.AccessibleRole;
44 import javax.accessibility.AccessibleState;
45 import javax.accessibility.AccessibleStateSet;
47 public class JOptionPane extends JComponent
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;
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;
65 final static String VALUE_PROPERTY = "value_prop";
66 final static String INPUT_VALUE_PROPERTY = "input_value_prop";
68 final static String UNINITIALIZED_VALUE = "uninit";
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;
78 public JDialog dialog;
80 /*****************************************************************************
83 * joptionpanels
86 ***********************************/
88 JOptionPane()
90 this("mess");
93 JOptionPane(Object m)
95 this(m, PLAIN_MESSAGE);
98 JOptionPane(Object m,
99 int mtype)
101 this(m, mtype, DEFAULT_OPTION);
104 JOptionPane(Object m,
105 int mtype,
106 int otype)
108 this(m, mtype, otype, null);
111 JOptionPane(Object m,
112 int mtype,
113 int otype,
114 Icon icon)
116 this(m, mtype, otype, icon, null);
119 JOptionPane(Object m,
120 int mtype,
121 int otype,
122 Icon icon,
123 Object []args)
125 this(m, mtype, otype, icon, args, null);
128 JOptionPane(Object msg,
129 int mtype,
130 int otype,
131 Icon icon,
132 Object []args,
133 Object init)
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;
143 updateUI();
147 /*****************************************************************************
153 ***********************************/
155 Object val;
156 public void setValue(Object v)
157 { val = v; }
158 public Object getValue()
159 { return val; }
161 public String getUIClassID()
162 { return "JOptionPane"; }
165 public void setUI(OptionPaneUI ui) {
166 super.setUI(ui);
169 public OptionPaneUI getUI() {
170 return (OptionPaneUI)ui;
173 public void updateUI() {
174 setUI((OptionPaneUI)UIManager.getUI(this));
178 public AccessibleContext getAccessibleContext()
180 return null;
183 protected String paramString()
185 return "JOptionPane";
188 public static void showMessageDialog(Component frame,
189 String msg,
190 String title,
191 int bla)
193 DoShowOptionDialog(frame,
194 msg,
195 title,
196 bla,
198 null,
199 null,
200 null);
203 public static void showMessageDialog(Component frame,
204 String msg,
205 String title,
206 int bla,
207 Icon icon)
209 DoShowOptionDialog(frame,
210 msg,
211 title,
212 bla,
214 icon,
215 null,
216 null);
219 public static void showMessageDialog(Component frame,
220 String msg)
222 showMessageDialog(frame,
223 msg,
224 null);
228 public static void showMessageDialog(Component frame,
229 String msg,
230 Icon icon)
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);
243 public static int showConfirmDialog(JFrame frame,
244 String yes,
245 String no,
246 int bla)
248 return 0;
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)
260 return (String) DoShowOptionDialog(frame,
261 msg,
262 title,
263 opt_type,
264 msg_type,
265 icon,
266 opts,
267 init);
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)
278 return DoShowOptionDialog(frame,
279 msg,
280 title,
281 opt_type,
282 0, //msg_type,
283 icon,
284 opts,
285 init);
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)
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();
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)
322 JOptionPane p = new JOptionPane(msg,
323 msg_type,
324 opt_type,
325 icon,
326 opts,
327 init);
328 System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " + p.msg);
331 JDialog a;
333 if (frame == null)
335 a = new JDialog((Frame)frame,
336 title,
337 true);
339 else if (frame instanceof Dialog)
341 a = new JDialog((Dialog) frame,
342 title,
343 true);
345 else if (frame instanceof Frame)
347 a = new JDialog((Frame) frame,
348 title,
349 true);
351 else
353 System.out.println("HUUUUHHH, not a frame or dialog !");
355 a = new JDialog((Frame)null,
356 title,
357 true);
360 p.dialog = a;
362 a.getContentPane().setLayout(new BorderLayout());
363 a.getContentPane().add(p,
364 BorderLayout.CENTER);
365 // package the deal
366 a.pack();
368 a.setVisible(true);
370 Object s = p.getValue();
372 System.out.println("RESULT FROM DIALOG = " + s);
374 if (s == null)
375 return null;
377 return s;