TButton animate for keyboard
[nikiroo-utils.git] / src / jexer / event / TMouseEvent.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2017 Kevin Lamonte
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29 package jexer.event;
30
31 /**
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.
35 */
36 public final class TMouseEvent extends TInputEvent {
37
38 /**
39 * The type of event generated.
40 */
41 public enum Type {
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 */
55 MOUSE_UP
56 }
57
58 /**
59 * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN.
60 */
61 private Type type;
62
63 /**
64 * Get type.
65 *
66 * @return type
67 */
68 public Type getType() {
69 return type;
70 }
71
72 /**
73 * Mouse X - relative coordinates.
74 */
75 private int x;
76
77 /**
78 * Get x.
79 *
80 * @return x
81 */
82 public int getX() {
83 return x;
84 }
85
86 /**
87 * Set x.
88 *
89 * @param x new relative X value
90 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
91 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
92 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
93 */
94 public void setX(final int x) {
95 this.x = x;
96 }
97
98 /**
99 * Mouse Y - relative coordinates.
100 */
101 private int y;
102
103 /**
104 * Get y.
105 *
106 * @return y
107 */
108 public int getY() {
109 return y;
110 }
111
112 /**
113 * Set y.
114 *
115 * @param y new relative Y value
116 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
117 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
118 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
119 */
120 public void setY(final int y) {
121 this.y = y;
122 }
123
124 /**
125 * Mouse X - absolute screen coordinates.
126 */
127 private int absoluteX;
128
129 /**
130 * Get absoluteX.
131 *
132 * @return absoluteX
133 */
134 public int getAbsoluteX() {
135 return absoluteX;
136 }
137
138 /**
139 * Mouse Y - absolute screen coordinate.
140 */
141 private int absoluteY;
142
143 /**
144 * Get absoluteY.
145 *
146 * @return absoluteY
147 */
148 public int getAbsoluteY() {
149 return absoluteY;
150 }
151
152 /**
153 * Mouse button 1 (left button).
154 */
155 private boolean mouse1;
156
157 /**
158 * Get mouse1.
159 *
160 * @return mouse1
161 */
162 public boolean isMouse1() {
163 return mouse1;
164 }
165
166 /**
167 * Mouse button 2 (right button).
168 */
169 private boolean mouse2;
170
171 /**
172 * Get mouse2.
173 *
174 * @return mouse2
175 */
176 public boolean isMouse2() {
177 return mouse2;
178 }
179
180 /**
181 * Mouse button 3 (middle button).
182 */
183 private boolean mouse3;
184
185 /**
186 * Get mouse3.
187 *
188 * @return mouse3
189 */
190 public boolean isMouse3() {
191 return mouse3;
192 }
193
194 /**
195 * Mouse wheel UP (button 4).
196 */
197 private boolean mouseWheelUp;
198
199 /**
200 * Get mouseWheelUp.
201 *
202 * @return mouseWheelUp
203 */
204 public boolean isMouseWheelUp() {
205 return mouseWheelUp;
206 }
207
208 /**
209 * Mouse wheel DOWN (button 5).
210 */
211 private boolean mouseWheelDown;
212
213 /**
214 * Get mouseWheelDown.
215 *
216 * @return mouseWheelDown
217 */
218 public boolean isMouseWheelDown() {
219 return mouseWheelDown;
220 }
221
222 /**
223 * Public contructor.
224 *
225 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
226 * @param x relative column
227 * @param y relative row
228 * @param absoluteX absolute column
229 * @param absoluteY absolute row
230 * @param mouse1 if true, left button is down
231 * @param mouse2 if true, right button is down
232 * @param mouse3 if true, middle button is down
233 * @param mouseWheelUp if true, mouse wheel (button 4) is down
234 * @param mouseWheelDown if true, mouse wheel (button 5) is down
235 */
236 public TMouseEvent(final Type type, final int x, final int y,
237 final int absoluteX, final int absoluteY,
238 final boolean mouse1, final boolean mouse2, final boolean mouse3,
239 final boolean mouseWheelUp, final boolean mouseWheelDown) {
240
241 this.type = type;
242 this.x = x;
243 this.y = y;
244 this.absoluteX = absoluteX;
245 this.absoluteY = absoluteY;
246 this.mouse1 = mouse1;
247 this.mouse2 = mouse2;
248 this.mouse3 = mouse3;
249 this.mouseWheelUp = mouseWheelUp;
250 this.mouseWheelDown = mouseWheelDown;
251 }
252
253 /**
254 * Make human-readable description of this TMouseEvent.
255 *
256 * @return displayable String
257 */
258 @Override
259 public String toString() {
260 return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
261 type,
262 x, y,
263 absoluteX, absoluteY,
264 mouse1,
265 mouse2,
266 mouse3,
267 mouseWheelUp,
268 mouseWheelDown);
269 }
270
271 }