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