2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / JOptionPane.java
blob5dc10c7dc037b9764deaebc8e97447b2c1ca334c
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. */
39 package javax.swing;
41 import java.awt.BorderLayout;
42 import java.awt.Component;
43 import java.awt.Dialog;
44 import java.awt.Frame;
45 import javax.accessibility.Accessible;
46 import javax.accessibility.AccessibleContext;
47 import javax.swing.plaf.OptionPaneUI;
49 public class JOptionPane extends JComponent
51 public static final int DEFAULT_OPTION = 0;
52 public static final int YES_NO_OPTION = 1;
53 public static final int YES_NO_CANCEL_OPTION = 2;
54 public static final int OK_CANCEL_OPTION = 3;
55 public static final int YES_OPTION = 4;
56 public static final int NO_OPTION = 5;
57 public static final int CANCEL_OPTION = 6;
58 public static final int OK_OPTION = 7;
59 public static final int CLOSED_OPTION = 8;
61 public static final int ERROR_MESSAGE = 0;
62 public static final int INFORMATION_MESSAGE = 1;
63 public static final int WARNING_MESSAGE = 2;
64 public static final int QUESTION_MESSAGE = 3;
65 public static final int PLAIN_MESSAGE = 4;
67 final static String VALUE_PROPERTY = "value_prop";
68 final static String INPUT_VALUE_PROPERTY = "input_value_prop";
70 final static String UNINITIALIZED_VALUE = "uninit";
72 // Ronald: shouldnt by public ?
73 public Object msg;
74 public int mtype;
75 public int otype;
76 public Icon icon;
77 public Object []args;
78 public Object init;
80 public JDialog dialog;
82 /*****************************************************************************
85 * joptionpanels
88 ***********************************/
90 JOptionPane()
92 this("mess");
95 JOptionPane(Object m)
97 this(m, PLAIN_MESSAGE);
100 JOptionPane(Object m,
101 int mtype)
103 this(m, mtype, DEFAULT_OPTION);
106 JOptionPane(Object m,
107 int mtype,
108 int otype)
110 this(m, mtype, otype, null);
113 JOptionPane(Object m,
114 int mtype,
115 int otype,
116 Icon icon)
118 this(m, mtype, otype, icon, null);
121 JOptionPane(Object m,
122 int mtype,
123 int otype,
124 Icon icon,
125 Object []args)
127 this(m, mtype, otype, icon, args, null);
130 JOptionPane(Object msg,
131 int mtype,
132 int otype,
133 Icon icon,
134 Object []args,
135 Object init)
137 // this(m, mtype, otype, icon, args, init);
138 this.msg = msg;
139 this.mtype = mtype;
140 this.otype = otype;
141 this.icon = icon;
142 this.args = args;
143 this.init = init;
145 updateUI();
149 /*****************************************************************************
155 ***********************************/
157 Object val;
158 public void setValue(Object v)
159 { val = v; }
160 public Object getValue()
161 { return val; }
163 public String getUIClassID()
164 { return "JOptionPane"; }
167 public void setUI(OptionPaneUI ui) {
168 super.setUI(ui);
171 public OptionPaneUI getUI() {
172 return (OptionPaneUI)ui;
175 public void updateUI() {
176 setUI((OptionPaneUI)UIManager.getUI(this));
180 public AccessibleContext getAccessibleContext()
182 return null;
185 protected String paramString()
187 return "JOptionPane";
190 public static void showMessageDialog(Component frame,
191 String msg,
192 String title,
193 int bla)
195 DoShowOptionDialog(frame,
196 msg,
197 title,
198 bla,
200 null,
201 null,
202 null);
205 public static void showMessageDialog(Component frame,
206 String msg,
207 String title,
208 int bla,
209 Icon icon)
211 DoShowOptionDialog(frame,
212 msg,
213 title,
214 bla,
216 icon,
217 null,
218 null);
221 public static void showMessageDialog(Component frame,
222 String msg)
224 showMessageDialog(frame,
225 msg,
226 null);
230 public static void showMessageDialog(Component frame,
231 String msg,
232 Icon icon)
234 //System.out.println("++++++++++++++++++creating message dialog:"+msg + ", frame="+frame);
235 DoShowOptionDialog(frame,
236 msg,
237 "Message",
238 DEFAULT_OPTION,
239 PLAIN_MESSAGE,
240 icon,
241 null,
242 null);
245 public static int showConfirmDialog(JFrame frame,
246 String yes,
247 String no,
248 int bla)
250 return 0;
253 public static String showInputDialog(JFrame frame,
254 String msg,
255 String title,
256 int opt_type,
257 int msg_type,
258 Icon icon,
259 Object[] opts,
260 Object init)
262 return (String) DoShowOptionDialog(frame,
263 msg,
264 title,
265 opt_type,
266 msg_type,
267 icon,
268 opts,
269 init);
272 public static Object showInputDialog(JFrame frame,
273 String msg,
274 String title,
275 int opt_type,
276 Icon icon,
277 Object[] opts,
278 Object init)
280 return DoShowOptionDialog(frame,
281 msg,
282 title,
283 opt_type,
284 0, //msg_type,
285 icon,
286 opts,
287 init);
291 // everybody comes here eventually
292 public static int showOptionDialog(Component frame,
293 String msg,
294 String title,
295 int opt_type,
296 int msg_type,
297 Icon icon,
298 Object[] opts,
299 Object init)
301 Integer a = (Integer) DoShowOptionDialog(frame,
302 msg,
303 title,
304 opt_type,
305 msg_type,
306 icon,
307 opts,
308 init);
309 if (a == null)
310 return -1;
311 return a.intValue();
314 public static Object DoShowOptionDialog(Component frame,
315 String msg,
316 String title,
317 int opt_type,
318 int msg_type,
319 Icon icon,
320 Object[] opts,
321 Object init)
324 JOptionPane p = new JOptionPane(msg,
325 msg_type,
326 opt_type,
327 icon,
328 opts,
329 init);
330 System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " + p.msg);
333 JDialog a;
335 if (frame == null)
337 a = new JDialog((Frame)frame,
338 title,
339 true);
341 else if (frame instanceof Dialog)
343 a = new JDialog((Dialog) frame,
344 title,
345 true);
347 else if (frame instanceof Frame)
349 a = new JDialog((Frame) frame,
350 title,
351 true);
353 else
355 System.out.println("HUUUUHHH, not a frame or dialog !");
357 a = new JDialog((Frame)null,
358 title,
359 true);
362 p.dialog = a;
364 a.getContentPane().setLayout(new BorderLayout());
365 a.getContentPane().add(p,
366 BorderLayout.CENTER);
367 // package the deal
368 a.pack();
370 a.setVisible(true);
372 Object s = p.getValue();
374 System.out.println("RESULT FROM DIALOG = " + s);
376 if (s == null)
377 return null;
379 return s;