e.g. Calendar Search Help
You must enter a value before pressing Search
jmeter

Class: org.apache.jmeter.gui.util.FileDialoger   ©

 OK to copy?
001 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/util/FileDialoger.java,v 1.7 2004/02/13 02:21:38 sebb Exp $
002 /*
003  * Copyright 2001-2004 The Apache Software Foundation.
004  *
005  * Licensed under the Apache License, Version 2.0 (the "License");
006  * you may not use this file except in compliance with the License.
007  * You may obtain a copy of the License at
008  *
009  *   http://www.apache.org/licenses/LICENSE-2.0
010  *
011  * Unless required by applicable law or agreed to in writing, software
012  * distributed under the License is distributed on an "AS IS" BASIS,
013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014  * See the License for the specific language governing permissions and
015  * limitations under the License.
016  * 
017 */
018 
019 package org.apache.jmeter.gui.util;
020 
021 import java.io.File;
022 
023 import javax.swing.JFileChooser;
024 import javax.swing.filechooser.FileFilter;
025 
026 import org.apache.jmeter.gui.GuiPackage;
027 import org.apache.jmeter.gui.JMeterFileFilter;
028 import org.apache.jmeter.util.JMeterUtils;
029 
030 /**
031  * @author    Michael Stover
032  * @version   $Revision: 1.7 $
033  */
034 public final class FileDialoger
035 {
036     /**
037      * The last directory visited by the user while choosing Files.
038      */
039     public static String lastJFCDirectory = null;//TODO: make private?
040     public static JFileChooser jfc = new JFileChooser();//TODO: make private?
041 
042     /**
043      * Prevent instantiation of utility class.
044      */
045     private FileDialoger()
046     {
047     }
048 
049     /**
050      * Prompts the user to choose a file from their filesystems for our own
051      * devious uses. This method maintains the last directory the user visited
052      * before dismissing the dialog. This does NOT imply they actually chose a
053      * file from that directory, only that they closed the dialog there. It is
054      * the caller's responsibility to check to see if the selected file is
055      * non-null.
056      *
057      * @return   the JFileChooser that interacted with the user, after they are
058      *           finished using it (accept or otherwise).
059      */
060     public static JFileChooser promptToOpenFile(String[] exts)
061     {
062         //JFileChooser jfc = null;
063 
064         if (lastJFCDirectory == null)
065         {
066             String start = JMeterUtils.getPropDefault("user.dir", "");
067 
068             if (!start.equals(""))
069             {
070                 jfc.setCurrentDirectory(new File(start));
071             }
072         }
073         clearFileFilters();
074         jfc.addChoosableFileFilter(new JMeterFileFilter(exts));
075         int retVal =
076             jfc.showOpenDialog(GuiPackage.getInstance().getMainFrame());
Rate077         lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
078 
079         if (retVal == JFileChooser.APPROVE_OPTION)
080         {
081             return jfc;
082         }
083         else
084         {
085             return null;
086         }
087     }
088 
089     private static void clearFileFilters()
090     {
091         FileFilter[] filters = jfc.getChoosableFileFilters();
092         for (int x = 0; x < filters.length; x++)
093         {
094             jfc.removeChoosableFileFilter(filters[x]);
095         }
096     }
097 
098     public static JFileChooser promptToOpenFile()
099     {
100         return promptToOpenFile(new String[0]);
101     }
102 
103     /**
104      * Prompts the user to choose a file from their filesystems for our own
105      * devious uses. This method maintains the last directory the user visited
106      * before dismissing the dialog. This does NOT imply they actually chose a
107      * file from that directory, only that they closed the dialog there. It is
108      * the caller's responsibility to check to see if the selected file is
109      * non-null.
110      *
111      * @return   the JFileChooser that interacted with the user, after they
112      *           are finished using it (accept or otherwise).
113      * @see             #promptToOpenFile
114      */
115     public static JFileChooser promptToSaveFile(String filename)
116     {
117         if (lastJFCDirectory == null)
118         {
119             String start = JMeterUtils.getPropDefault("user.dir", "");
120             if (!start.equals(""))
121             {
122                 jfc = new JFileChooser(new File(start));
123             }
Rate124             lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
125         }
126         String ext = ".jmx";
127         if (filename != null)
128         {
129             jfc.setSelectedFile(new File(lastJFCDirectory, filename));
130             int i = -1;
131             if ((i = filename.indexOf(".")) > -1)
132             {
133                 ext = filename.substring(i);
134             }
135         }
136         clearFileFilters();
137         jfc.addChoosableFileFilter(new JMeterFileFilter(new String[] { ext }));
138 
139         int retVal =
140             jfc.showSaveDialog(GuiPackage.getInstance().getMainFrame());
Rate141         lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
142         if (retVal == JFileChooser.APPROVE_OPTION)
143         {
144             return jfc;
145         }
146         else
147         {
148             return null;
149         }
150     }
151 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
77 0% of 0
124 0% of 0
141 0% of 0