Source Code Cross Referenced for JFileChooserTester.java in  » Testing » abbot-1.0.1 » abbot » tester » 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 » abbot 1.0.1 » abbot.tester 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package abbot.tester;
002:
003:        import java.awt.*;
004:        import java.io.File;
005:        import javax.swing.*;
006:
007:        import abbot.finder.*;
008:        import abbot.finder.matchers.*;
009:        import abbot.i18n.Strings;
010:
011:        /**
012:         * Tester for the {@link JFileChooser}.  
013:         * Note: only a small subset of JFileChooser functionality is exposed here.
014:         * @author twall@users.sf.net
015:         */
016:        public class JFileChooserTester extends JComponentTester {
017:
018:            private JTextComponentTester tester = new JTextComponentTester();
019:            private ComponentFinder finder = BasicFinder.getDefault();
020:
021:            private Component find(Container chooser, Matcher m) {
022:                try {
023:                    return finder.find(chooser, m);
024:                } catch (ComponentSearchException e) {
025:                    return null;
026:                }
027:            }
028:
029:            private JButton findButton(Container chooser, final String text) {
030:                JButton button = (JButton) find(chooser, new ClassMatcher(
031:                        JButton.class) {
032:                    public boolean matches(Component c) {
033:                        return super .matches(c)
034:                                && text.equals(((JButton) c).getText());
035:                    }
036:                });
037:                return button;
038:            }
039:
040:            /** Sets the selected file. */
041:            public void actionSetSelectedFile(Component c, final File file) {
042:                final JFileChooser chooser = (JFileChooser) c;
043:                int mode = chooser.getFileSelectionMode();
044:                if (mode == JFileChooser.FILES_ONLY && file.isDirectory()) {
045:                    String msg = Strings.get("tester.JFileChooser.files_only");
046:                    throw new ActionFailedException(msg);
047:                }
048:                if (mode == JFileChooser.DIRECTORIES_ONLY
049:                        && !file.isDirectory()) {
050:                    String msg = Strings.get("tester.JFileChooser.dirs_only");
051:                    throw new ActionFailedException(msg);
052:                }
053:                invokeAndWait(new Runnable() {
054:                    public void run() {
055:                        chooser.setSelectedFile(file);
056:                    }
057:                });
058:            }
059:
060:            /** Sets the text in the file name/path text field.  Note that the 
061:             * {@link JFileChooser} may behave differently depending on what
062:             * you actually feed into that field.
063:             */
064:            public void actionSetFilename(Component c, String filename) {
065:                JTextField tf = (JTextField) find((JFileChooser) c,
066:                        new ClassMatcher(JTextField.class));
067:                if (tf == null) {
068:                    String msg = Strings
069:                            .get("tester.JFileChooser.filename_not_found");
070:                    throw new ActionFailedException(msg);
071:                }
072:                tester.actionEnterText(tf, filename);
073:            }
074:
075:            /** Sets the current directory from which a file or directory may
076:             * be selected.  This is not the same thing as setting the 
077:             * <em>selected</em> directory when in directory selection mode.
078:             */
079:            public void actionSetDirectory(Component c, final String path) {
080:                final JFileChooser chooser = (JFileChooser) c;
081:                invokeAndWait(new Runnable() {
082:                    public void run() {
083:                        chooser.setCurrentDirectory(new File(path));
084:                    }
085:                });
086:                waitForIdle();
087:            }
088:
089:            /** Press the approve button.  Fails if the button is disabled.
090:             */
091:            public void actionApprove(Component c) {
092:                // Could invoke chooser.approveSelection, but that doesn't actually
093:                // fire the approve button.
094:                JFileChooser chooser = (JFileChooser) c;
095:                String text = chooser.getApproveButtonText();
096:                if (text == null) {
097:                    text = chooser.getUI().getApproveButtonText(chooser);
098:                }
099:                JButton approve = findButton(chooser, text);
100:                if (approve == null) {
101:                    String msg = Strings
102:                            .get("tester.JFileChooser.approve_not_found");
103:                    throw new ActionFailedException(msg);
104:                }
105:                if (!approve.isEnabled()) {
106:                    String msg = Strings
107:                            .get("tester.JFileChooser.approve_not_enabled");
108:                    throw new ActionFailedException(msg);
109:                }
110:                actionClick(approve);
111:            }
112:
113:            /** Press the cancel button.  Fails if the button is disabled. */
114:            public void actionCancel(Component c) {
115:                // We could invoke chooser.cancelSelection, but that wouldn't actually
116:                // fire the cancel button...
117:                JFileChooser chooser = (JFileChooser) c;
118:                JButton cancel = findButton(chooser, UIManager
119:                        .getString("FileChooser.cancelButtonText"));
120:                if (cancel == null) {
121:                    String msg = Strings
122:                            .get("tester.JFileChooser.cancel_not_found");
123:                    throw new ActionFailedException(msg);
124:                }
125:                if (!cancel.isEnabled()) {
126:                    String msg = Strings
127:                            .get("tester.JFileChooser.cancel_not_enabled");
128:                    throw new ActionFailedException(msg);
129:                }
130:                actionClick(cancel);
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.