Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / jexer / event / TMouseEvent.java
CommitLineData
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 */
29package 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 36public 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
6e9daafb
KL
121 /**
122 * Keyboard modifier ALT.
123 */
124 private boolean alt;
125
126 /**
127 * Keyboard modifier CTRL.
128 */
129 private boolean ctrl;
130
131 /**
132 * Keyboard modifier SHIFT.
133 */
134 private boolean shift;
135
d36057df
KL
136 // ------------------------------------------------------------------------
137 // Constructors -----------------------------------------------------------
138 // ------------------------------------------------------------------------
139
140 /**
141 * Public contructor.
142 *
143 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
144 * @param x relative column
145 * @param y relative row
146 * @param absoluteX absolute column
147 * @param absoluteY absolute row
148 * @param mouse1 if true, left button is down
149 * @param mouse2 if true, right button is down
150 * @param mouse3 if true, middle button is down
151 * @param mouseWheelUp if true, mouse wheel (button 4) is down
152 * @param mouseWheelDown if true, mouse wheel (button 5) is down
6e9daafb
KL
153 * @param alt if true, ALT was pressed with this mouse event
154 * @param ctrl if true, CTRL was pressed with this mouse event
155 * @param shift if true, SHIFT was pressed with this mouse event
d36057df
KL
156 */
157 public TMouseEvent(final Type type, final int x, final int y,
158 final int absoluteX, final int absoluteY,
159 final boolean mouse1, final boolean mouse2, final boolean mouse3,
6e9daafb
KL
160 final boolean mouseWheelUp, final boolean mouseWheelDown,
161 final boolean alt, final boolean ctrl, final boolean shift) {
d36057df
KL
162
163 this.type = type;
164 this.x = x;
165 this.y = y;
166 this.absoluteX = absoluteX;
167 this.absoluteY = absoluteY;
168 this.mouse1 = mouse1;
169 this.mouse2 = mouse2;
170 this.mouse3 = mouse3;
171 this.mouseWheelUp = mouseWheelUp;
172 this.mouseWheelDown = mouseWheelDown;
6e9daafb
KL
173 this.alt = alt;
174 this.ctrl = ctrl;
175 this.shift = shift;
d36057df
KL
176 }
177
178 // ------------------------------------------------------------------------
179 // TMouseEvent ------------------------------------------------------------
180 // ------------------------------------------------------------------------
181
d4a29741
KL
182 /**
183 * Get type.
184 *
185 * @return type
186 */
187 public Type getType() {
188 return type;
189 }
df8de03f 190
d4a29741
KL
191 /**
192 * Get x.
193 *
194 * @return x
195 */
196 public int getX() {
197 return x;
198 }
df8de03f 199
48e27807
KL
200 /**
201 * Set x.
202 *
203 * @param x new relative X value
204 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
205 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
206 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
207 */
208 public void setX(final int x) {
209 this.x = x;
210 }
211
d4a29741
KL
212 /**
213 * Get y.
214 *
215 * @return y
216 */
217 public int getY() {
218 return y;
219 }
df8de03f 220
48e27807
KL
221 /**
222 * Set y.
223 *
224 * @param y new relative Y value
225 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
226 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
227 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
228 */
229 public void setY(final int y) {
230 this.y = y;
231 }
232
d4a29741
KL
233 /**
234 * Get absoluteX.
235 *
236 * @return absoluteX
237 */
238 public int getAbsoluteX() {
239 return absoluteX;
240 }
df8de03f 241
3e074355
KL
242 /**
243 * Set absoluteX.
244 *
245 * @param absoluteX the new value
246 */
247 public void setAbsoluteX(final int absoluteX) {
248 this.absoluteX = absoluteX;
249 }
250
d4a29741
KL
251 /**
252 * Get absoluteY.
253 *
254 * @return absoluteY
255 */
256 public int getAbsoluteY() {
257 return absoluteY;
258 }
df8de03f 259
3e074355
KL
260 /**
261 * Set absoluteY.
262 *
263 * @param absoluteY the new value
264 */
265 public void setAbsoluteY(final int absoluteY) {
266 this.absoluteY = absoluteY;
267 }
268
d4a29741
KL
269 /**
270 * Get mouse1.
271 *
272 * @return mouse1
273 */
7c870d89 274 public boolean isMouse1() {
d4a29741
KL
275 return mouse1;
276 }
df8de03f 277
d4a29741
KL
278 /**
279 * Get mouse2.
280 *
281 * @return mouse2
282 */
7c870d89 283 public boolean isMouse2() {
d4a29741
KL
284 return mouse2;
285 }
df8de03f 286
d4a29741
KL
287 /**
288 * Get mouse3.
289 *
290 * @return mouse3
291 */
7c870d89 292 public boolean isMouse3() {
d4a29741
KL
293 return mouse3;
294 }
df8de03f 295
d4a29741
KL
296 /**
297 * Get mouseWheelUp.
298 *
299 * @return mouseWheelUp
300 */
7c870d89 301 public boolean isMouseWheelUp() {
d4a29741
KL
302 return mouseWheelUp;
303 }
df8de03f 304
d4a29741
KL
305 /**
306 * Get mouseWheelDown.
307 *
308 * @return mouseWheelDown
309 */
7c870d89 310 public boolean isMouseWheelDown() {
d4a29741
KL
311 return mouseWheelDown;
312 }
df8de03f 313
6e9daafb
KL
314 /**
315 * Getter for ALT.
316 *
317 * @return alt value
318 */
319 public boolean isAlt() {
320 return alt;
321 }
322
323 /**
324 * Getter for CTRL.
325 *
326 * @return ctrl value
327 */
328 public boolean isCtrl() {
329 return ctrl;
330 }
331
332 /**
333 * Getter for SHIFT.
334 *
335 * @return shift value
336 */
337 public boolean isShift() {
338 return shift;
339 }
340
3e074355
KL
341 /**
342 * Create a duplicate instance.
343 *
344 * @return duplicate intance
345 */
346 public TMouseEvent dup() {
347 TMouseEvent mouse = new TMouseEvent(type, x, y, absoluteX, absoluteY,
6e9daafb
KL
348 mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown,
349 alt, ctrl, shift);
350
3e074355
KL
351 return mouse;
352 }
353
df8de03f 354 /**
7b5261bc
KL
355 * Make human-readable description of this TMouseEvent.
356 *
357 * @return displayable String
df8de03f
KL
358 */
359 @Override
d4a29741 360 public String toString() {
6e9daafb 361 return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s ALT %s CTRL %s SHIFT %s",
7b5261bc
KL
362 type,
363 x, y,
364 absoluteX, absoluteY,
365 mouse1,
366 mouse2,
367 mouse3,
368 mouseWheelUp,
6e9daafb
KL
369 mouseWheelDown,
370 alt, ctrl, shift);
df8de03f
KL
371 }
372
373}