< prev index next >

core/JemmyCore/src/org/jemmy/input/KnobDragScrollerImpl.java

Print this page




  32 import org.jemmy.action.Action;
  33 import org.jemmy.control.Wrap;
  34 import org.jemmy.interfaces.Caret;
  35 import org.jemmy.interfaces.Drag;
  36 import org.jemmy.interfaces.Scroll;
  37 
  38 /**
  39  * Performs scrolling by doing d'n'd of a "knob" wrap. To be used for controls
  40  * like scroll bars, sliders.
  41  * @author shura
  42  */
  43 public abstract class KnobDragScrollerImpl implements Caret {
  44 
  45     public static final int MAX_SCROLL_ATTEMPTS = 5;
  46 
  47     Wrap<?> wrap;
  48     Scroll scroll;
  49     float dragDelta = 1;
  50     boolean reverse;
  51 
  52     /**
  53      *
  54      * @param wrap
  55      * @param scroll
  56      */
  57     public KnobDragScrollerImpl(Wrap<?> wrap, Scroll scroll) {
  58         this.wrap = wrap;
  59         this.scroll = scroll;
  60     }
  61 
  62     public KnobDragScrollerImpl(Wrap<?> wrap, Scroll scroll, boolean reverse) {
  63         this(wrap, scroll);
  64         this.reverse = reverse;
  65     }
  66 
  67     /**
  68      *
  69      * @return
  70      */
  71     public Wrap<?> getWrap() {
  72         return wrap;
  73     }
  74 
  75     /**
  76      *
  77      * @return
  78      */
  79     public abstract Vector getScrollVector();
  80 
  81     /**
  82      *
  83      * @param dragDelta
  84      */
  85     public void setDragDelta(float dragDelta) {
  86         this.dragDelta = dragDelta;
  87     }
  88 
  89     private void toKnob(Wrap<?> knob, Point inWrap) {
  90         inWrap.translate(wrap.getScreenBounds().x, wrap.getScreenBounds().y);
  91         inWrap.translate(-knob.getScreenBounds().x, -knob.getScreenBounds().y);
  92     }
  93 
  94     private void toWrap(Wrap<?> knob, Point inWrap) {
  95         inWrap.translate(knob.getScreenBounds().x, knob.getScreenBounds().y);
  96         inWrap.translate(-wrap.getScreenBounds().x, -wrap.getScreenBounds().y);
  97     }
  98 
  99     public void to(double value) {
 100         scroll.to(value);
 101     }
 102 
 103     public void to(final Direction condition) {
 104         wrap.getEnvironment().getExecutor().execute(wrap.getEnvironment(), false, new Action() {


 149         });
 150     }
 151 
 152     /*
 153      * Create another class for this perhaps
 154     private void initialDrag(double value) {
 155     Point hp = getEndPoint(false);
 156     Point lp = getEndPoint(true);
 157     double xdiff = hp.x - lp.x;
 158     double ydiff = hp.y - lp.y;
 159     double ratio = value / (scroll.maximum() - scroll.minimum());
 160     Wrap<?> knob = getKnob();
 161     Point p = new Point(xdiff * ratio, ydiff * ratio);
 162     toKnob(knob, p);
 163     Point clickPoint = knob.getClickPoint();
 164     p.translate(clickPoint.x, clickPoint.y);
 165     knob.drag().dnd(clickPoint, knob, p);
 166     }
 167      *
 168      */
 169     /**
 170      *
 171      * @return
 172      */
 173     protected abstract Wrap<?> getKnob();
 174 }


  32 import org.jemmy.action.Action;
  33 import org.jemmy.control.Wrap;
  34 import org.jemmy.interfaces.Caret;
  35 import org.jemmy.interfaces.Drag;
  36 import org.jemmy.interfaces.Scroll;
  37 
  38 /**
  39  * Performs scrolling by doing d'n'd of a "knob" wrap. To be used for controls
  40  * like scroll bars, sliders.
  41  * @author shura
  42  */
  43 public abstract class KnobDragScrollerImpl implements Caret {
  44 
  45     public static final int MAX_SCROLL_ATTEMPTS = 5;
  46 
  47     Wrap<?> wrap;
  48     Scroll scroll;
  49     float dragDelta = 1;
  50     boolean reverse;
  51 





  52     public KnobDragScrollerImpl(Wrap<?> wrap, Scroll scroll) {
  53         this.wrap = wrap;
  54         this.scroll = scroll;
  55     }
  56 
  57     public KnobDragScrollerImpl(Wrap<?> wrap, Scroll scroll, boolean reverse) {
  58         this(wrap, scroll);
  59         this.reverse = reverse;
  60     }
  61 




  62     public Wrap<?> getWrap() {
  63         return wrap;
  64     }
  65 




  66     public abstract Vector getScrollVector();
  67 




  68     public void setDragDelta(float dragDelta) {
  69         this.dragDelta = dragDelta;
  70     }
  71 
  72     private void toKnob(Wrap<?> knob, Point inWrap) {
  73         inWrap.translate(wrap.getScreenBounds().x, wrap.getScreenBounds().y);
  74         inWrap.translate(-knob.getScreenBounds().x, -knob.getScreenBounds().y);
  75     }
  76 
  77     private void toWrap(Wrap<?> knob, Point inWrap) {
  78         inWrap.translate(knob.getScreenBounds().x, knob.getScreenBounds().y);
  79         inWrap.translate(-wrap.getScreenBounds().x, -wrap.getScreenBounds().y);
  80     }
  81 
  82     public void to(double value) {
  83         scroll.to(value);
  84     }
  85 
  86     public void to(final Direction condition) {
  87         wrap.getEnvironment().getExecutor().execute(wrap.getEnvironment(), false, new Action() {


 132         });
 133     }
 134 
 135     /*
 136      * Create another class for this perhaps
 137     private void initialDrag(double value) {
 138     Point hp = getEndPoint(false);
 139     Point lp = getEndPoint(true);
 140     double xdiff = hp.x - lp.x;
 141     double ydiff = hp.y - lp.y;
 142     double ratio = value / (scroll.maximum() - scroll.minimum());
 143     Wrap<?> knob = getKnob();
 144     Point p = new Point(xdiff * ratio, ydiff * ratio);
 145     toKnob(knob, p);
 146     Point clickPoint = knob.getClickPoint();
 147     p.translate(clickPoint.x, clickPoint.y);
 148     knob.drag().dnd(clickPoint, knob, p);
 149     }
 150      *
 151      */
 152 



 153     protected abstract Wrap<?> getKnob();
 154 }
< prev index next >