Source Code Cross Referenced for AbstractScrollDriver.java in  » IDE-Netbeans » jemmy » org » netbeans » jemmy » drivers » scrolling » 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 » IDE Netbeans » jemmy » org.netbeans.jemmy.drivers.scrolling 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s): Alexandre Iline.
025:         *
026:         * The Original Software is the Jemmy library.
027:         * The Initial Developer of the Original Software is Alexandre Iline.
028:         * All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         *
041:         *
042:         *
043:         * $Id$ $Revision$ $Date$
044:         *
045:         */
046:
047:        package org.netbeans.jemmy.drivers.scrolling;
048:
049:        import java.awt.Adjustable;
050:        import java.awt.Point;
051:
052:        import org.netbeans.jemmy.Timeout;
053:
054:        import org.netbeans.jemmy.drivers.ScrollDriver;
055:        import org.netbeans.jemmy.drivers.LightSupportiveDriver;
056:
057:        import org.netbeans.jemmy.operators.ComponentOperator;
058:
059:        /**
060:         * Superclass for all scroll drivers.
061:         * Contains all the logic of scrolling.
062:         * Tryes allowed operations in this order:
063:         * "jump", "drag'n'drop", "push'n'wait", "step".
064:         * Repeats "step" scrolling while scroller value is not equal
065:         * to the necessary value, but no more than <code>ADJUST_CLICK_COUNT</code>.
066:         *
067:         * @author Alexandre Iline(alexandre.iline@sun.com)
068:         */
069:        public abstract class AbstractScrollDriver extends
070:                LightSupportiveDriver implements  ScrollDriver {
071:
072:            /**
073:             * Maximal number of attemps to reach required position
074:             * by minimal scrolling operation.
075:             */
076:            public static final int ADJUST_CLICK_COUNT = 10;
077:
078:            /**
079:             * Constructs an AbstractScrollDriver.
080:             * @param supported an array of supported class names
081:             */
082:            public AbstractScrollDriver(String[] supported) {
083:                super (supported);
084:            }
085:
086:            public void scroll(ComponentOperator oper, ScrollAdjuster adj) {
087:                if (canJump(oper)) {
088:                    doJumps(oper, adj);
089:                }
090:                if (canDragAndDrop(oper)) {
091:                    doDragAndDrop(oper, adj);
092:                }
093:                if (canPushAndWait(oper)) {
094:                    doPushAndWait(oper, adj);
095:                }
096:                for (int i = 0; i < ADJUST_CLICK_COUNT; i++) {
097:                    doSteps(oper, adj);
098:                }
099:            }
100:
101:            /**
102:             * Performs minimal scrolling step.
103:             * @param oper an operator.
104:             * @param adj a scroll adjuster
105:             */
106:            protected abstract void step(ComponentOperator oper,
107:                    ScrollAdjuster adj);
108:
109:            /**
110:             * Performs maximal scroll step.
111:             * @param oper an operator.
112:             * @param adj a scroll adjuster
113:             */
114:            protected abstract void jump(ComponentOperator oper,
115:                    ScrollAdjuster adj);
116:
117:            /**
118:             * Presses something like a scroll button.
119:             * @param oper an operator.
120:             * @param direction - one of the ScrollAdjister.INCREASE_SCROLL_DIRECTION, 
121:             * ScrollAdjister.DECREASE_SCROLL_DIRECTION, ScrollAdjister.DO_NOT_TOUCH_SCROLL_DIRECTION values.
122:             * @param orientation one of the Adjustable.HORIZONTAL or Adjustable.VERTICAL values.
123:             */
124:            protected abstract void startPushAndWait(ComponentOperator oper,
125:                    int direction, int orientation);
126:
127:            /**
128:             * Releases something like a scroll button.
129:             * @param oper an operator.
130:             * @param direction - one of the ScrollAdjister.INCREASE_SCROLL_DIRECTION, 
131:             * ScrollAdjister.DECREASE_SCROLL_DIRECTION, ScrollAdjister.DO_NOT_TOUCH_SCROLL_DIRECTION values.
132:             * @param orientation one of the Adjustable.HORIZONTAL or Adjustable.VERTICAL values.
133:             */
134:            protected abstract void stopPushAndWait(ComponentOperator oper,
135:                    int direction, int orientation);
136:
137:            /**
138:             * Starts drag'n'drop scrolling.
139:             * @param oper an operator.
140:             * @return start drigging point.
141:             */
142:            protected abstract Point startDragging(ComponentOperator oper);
143:
144:            /**
145:             * Drop at a specified point.
146:             * @param oper an operator.
147:             * @param pnt the point to drop.
148:             */
149:            protected abstract void drop(ComponentOperator oper, Point pnt);
150:
151:            /**
152:             * Drag to a specified point.
153:             * @param oper an operator.
154:             * @param pnt the point to drag to.
155:             */
156:            protected abstract void drag(ComponentOperator oper, Point pnt);
157:
158:            /**
159:             * Returns a timeout for sleeping between verifications during
160:             * "push and wait" scrolling.
161:             * @param oper an operator.
162:             * @return a timeout
163:             */
164:            protected abstract Timeout getScrollDeltaTimeout(
165:                    ComponentOperator oper);
166:
167:            /**
168:             * Tells if this driver allows to perform drag'n'drop scrolling.
169:             * @param oper an operator.
170:             * @return true if this driver allows to drag'n'drop.
171:             */
172:            protected abstract boolean canDragAndDrop(ComponentOperator oper);
173:
174:            /**
175:             * Tells if this driver allows to perform jumps.
176:             * @param oper an operator.
177:             * @return true if this driver allows to jump.
178:             */
179:            protected abstract boolean canJump(ComponentOperator oper);
180:
181:            /**
182:             * Tells if this driver allows to perform "push and wait" scrolling.
183:             * @param oper an operator.
184:             * @return true if this driver allows to "push and wait".
185:             */
186:            protected abstract boolean canPushAndWait(ComponentOperator oper);
187:
188:            /**
189:             * Returns a number of pixels in one drag and drop scrolling.
190:             * @param oper an operator.
191:             * @return drag'n'drop step length.
192:             */
193:            protected abstract int getDragAndDropStepLength(
194:                    ComponentOperator oper);
195:
196:            /**
197:             * Performs drag'n'drop scrolling till scroller's value
198:             * does not cross required value.
199:             * @param oper an operator.
200:             * @param adj a scroll adjuster
201:             */
202:            protected void doDragAndDrop(ComponentOperator oper,
203:                    ScrollAdjuster adj) {
204:                int direction = adj.getScrollDirection();
205:                if (direction != adj.DO_NOT_TOUCH_SCROLL_DIRECTION) {
206:                    Point pnt = startDragging(oper);
207:                    while (adj.getScrollDirection() == direction) {
208:                        drag(oper, pnt = increasePoint(oper, pnt, adj,
209:                                direction));
210:                    }
211:                    drop(oper, pnt);
212:                }
213:            }
214:
215:            /**
216:             * Performs jump scrolling till scroller's value
217:             * does not cross required value.
218:             * @param oper an operator.
219:             * @param adj a scroll adjuster
220:             */
221:            protected void doJumps(ComponentOperator oper, ScrollAdjuster adj) {
222:                int direction = adj.getScrollDirection();
223:                if (direction != adj.DO_NOT_TOUCH_SCROLL_DIRECTION) {
224:                    while (adj.getScrollDirection() == direction) {
225:                        jump(oper, adj);
226:                    }
227:                }
228:            }
229:
230:            /**
231:             * Performs "push and wait" scrolling till scroller's value
232:             * does not cross required value.
233:             * @param oper an operator.
234:             * @param adj a scroll adjuster
235:             */
236:            protected void doPushAndWait(ComponentOperator oper,
237:                    ScrollAdjuster adj) {
238:                int direction = adj.getScrollDirection();
239:                int orientation = adj.getScrollOrientation();
240:                if (direction != adj.DO_NOT_TOUCH_SCROLL_DIRECTION) {
241:                    Timeout delta = getScrollDeltaTimeout(oper);
242:                    startPushAndWait(oper, direction, orientation);
243:                    while (adj.getScrollDirection() == direction) {
244:                        delta.sleep();
245:                    }
246:                    stopPushAndWait(oper, direction, orientation);
247:                }
248:            }
249:
250:            /**
251:             * Performs minimal scrollings till scroller's value
252:             * does not cross required value.
253:             * @param oper an operator.
254:             * @param adj a scroll adjuster
255:             */
256:            protected void doSteps(ComponentOperator oper, ScrollAdjuster adj) {
257:                int direction = adj.getScrollDirection();
258:                if (direction != adj.DO_NOT_TOUCH_SCROLL_DIRECTION) {
259:                    while (adj.getScrollDirection() == direction) {
260:                        step(oper, adj);
261:                    }
262:                }
263:            }
264:
265:            private Point increasePoint(ComponentOperator oper, Point pnt,
266:                    ScrollAdjuster adj, int direction) {
267:                return ((adj.getScrollOrientation() == Adjustable.HORIZONTAL) ? new Point(
268:                        pnt.x + ((direction == 1) ? 1 : -1)
269:                                * getDragAndDropStepLength(oper), pnt.y)
270:                        : new Point(pnt.x, pnt.y + ((direction == 1) ? 1 : -1)
271:                                * getDragAndDropStepLength(oper)));
272:            }
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.