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)
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
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
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. */
41 import java
.awt
.peer
.FileDialogPeer
;
42 import java
.io
.FilenameFilter
;
43 import java
.io
.Serializable
;
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
59 * Indicates that the purpose of the dialog is for opening a file.
61 public static final int LOAD
= 0;
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 /*************************************************************************/
78 * @serial The directory for this file dialog.
83 * @serial The filename for this file dialog
88 * @serial The filter for selecting filenames to display
90 private FilenameFilter filter
;
93 * @serial The mode of this dialog, either <code>LOAD</code> or
98 /*************************************************************************/
105 * Initializes a new instance of <code>FileDialog</code> with the
106 * specified parent. This dialog will have no title and will be for
109 * @param parent The parent frame for this dialog.
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.
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
143 * @exception IllegalArgumentException If an illegal file dialog mode
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");
158 /*************************************************************************/
165 * Returns the mode of this dialog, either <code>LOAD</code> or
168 * @return The mode of this dialog.
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
183 * @param mode The new mode of this file dialog.
185 * @exception IllegalArgumentException If an illegal file dialog mode
191 if ((mode
!= LOAD
) && (mode
!= SAVE
))
192 throw new IllegalArgumentException("Bad mode: " + mode
);
197 /*************************************************************************/
200 * Returns the directory for this file dialog.
202 * @return The directory for this file dialog.
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
)
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.
241 /*************************************************************************/
244 * Sets the selected file for this dialog.
246 * @param file The selected file for this dialog.
248 public synchronized void
254 FileDialogPeer f
= (FileDialogPeer
) peer
;
259 /*************************************************************************/
262 * Returns the filename filter being used by this dialog.
264 * @return The filename filter being used by this dialog.
266 public FilenameFilter
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
;
285 FileDialogPeer f
= (FileDialogPeer
) peer
;
286 f
.setFilenameFilter (filter
);
290 /*************************************************************************/
293 * Creates the native peer for this file dialog box.
299 peer
= getToolkit ().createFileDialog (this);
303 /*************************************************************************/
306 * Returns a debugging string for this object.
308 * @return A debugging string for this object.
313 return ("dir=" + dir
+ ",file=" + file
+
314 ",mode=" + mode
+ "," + super.paramString());
317 } // class FileDialog