Source Code Cross Referenced for AbstractTextBoxHandlerForTextComponent.java in  » Testing » UISpec4J » org » uispec4j » 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 » UISpec4J » org.uispec4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j;
002:
003:        import junit.framework.Assert;
004:        import org.uispec4j.assertion.Assertion;
005:        import org.uispec4j.assertion.UISpecAssert;
006:        import org.uispec4j.utils.KeyUtils;
007:
008:        import javax.swing.*;
009:        import javax.swing.text.BadLocationException;
010:        import javax.swing.text.Document;
011:        import javax.swing.text.JTextComponent;
012:        import java.awt.*;
013:
014:        abstract class AbstractTextBoxHandlerForTextComponent implements 
015:                TextBox.Handler {
016:            protected JTextComponent jTextComponent;
017:
018:            public AbstractTextBoxHandlerForTextComponent(
019:                    JTextComponent textComponent) {
020:                this .jTextComponent = textComponent;
021:            }
022:
023:            public Component getAwtComponent() {
024:                return jTextComponent;
025:            }
026:
027:            public void setText(String text) {
028:                UISpecAssert.assertTrue(isEditable());
029:                jTextComponent.setText(text);
030:                if (jTextComponent instanceof  JTextField) {
031:                    ((JTextField) jTextComponent).postActionEvent();
032:                }
033:            }
034:
035:            public void insertText(String text, int position) {
036:                UISpecAssert.assertTrue(isEditable());
037:                Document document = jTextComponent.getDocument();
038:                try {
039:                    document.insertString(position, text, document
040:                            .getDefaultRootElement().getAttributes());
041:                } catch (BadLocationException e) {
042:                    Assert.fail("Position should be between 0 and "
043:                            + document.getLength());
044:                }
045:            }
046:
047:            public String getText() {
048:                return jTextComponent.getText();
049:            }
050:
051:            public Assertion textContains(final String text) {
052:                return new Assertion() {
053:                    public void check() {
054:                        String actual = jTextComponent.getText().replaceAll(
055:                                "\n    ", "").replaceAll("\n  </body>",
056:                                "</body>");
057:                        Assert.assertTrue(
058:                                "The component text does not contain '" + text
059:                                        + "' - actual content is:" + actual,
060:                                actual.indexOf(text.trim()) >= 0);
061:                    }
062:                };
063:            }
064:
065:            public Assertion textDoesNotContain(final String text) {
066:                return new Assertion() {
067:                    public void check() {
068:                        String actual = jTextComponent.getText();
069:                        Assert.assertTrue(
070:                                "The component text should not contain '"
071:                                        + text + "' - actual content is:"
072:                                        + actual, actual.indexOf(text) < 0);
073:                    }
074:                };
075:            }
076:
077:            public Assertion isEditable() {
078:                return new Assertion() {
079:                    public void check() {
080:                        Assert.assertTrue("The text box is not editable",
081:                                jTextComponent.isEditable());
082:                    }
083:                };
084:            }
085:
086:            public void pressKey(Key key) {
087:                KeyUtils.pressKey(jTextComponent, key);
088:                if (jTextComponent.isEditable() && key.isPrintable()) {
089:                    Document document = jTextComponent.getDocument();
090:                    try {
091:                        int position = jTextComponent.getCaretPosition();
092:                        document.insertString(position, new Character(
093:                                (char) key.getCode()).toString(), document
094:                                .getDefaultRootElement().getAttributes());
095:                        jTextComponent.moveCaretPosition(document
096:                                .getEndPosition().getOffset() - 1);
097:                        //        jTextComponent.moveCaretPosition(position + 1);
098:                    } catch (BadLocationException e) {
099:                        Assert.fail(e.getMessage());
100:                    }
101:                }
102:            }
103:
104:            public Assertion iconEquals(Icon icon) {
105:                throw new UnsupportedOperationException(
106:                        "assertIconEquals is not supported for JTextComponent components");
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.