< prev index next >

core/JemmyCore/src/org/jemmy/lookup/RelativeCoordinateLookup.java

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.jemmy.lookup;
  26 
  27 import org.jemmy.Rectangle;
  28 import org.jemmy.control.Wrap;
  29 
  30 /**
  31  *
  32  * @param <CONTROL>
  33  * @author shura
  34  */
  35 public abstract class RelativeCoordinateLookup<CONTROL> extends CoordinateLookup<CONTROL> {
  36 
  37     private static final int MAX_SCREEN_SIZE = 100000;
  38 
  39     private Wrap wrap;
  40     private boolean includeControl;
  41     private int hr;
  42     private int vr;
  43 
  44     /**
  45      *
  46      * @param wrap
  47      * @param includeControl
  48      * @param hr
  49      * @param vr
  50      */
  51     public RelativeCoordinateLookup(Wrap wrap, boolean includeControl, int hr, int vr) {
  52         super(wrap.getScreenBounds());
  53         this.wrap = wrap;
  54         this.includeControl = includeControl;
  55         this.hr = hr;
  56         this.vr = vr;
  57     }
  58 
  59     /**
  60      *
  61      * @return
  62      */
  63     @Override
  64     protected Rectangle getArea() {
  65         return constructArea(wrap, includeControl, hr, vr);
  66     }
  67 
  68     private static Rectangle constructArea(Wrap wrap, boolean includeControl, int hr, int vr) {
  69         Rectangle res = new Rectangle();
  70         res.width = MAX_SCREEN_SIZE;
  71         res.height = MAX_SCREEN_SIZE;
  72         Rectangle bounds = wrap.getScreenBounds();
  73         if (hr != 0) {
  74             if (hr < 0) {
  75                 res.x = -MAX_SCREEN_SIZE + bounds.x + (includeControl ? bounds.width : 0);
  76             } else {
  77                 res.x = bounds.x + (includeControl ? 0 : bounds.width);
  78             }
  79         } else {
  80             res.x = -MAX_SCREEN_SIZE / 2 + bounds.x + (includeControl ? bounds.width / 2 : 0);
  81         }
  82         if (vr != 0) {


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package org.jemmy.lookup;
  26 
  27 import org.jemmy.Rectangle;
  28 import org.jemmy.control.Wrap;
  29 
  30 /**


  31  * @author shura
  32  */
  33 public abstract class RelativeCoordinateLookup<CONTROL> extends CoordinateLookup<CONTROL> {
  34 
  35     private static final int MAX_SCREEN_SIZE = 100000;
  36 
  37     private Wrap wrap;
  38     private boolean includeControl;
  39     private int hr;
  40     private int vr;
  41 







  42     public RelativeCoordinateLookup(Wrap wrap, boolean includeControl, int hr, int vr) {
  43         super(wrap.getScreenBounds());
  44         this.wrap = wrap;
  45         this.includeControl = includeControl;
  46         this.hr = hr;
  47         this.vr = vr;
  48     }
  49 




  50     @Override
  51     protected Rectangle getArea() {
  52         return constructArea(wrap, includeControl, hr, vr);
  53     }
  54 
  55     private static Rectangle constructArea(Wrap wrap, boolean includeControl, int hr, int vr) {
  56         Rectangle res = new Rectangle();
  57         res.width = MAX_SCREEN_SIZE;
  58         res.height = MAX_SCREEN_SIZE;
  59         Rectangle bounds = wrap.getScreenBounds();
  60         if (hr != 0) {
  61             if (hr < 0) {
  62                 res.x = -MAX_SCREEN_SIZE + bounds.x + (includeControl ? bounds.width : 0);
  63             } else {
  64                 res.x = bounds.x + (includeControl ? 0 : bounds.width);
  65             }
  66         } else {
  67             res.x = -MAX_SCREEN_SIZE / 2 + bounds.x + (includeControl ? bounds.width / 2 : 0);
  68         }
  69         if (vr != 0) {
< prev index next >