Source Code Cross Referenced for JListTester.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:
005:        import javax.swing.*;
006:
007:        import abbot.Log;
008:        import abbot.i18n.Strings;
009:        import abbot.script.ArgumentParser;
010:        import abbot.util.Condition;
011:
012:        /** Provide actions and assertions for a {@link JList} component.
013:         The {@link JList} substructure is a "row", and {@link JListLocation}
014:         provides different identifiers for a row.
015:         <ul>
016:         <li>Select an item by index
017:         <li>Select an item by value (its string representation)
018:         </ul>
019:         Note that {@link JList} uses "index" and "value" in its API.  For
020:         convenience, the <code>JListTester</code> API also provides "row" and
021:         "item" as synonyms for "index".
022:
023:         @see JListLocation
024:         */
025:        // TODO multi-select
026:        public class JListTester extends JComponentTester {
027:
028:            /** Convert the value in the list at the given index into a reasonable
029:                string representation, or null if one can not be obtained.
030:             */
031:            public static String valueToString(JList list, int index) {
032:                Object value = list.getModel().getElementAt(index);
033:                Component cr = list.getCellRenderer()
034:                        .getListCellRendererComponent(list, value, index,
035:                                false, false);
036:                String string = convertRendererToString(cr);
037:                return string;
038:            }
039:
040:            /** JList doesn't provide direct access to its contents, so make up for
041:             * that oversight.
042:             */
043:            public Object getElementAt(JList list, int index) {
044:                return list.getModel().getElementAt(index);
045:            }
046:
047:            /** Return the size of the given list. */
048:            public int getSize(JList list) {
049:                return list.getModel().getSize();
050:            }
051:
052:            /** Return an array of strings that represents the list's contents. */
053:            public String[] getContents(JList list) {
054:                ListModel model = list.getModel();
055:                String[] values = new String[model.getSize()];
056:                for (int i = 0; i < values.length; i++) {
057:                    values[i] = model.getElementAt(i).toString();
058:                }
059:                return values;
060:            }
061:
062:            /** Select the given index.
063:                Equivalent to actionSelectRow(c, new JListLocation(index), delay).
064:             */
065:            public void actionSelectIndex(Component c, int index, long delay) {
066:                actionSelectRow(c, new JListLocation(index), delay);
067:            }
068:
069:            /** Select the given index.
070:                Equivalent to actionSelectRow(c, new JListLocation(index)).
071:             */
072:            public void actionSelectIndex(Component c, int index) {
073:                actionSelectRow(c, new JListLocation(index));
074:            }
075:
076:            /** Select the first item in the list matching the given String
077:                representation of the item.<p>
078:                Equivalent to actionSelectRow(c, new JListLocation(item), delay).
079:             */
080:            public void actionSelectItem(Component c, String item, long delay) {
081:                actionSelectRow(c, new JListLocation(item), delay);
082:            }
083:
084:            /** Select the first item in the list matching the given String
085:                representation of the item.<p>
086:                Equivalent to actionSelectRow(c, new JListLocation(item)).
087:             */
088:            public void actionSelectItem(Component c, String item) {
089:                actionSelectRow(c, new JListLocation(item));
090:            }
091:
092:            /** Select the first value in the list matching the given String
093:                representation of the value.<p>
094:                Equivalent to actionSelectRow(c, new JListLocation(value)).
095:             */
096:            public void actionSelectValue(Component c, String value) {
097:                actionSelectRow(c, new JListLocation(value));
098:            }
099:
100:            /** Select the given row.  Does nothing if the index is already
101:             * selected.
102:             */
103:            public void actionSelectRow(Component c,
104:                    final JListLocation location) {
105:                actionSelectRow(c, location, componentDelay);
106:            }
107:
108:            /** Select the given row.  Does nothing if the index is already
109:             * selected.
110:             */
111:            public void actionSelectRow(Component c,
112:                    final JListLocation location, long delay) {
113:                final JList list = (JList) c;
114:
115:                // Wait for the selected location to become avaliable
116:                //
117:
118:                wait(new Condition() {
119:                    public boolean test() {
120:                        int index = location.getIndex(list);
121:                        return index >= 0 && index < list.getModel().getSize();
122:                    }
123:
124:                    public String toString() {
125:                        return Strings.get("tester.Component.show_wait",
126:                                new Object[] { location.toString() });
127:                    }
128:                }, delay);
129:
130:                // Select the location
131:                // 
132:
133:                int index = location.getIndex(list);
134:                if (index < 0 || index >= list.getModel().getSize()) {
135:                    String msg = Strings.get("tester.JList.invalid_index",
136:                            new Object[] { new Integer(index) });
137:                    throw new ActionFailedException(msg);
138:                }
139:                if (list.getSelectedIndex() != index) {
140:                    Log.debug("Click on index=" + index);
141:                    super .actionClick(c, location);
142:                }
143:            }
144:
145:            /** Parse the String representation of a JListLocation into the actual
146:                JListLocation object.
147:             */
148:            public ComponentLocation parseLocation(String encoded) {
149:                return new JListLocation().parse(encoded);
150:            }
151:
152:            /** Return the value, row, or coordinate location. */
153:            public ComponentLocation getLocation(Component c, Point p) {
154:                JList list = (JList) c;
155:                int index = list.locationToIndex(p);
156:                String value = valueToString(list, index);
157:                if (value != null) {
158:                    return new JListLocation(value);
159:                } else if (index != -1) {
160:                    return new JListLocation(index);
161:                }
162:                return new JListLocation(p);
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.