1 package org.wcb.autohome.util;
2
3 import javax.swing.JFileChooser;
4 import java.io.File;
5
6 /***
7 * Copyright (C) 1999 Walter Bogaardt
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 *
23 * Project: Alice X10 Home Automation
24 *
25 * $Log: SaveFileDialog.java,v $
26 * Revision 1.2 2004/02/25 21:41:38 wbogaardt
27 * fixed formating to checkstyle standard
28 *
29 * Revision 1.1 2003/12/30 21:20:17 wbogaardt
30 * added new file saving dialog to actually save files in .x10 extension.
31 *
32 */
33 public class SaveFileDialog {
34
35 private static JFileChooser jfcChooser = null;
36 private String sDirectory;
37 private boolean bIsFile = false;
38
39 /***
40 * Allows saving of file using the default X10File filter this means
41 * that the file will be saved with .x10 extension.
42 */
43 public SaveFileDialog() {
44 if (jfcChooser == null)
45 {
46 jfcChooser = new JFileChooser();
47 jfcChooser.addChoosableFileFilter(new X10Filter());
48 }
49 int fileState = jfcChooser.showSaveDialog(null);
50 File file = jfcChooser.getSelectedFile();
51 if (file != null && fileState == JFileChooser.APPROVE_OPTION)
52 {
53 setFilePath(file.getAbsolutePath());
54 }
55 else if (fileState == JFileChooser.CANCEL_OPTION)
56 {
57 bIsFile = false;
58 }
59 }
60
61 /***
62 * gets the file path of the file and appends the .x10 extension
63 * @return file with .x10 extension
64 */
65 public String getFilePath() {
66 return sDirectory + ".x10";
67 }
68
69 /***
70 * Determins that a file name was entered or selected.
71 * @return true indicates file was selected.
72 */
73 public boolean isFileSelected() {
74 return bIsFile;
75 }
76
77 /***
78 * sets the file path.
79 * @param fpath The file path that the saved file was set.
80 */
81 private void setFilePath(String fpath) {
82 sDirectory = fpath;
83 bIsFile = true;
84 }
85 }