Source Code Cross Referenced for FileDialoger.java in  » Testing » jakarta-jmeter » org » apache » jmeter » gui » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.gui.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  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: 571988 $
033:         */
034:        public final class FileDialoger {
035:            /**
036:             * The last directory visited by the user while choosing Files.
037:             */
038:            private static String lastJFCDirectory = null;
039:
040:            private static JFileChooser jfc = new JFileChooser();
041:
042:            /**
043:             * Prevent instantiation of utility class.
044:             */
045:            private FileDialoger() {
046:            }
047:
048:            /**
049:             * Prompts the user to choose a file from their filesystems for our own
050:             * devious uses. This method maintains the last directory the user visited
051:             * before dismissing the dialog. This does NOT imply they actually chose a
052:             * file from that directory, only that they closed the dialog there. It is
053:             * the caller's responsibility to check to see if the selected file is
054:             * non-null.
055:             * 
056:             * @return the JFileChooser that interacted with the user, after they are
057:             *         finished using it (accept or otherwise).
058:             */
059:            public static JFileChooser promptToOpenFile(String[] exts) {
060:                // JFileChooser jfc = null;
061:
062:                if (lastJFCDirectory == null) {
063:                    String start = JMeterUtils.getPropDefault("user.dir", ""); //$NON-NLS-1$//$NON-NLS-2$
064:
065:                    if (start.length() > 0) {
066:                        jfc.setCurrentDirectory(new File(start));
067:                    }
068:                }
069:                clearFileFilters();
070:                if (exts != null && exts.length > 0) {
071:                    jfc.addChoosableFileFilter(new JMeterFileFilter(exts));
072:                }
073:                int retVal = jfc.showOpenDialog(GuiPackage.getInstance()
074:                        .getMainFrame());
075:                lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
076:
077:                if (retVal == JFileChooser.APPROVE_OPTION) {
078:                    return jfc;
079:                } else {
080:                    return null;
081:                }
082:            }
083:
084:            private static void clearFileFilters() {
085:                FileFilter[] filters = jfc.getChoosableFileFilters();
086:                for (int x = 0; x < filters.length; x++) {
087:                    jfc.removeChoosableFileFilter(filters[x]);
088:                }
089:            }
090:
091:            public static JFileChooser promptToOpenFile() {
092:                return promptToOpenFile(new String[0]);
093:            }
094:
095:            /**
096:             * Prompts the user to choose a file from their filesystems for our own
097:             * devious uses. This method maintains the last directory the user visited
098:             * before dismissing the dialog. This does NOT imply they actually chose a
099:             * file from that directory, only that they closed the dialog there. It is
100:             * the caller's responsibility to check to see if the selected file is
101:             * non-null.
102:             * 
103:             * @return the JFileChooser that interacted with the user, after they are
104:             *         finished using it (accept or otherwise).
105:             * @see #promptToOpenFile()
106:             */
107:            public static JFileChooser promptToSaveFile(String filename) {
108:                return promptToSaveFile(filename, null);
109:            }
110:
111:            /**
112:             * Get a JFileChooser with a new FileFilter.
113:             * 
114:             * @param filename file name
115:             * @param extensions list of extensions
116:             * @return the FileChooser
117:             */
118:            public static JFileChooser promptToSaveFile(String filename,
119:                    String[] extensions) {
120:                if (lastJFCDirectory == null) {
121:                    String start = JMeterUtils.getPropDefault("user.dir", "");//$NON-NLS-1$//$NON-NLS-2$
122:                    if (start.length() > 0) {
123:                        jfc = new JFileChooser(new File(start));
124:                    }
125:                    lastJFCDirectory = jfc.getCurrentDirectory()
126:                            .getAbsolutePath();
127:                }
128:                String ext = ".jmx";//$NON-NLS-1$
129:                if (filename != null) {
130:                    jfc.setSelectedFile(new File(lastJFCDirectory, filename));
131:                    int i = -1;
132:                    if ((i = filename.lastIndexOf(".")) > -1) {//$NON-NLS-1$
133:                        ext = filename.substring(i);
134:                    }
135:                }
136:                clearFileFilters();
137:                if (extensions != null) {
138:                    jfc
139:                            .addChoosableFileFilter(new JMeterFileFilter(
140:                                    extensions));
141:                } else {
142:                    jfc.addChoosableFileFilter(new JMeterFileFilter(
143:                            new String[] { ext }));
144:                }
145:
146:                int retVal = jfc.showSaveDialog(GuiPackage.getInstance()
147:                        .getMainFrame());
148:                lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath();
149:                if (retVal == JFileChooser.APPROVE_OPTION) {
150:                    return jfc;
151:                } else {
152:                    return null;
153:                }
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.