source: trunk/src/gcc/libjava/java/awt/FileDialog.java@ 736

Last change on this file since 736 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.5 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 ([email protected])
52 * @author Tom Tromey <[email protected]>
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 */
146public
147FileDialog(Frame parent, String title, int mode)
148{
149 super(parent, title, true);
150
151 if ((mode != LOAD) && (mode != SAVE))
152 throw new IllegalArgumentException("Bad mode: " + mode);
153
154 this.mode = mode;
155}
156
157/*************************************************************************/
158
159/*
160 * Instance Methods
161 */
162
163/**
164 * Returns the mode of this dialog, either <code>LOAD</code> or
165 * <code>SAVE</code>.
166 *
167 * @return The mode of this dialog.
168 */
169public int
170getMode()
171{
172 return(mode);
173}
174
175/*************************************************************************/
176
177/**
178 * Sets the mode of this dialog to either <code>LOAD</code> or
179 * <code>SAVE</code>. This method is only effective before the native
180 * peer is created.
181 *
182 * @param mode The new mode of this file dialog.
183 */
184public void
185setMode(int mode)
186{
187 if ((mode != LOAD) && (mode != SAVE))
188 throw new IllegalArgumentException("Bad mode: " + mode);
189
190 this.mode = mode;
191}
192
193/*************************************************************************/
194
195/**
196 * Returns the directory for this file dialog.
197 *
198 * @return The directory for this file dialog.
199 */
200public String
201getDirectory()
202{
203 return(dir);
204}
205
206/*************************************************************************/
207
208/**
209 * Sets the directory for this file dialog.
210 *
211 * @param dir The new directory for this file dialog.
212 */
213public synchronized void
214setDirectory(String dir)
215{
216 this.dir = dir;
217 if (peer != null)
218 {
219 FileDialogPeer f = (FileDialogPeer) peer;
220 f.setDirectory (dir);
221 }
222}
223
224/*************************************************************************/
225
226/**
227 * Returns the file that is selected in this dialog.
228 *
229 * @return The file that is selected in this dialog.
230 */
231public String
232getFile()
233{
234 return(file);
235}
236
237/*************************************************************************/
238
239/**
240 * Sets the selected file for this dialog.
241 *
242 * @param file The selected file for this dialog.
243 */
244public synchronized void
245setFile(String file)
246{
247 this.file = file;
248 if (peer != null)
249 {
250 FileDialogPeer f = (FileDialogPeer) peer;
251 f.setFile (file);
252 }
253}
254
255/*************************************************************************/
256
257/**
258 * Returns the filename filter being used by this dialog.
259 *
260 * @param The filename filter being used by this dialog.
261 */
262public FilenameFilter
263getFilenameFilter()
264{
265 return(filter);
266}
267
268/*************************************************************************/
269
270/**
271 * Sets the filename filter used by this dialog.
272 *
273 * @param filter The new filename filter for this file dialog box.
274 */
275public synchronized void
276setFilenameFilter(FilenameFilter filter)
277{
278 this.filter = filter;
279 if (peer != null)
280 {
281 FileDialogPeer f = (FileDialogPeer) peer;
282 f.setFilenameFilter (filter);
283 }
284}
285
286/*************************************************************************/
287
288/**
289 * Creates the native peer for this file dialog box.
290 */
291public void
292addNotify()
293{
294 if (peer == null)
295 peer = getToolkit ().createFileDialog (this);
296 super.addNotify ();
297}
298
299/*************************************************************************/
300
301/**
302 * Returns a debugging string for this object.
303 *
304 * @return A debugging string for this object.
305 */
306protected String
307paramString()
308{
309 return ("dir=" + dir + ",file=" + file +
310 ",mode=" + mode + "," + super.paramString());
311}
312
313} // class FileDialog
314
Note: See TracBrowser for help on using the repository browser.