KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > apollo > dev > DevFileOpenService


1 /*
2 ** Apollo - Test Skeleton Toolkit for Web Start/JNLP
3 ** Copyright (c) 2001, 2002, 2003 by Gerald Bauer
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** General Public License as published by the Free Software Foundation.
9 ** Version 2 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

22
23 package apollo.dev;
24
25 import java.io.*;
26 import javax.swing.JFileChooser JavaDoc;
27 import apollo.*;
28
29 public class DevFileOpenService implements FileOpenService
30 {
31    JFileChooser JavaDoc _chooser;
32
33    public DevFileOpenService()
34    {
35       _chooser = new JFileChooser JavaDoc();
36    }
37
38    public FileContents openFileDialog( String JavaDoc pathHint, String JavaDoc exts[] )
39           throws IOException
40    {
41       if( pathHint != null )
42          _chooser.setCurrentDirectory( new File( pathHint ) );
43
44       // todo: add extension file filters
45

46       _chooser.setMultiSelectionEnabled( false );
47       if( _chooser.showOpenDialog( null ) == JFileChooser.CANCEL_OPTION )
48          return null;
49
50       File file = _chooser.getSelectedFile();
51       if( file == null )
52          return null;
53       else
54          return new DevFileContents( file );
55    }
56
57    public FileContents[] openMultiFileDialog( String JavaDoc pathHint, String JavaDoc exts[] )
58           throws IOException
59    {
60       if( pathHint != null )
61          _chooser.setCurrentDirectory( new File( pathHint ) );
62
63       _chooser.setMultiSelectionEnabled( true );
64       if( _chooser.showOpenDialog( null ) == JFileChooser.CANCEL_OPTION )
65          return null;
66
67       File file[] = _chooser.getSelectedFiles();
68       DevFileContents contents[] = new DevFileContents[file.length];
69       for( int i = 0; i < file.length; i++ )
70          contents[i] = new DevFileContents( file[i] );
71
72       return contents;
73    }
74 }
75
Popular Tags