Commit | Line | Data |
---|---|---|
daa4106c | 1 | /* |
df8de03f KL |
2 | * Jexer - Java Text User Interface |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
df8de03f | 5 | * |
a69ed767 | 6 | * Copyright (C) 2019 Kevin Lamonte |
df8de03f | 7 | * |
e16dda65 KL |
8 | * Permission is hereby granted, free of charge, to any person obtaining a |
9 | * copy of this software and associated documentation files (the "Software"), | |
10 | * to deal in the Software without restriction, including without limitation | |
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
12 | * and/or sell copies of the Software, and to permit persons to whom the | |
13 | * Software is furnished to do so, subject to the following conditions: | |
df8de03f | 14 | * |
e16dda65 KL |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
df8de03f | 17 | * |
e16dda65 KL |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
24 | * DEALINGS IN THE SOFTWARE. | |
7b5261bc KL |
25 | * |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
df8de03f KL |
28 | */ |
29 | package jexer.event; | |
30 | ||
31 | /** | |
48e27807 KL |
32 | * This class encapsulates several kinds of mouse input events. Note that |
33 | * the relative (x,y) ARE MUTABLE: TWidget's onMouse() handlers perform that | |
34 | * update during event dispatching. | |
df8de03f | 35 | */ |
051e2913 | 36 | public class TMouseEvent extends TInputEvent { |
df8de03f | 37 | |
d36057df KL |
38 | // ------------------------------------------------------------------------ |
39 | // Constants -------------------------------------------------------------- | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
7b5261bc KL |
42 | /** |
43 | * The type of event generated. | |
44 | */ | |
b1589621 | 45 | public enum Type { |
7b5261bc KL |
46 | /** |
47 | * Mouse motion. X and Y will have screen coordinates. | |
48 | */ | |
49 | MOUSE_MOTION, | |
50 | ||
51 | /** | |
52 | * Mouse button down. X and Y will have screen coordinates. | |
53 | */ | |
54 | MOUSE_DOWN, | |
55 | ||
56 | /** | |
57 | * Mouse button up. X and Y will have screen coordinates. | |
58 | */ | |
b6faeac0 KL |
59 | MOUSE_UP, |
60 | ||
61 | /** | |
62 | * Mouse double-click. X and Y will have screen coordinates. | |
63 | */ | |
64 | MOUSE_DOUBLE_CLICK | |
df8de03f KL |
65 | } |
66 | ||
d36057df KL |
67 | // ------------------------------------------------------------------------ |
68 | // Variables -------------------------------------------------------------- | |
69 | // ------------------------------------------------------------------------ | |
70 | ||
df8de03f | 71 | /** |
bd8d51fa | 72 | * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN. |
df8de03f | 73 | */ |
d4a29741 KL |
74 | private Type type; |
75 | ||
d36057df KL |
76 | /** |
77 | * Mouse X - relative coordinates. | |
78 | */ | |
79 | private int x; | |
80 | ||
81 | /** | |
82 | * Mouse Y - relative coordinates. | |
83 | */ | |
84 | private int y; | |
85 | ||
86 | /** | |
87 | * Mouse X - absolute screen coordinates. | |
88 | */ | |
89 | private int absoluteX; | |
90 | ||
91 | /** | |
92 | * Mouse Y - absolute screen coordinate. | |
93 | */ | |
94 | private int absoluteY; | |
95 | ||
96 | /** | |
97 | * Mouse button 1 (left button). | |
98 | */ | |
99 | private boolean mouse1; | |
100 | ||
101 | /** | |
102 | * Mouse button 2 (right button). | |
103 | */ | |
104 | private boolean mouse2; | |
105 | ||
106 | /** | |
107 | * Mouse button 3 (middle button). | |
108 | */ | |
109 | private boolean mouse3; | |
110 | ||
111 | /** | |
112 | * Mouse wheel UP (button 4). | |
113 | */ | |
114 | private boolean mouseWheelUp; | |
115 | ||
116 | /** | |
117 | * Mouse wheel DOWN (button 5). | |
118 | */ | |
119 | private boolean mouseWheelDown; | |
120 | ||
121 | // ------------------------------------------------------------------------ | |
122 | // Constructors ----------------------------------------------------------- | |
123 | // ------------------------------------------------------------------------ | |
124 | ||
125 | /** | |
126 | * Public contructor. | |
127 | * | |
128 | * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP | |
129 | * @param x relative column | |
130 | * @param y relative row | |
131 | * @param absoluteX absolute column | |
132 | * @param absoluteY absolute row | |
133 | * @param mouse1 if true, left button is down | |
134 | * @param mouse2 if true, right button is down | |
135 | * @param mouse3 if true, middle button is down | |
136 | * @param mouseWheelUp if true, mouse wheel (button 4) is down | |
137 | * @param mouseWheelDown if true, mouse wheel (button 5) is down | |
138 | */ | |
139 | public TMouseEvent(final Type type, final int x, final int y, | |
140 | final int absoluteX, final int absoluteY, | |
141 | final boolean mouse1, final boolean mouse2, final boolean mouse3, | |
142 | final boolean mouseWheelUp, final boolean mouseWheelDown) { | |
143 | ||
144 | this.type = type; | |
145 | this.x = x; | |
146 | this.y = y; | |
147 | this.absoluteX = absoluteX; | |
148 | this.absoluteY = absoluteY; | |
149 | this.mouse1 = mouse1; | |
150 | this.mouse2 = mouse2; | |
151 | this.mouse3 = mouse3; | |
152 | this.mouseWheelUp = mouseWheelUp; | |
153 | this.mouseWheelDown = mouseWheelDown; | |
154 | } | |
155 | ||
156 | // ------------------------------------------------------------------------ | |
157 | // TMouseEvent ------------------------------------------------------------ | |
158 | // ------------------------------------------------------------------------ | |
159 | ||
d4a29741 KL |
160 | /** |
161 | * Get type. | |
162 | * | |
163 | * @return type | |
164 | */ | |
165 | public Type getType() { | |
166 | return type; | |
167 | } | |
df8de03f | 168 | |
d4a29741 KL |
169 | /** |
170 | * Get x. | |
171 | * | |
172 | * @return x | |
173 | */ | |
174 | public int getX() { | |
175 | return x; | |
176 | } | |
df8de03f | 177 | |
48e27807 KL |
178 | /** |
179 | * Set x. | |
180 | * | |
181 | * @param x new relative X value | |
182 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
183 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
184 | * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse) | |
185 | */ | |
186 | public void setX(final int x) { | |
187 | this.x = x; | |
188 | } | |
189 | ||
d4a29741 KL |
190 | /** |
191 | * Get y. | |
192 | * | |
193 | * @return y | |
194 | */ | |
195 | public int getY() { | |
196 | return y; | |
197 | } | |
df8de03f | 198 | |
48e27807 KL |
199 | /** |
200 | * Set y. | |
201 | * | |
202 | * @param y new relative Y value | |
203 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
204 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
205 | * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse) | |
206 | */ | |
207 | public void setY(final int y) { | |
208 | this.y = y; | |
209 | } | |
210 | ||
d4a29741 KL |
211 | /** |
212 | * Get absoluteX. | |
213 | * | |
214 | * @return absoluteX | |
215 | */ | |
216 | public int getAbsoluteX() { | |
217 | return absoluteX; | |
218 | } | |
df8de03f | 219 | |
3e074355 KL |
220 | /** |
221 | * Set absoluteX. | |
222 | * | |
223 | * @param absoluteX the new value | |
224 | */ | |
225 | public void setAbsoluteX(final int absoluteX) { | |
226 | this.absoluteX = absoluteX; | |
227 | } | |
228 | ||
d4a29741 KL |
229 | /** |
230 | * Get absoluteY. | |
231 | * | |
232 | * @return absoluteY | |
233 | */ | |
234 | public int getAbsoluteY() { | |
235 | return absoluteY; | |
236 | } | |
df8de03f | 237 | |
3e074355 KL |
238 | /** |
239 | * Set absoluteY. | |
240 | * | |
241 | * @param absoluteY the new value | |
242 | */ | |
243 | public void setAbsoluteY(final int absoluteY) { | |
244 | this.absoluteY = absoluteY; | |
245 | } | |
246 | ||
d4a29741 KL |
247 | /** |
248 | * Get mouse1. | |
249 | * | |
250 | * @return mouse1 | |
251 | */ | |
7c870d89 | 252 | public boolean isMouse1() { |
d4a29741 KL |
253 | return mouse1; |
254 | } | |
df8de03f | 255 | |
d4a29741 KL |
256 | /** |
257 | * Get mouse2. | |
258 | * | |
259 | * @return mouse2 | |
260 | */ | |
7c870d89 | 261 | public boolean isMouse2() { |
d4a29741 KL |
262 | return mouse2; |
263 | } | |
df8de03f | 264 | |
d4a29741 KL |
265 | /** |
266 | * Get mouse3. | |
267 | * | |
268 | * @return mouse3 | |
269 | */ | |
7c870d89 | 270 | public boolean isMouse3() { |
d4a29741 KL |
271 | return mouse3; |
272 | } | |
df8de03f | 273 | |
d4a29741 KL |
274 | /** |
275 | * Get mouseWheelUp. | |
276 | * | |
277 | * @return mouseWheelUp | |
278 | */ | |
7c870d89 | 279 | public boolean isMouseWheelUp() { |
d4a29741 KL |
280 | return mouseWheelUp; |
281 | } | |
df8de03f | 282 | |
d4a29741 KL |
283 | /** |
284 | * Get mouseWheelDown. | |
285 | * | |
286 | * @return mouseWheelDown | |
287 | */ | |
7c870d89 | 288 | public boolean isMouseWheelDown() { |
d4a29741 KL |
289 | return mouseWheelDown; |
290 | } | |
df8de03f | 291 | |
3e074355 KL |
292 | /** |
293 | * Create a duplicate instance. | |
294 | * | |
295 | * @return duplicate intance | |
296 | */ | |
297 | public TMouseEvent dup() { | |
298 | TMouseEvent mouse = new TMouseEvent(type, x, y, absoluteX, absoluteY, | |
299 | mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown); | |
300 | return mouse; | |
301 | } | |
302 | ||
df8de03f | 303 | /** |
7b5261bc KL |
304 | * Make human-readable description of this TMouseEvent. |
305 | * | |
306 | * @return displayable String | |
df8de03f KL |
307 | */ |
308 | @Override | |
d4a29741 | 309 | public String toString() { |
7b5261bc KL |
310 | return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s", |
311 | type, | |
312 | x, y, | |
313 | absoluteX, absoluteY, | |
314 | mouse1, | |
315 | mouse2, | |
316 | mouse3, | |
317 | mouseWheelUp, | |
318 | mouseWheelDown); | |
df8de03f KL |
319 | } |
320 | ||
321 | } |