source: trunk/gcc/libjava/java/awt/FileDialog.java

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

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.6 KB
Line 
1/* FileDialog.java -- A filename selection dialog box
2 Copyright (C) 1999, 2000, 2001, 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
38
39package java.awt;
40
41import java.awt.peer.FileDialogPeer;
42import java.awt.peer.DialogPeer;
43import java.awt.peer.WindowPeer;
44import java.awt.peer.ContainerPeer;
45import java.awt.peer.ComponentPeer;
46import java.io.FilenameFilter;
47
48/**
49 * This class implements a file selection dialog box widget.
50 *
51 * @author Aaron M. Renn (arenn@urbanophile.com)
52 * @author Tom Tromey <tromey@redhat.com>
53 */
54public class FileDialog extends Dialog implements java.io.Serializable
55{
56
57/*
58 * Static Variables
59 */
60
61/**
62 * Indicates that the purpose of the dialog is for opening a file.
63 */
64public static final int LOAD = 0;
65
66/**
67 * Indicates that the purpose of the dialog is for saving a file.
68 */
69public static final int SAVE = 1;
70
71// Serialization constant
72private static final long serialVersionUID = 5035145889651310422L;
73
74/*************************************************************************/
75
76/*
77 * Instance Variables
78 */
79
80/**
81 * @serial The directory for this file dialog.
82 */
83private String dir;
84
85/**
86 * @serial The filename for this file dialog
87 */
88private String file;
89
90/**
91 * @serial The filter for selecting filenames to display
92 */
93private FilenameFilter filter;
94
95/**
96 * @serial The mode of this dialog, either <code>LOAD</code> or
97 * <code>SAVE</code>.
98 */
99private int mode;
100
101/*************************************************************************/
102
103/*
104 * Constructors
105 */
106
107/**
108 * Initializes a new instance of <code>FileDialog</code> with the
109 * specified parent. This dialog will have no title and will be for
110 * loading a file.
111 *
112 * @param parent The parent frame for this dialog.
113 */
114public
115FileDialog(Frame parent)
116{
117 this(parent, "", LOAD);
118}
119
120/*************************************************************************/
121
122/**
123 * Initialized a new instance of <code>FileDialog</code> with the
124 * specified parent and title. This dialog will be for opening a file.
125 *
126 * @param parent The parent frame for this dialog.
127 * @param title The title for this dialog.
128 */
129public
130FileDialog(Frame parent, String title)
131{
132 this(parent, title, LOAD);
133}
134
135/*************************************************************************/
136
137/**
138 * Initialized a new instance of <code>FileDialog</code> with the
139 * specified parent, title, and mode.
140 *
141 * @param parent The parent frame for this dialog.
142 * @param title The title for this dialog.
143 * @param mode The mode of the dialog, either <code>LOAD</code> or
144 * <code>SAVE</code>.
145 *
146 * @exception IllegalArgumentException If an illegal file dialog mode
147 * is supplied.
148 */
149public
150FileDialog(Frame parent, String title, int mode)
151{
152 super(parent, title, true);
153 setMode (mode);
154}
155
156/*************************************************************************/
157
158/*
159 * Instance Methods
160 */
161
162/**
163 * Returns the mode of this dialog, either <code>LOAD</code> or
164 * <code>SAVE</code>.
165 *
166 * @return The mode of this dialog.
167 */
168public int
169getMode()
170{
171 return(mode);
172}
173
174/*************************************************************************/
175
176/**
177 * Sets the mode of this dialog to either <code>LOAD</code> or
178 * <code>SAVE</code>. This method is only effective before the native
179 * peer is created.
180 *
181 * @param mode The new mode of this file dialog.
182 *
183 * @exception IllegalArgumentException If an illegal file dialog mode
184 * is supplied.
185 */
186public void
187setMode(int mode)
188{
189 if ((mode != LOAD) && (mode != SAVE))
190 throw new IllegalArgumentException("Bad mode: " + mode);
191
192 this.mode = mode;
193}
194
195/*************************************************************************/
196
197/**
198 * Returns the directory for this file dialog.
199 *
200 * @return The directory for this file dialog.
201 */
202public String
203getDirectory()
204{
205 return(dir);
206}
207
208/*************************************************************************/
209
210/**
211 * Sets the directory for this file dialog.
212 *
213 * @param dir The new directory for this file dialog.
214 */
215public synchronized void
216setDirectory(String dir)
217{
218 this.dir = dir;
219 if (peer != null)
220 {
221 FileDialogPeer f = (FileDialogPeer) peer;
222 f.setDirectory (dir);
223 }
224}
225
226/*************************************************************************/
227
228/**
229 * Returns the file that is selected in this dialog.
230 *
231 * @return The file that is selected in this dialog.
232 */
233public String
234getFile()
235{
236 return(file);
237}
238
239/*************************************************************************/
240
241/**
242 * Sets the selected file for this dialog.
243 *
244 * @param file The selected file for this dialog.
245 */
246public synchronized void
247setFile(String file)
248{
249 this.file = file;
250 if (peer != null)
251 {
252 FileDialogPeer f = (FileDialogPeer) peer;
253 f.setFile (file);
254 }
255}
256
257/*************************************************************************/
258
259/**
260 * Returns the filename filter being used by this dialog.
261 *
262 * @param The filename filter being used by this dialog.
263 */
264public FilenameFilter
265getFilenameFilter()
266{
267 return(filter);
268}
269
270/*************************************************************************/
271
272/**
273 * Sets the filename filter used by this dialog.
274 *
275 * @param filter The new filename filter for this file dialog box.
276 */
277public synchronized void
278setFilenameFilter(FilenameFilter filter)
279{
280 this.filter = filter;
281 if (peer != null)
282 {
283 FileDialogPeer f = (FileDialogPeer) peer;
284 f.setFilenameFilter (filter);
285 }
286}
287
288/*************************************************************************/
289
290/**
291 * Creates the native peer for this file dialog box.
292 */
293public void
294addNotify()
295{
296 if (peer == null)
297 peer = getToolkit ().createFileDialog (this);
298 super.addNotify ();
299}
300
301/*************************************************************************/
302
303/**
304 * Returns a debugging string for this object.
305 *
306 * @return A debugging string for this object.
307 */
308protected String
309paramString()
310{
311 return ("dir=" + dir + ",file=" + file +
312 ",mode=" + mode + "," + super.paramString());
313}
314
315} // class FileDialog
316
Note: See TracBrowser for help on using the repository browser.