< prev index next >

tests/system/src/test/java/test/robot/com/sun/glass/ui/monocle/input/devices/TestTouchDevice.java

Print this page
rev 9504 : need to fix test log and others


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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 
  26 package test.robot.com.sun.glass.ui.monocle.input.devices;
  27 
  28 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  29 import com.sun.glass.ui.monocle.TestLog;
  30 import javafx.geometry.Rectangle2D;
  31 
  32 import java.util.HashMap;
  33 import java.util.Map;
  34 
  35 public abstract class TestTouchDevice extends TestDevice {
  36 
  37     protected final int[] transformedXs;
  38     protected final int[] transformedYs;
  39     protected final double[] xs;
  40     protected final double[] ys;
  41     protected final boolean[] points;
  42     protected int pressedPoints = 0;
  43     protected int previousPressedPoints = 0;
  44     private double absXMax, absYMax;
  45     private Map<Integer, Integer> ids = new HashMap<>();
  46 
  47     public TestTouchDevice(int maxPointCount) {
  48         this.transformedXs = new int[maxPointCount];
  49         this.transformedYs = new int[maxPointCount];


  86     protected int transformY(double y) {
  87         if (absXMax == 0.0) {
  88             return (int) Math.round(y);
  89         } else {
  90             Rectangle2D r = TestApplication.getScreenBounds();
  91             return (int) Math.round(y * absYMax / r.getHeight());
  92         }
  93     }
  94 
  95     public int addPoint(double x, double y) {
  96         int point = -1;
  97         for (int i = 0; i < points.length; i++) {
  98             if (!points[i]) {
  99                 point = i;
 100                 break;
 101             }
 102         }
 103         if (point == -1) {
 104             throw new IllegalStateException("Cannot add any more points");
 105         }
 106         TestLog.format("TestTouchDevice: addPoint %d, %.0f, %.0f\n",
 107                        point, x, y);
 108         xs[point] = x;
 109         ys[point] = y;
 110         transformedXs[point] = transformX(x);
 111         transformedYs[point] = transformY(y);
 112         points[point] = true;
 113         pressedPoints ++;
 114         return point;
 115     }
 116 
 117     public void removePoint(int point) {
 118         TestLog.format("TestTouchDevice: removePoint %d\n", point);
 119         if (!points[point]) {
 120             throw new IllegalStateException("Point not pressed");
 121         }
 122         points[point] = false;
 123         pressedPoints --;
 124         ids.remove(point);
 125     }
 126 
 127     public void setPoint(int point, double x, double y) {
 128         TestLog.format("TestTouchDevice: setPoint %d, %.0f, %.0f\n",
 129                        point, x, y);
 130         if (!points[point]) {
 131             throw new IllegalStateException("Point not pressed");
 132         }
 133         xs[point] = x;
 134         ys[point] = y;
 135         transformedXs[point] = transformX(x);
 136         transformedYs[point] = transformY(y);
 137     }
 138 
 139     public void setAndRemovePoint(int point, double x, double y) {
 140         TestLog.format("TestTouchDevice: setAndRemovePoint %d, %.0f, %.0f\n",
 141                        point, x, y);
 142         setPoint(point, x, y);
 143         removePoint(point);
 144     }
 145 
 146     @Override
 147     public void sync() {
 148         TestLog.log("TestTouchDevice: sync");
 149         super.sync();
 150         previousPressedPoints = pressedPoints;
 151     }
 152 
 153     public void resendStateAndSync() {
 154         TestLog.log("TestTouchDevice: sync");
 155         sync();
 156     }
 157 
 158     protected void setAbsScale(int absXMax, int absYMax) {
 159         this.absXMax = (double) absXMax;
 160         this.absYMax = (double) absYMax;
 161     }
 162 
 163     public int getTapRadius() {
 164         return TestApplication.getTapRadius();
 165     }
 166 
 167     public String toString() {
 168         if (getClass().getPackage().equals(TestTouchDevice.class.getPackage())) {
 169             return getClass().getSimpleName();
 170         } else {
 171             return getClass().getName();
 172         }
 173     }
 174 


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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 
  26 package test.robot.com.sun.glass.ui.monocle.input.devices;
  27 
  28 import test.robot.com.sun.glass.ui.monocle.TestApplication;
  29 import com.sun.glass.ui.monocle.TestLogShim;
  30 import javafx.geometry.Rectangle2D;
  31 
  32 import java.util.HashMap;
  33 import java.util.Map;
  34 
  35 public abstract class TestTouchDevice extends TestDevice {
  36 
  37     protected final int[] transformedXs;
  38     protected final int[] transformedYs;
  39     protected final double[] xs;
  40     protected final double[] ys;
  41     protected final boolean[] points;
  42     protected int pressedPoints = 0;
  43     protected int previousPressedPoints = 0;
  44     private double absXMax, absYMax;
  45     private Map<Integer, Integer> ids = new HashMap<>();
  46 
  47     public TestTouchDevice(int maxPointCount) {
  48         this.transformedXs = new int[maxPointCount];
  49         this.transformedYs = new int[maxPointCount];


  86     protected int transformY(double y) {
  87         if (absXMax == 0.0) {
  88             return (int) Math.round(y);
  89         } else {
  90             Rectangle2D r = TestApplication.getScreenBounds();
  91             return (int) Math.round(y * absYMax / r.getHeight());
  92         }
  93     }
  94 
  95     public int addPoint(double x, double y) {
  96         int point = -1;
  97         for (int i = 0; i < points.length; i++) {
  98             if (!points[i]) {
  99                 point = i;
 100                 break;
 101             }
 102         }
 103         if (point == -1) {
 104             throw new IllegalStateException("Cannot add any more points");
 105         }
 106         TestLogShim.format("TestTouchDevice: addPoint %d, %.0f, %.0f\n",
 107                        point, x, y);
 108         xs[point] = x;
 109         ys[point] = y;
 110         transformedXs[point] = transformX(x);
 111         transformedYs[point] = transformY(y);
 112         points[point] = true;
 113         pressedPoints ++;
 114         return point;
 115     }
 116 
 117     public void removePoint(int point) {
 118         TestLogShim.format("TestTouchDevice: removePoint %d\n", point);
 119         if (!points[point]) {
 120             throw new IllegalStateException("Point not pressed");
 121         }
 122         points[point] = false;
 123         pressedPoints --;
 124         ids.remove(point);
 125     }
 126 
 127     public void setPoint(int point, double x, double y) {
 128         TestLogShim.format("TestTouchDevice: setPoint %d, %.0f, %.0f\n",
 129                        point, x, y);
 130         if (!points[point]) {
 131             throw new IllegalStateException("Point not pressed");
 132         }
 133         xs[point] = x;
 134         ys[point] = y;
 135         transformedXs[point] = transformX(x);
 136         transformedYs[point] = transformY(y);
 137     }
 138 
 139     public void setAndRemovePoint(int point, double x, double y) {
 140         TestLogShim.format("TestTouchDevice: setAndRemovePoint %d, %.0f, %.0f\n",
 141                        point, x, y);
 142         setPoint(point, x, y);
 143         removePoint(point);
 144     }
 145 
 146     @Override
 147     public void sync() {
 148         TestLogShim.log("TestTouchDevice: sync");
 149         super.sync();
 150         previousPressedPoints = pressedPoints;
 151     }
 152 
 153     public void resendStateAndSync() {
 154         TestLogShim.log("TestTouchDevice: sync");
 155         sync();
 156     }
 157 
 158     protected void setAbsScale(int absXMax, int absYMax) {
 159         this.absXMax = (double) absXMax;
 160         this.absYMax = (double) absYMax;
 161     }
 162 
 163     public int getTapRadius() {
 164         return TestApplication.getTapRadius();
 165     }
 166 
 167     public String toString() {
 168         if (getClass().getPackage().equals(TestTouchDevice.class.getPackage())) {
 169             return getClass().getSimpleName();
 170         } else {
 171             return getClass().getName();
 172         }
 173     }
 174 
< prev index next >