6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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 com.sun.glass.ui.monocle;
27
28 import javafx.geometry.Rectangle2D;
29 import javafx.stage.Screen;
30 import org.junit.Assert;
31 import org.junit.Assume;
32 import org.junit.Before;
33 import org.junit.Test;
34
35 /**
36 * Test installation of custom touch filters
37 */
38 public class TouchPipelineTest extends TouchTestBase {
39
40 public static class TranslateFilter implements TouchFilter {
41 @Override
42 public boolean filter(TouchState state) {
43 for (int i = 0; i < state.getPointCount(); i++) {
44 state.getPoint(i).x += 8;
45 state.getPoint(i).y -= 5;
46 }
47 return false;
48 }
49
50 @Override
51 public int getPriority() {
52 return 50;
53 }
54
55 @Override
56 public boolean flush(TouchState state) {
57 return false;
58 }
59 }
60
61 public static class OverrideIDFilter implements TouchFilter {
62 @Override
63 public boolean filter(TouchState state) {
64 for (int i = 0; i < state.getPointCount(); i++) {
65 state.getPoint(i).id = 5;
66 }
67 return false;
68 }
69
70 @Override
71 public int getPriority() {
72 return -50;
73 }
74
75 @Override
76 public boolean flush(TouchState state) {
77 return false;
78 }
79 }
80
81 public static class NoMultiplesOfTenOnXFilter implements TouchFilter {
82 @Override
83 public boolean filter(TouchState state) {
84 for (int i = 0; i < state.getPointCount(); i++) {
85 if (state.getPoint(i).x % 10 == 0) {
86 return true;
87 }
88 }
89 return false;
90 }
91
92 @Override
93 public int getPriority() {
94 return 60;
95 }
96
97 @Override
98 public boolean flush(TouchState state) {
99 return false;
100 }
101 }
102
103 public static class LoggingFilter implements TouchFilter {
104 @Override
105 public boolean filter(TouchState state) {
106 for (int i = 0; i < state.getPointCount(); i++) {
107 TestLog.format("Touch point id=%d at %d,%d",
108 state.getPoint(i).id,
109 state.getPoint(i).x,
110 state.getPoint(i).y);
111 }
112 return false;
113 }
114
115 @Override
116 public int getPriority() {
117 return -100;
118 }
119
120 @Override
121 public boolean flush(TouchState state) {
122 return false;
123 }
124 }
125
126 public static class FlushingFilter implements TouchFilter {
127 int i = 3;
128 @Override
129 public boolean filter(TouchState state) {
130 return false;
131 }
132
133 @Override
134 public int getPriority() {
135 return 90;
136 }
137
138 @Override
139 public boolean flush(TouchState state) {
140 if (i > 0) {
141 i --;
142 state.clear();
143 TouchState.Point p = state.addPoint(null);
144 p.x = 205 + i * 100;
145 p.y = 100;
146 p.id = -1;
147 return true;
148 } else {
149 return false;
150 }
151 }
152 }
153
154 @Before
155 public void createDevice() throws Exception {
156 Assume.assumeTrue(TestApplication.isMonocle());
157 ui = new UInput();
158 TestApplication.showFullScreenScene();
159 TestApplication.addMouseListeners();
160 TestApplication.addTouchListeners();
161 TestLog.reset();
162 System.setProperty("monocle.input.ca/fe/ba/be.touchFilters",
163 TranslateFilter.class.getName() + ","
164 + OverrideIDFilter.class.getName() + ","
165 + FlushingFilter.class.getName() + ","
166 + LoggingFilter.class.getName() + ","
167 + NoMultiplesOfTenOnXFilter.class.getName());
168 Rectangle2D r = Screen.getPrimary().getBounds();
169 ui.processLine("OPEN");
170 ui.processLine("EVBIT EV_SYN");
171 ui.processLine("EVBIT EV_KEY");
172 ui.processLine("KEYBIT BTN_TOUCH");
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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;
27
28 import com.sun.glass.ui.monocle.TestLog;
29 import test.robot.com.sun.glass.ui.monocle.TestApplication;
30 import com.sun.glass.ui.monocle.TouchFilterShim.FlushingFilter;
31 import com.sun.glass.ui.monocle.TouchFilterShim.LoggingFilter;
32 import com.sun.glass.ui.monocle.TouchFilterShim.NoMultiplesOfTenOnXFilter;
33 import com.sun.glass.ui.monocle.TouchFilterShim.OverrideIDFilter;
34 import com.sun.glass.ui.monocle.TouchFilterShim.TranslateFilter;
35 import javafx.geometry.Rectangle2D;
36 import javafx.stage.Screen;
37 import org.junit.Assert;
38 import org.junit.Assume;
39 import org.junit.Before;
40 import org.junit.Test;
41
42 /**
43 * Test installation of custom touch filters
44 */
45 public class TouchPipelineTest extends TouchTestBase {
46
47 @Before
48 public void createDevice() throws Exception {
49 Assume.assumeTrue(TestApplication.isMonocle());
50 ui = new UInput();
51 TestApplication.showFullScreenScene();
52 TestApplication.addMouseListeners();
53 TestApplication.addTouchListeners();
54 TestLog.reset();
55 System.setProperty("monocle.input.ca/fe/ba/be.touchFilters",
56 TranslateFilter.class.getName() + ","
57 + OverrideIDFilter.class.getName() + ","
58 + FlushingFilter.class.getName() + ","
59 + LoggingFilter.class.getName() + ","
60 + NoMultiplesOfTenOnXFilter.class.getName());
61 Rectangle2D r = Screen.getPrimary().getBounds();
62 ui.processLine("OPEN");
63 ui.processLine("EVBIT EV_SYN");
64 ui.processLine("EVBIT EV_KEY");
65 ui.processLine("KEYBIT BTN_TOUCH");
|