~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/util/image/FileSave.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; either version 2 of the License, or
 
5
 * (at your option) any later version.
 
6
 * This program is distributed in the hope that it will be useful,
 
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
 * GNU General Public License for more details.
 
10
 * You should have received a copy of the GNU General Public License
 
11
 * along with this program; if not, write to the Free Software
 
12
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
13
 */
 
14
 
 
15
 
 
16
/*
 
17
  @author George El-Haddad
 
18
  @email  nekromancer@users.sourceforge.net
 
19
 */
 
20
 
 
21
package util.image;
 
22
 
 
23
import java.io.*;
 
24
import javax.swing.*;
 
25
 
 
26
public class FileSave 
 
27
{
 
28
        private File file = null;
 
29
 
 
30
        /**
 
31
           Default Constructor.
 
32
           
 
33
           Creates a file selection dialog starting at the current
 
34
           working directory. The user will specify what directory
 
35
           or folder they want their files to be saved in.
 
36
           
 
37
           @param java.lang.String title  the title of the JFileChooser
 
38
           @param java.lang.String name   a recomended name
 
39
           
 
40
           @exception java.lang.Exception  ex
 
41
        */
 
42
        public FileSave(String title, String name) 
 
43
        {
 
44
                JFileChooser chooser = new JFileChooser();
 
45
                
 
46
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
 
47
                chooser.setDialogTitle(title);
 
48
                chooser.setCurrentDirectory(new File(System.getProperties().getProperty("user.dir")));
 
49
                chooser.setFileFilter(new javax.swing.filechooser.FileFilter()
 
50
                {
 
51
                        public boolean accept(File f)
 
52
                        {
 
53
                                return f.isDirectory();
 
54
                        }
 
55
                        
 
56
                        public String getDescription()
 
57
                        {
 
58
                                return "Folder To Save In";
 
59
                        }
 
60
                });
 
61
 
 
62
                //show the file chooser dialog
 
63
                int r = chooser.showSaveDialog(null);
 
64
 
 
65
                if (r == JFileChooser.APPROVE_OPTION)
 
66
                {
 
67
                        if(name != null)
 
68
                        {
 
69
                                file = new File(chooser.getSelectedFile().getPath()+File.separator+name);
 
70
                        }
 
71
                        else {
 
72
                                file = new File(chooser.getSelectedFile().getPath());
 
73
                        }
 
74
                }
 
75
        }
 
76
        
 
77
        
 
78
        /**
 
79
           File getFile()
 
80
           
 
81
           Returns the directory path as
 
82
           a File object.
 
83
 
 
84
           @return java.io.File
 
85
        */
 
86
        public File getFile()
 
87
        {
 
88
                return file;
 
89
        }
 
90
 
 
91
 
 
92
        /**
 
93
           String getPathString()
 
94
           
 
95
           Returns the directory path as
 
96
           as string.
 
97
 
 
98
           @return java.lang.String
 
99
        */
 
100
        public String getPathString()
 
101
        {
 
102
                if(file == null)
 
103
                {
 
104
                        return null;
 
105
                }
 
106
                else
 
107
                {
 
108
                        return file.getPath();
 
109
                }
 
110
        }
 
111
        
 
112
        
 
113
}//end class FileSave