Commit | Line | Data |
---|---|---|
df8de03f KL |
1 | /** |
2 | * Jexer - Java Text User Interface | |
3 | * | |
df8de03f KL |
4 | * License: LGPLv3 or later |
5 | * | |
7b5261bc KL |
6 | * This module is licensed under the GNU Lesser General Public License |
7 | * Version 3. Please see the file "COPYING" in this directory for more | |
8 | * information about the GNU Lesser General Public License Version 3. | |
df8de03f KL |
9 | * |
10 | * Copyright (C) 2015 Kevin Lamonte | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public License | |
14 | * as published by the Free Software Foundation; either version 3 of | |
15 | * the License, or (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this program; if not, see | |
24 | * http://www.gnu.org/licenses/, or write to the Free Software | |
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
26 | * 02110-1301 USA | |
7b5261bc KL |
27 | * |
28 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
29 | * @version 1 | |
df8de03f KL |
30 | */ |
31 | package jexer.event; | |
32 | ||
33 | /** | |
48e27807 KL |
34 | * This class encapsulates several kinds of mouse input events. Note that |
35 | * the relative (x,y) ARE MUTABLE: TWidget's onMouse() handlers perform that | |
36 | * update during event dispatching. | |
df8de03f | 37 | */ |
d4a29741 | 38 | public final class TMouseEvent extends TInputEvent { |
df8de03f | 39 | |
7b5261bc KL |
40 | /** |
41 | * The type of event generated. | |
42 | */ | |
b1589621 | 43 | public enum Type { |
7b5261bc KL |
44 | /** |
45 | * Mouse motion. X and Y will have screen coordinates. | |
46 | */ | |
47 | MOUSE_MOTION, | |
48 | ||
49 | /** | |
50 | * Mouse button down. X and Y will have screen coordinates. | |
51 | */ | |
52 | MOUSE_DOWN, | |
53 | ||
54 | /** | |
55 | * Mouse button up. X and Y will have screen coordinates. | |
56 | */ | |
57 | MOUSE_UP | |
df8de03f KL |
58 | } |
59 | ||
60 | /** | |
bd8d51fa | 61 | * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN. |
df8de03f | 62 | */ |
d4a29741 KL |
63 | private Type type; |
64 | ||
65 | /** | |
66 | * Get type. | |
67 | * | |
68 | * @return type | |
69 | */ | |
70 | public Type getType() { | |
71 | return type; | |
72 | } | |
df8de03f KL |
73 | |
74 | /** | |
7b5261bc | 75 | * Mouse X - relative coordinates. |
df8de03f | 76 | */ |
d4a29741 KL |
77 | private int x; |
78 | ||
79 | /** | |
80 | * Get x. | |
81 | * | |
82 | * @return x | |
83 | */ | |
84 | public int getX() { | |
85 | return x; | |
86 | } | |
df8de03f | 87 | |
48e27807 KL |
88 | /** |
89 | * Set x. | |
90 | * | |
91 | * @param x new relative X value | |
92 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
93 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
94 | * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse) | |
95 | */ | |
96 | public void setX(final int x) { | |
97 | this.x = x; | |
98 | } | |
99 | ||
df8de03f | 100 | /** |
7b5261bc | 101 | * Mouse Y - relative coordinates. |
df8de03f | 102 | */ |
d4a29741 KL |
103 | private int y; |
104 | ||
105 | /** | |
106 | * Get y. | |
107 | * | |
108 | * @return y | |
109 | */ | |
110 | public int getY() { | |
111 | return y; | |
112 | } | |
df8de03f | 113 | |
48e27807 KL |
114 | /** |
115 | * Set y. | |
116 | * | |
117 | * @param y new relative Y value | |
118 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
119 | * @see jexer.TWidget#onMouseDown(TMouseEvent mouse) | |
120 | * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse) | |
121 | */ | |
122 | public void setY(final int y) { | |
123 | this.y = y; | |
124 | } | |
125 | ||
df8de03f | 126 | /** |
7b5261bc | 127 | * Mouse X - absolute screen coordinates. |
df8de03f | 128 | */ |
d4a29741 KL |
129 | private int absoluteX; |
130 | ||
131 | /** | |
132 | * Get absoluteX. | |
133 | * | |
134 | * @return absoluteX | |
135 | */ | |
136 | public int getAbsoluteX() { | |
137 | return absoluteX; | |
138 | } | |
df8de03f KL |
139 | |
140 | /** | |
7b5261bc | 141 | * Mouse Y - absolute screen coordinate. |
df8de03f | 142 | */ |
d4a29741 KL |
143 | private int absoluteY; |
144 | ||
145 | /** | |
146 | * Get absoluteY. | |
147 | * | |
148 | * @return absoluteY | |
149 | */ | |
150 | public int getAbsoluteY() { | |
151 | return absoluteY; | |
152 | } | |
df8de03f KL |
153 | |
154 | /** | |
7b5261bc | 155 | * Mouse button 1 (left button). |
df8de03f | 156 | */ |
d4a29741 KL |
157 | private boolean mouse1; |
158 | ||
159 | /** | |
160 | * Get mouse1. | |
161 | * | |
162 | * @return mouse1 | |
163 | */ | |
7c870d89 | 164 | public boolean isMouse1() { |
d4a29741 KL |
165 | return mouse1; |
166 | } | |
df8de03f KL |
167 | |
168 | /** | |
7b5261bc | 169 | * Mouse button 2 (right button). |
df8de03f | 170 | */ |
d4a29741 KL |
171 | private boolean mouse2; |
172 | ||
173 | /** | |
174 | * Get mouse2. | |
175 | * | |
176 | * @return mouse2 | |
177 | */ | |
7c870d89 | 178 | public boolean isMouse2() { |
d4a29741 KL |
179 | return mouse2; |
180 | } | |
df8de03f KL |
181 | |
182 | /** | |
7b5261bc | 183 | * Mouse button 3 (middle button). |
df8de03f | 184 | */ |
d4a29741 KL |
185 | private boolean mouse3; |
186 | ||
187 | /** | |
188 | * Get mouse3. | |
189 | * | |
190 | * @return mouse3 | |
191 | */ | |
7c870d89 | 192 | public boolean isMouse3() { |
d4a29741 KL |
193 | return mouse3; |
194 | } | |
df8de03f KL |
195 | |
196 | /** | |
7b5261bc | 197 | * Mouse wheel UP (button 4). |
df8de03f | 198 | */ |
d4a29741 KL |
199 | private boolean mouseWheelUp; |
200 | ||
201 | /** | |
202 | * Get mouseWheelUp. | |
203 | * | |
204 | * @return mouseWheelUp | |
205 | */ | |
7c870d89 | 206 | public boolean isMouseWheelUp() { |
d4a29741 KL |
207 | return mouseWheelUp; |
208 | } | |
df8de03f KL |
209 | |
210 | /** | |
7b5261bc | 211 | * Mouse wheel DOWN (button 5). |
df8de03f | 212 | */ |
d4a29741 KL |
213 | private boolean mouseWheelDown; |
214 | ||
215 | /** | |
216 | * Get mouseWheelDown. | |
217 | * | |
218 | * @return mouseWheelDown | |
219 | */ | |
7c870d89 | 220 | public boolean isMouseWheelDown() { |
d4a29741 KL |
221 | return mouseWheelDown; |
222 | } | |
df8de03f KL |
223 | |
224 | /** | |
7b5261bc | 225 | * Public contructor. |
df8de03f KL |
226 | * |
227 | * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP | |
d4a29741 KL |
228 | * @param x relative column |
229 | * @param y relative row | |
230 | * @param absoluteX absolute column | |
231 | * @param absoluteY absolute row | |
232 | * @param mouse1 if true, left button is down | |
233 | * @param mouse2 if true, right button is down | |
234 | * @param mouse3 if true, middle button is down | |
235 | * @param mouseWheelUp if true, mouse wheel (button 4) is down | |
236 | * @param mouseWheelDown if true, mouse wheel (button 5) is down | |
df8de03f | 237 | */ |
d4a29741 KL |
238 | public TMouseEvent(final Type type, final int x, final int y, |
239 | final int absoluteX, final int absoluteY, | |
240 | final boolean mouse1, final boolean mouse2, final boolean mouse3, | |
241 | final boolean mouseWheelUp, final boolean mouseWheelDown) { | |
242 | ||
243 | this.type = type; | |
244 | this.x = x; | |
245 | this.y = y; | |
246 | this.absoluteX = absoluteX; | |
247 | this.absoluteY = absoluteY; | |
248 | this.mouse1 = mouse1; | |
249 | this.mouse2 = mouse2; | |
250 | this.mouse3 = mouse3; | |
251 | this.mouseWheelUp = mouseWheelUp; | |
252 | this.mouseWheelDown = mouseWheelDown; | |
df8de03f KL |
253 | } |
254 | ||
255 | /** | |
7b5261bc KL |
256 | * Make human-readable description of this TMouseEvent. |
257 | * | |
258 | * @return displayable String | |
df8de03f KL |
259 | */ |
260 | @Override | |
d4a29741 | 261 | public String toString() { |
7b5261bc KL |
262 | return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s", |
263 | type, | |
264 | x, y, | |
265 | absoluteX, absoluteY, | |
266 | mouse1, | |
267 | mouse2, | |
268 | mouse3, | |
269 | mouseWheelUp, | |
270 | mouseWheelDown); | |
df8de03f KL |
271 | } |
272 | ||
273 | } |