Pull demo into jar
[nikiroo-utils.git] / src / jexer / event / TMouseEvent.java
CommitLineData
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 */
31package 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 38public 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 /**
61 * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN, or
7b5261bc 62 * KEYPRESS.
df8de03f 63 */
d4a29741
KL
64 private Type type;
65
66 /**
67 * Get type.
68 *
69 * @return type
70 */
71 public Type getType() {
72 return type;
73 }
df8de03f
KL
74
75 /**
7b5261bc 76 * Mouse X - relative coordinates.
df8de03f 77 */
d4a29741
KL
78 private int x;
79
80 /**
81 * Get x.
82 *
83 * @return x
84 */
85 public int getX() {
86 return x;
87 }
df8de03f 88
48e27807
KL
89 /**
90 * Set x.
91 *
92 * @param x new relative X value
93 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
94 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
95 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
96 */
97 public void setX(final int x) {
98 this.x = x;
99 }
100
df8de03f 101 /**
7b5261bc 102 * Mouse Y - relative coordinates.
df8de03f 103 */
d4a29741
KL
104 private int y;
105
106 /**
107 * Get y.
108 *
109 * @return y
110 */
111 public int getY() {
112 return y;
113 }
df8de03f 114
48e27807
KL
115 /**
116 * Set y.
117 *
118 * @param y new relative Y value
119 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
120 * @see jexer.TWidget#onMouseDown(TMouseEvent mouse)
121 * @see jexer.TWidget#onMouseMotion(TMouseEvent mouse)
122 */
123 public void setY(final int y) {
124 this.y = y;
125 }
126
df8de03f 127 /**
7b5261bc 128 * Mouse X - absolute screen coordinates.
df8de03f 129 */
d4a29741
KL
130 private int absoluteX;
131
132 /**
133 * Get absoluteX.
134 *
135 * @return absoluteX
136 */
137 public int getAbsoluteX() {
138 return absoluteX;
139 }
df8de03f
KL
140
141 /**
7b5261bc 142 * Mouse Y - absolute screen coordinate.
df8de03f 143 */
d4a29741
KL
144 private int absoluteY;
145
146 /**
147 * Get absoluteY.
148 *
149 * @return absoluteY
150 */
151 public int getAbsoluteY() {
152 return absoluteY;
153 }
df8de03f
KL
154
155 /**
7b5261bc 156 * Mouse button 1 (left button).
df8de03f 157 */
d4a29741
KL
158 private boolean mouse1;
159
160 /**
161 * Get mouse1.
162 *
163 * @return mouse1
164 */
165 public boolean getMouse1() {
166 return mouse1;
167 }
df8de03f
KL
168
169 /**
7b5261bc 170 * Mouse button 2 (right button).
df8de03f 171 */
d4a29741
KL
172 private boolean mouse2;
173
174 /**
175 * Get mouse2.
176 *
177 * @return mouse2
178 */
179 public boolean getMouse2() {
180 return mouse2;
181 }
df8de03f
KL
182
183 /**
7b5261bc 184 * Mouse button 3 (middle button).
df8de03f 185 */
d4a29741
KL
186 private boolean mouse3;
187
188 /**
189 * Get mouse3.
190 *
191 * @return mouse3
192 */
193 public boolean getMouse3() {
194 return mouse3;
195 }
df8de03f
KL
196
197 /**
7b5261bc 198 * Mouse wheel UP (button 4).
df8de03f 199 */
d4a29741
KL
200 private boolean mouseWheelUp;
201
202 /**
203 * Get mouseWheelUp.
204 *
205 * @return mouseWheelUp
206 */
207 public boolean getMouseWheelUp() {
208 return mouseWheelUp;
209 }
df8de03f
KL
210
211 /**
7b5261bc 212 * Mouse wheel DOWN (button 5).
df8de03f 213 */
d4a29741
KL
214 private boolean mouseWheelDown;
215
216 /**
217 * Get mouseWheelDown.
218 *
219 * @return mouseWheelDown
220 */
221 public boolean getMouseWheelDown() {
222 return mouseWheelDown;
223 }
df8de03f
KL
224
225 /**
7b5261bc 226 * Public contructor.
df8de03f
KL
227 *
228 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
d4a29741
KL
229 * @param x relative column
230 * @param y relative row
231 * @param absoluteX absolute column
232 * @param absoluteY absolute row
233 * @param mouse1 if true, left button is down
234 * @param mouse2 if true, right button is down
235 * @param mouse3 if true, middle button is down
236 * @param mouseWheelUp if true, mouse wheel (button 4) is down
237 * @param mouseWheelDown if true, mouse wheel (button 5) is down
df8de03f 238 */
d4a29741
KL
239 public TMouseEvent(final Type type, final int x, final int y,
240 final int absoluteX, final int absoluteY,
241 final boolean mouse1, final boolean mouse2, final boolean mouse3,
242 final boolean mouseWheelUp, final boolean mouseWheelDown) {
243
244 this.type = type;
245 this.x = x;
246 this.y = y;
247 this.absoluteX = absoluteX;
248 this.absoluteY = absoluteY;
249 this.mouse1 = mouse1;
250 this.mouse2 = mouse2;
251 this.mouse3 = mouse3;
252 this.mouseWheelUp = mouseWheelUp;
253 this.mouseWheelDown = mouseWheelDown;
df8de03f
KL
254 }
255
256 /**
7b5261bc
KL
257 * Make human-readable description of this TMouseEvent.
258 *
259 * @return displayable String
df8de03f
KL
260 */
261 @Override
d4a29741 262 public String toString() {
7b5261bc
KL
263 return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
264 type,
265 x, y,
266 absoluteX, absoluteY,
267 mouse1,
268 mouse2,
269 mouse3,
270 mouseWheelUp,
271 mouseWheelDown);
df8de03f
KL
272 }
273
274}