Merge from the pain train
[official-gcc.git] / libjava / java / awt / FileDialog.java
blob3e22d02e53dd7cd28ea176d97dbc95be43f2bcdb
1 /* FileDialog.java -- A filename selection dialog box
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 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 java.awt;
41 import java.awt.peer.FileDialogPeer;
42 import java.io.FilenameFilter;
43 import java.io.Serializable;
45 /**
46 * This class implements a file selection dialog box widget.
48 * @author Aaron M. Renn (arenn@urbanophile.com)
49 * @author Tom Tromey (tromey@redhat.com)
51 public class FileDialog extends Dialog implements Serializable
55 * Static Variables
58 /**
59 * Indicates that the purpose of the dialog is for opening a file.
61 public static final int LOAD = 0;
63 /**
64 * Indicates that the purpose of the dialog is for saving a file.
66 public static final int SAVE = 1;
68 // Serialization constant
69 private static final long serialVersionUID = 5035145889651310422L;
71 /*************************************************************************/
74 * Instance Variables
77 /**
78 * @serial The directory for this file dialog.
80 private String dir;
82 /**
83 * @serial The filename for this file dialog
85 private String file;
87 /**
88 * @serial The filter for selecting filenames to display
90 private FilenameFilter filter;
92 /**
93 * @serial The mode of this dialog, either <code>LOAD</code> or
94 * <code>SAVE</code>.
96 private int mode;
98 /*************************************************************************/
101 * Constructors
105 * Initializes a new instance of <code>FileDialog</code> with the
106 * specified parent. This dialog will have no title and will be for
107 * loading a file.
109 * @param parent The parent frame for this dialog.
111 public
112 FileDialog(Frame parent)
114 this(parent, "", LOAD);
117 /*************************************************************************/
120 * Initialized a new instance of <code>FileDialog</code> with the
121 * specified parent and title. This dialog will be for opening a file.
123 * @param parent The parent frame for this dialog.
124 * @param title The title for this dialog.
126 public
127 FileDialog(Frame parent, String title)
129 this(parent, title, LOAD);
132 /*************************************************************************/
135 * Initialized a new instance of <code>FileDialog</code> with the
136 * specified parent, title, and mode.
138 * @param parent The parent frame for this dialog.
139 * @param title The title for this dialog.
140 * @param mode The mode of the dialog, either <code>LOAD</code> or
141 * <code>SAVE</code>.
143 * @exception IllegalArgumentException If an illegal file dialog mode
144 * is supplied.
146 public
147 FileDialog(Frame parent, String title, int mode)
149 super(parent, title, true);
151 if ((mode != LOAD) && (mode != SAVE))
152 throw new IllegalArgumentException (
153 "Mode argument must be either LOAD or SAVE");
155 setMode (mode);
158 /*************************************************************************/
161 * Instance Methods
165 * Returns the mode of this dialog, either <code>LOAD</code> or
166 * <code>SAVE</code>.
168 * @return The mode of this dialog.
170 public int
171 getMode()
173 return(mode);
176 /*************************************************************************/
179 * Sets the mode of this dialog to either <code>LOAD</code> or
180 * <code>SAVE</code>. This method is only effective before the native
181 * peer is created.
183 * @param mode The new mode of this file dialog.
185 * @exception IllegalArgumentException If an illegal file dialog mode
186 * is supplied.
188 public void
189 setMode(int mode)
191 if ((mode != LOAD) && (mode != SAVE))
192 throw new IllegalArgumentException("Bad mode: " + mode);
194 this.mode = mode;
197 /*************************************************************************/
200 * Returns the directory for this file dialog.
202 * @return The directory for this file dialog.
204 public String
205 getDirectory()
207 return(dir);
210 /*************************************************************************/
213 * Sets the directory for this file dialog.
215 * @param dir The new directory for this file dialog.
217 public synchronized void
218 setDirectory(String dir)
220 this.dir = dir;
221 if (peer != null)
223 FileDialogPeer f = (FileDialogPeer) peer;
224 f.setDirectory (dir);
228 /*************************************************************************/
231 * Returns the file that is selected in this dialog.
233 * @return The file that is selected in this dialog.
235 public String
236 getFile()
238 return(file);
241 /*************************************************************************/
244 * Sets the selected file for this dialog.
246 * @param file The selected file for this dialog.
248 public synchronized void
249 setFile(String file)
251 this.file = file;
252 if (peer != null)
254 FileDialogPeer f = (FileDialogPeer) peer;
255 f.setFile (file);
259 /*************************************************************************/
262 * Returns the filename filter being used by this dialog.
264 * @return The filename filter being used by this dialog.
266 public FilenameFilter
267 getFilenameFilter()
269 return(filter);
272 /*************************************************************************/
275 * Sets the filename filter used by this dialog.
277 * @param filter The new filename filter for this file dialog box.
279 public synchronized void
280 setFilenameFilter(FilenameFilter filter)
282 this.filter = filter;
283 if (peer != null)
285 FileDialogPeer f = (FileDialogPeer) peer;
286 f.setFilenameFilter (filter);
290 /*************************************************************************/
293 * Creates the native peer for this file dialog box.
295 public void
296 addNotify()
298 if (peer == null)
299 peer = getToolkit ().createFileDialog (this);
300 super.addNotify ();
303 /*************************************************************************/
306 * Returns a debugging string for this object.
308 * @return A debugging string for this object.
310 protected String
311 paramString()
313 return ("dir=" + dir + ",file=" + file +
314 ",mode=" + mode + "," + super.paramString());
317 } // class FileDialog