01: // $Header $
02: /*
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: */
19:
20: package org.apache.jmeter.gui.util;
21:
22: import java.io.File;
23:
24: import javax.swing.JFileChooser;
25:
26: import org.apache.jmeter.gui.ReportGuiPackage;
27: import org.apache.jmeter.util.JMeterUtils;
28:
29: public final class DirectoryDialoger {
30: /**
31: * The last directory visited by the user while choosing Files.
32: */
33: private static String lastJFCDirectory = null;
34:
35: private static JFileChooser jfc = new JFileChooser();
36:
37: /**
38: * Prevent instantiation of utility class.
39: */
40: private DirectoryDialoger() {
41: }
42:
43: public static JFileChooser promptToOpenFile() {
44:
45: if (lastJFCDirectory == null) {
46: String start = JMeterUtils.getPropDefault("user.dir", "");
47:
48: if (!start.equals("")) {
49: jfc.setCurrentDirectory(new File(start));
50: }
51: }
52: jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
53: int retVal = jfc.showDialog(ReportGuiPackage.getInstance()
54: .getMainFrame(), JMeterUtils
55: .getResString("report_select"));
56: lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
57:
58: if (retVal == JFileChooser.APPROVE_OPTION) {
59: return jfc;
60: } else {
61: return null;
62: }
63: }
64:
65: }
|