immutable TMouseEvent
[nikiroo-utils.git] / src / jexer / event / TMouseEvent.java
1 /**
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
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.
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
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31 package jexer.event;
32
33 /**
34 * This class encapsulates several kinds of mouse input events.
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, or
60 * KEYPRESS.
61 */
62 private Type type;
63
64 /**
65 * Get type.
66 *
67 * @return type
68 */
69 public Type getType() {
70 return type;
71 }
72
73 /**
74 * Mouse X - relative coordinates.
75 */
76 private int x;
77
78 /**
79 * Get x.
80 *
81 * @return x
82 */
83 public int getX() {
84 return x;
85 }
86
87 /**
88 * Mouse Y - relative coordinates.
89 */
90 private int y;
91
92 /**
93 * Get y.
94 *
95 * @return y
96 */
97 public int getY() {
98 return y;
99 }
100
101 /**
102 * Mouse X - absolute screen coordinates.
103 */
104 private int absoluteX;
105
106 /**
107 * Get absoluteX.
108 *
109 * @return absoluteX
110 */
111 public int getAbsoluteX() {
112 return absoluteX;
113 }
114
115 /**
116 * Mouse Y - absolute screen coordinate.
117 */
118 private int absoluteY;
119
120 /**
121 * Get absoluteY.
122 *
123 * @return absoluteY
124 */
125 public int getAbsoluteY() {
126 return absoluteY;
127 }
128
129 /**
130 * Mouse button 1 (left button).
131 */
132 private boolean mouse1;
133
134 /**
135 * Get mouse1.
136 *
137 * @return mouse1
138 */
139 public boolean getMouse1() {
140 return mouse1;
141 }
142
143 /**
144 * Mouse button 2 (right button).
145 */
146 private boolean mouse2;
147
148 /**
149 * Get mouse2.
150 *
151 * @return mouse2
152 */
153 public boolean getMouse2() {
154 return mouse2;
155 }
156
157 /**
158 * Mouse button 3 (middle button).
159 */
160 private boolean mouse3;
161
162 /**
163 * Get mouse3.
164 *
165 * @return mouse3
166 */
167 public boolean getMouse3() {
168 return mouse3;
169 }
170
171 /**
172 * Mouse wheel UP (button 4).
173 */
174 private boolean mouseWheelUp;
175
176 /**
177 * Get mouseWheelUp.
178 *
179 * @return mouseWheelUp
180 */
181 public boolean getMouseWheelUp() {
182 return mouseWheelUp;
183 }
184
185 /**
186 * Mouse wheel DOWN (button 5).
187 */
188 private boolean mouseWheelDown;
189
190 /**
191 * Get mouseWheelDown.
192 *
193 * @return mouseWheelDown
194 */
195 public boolean getMouseWheelDown() {
196 return mouseWheelDown;
197 }
198
199 /**
200 * Public contructor.
201 *
202 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
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
212 */
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;
228 }
229
230 /**
231 * Make human-readable description of this TMouseEvent.
232 *
233 * @return displayable String
234 */
235 @Override
236 public String toString() {
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);
246 }
247
248 }