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