Expose width/height in TApplication constructor, attempt on ECMA48
[nikiroo-utils.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 *
a2018e99 6 * Copyright (C) 2017 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 */
d4a29741 36public final class TMouseEvent extends TInputEvent {
df8de03f 37
7b5261bc
KL
38 /**
39 * The type of event generated.
40 */
b1589621 41 public enum Type {
7b5261bc
KL
42 /**
43 * Mouse motion. X and Y will have screen coordinates.
44 */
45 MOUSE_MOTION,
46
47 /**
48 * Mouse button down. X and Y will have screen coordinates.
49 */
50 MOUSE_DOWN,
51
52 /**
53 * Mouse button up. X and Y will have screen coordinates.
54 */
b6faeac0
KL
55 MOUSE_UP,
56
57 /**
58 * Mouse double-click. X and Y will have screen coordinates.
59 */
60 MOUSE_DOUBLE_CLICK
df8de03f
KL
61 }
62
63 /**
bd8d51fa 64 * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN.
df8de03f 65 */
d4a29741
KL
66 private Type type;
67
68 /**
69 * Get type.
70 *
71 * @return type
72 */
73 public Type getType() {
74 return type;
75 }
df8de03f
KL
76
77 /**
7b5261bc 78 * Mouse X - relative coordinates.
df8de03f 79 */
d4a29741
KL
80 private int x;
81
82 /**
83 * Get x.
84 *
85 * @return x
86 */
87 public int getX() {
88 return x;
89 }
df8de03f 90
48e27807
KL
91 /**
92 * Set x.
93 *
94 * @param x new relative X value
95 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
96 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
97 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
98 */
99 public void setX(final int x) {
100 this.x = x;
101 }
102
df8de03f 103 /**
7b5261bc 104 * Mouse Y - relative coordinates.
df8de03f 105 */
d4a29741
KL
106 private int y;
107
108 /**
109 * Get y.
110 *
111 * @return y
112 */
113 public int getY() {
114 return y;
115 }
df8de03f 116
48e27807
KL
117 /**
118 * Set y.
119 *
120 * @param y new relative Y value
121 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
122 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
123 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
124 */
125 public void setY(final int y) {
126 this.y = y;
127 }
128
df8de03f 129 /**
7b5261bc 130 * Mouse X - absolute screen coordinates.
df8de03f 131 */
d4a29741
KL
132 private int absoluteX;
133
134 /**
135 * Get absoluteX.
136 *
137 * @return absoluteX
138 */
139 public int getAbsoluteX() {
140 return absoluteX;
141 }
df8de03f 142
3e074355
KL
143 /**
144 * Set absoluteX.
145 *
146 * @param absoluteX the new value
147 */
148 public void setAbsoluteX(final int absoluteX) {
149 this.absoluteX = absoluteX;
150 }
151
df8de03f 152 /**
7b5261bc 153 * Mouse Y - absolute screen coordinate.
df8de03f 154 */
d4a29741
KL
155 private int absoluteY;
156
157 /**
158 * Get absoluteY.
159 *
160 * @return absoluteY
161 */
162 public int getAbsoluteY() {
163 return absoluteY;
164 }
df8de03f 165
3e074355
KL
166 /**
167 * Set absoluteY.
168 *
169 * @param absoluteY the new value
170 */
171 public void setAbsoluteY(final int absoluteY) {
172 this.absoluteY = absoluteY;
173 }
174
df8de03f 175 /**
7b5261bc 176 * Mouse button 1 (left button).
df8de03f 177 */
d4a29741
KL
178 private boolean mouse1;
179
180 /**
181 * Get mouse1.
182 *
183 * @return mouse1
184 */
7c870d89 185 public boolean isMouse1() {
d4a29741
KL
186 return mouse1;
187 }
df8de03f
KL
188
189 /**
7b5261bc 190 * Mouse button 2 (right button).
df8de03f 191 */
d4a29741
KL
192 private boolean mouse2;
193
194 /**
195 * Get mouse2.
196 *
197 * @return mouse2
198 */
7c870d89 199 public boolean isMouse2() {
d4a29741
KL
200 return mouse2;
201 }
df8de03f
KL
202
203 /**
7b5261bc 204 * Mouse button 3 (middle button).
df8de03f 205 */
d4a29741
KL
206 private boolean mouse3;
207
208 /**
209 * Get mouse3.
210 *
211 * @return mouse3
212 */
7c870d89 213 public boolean isMouse3() {
d4a29741
KL
214 return mouse3;
215 }
df8de03f
KL
216
217 /**
7b5261bc 218 * Mouse wheel UP (button 4).
df8de03f 219 */
d4a29741
KL
220 private boolean mouseWheelUp;
221
222 /**
223 * Get mouseWheelUp.
224 *
225 * @return mouseWheelUp
226 */
7c870d89 227 public boolean isMouseWheelUp() {
d4a29741
KL
228 return mouseWheelUp;
229 }
df8de03f
KL
230
231 /**
7b5261bc 232 * Mouse wheel DOWN (button 5).
df8de03f 233 */
d4a29741
KL
234 private boolean mouseWheelDown;
235
236 /**
237 * Get mouseWheelDown.
238 *
239 * @return mouseWheelDown
240 */
7c870d89 241 public boolean isMouseWheelDown() {
d4a29741
KL
242 return mouseWheelDown;
243 }
df8de03f
KL
244
245 /**
7b5261bc 246 * Public contructor.
df8de03f
KL
247 *
248 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
d4a29741
KL
249 * @param x relative column
250 * @param y relative row
251 * @param absoluteX absolute column
252 * @param absoluteY absolute row
253 * @param mouse1 if true, left button is down
254 * @param mouse2 if true, right button is down
255 * @param mouse3 if true, middle button is down
256 * @param mouseWheelUp if true, mouse wheel (button 4) is down
257 * @param mouseWheelDown if true, mouse wheel (button 5) is down
df8de03f 258 */
d4a29741
KL
259 public TMouseEvent(final Type type, final int x, final int y,
260 final int absoluteX, final int absoluteY,
261 final boolean mouse1, final boolean mouse2, final boolean mouse3,
262 final boolean mouseWheelUp, final boolean mouseWheelDown) {
263
264 this.type = type;
265 this.x = x;
266 this.y = y;
267 this.absoluteX = absoluteX;
268 this.absoluteY = absoluteY;
269 this.mouse1 = mouse1;
270 this.mouse2 = mouse2;
271 this.mouse3 = mouse3;
272 this.mouseWheelUp = mouseWheelUp;
273 this.mouseWheelDown = mouseWheelDown;
df8de03f
KL
274 }
275
3e074355
KL
276 /**
277 * Create a duplicate instance.
278 *
279 * @return duplicate intance
280 */
281 public TMouseEvent dup() {
282 TMouseEvent mouse = new TMouseEvent(type, x, y, absoluteX, absoluteY,
283 mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown);
284 return mouse;
285 }
286
df8de03f 287 /**
7b5261bc
KL
288 * Make human-readable description of this TMouseEvent.
289 *
290 * @return displayable String
df8de03f
KL
291 */
292 @Override
d4a29741 293 public String toString() {
7b5261bc
KL
294 return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
295 type,
296 x, y,
297 absoluteX, absoluteY,
298 mouse1,
299 mouse2,
300 mouse3,
301 mouseWheelUp,
302 mouseWheelDown);
df8de03f
KL
303 }
304
305}