custom command line terminal window, blinking in color theme, scrolling region resize
[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 *
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 */
55 MOUSE_UP
df8de03f
KL
56 }
57
58 /**
bd8d51fa 59 * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN.
df8de03f 60 */
d4a29741
KL
61 private Type type;
62
63 /**
64 * Get type.
65 *
66 * @return type
67 */
68 public Type getType() {
69 return type;
70 }
df8de03f
KL
71
72 /**
7b5261bc 73 * Mouse X - relative coordinates.
df8de03f 74 */
d4a29741
KL
75 private int x;
76
77 /**
78 * Get x.
79 *
80 * @return x
81 */
82 public int getX() {
83 return x;
84 }
df8de03f 85
48e27807
KL
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
df8de03f 98 /**
7b5261bc 99 * Mouse Y - relative coordinates.
df8de03f 100 */
d4a29741
KL
101 private int y;
102
103 /**
104 * Get y.
105 *
106 * @return y
107 */
108 public int getY() {
109 return y;
110 }
df8de03f 111
48e27807
KL
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
df8de03f 124 /**
7b5261bc 125 * Mouse X - absolute screen coordinates.
df8de03f 126 */
d4a29741
KL
127 private int absoluteX;
128
129 /**
130 * Get absoluteX.
131 *
132 * @return absoluteX
133 */
134 public int getAbsoluteX() {
135 return absoluteX;
136 }
df8de03f 137
3e074355
KL
138 /**
139 * Set absoluteX.
140 *
141 * @param absoluteX the new value
142 */
143 public void setAbsoluteX(final int absoluteX) {
144 this.absoluteX = absoluteX;
145 }
146
df8de03f 147 /**
7b5261bc 148 * Mouse Y - absolute screen coordinate.
df8de03f 149 */
d4a29741
KL
150 private int absoluteY;
151
152 /**
153 * Get absoluteY.
154 *
155 * @return absoluteY
156 */
157 public int getAbsoluteY() {
158 return absoluteY;
159 }
df8de03f 160
3e074355
KL
161 /**
162 * Set absoluteY.
163 *
164 * @param absoluteY the new value
165 */
166 public void setAbsoluteY(final int absoluteY) {
167 this.absoluteY = absoluteY;
168 }
169
df8de03f 170 /**
7b5261bc 171 * Mouse button 1 (left button).
df8de03f 172 */
d4a29741
KL
173 private boolean mouse1;
174
175 /**
176 * Get mouse1.
177 *
178 * @return mouse1
179 */
7c870d89 180 public boolean isMouse1() {
d4a29741
KL
181 return mouse1;
182 }
df8de03f
KL
183
184 /**
7b5261bc 185 * Mouse button 2 (right button).
df8de03f 186 */
d4a29741
KL
187 private boolean mouse2;
188
189 /**
190 * Get mouse2.
191 *
192 * @return mouse2
193 */
7c870d89 194 public boolean isMouse2() {
d4a29741
KL
195 return mouse2;
196 }
df8de03f
KL
197
198 /**
7b5261bc 199 * Mouse button 3 (middle button).
df8de03f 200 */
d4a29741
KL
201 private boolean mouse3;
202
203 /**
204 * Get mouse3.
205 *
206 * @return mouse3
207 */
7c870d89 208 public boolean isMouse3() {
d4a29741
KL
209 return mouse3;
210 }
df8de03f
KL
211
212 /**
7b5261bc 213 * Mouse wheel UP (button 4).
df8de03f 214 */
d4a29741
KL
215 private boolean mouseWheelUp;
216
217 /**
218 * Get mouseWheelUp.
219 *
220 * @return mouseWheelUp
221 */
7c870d89 222 public boolean isMouseWheelUp() {
d4a29741
KL
223 return mouseWheelUp;
224 }
df8de03f
KL
225
226 /**
7b5261bc 227 * Mouse wheel DOWN (button 5).
df8de03f 228 */
d4a29741
KL
229 private boolean mouseWheelDown;
230
231 /**
232 * Get mouseWheelDown.
233 *
234 * @return mouseWheelDown
235 */
7c870d89 236 public boolean isMouseWheelDown() {
d4a29741
KL
237 return mouseWheelDown;
238 }
df8de03f
KL
239
240 /**
7b5261bc 241 * Public contructor.
df8de03f
KL
242 *
243 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
d4a29741
KL
244 * @param x relative column
245 * @param y relative row
246 * @param absoluteX absolute column
247 * @param absoluteY absolute row
248 * @param mouse1 if true, left button is down
249 * @param mouse2 if true, right button is down
250 * @param mouse3 if true, middle button is down
251 * @param mouseWheelUp if true, mouse wheel (button 4) is down
252 * @param mouseWheelDown if true, mouse wheel (button 5) is down
df8de03f 253 */
d4a29741
KL
254 public TMouseEvent(final Type type, final int x, final int y,
255 final int absoluteX, final int absoluteY,
256 final boolean mouse1, final boolean mouse2, final boolean mouse3,
257 final boolean mouseWheelUp, final boolean mouseWheelDown) {
258
259 this.type = type;
260 this.x = x;
261 this.y = y;
262 this.absoluteX = absoluteX;
263 this.absoluteY = absoluteY;
264 this.mouse1 = mouse1;
265 this.mouse2 = mouse2;
266 this.mouse3 = mouse3;
267 this.mouseWheelUp = mouseWheelUp;
268 this.mouseWheelDown = mouseWheelDown;
df8de03f
KL
269 }
270
3e074355
KL
271 /**
272 * Create a duplicate instance.
273 *
274 * @return duplicate intance
275 */
276 public TMouseEvent dup() {
277 TMouseEvent mouse = new TMouseEvent(type, x, y, absoluteX, absoluteY,
278 mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown);
279 return mouse;
280 }
281
df8de03f 282 /**
7b5261bc
KL
283 * Make human-readable description of this TMouseEvent.
284 *
285 * @return displayable String
df8de03f
KL
286 */
287 @Override
d4a29741 288 public String toString() {
7b5261bc
KL
289 return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
290 type,
291 x, y,
292 absoluteX, absoluteY,
293 mouse1,
294 mouse2,
295 mouse3,
296 mouseWheelUp,
297 mouseWheelDown);
df8de03f
KL
298 }
299
300}