c29ebc3520d8db88dfd5107fd46aa50b598f5dd0
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
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.
36 public final class TMouseEvent
extends TInputEvent
{
39 * The type of event generated.
43 * Mouse motion. X and Y will have screen coordinates.
48 * Mouse button down. X and Y will have screen coordinates.
53 * Mouse button up. X and Y will have screen coordinates.
59 * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN.
68 public Type
getType() {
73 * Mouse X - relative coordinates.
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)
94 public void setX(final int x
) {
99 * Mouse Y - relative coordinates.
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)
120 public void setY(final int y
) {
125 * Mouse X - absolute screen coordinates.
127 private int absoluteX
;
134 public int getAbsoluteX() {
141 * @param absoluteX the new value
143 public void setAbsoluteX(final int absoluteX
) {
144 this.absoluteX
= absoluteX
;
148 * Mouse Y - absolute screen coordinate.
150 private int absoluteY
;
157 public int getAbsoluteY() {
164 * @param absoluteY the new value
166 public void setAbsoluteY(final int absoluteY
) {
167 this.absoluteY
= absoluteY
;
171 * Mouse button 1 (left button).
173 private boolean mouse1
;
180 public boolean isMouse1() {
185 * Mouse button 2 (right button).
187 private boolean mouse2
;
194 public boolean isMouse2() {
199 * Mouse button 3 (middle button).
201 private boolean mouse3
;
208 public boolean isMouse3() {
213 * Mouse wheel UP (button 4).
215 private boolean mouseWheelUp
;
220 * @return mouseWheelUp
222 public boolean isMouseWheelUp() {
227 * Mouse wheel DOWN (button 5).
229 private boolean mouseWheelDown
;
232 * Get mouseWheelDown.
234 * @return mouseWheelDown
236 public boolean isMouseWheelDown() {
237 return mouseWheelDown
;
243 * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
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
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
) {
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
;
272 * Create a duplicate instance.
274 * @return duplicate intance
276 public TMouseEvent
dup() {
277 TMouseEvent mouse
= new TMouseEvent(type
, x
, y
, absoluteX
, absoluteY
,
278 mouse1
, mouse2
, mouse3
, mouseWheelUp
, mouseWheelDown
);
283 * Make human-readable description of this TMouseEvent.
285 * @return displayable String
288 public String
toString() {
289 return String
.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
292 absoluteX
, absoluteY
,