Source Code Cross Referenced for JListLocation.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.JList;
006:
007:        import abbot.i18n.Strings;
008:        import abbot.util.ExtendedComparator;
009:
010:        /** Provides encapsulation of the location of a row on a JList (a coordinate,
011:         * item index or value). 
012:         */
013:
014:        public class JListLocation extends ComponentLocation {
015:            private Object value;
016:            private int row = -1;
017:
018:            /** The center of the target list. */
019:            public JListLocation() {
020:            }
021:
022:            /** Specify location by explicit reference to an object. */
023:            public JListLocation(Object value) {
024:                this .value = value;
025:            }
026:
027:            /** Specify location by string representation of an object. 
028:             * @see JListTester#valueToString 
029:             */
030:            public JListLocation(String value) {
031:                this ((Object) value);
032:            }
033:
034:            /** Specify location by row in the list. */
035:            public JListLocation(int row) {
036:                if (row < 0) {
037:                    String msg = Strings.get("tester.JList.invalid_index",
038:                            new Object[] { new Integer(row) });
039:                    throw new LocationUnavailableException(msg);
040:                }
041:                this .row = row;
042:            }
043:
044:            /** Specify a location by component-relative coordinate. */
045:            public JListLocation(Point where) {
046:                super (where);
047:            }
048:
049:            protected String badFormat(String encoded) {
050:                return Strings.get("location.list.bad_format",
051:                        new Object[] { encoded });
052:            }
053:
054:            /** Convert the given index into a coordinate. */
055:            protected Point indexToPoint(JList list, int index) {
056:                if (index < 0 || index >= list.getModel().getSize()) {
057:                    String msg = Strings.get("tester.JList.invalid_index",
058:                            new Object[] { new Integer(index) });
059:                    throw new LocationUnavailableException(msg);
060:                }
061:                Rectangle rect = list.getCellBounds(index, index);
062:                return new Point(rect.x + rect.width / 2, rect.y + rect.height
063:                        / 2);
064:            }
065:
066:            /** Find the first String match in the list and return the index. */
067:            private int valueToIndex(JList list, Object value) {
068:                int size = list.getModel().getSize();
069:                if (value instanceof  String) {
070:                    for (int i = 0; i < size; i++) {
071:                        String str = JListTester.valueToString(list, i);
072:                        if (ExtendedComparator
073:                                .stringsMatch((String) value, str)) {
074:                            return i;
075:                        }
076:                    }
077:                } else {
078:                    for (int i = 0; i < size; i++) {
079:                        Object el = list.getModel().getElementAt(i);
080:                        if (el == null && value == null || el != null
081:                                && el.equals(value)) {
082:                            return i;
083:                        }
084:                    }
085:                }
086:                return -1;
087:            }
088:
089:            public int getIndex(JList list) {
090:                if (value != null)
091:                    return valueToIndex(list, value);
092:                if (row != -1) {
093:                    return row;
094:                }
095:                return list.locationToIndex(super .getPoint(list));
096:            }
097:
098:            /** Return a concrete point for the abstract location. */
099:            public Point getPoint(Component c) {
100:                JList list = (JList) c;
101:                if (value != null || row != -1) {
102:                    int idx = getIndex(list);
103:                    if (idx == -1) {
104:                        throw new LocationUnavailableException(
105:                                invalidMessage(list));
106:                    }
107:                    return indexToPoint(list, idx);
108:                }
109:                return super .getPoint(list);
110:            }
111:
112:            private String invalidMessage(JList list) {
113:                if (value != null) {
114:                    return Strings.get("tester.JList.item_not_found",
115:                            new Object[] { value });
116:                }
117:                if (row != -1) {
118:                    return Strings.get("tester.JList.invalid_index",
119:                            new Object[] { new Integer(row) });
120:                }
121:                return Strings.get("tester.JList.point_not_found",
122:                        new Object[] { super .getPoint(list) });
123:            }
124:
125:            public Rectangle getBounds(Component c) {
126:                JList list = (JList) c;
127:                int index = getIndex(list);
128:                if (index == -1) {
129:                    throw new LocationUnavailableException(invalidMessage(list));
130:                }
131:                return list.getCellBounds(index, index);
132:            }
133:
134:            public boolean equals(Object o) {
135:                if (o instanceof  JListLocation) {
136:                    JListLocation loc = (JListLocation) o;
137:                    if (value != null)
138:                        return value.equals(loc.value);
139:                    if (row != -1)
140:                        return row == loc.row;
141:                }
142:                return super .equals(o);
143:            }
144:
145:            public String toString() {
146:                if (value != null)
147:                    return encodeValue(value.toString());
148:                if (row != -1)
149:                    return encodeIndex(row);
150:                return super .toString();
151:            }
152:
153:            public ComponentLocation parse(String encoded) {
154:                encoded = encoded.trim();
155:                if (isValue(encoded)) {
156:                    value = parseValue(encoded);
157:                    return this;
158:                }
159:                if (isIndex(encoded)) {
160:                    row = parseIndex(encoded);
161:                    return this;
162:                }
163:                return super.parse(encoded);
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.