28 import org.jemmy.Rectangle; 29 import org.jemmy.control.Wrap; 30 import org.jemmy.env.Timeout; 31 import org.jemmy.interfaces.Caret; 32 import org.jemmy.interfaces.CaretOwner; 33 import org.jemmy.interfaces.Scroll; 34 35 /** 36 * Performs scrolling by clicking at a certain position. 37 * @author shura 38 */ 39 public abstract class ScrollerImpl extends CaretImpl { 40 41 /** 42 * @deprecated Use AdvancedScroller.SCROLL_TIMEOUT 43 */ 44 public static final Timeout SCROLL_TIMEOUT = CaretImpl.SCROLL_TIMEOUT; 45 46 Scroll scroll; 47 48 /** 49 * 50 * @param target 51 * @param caret 52 */ 53 public ScrollerImpl(Wrap target, CaretOwner caret) { 54 super(target, caret); 55 scroll = new CaretScroll(caret); 56 addScrollAction(new ScrollAction() { 57 58 public void scrollTo(int direction) { 59 getWrap().mouse().click(1, getScrollClickPoint(direction > 0)); 60 } 61 }); 62 } 63 64 /** 65 * @param increase 66 * @return a point to click in order to decrease/increase the value 67 */ 68 protected abstract Point getScrollClickPoint(boolean increase); 69 70 /** 71 * An auxiliary function to calculate click point, on the appropriate side 72 * of the control depending on the parameters. 73 * @param c 74 * @param horizontal - horizontal or vertical 75 * @param increase - increase or decrease 76 * @param offset distance from the border 77 * @return 78 */ 79 public static Point createScrollPoint(Wrap c, boolean horizontal, boolean increase, int offset) { 80 return createScrollPoint(c.getScreenBounds(), horizontal, increase, offset); 81 } 82 83 /** 84 * 85 * @param bounds 86 * @param horizontal 87 * @param increase 88 * @param offset 89 * @return 90 */ 91 public static Point createScrollPoint(Rectangle bounds, boolean horizontal, boolean increase, int offset) { 92 if(horizontal) { 93 return new Point(increase ? (bounds.width - 1 - offset) : offset, bounds.height / 2); 94 } else { 95 return new Point(bounds.width / 2, increase ? (bounds.height - 1 - offset) : offset); 96 } 97 } 98 99 //only the value is used from it 100 /** 101 * 102 */ 103 public static class CaretScroll implements Scroll { 104 105 CaretOwner co; 106 107 /** 108 * 109 * @param co 110 */ 111 public CaretScroll(CaretOwner co) { 112 this.co = co; 113 } 114 115 public double maximum() { 116 throw new UnsupportedOperationException("Not supported yet."); 117 } 118 119 public double minimum() { 120 throw new UnsupportedOperationException("Not supported yet."); 121 } 122 123 public double position() { 124 return co.position(); 125 } 126 127 public Caret caret() { 128 throw new UnsupportedOperationException("Not supported yet."); 129 } 130 | 28 import org.jemmy.Rectangle; 29 import org.jemmy.control.Wrap; 30 import org.jemmy.env.Timeout; 31 import org.jemmy.interfaces.Caret; 32 import org.jemmy.interfaces.CaretOwner; 33 import org.jemmy.interfaces.Scroll; 34 35 /** 36 * Performs scrolling by clicking at a certain position. 37 * @author shura 38 */ 39 public abstract class ScrollerImpl extends CaretImpl { 40 41 /** 42 * @deprecated Use AdvancedScroller.SCROLL_TIMEOUT 43 */ 44 public static final Timeout SCROLL_TIMEOUT = CaretImpl.SCROLL_TIMEOUT; 45 46 Scroll scroll; 47 48 public ScrollerImpl(Wrap target, CaretOwner caret) { 49 super(target, caret); 50 scroll = new CaretScroll(caret); 51 addScrollAction(new ScrollAction() { 52 53 public void scrollTo(int direction) { 54 getWrap().mouse().click(1, getScrollClickPoint(direction > 0)); 55 } 56 }); 57 } 58 59 /** 60 * @param increase <code>true</code> to increase, <code>false</code> to decrease the value 61 * @return a point to click in order to decrease/increase the value 62 */ 63 protected abstract Point getScrollClickPoint(boolean increase); 64 65 /** 66 * An auxiliary function to calculate click point, on the appropriate side 67 * of the control depending on the parameters. 68 * @param c the control wrapper 69 * @param horizontal - horizontal or vertical 70 * @param increase - increase or decrease 71 * @param offset distance from the border 72 * @return the point instance 73 */ 74 public static Point createScrollPoint(Wrap c, boolean horizontal, boolean increase, int offset) { 75 return createScrollPoint(c.getScreenBounds(), horizontal, increase, offset); 76 } 77 78 public static Point createScrollPoint(Rectangle bounds, boolean horizontal, boolean increase, int offset) { 79 if(horizontal) { 80 return new Point(increase ? (bounds.width - 1 - offset) : offset, bounds.height / 2); 81 } else { 82 return new Point(bounds.width / 2, increase ? (bounds.height - 1 - offset) : offset); 83 } 84 } 85 86 public static class CaretScroll implements Scroll { 87 88 CaretOwner co; 89 90 public CaretScroll(CaretOwner co) { 91 this.co = co; 92 } 93 94 public double maximum() { 95 throw new UnsupportedOperationException("Not supported yet."); 96 } 97 98 public double minimum() { 99 throw new UnsupportedOperationException("Not supported yet."); 100 } 101 102 public double position() { 103 return co.position(); 104 } 105 106 public Caret caret() { 107 throw new UnsupportedOperationException("Not supported yet."); 108 } 109 |