1 /* 2 * Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.jemmy.input; 24 25 import org.jemmy.Point; 26 import org.jemmy.Rectangle; 27 import org.jemmy.control.Wrap; 28 import org.jemmy.env.Timeout; 29 import org.jemmy.interfaces.Caret; 30 import org.jemmy.interfaces.CaretOwner; 31 import org.jemmy.interfaces.Scroll; 32 33 /** 34 * Performs scrolling by clicking at a certain position. 35 * @author shura 36 */ 37 public abstract class ScrollerImpl extends CaretImpl { 38 39 /** 40 * @deprecated Use AdvancedScroller.SCROLL_TIMEOUT 41 */ 42 public static final Timeout SCROLL_TIMEOUT = CaretImpl.SCROLL_TIMEOUT; 43 44 Scroll scroll; 45 46 /** 47 * 48 * @param target 49 * @param caret 50 */ 51 public ScrollerImpl(Wrap target, CaretOwner caret) { 52 super(target, caret); 53 scroll = new CaretScroll(caret); 54 addScrollAction(new ScrollAction() { 55 56 public void scrollTo(int direction) { 57 getWrap().mouse().click(1, getScrollClickPoint(direction > 0)); 58 } 59 }); 60 } 61 62 /** 63 * @param increase 64 * @return a point to click in order to decrease/increase the value 65 */ 66 protected abstract Point getScrollClickPoint(boolean increase); 67 68 /** 69 * An auxiliary function to calculate click point, on the appropriate side 70 * of the control depending on the parameters. 71 * @param c 72 * @param horizontal - horizontal or vertical 73 * @param increase - increase or decrease 74 * @param offset distance from the border 75 * @return 76 */ 77 public static Point createScrollPoint(Wrap c, boolean horizontal, boolean increase, int offset) { 78 return createScrollPoint(c.getScreenBounds(), horizontal, increase, offset); 79 } 80 81 /** 82 * 83 * @param bounds 84 * @param horizontal 85 * @param increase 86 * @param offset 87 * @return 88 */ 89 public static Point createScrollPoint(Rectangle bounds, boolean horizontal, boolean increase, int offset) { 90 if(horizontal) { 91 return new Point(increase ? (bounds.width - 1 - offset) : offset, bounds.height / 2); 92 } else { 93 return new Point(bounds.width / 2, increase ? (bounds.height - 1 - offset) : offset); 94 } 95 } 96 97 //only the value is used from it 98 /** 99 * 100 */ 101 public static class CaretScroll implements Scroll { 102 103 CaretOwner co; 104 105 /** 106 * 107 * @param co 108 */ 109 public CaretScroll(CaretOwner co) { 110 this.co = co; 111 } 112 113 public double maximum() { 114 throw new UnsupportedOperationException("Not supported yet."); 115 } 116 117 public double minimum() { 118 throw new UnsupportedOperationException("Not supported yet."); 119 } 120 121 public double position() { 122 return co.position(); 123 } 124 125 public Caret caret() { 126 throw new UnsupportedOperationException("Not supported yet."); 127 } 128 129 public void to(double position) { 130 throw new UnsupportedOperationException("Not supported yet."); 131 } 132 } 133 134 }