1 22 23 package apollo; 24 25 import java.io.*; 26 27 public class SecureFileChooser 28 { 29 public final static int CANCEL = 2; 30 34 public final static int OK = 1; 35 36 private FileContents _file; 37 38 private FileOpenService _fileOpenService; 39 private FileSaveService _fileSaveService; 40 private FileContents _files[]; 41 42 public SecureFileChooser() 43 { 44 _fileOpenService = ServiceManager.lookupFileOpenService(); 45 _fileSaveService = ServiceManager.lookupFileSaveService(); 46 } 47 48 public FileContents getFileContents() 49 { 50 return _file; 52 } 53 54 public FileContents[] getMultiFileContents() 55 { 56 return _files; 59 } 60 61 public int showOpenDialog() throws IOException 62 { 63 clear(); 64 _file = _fileOpenService.openFileDialog( null, null ); 65 66 if( _file == null ) 67 return CANCEL; 68 else 69 return OK; 70 } 71 72 public int showSaveAsDialog( FileContents contents ) throws IOException 73 { 74 clear(); 75 _file = _fileSaveService.saveAsFileDialog( null, null, contents ); 76 77 if( _file == null ) 78 return CANCEL; 79 else 80 return OK; 81 } 82 83 public int showSaveDialog( InputStream stream ) throws IOException 84 { 85 clear(); 86 _file = _fileSaveService.saveFileDialog( null, null, stream, null ); 87 88 if( _file == null ) 89 return CANCEL; 90 else 91 return OK; 92 } 93 94 private void clear() 95 { 96 _file = null; 97 _files = null; 98 } 99 } 100 | Popular Tags |