1 package org.wcb.gui.dialog.file;
2
3 import org.wcb.gui.dialog.filter.CSVFileExtensionFilter;
4
5 import javax.swing.*;
6 import java.io.File;
7
8 /**
9 * <small>
10 * Copyright (c) 2006 wbogaardt.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * <p/>
25 * $File: $ <br>
26 * $Change: $ submitted by $Author: wbogaardt $ at $DateTime: Apr 3, 2006 1:57:27 PM $ <br>
27 * </small>
28 *
29 * @author wbogaardt
30 * @version 1
31 * Date: Apr 3, 2006
32 * Time: 1:57:27 PM
33 */
34
35 public class ExportFileDialog {
36
37 private static JFileChooser jfcChooser = null;
38 private String sDirectory;
39 private boolean bIsFile = false;
40
41 /**
42 * Allows saving of file using the default X10File filter this means
43 * that the file will be saved with .x10 extension.
44 */
45 public ExportFileDialog() {
46 if (jfcChooser == null)
47 {
48 jfcChooser = new JFileChooser();
49 jfcChooser.addChoosableFileFilter(new CSVFileExtensionFilter());
50 }
51 int fileState = jfcChooser.showSaveDialog(null);
52 File file = jfcChooser.getSelectedFile();
53 if (file != null && fileState == JFileChooser.APPROVE_OPTION)
54 {
55 setFilePath(file.getAbsolutePath());
56 }
57 else if (fileState == JFileChooser.CANCEL_OPTION)
58 {
59 bIsFile = false;
60 }
61 }
62
63 /**
64 * gets the file path of the file and appends the .cvs extension.
65 * @return file with .cvs extension
66 */
67 public String getFilePath() {
68 if(sDirectory == null) {
69 return null;
70 }
71 return sDirectory + ".csv";
72 }
73
74 /**
75 * Determins that a file name was entered or selected.
76 * @return true indicates file was selected.
77 */
78 public boolean isFileSelected() {
79 return bIsFile;
80 }
81
82 /**
83 * sets the file path.
84 * @param fpath The file path that the saved file was set.
85 */
86 private void setFilePath(String fpath) {
87 sDirectory = fpath;
88 bIsFile = true;
89 }
90 }