Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / jexer / event / TMouseEvent.java
index c29ebc3520d8db88dfd5107fd46aa50b598f5dd0..e52989814005bec2d2d303372519276ed4e4410f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -33,7 +33,11 @@ package jexer.event;
  * the relative (x,y) ARE MUTABLE: TWidget's onMouse() handlers perform that
  * update during event dispatching.
  */
-public final class TMouseEvent extends TInputEvent {
+public class TMouseEvent extends TInputEvent {
+
+    // ------------------------------------------------------------------------
+    // Constants --------------------------------------------------------------
+    // ------------------------------------------------------------------------
 
     /**
      * The type of event generated.
@@ -52,14 +56,129 @@ public final class TMouseEvent extends TInputEvent {
         /**
          * Mouse button up.  X and Y will have screen coordinates.
          */
-        MOUSE_UP
+        MOUSE_UP,
+
+        /**
+         * Mouse double-click.  X and Y will have screen coordinates.
+         */
+        MOUSE_DOUBLE_CLICK
     }
 
+    // ------------------------------------------------------------------------
+    // Variables --------------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Type of event, one of MOUSE_MOTION, MOUSE_UP, or MOUSE_DOWN.
      */
     private Type type;
 
+    /**
+     * Mouse X - relative coordinates.
+     */
+    private int x;
+
+    /**
+     * Mouse Y - relative coordinates.
+     */
+    private int y;
+
+    /**
+     * Mouse X - absolute screen coordinates.
+     */
+    private int absoluteX;
+
+    /**
+     * Mouse Y - absolute screen coordinate.
+     */
+    private int absoluteY;
+
+    /**
+     * Mouse button 1 (left button).
+     */
+    private boolean mouse1;
+
+    /**
+     * Mouse button 2 (right button).
+     */
+    private boolean mouse2;
+
+    /**
+     * Mouse button 3 (middle button).
+     */
+    private boolean mouse3;
+
+    /**
+     * Mouse wheel UP (button 4).
+     */
+    private boolean mouseWheelUp;
+
+    /**
+     * Mouse wheel DOWN (button 5).
+     */
+    private boolean mouseWheelDown;
+
+    /**
+     * Keyboard modifier ALT.
+     */
+    private boolean alt;
+
+    /**
+     * Keyboard modifier CTRL.
+     */
+    private boolean ctrl;
+
+    /**
+     * Keyboard modifier SHIFT.
+     */
+    private boolean shift;
+
+    // ------------------------------------------------------------------------
+    // Constructors -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
+    /**
+     * Public contructor.
+     *
+     * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
+     * @param x relative column
+     * @param y relative row
+     * @param absoluteX absolute column
+     * @param absoluteY absolute row
+     * @param mouse1 if true, left button is down
+     * @param mouse2 if true, right button is down
+     * @param mouse3 if true, middle button is down
+     * @param mouseWheelUp if true, mouse wheel (button 4) is down
+     * @param mouseWheelDown if true, mouse wheel (button 5) is down
+     * @param alt if true, ALT was pressed with this mouse event
+     * @param ctrl if true, CTRL was pressed with this mouse event
+     * @param shift if true, SHIFT was pressed with this mouse event
+     */
+    public TMouseEvent(final Type type, final int x, final int y,
+        final int absoluteX, final int absoluteY,
+        final boolean mouse1, final boolean mouse2, final boolean mouse3,
+        final boolean mouseWheelUp, final boolean mouseWheelDown,
+        final boolean alt, final boolean ctrl, final boolean shift) {
+
+        this.type               = type;
+        this.x                  = x;
+        this.y                  = y;
+        this.absoluteX          = absoluteX;
+        this.absoluteY          = absoluteY;
+        this.mouse1             = mouse1;
+        this.mouse2             = mouse2;
+        this.mouse3             = mouse3;
+        this.mouseWheelUp       = mouseWheelUp;
+        this.mouseWheelDown     = mouseWheelDown;
+        this.alt                = alt;
+        this.ctrl               = ctrl;
+        this.shift              = shift;
+    }
+
+    // ------------------------------------------------------------------------
+    // TMouseEvent ------------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Get type.
      *
@@ -69,11 +188,6 @@ public final class TMouseEvent extends TInputEvent {
         return type;
     }
 
-    /**
-     * Mouse X - relative coordinates.
-     */
-    private int x;
-
     /**
      * Get x.
      *
@@ -95,11 +209,6 @@ public final class TMouseEvent extends TInputEvent {
         this.x = x;
     }
 
-    /**
-     * Mouse Y - relative coordinates.
-     */
-    private int y;
-
     /**
      * Get y.
      *
@@ -121,11 +230,6 @@ public final class TMouseEvent extends TInputEvent {
         this.y = y;
     }
 
-    /**
-     * Mouse X - absolute screen coordinates.
-     */
-    private int absoluteX;
-
     /**
      * Get absoluteX.
      *
@@ -144,11 +248,6 @@ public final class TMouseEvent extends TInputEvent {
         this.absoluteX = absoluteX;
     }
 
-    /**
-     * Mouse Y - absolute screen coordinate.
-     */
-    private int absoluteY;
-
     /**
      * Get absoluteY.
      *
@@ -167,11 +266,6 @@ public final class TMouseEvent extends TInputEvent {
         this.absoluteY = absoluteY;
     }
 
-    /**
-     * Mouse button 1 (left button).
-     */
-    private boolean mouse1;
-
     /**
      * Get mouse1.
      *
@@ -181,11 +275,6 @@ public final class TMouseEvent extends TInputEvent {
         return mouse1;
     }
 
-    /**
-     * Mouse button 2 (right button).
-     */
-    private boolean mouse2;
-
     /**
      * Get mouse2.
      *
@@ -195,11 +284,6 @@ public final class TMouseEvent extends TInputEvent {
         return mouse2;
     }
 
-    /**
-     * Mouse button 3 (middle button).
-     */
-    private boolean mouse3;
-
     /**
      * Get mouse3.
      *
@@ -209,11 +293,6 @@ public final class TMouseEvent extends TInputEvent {
         return mouse3;
     }
 
-    /**
-     * Mouse wheel UP (button 4).
-     */
-    private boolean mouseWheelUp;
-
     /**
      * Get mouseWheelUp.
      *
@@ -223,11 +302,6 @@ public final class TMouseEvent extends TInputEvent {
         return mouseWheelUp;
     }
 
-    /**
-     * Mouse wheel DOWN (button 5).
-     */
-    private boolean mouseWheelDown;
-
     /**
      * Get mouseWheelDown.
      *
@@ -238,34 +312,30 @@ public final class TMouseEvent extends TInputEvent {
     }
 
     /**
-     * Public contructor.
+     * Getter for ALT.
      *
-     * @param type the type of event, MOUSE_MOTION, MOUSE_DOWN, or MOUSE_UP
-     * @param x relative column
-     * @param y relative row
-     * @param absoluteX absolute column
-     * @param absoluteY absolute row
-     * @param mouse1 if true, left button is down
-     * @param mouse2 if true, right button is down
-     * @param mouse3 if true, middle button is down
-     * @param mouseWheelUp if true, mouse wheel (button 4) is down
-     * @param mouseWheelDown if true, mouse wheel (button 5) is down
+     * @return alt value
      */
-    public TMouseEvent(final Type type, final int x, final int y,
-        final int absoluteX, final int absoluteY,
-        final boolean mouse1, final boolean mouse2, final boolean mouse3,
-        final boolean mouseWheelUp, final boolean mouseWheelDown) {
+    public boolean isAlt() {
+        return alt;
+    }
 
-        this.type               = type;
-        this.x                  = x;
-        this.y                  = y;
-        this.absoluteX          = absoluteX;
-        this.absoluteY          = absoluteY;
-        this.mouse1             = mouse1;
-        this.mouse2             = mouse2;
-        this.mouse3             = mouse3;
-        this.mouseWheelUp       = mouseWheelUp;
-        this.mouseWheelDown     = mouseWheelDown;
+    /**
+     * Getter for CTRL.
+     *
+     * @return ctrl value
+     */
+    public boolean isCtrl() {
+        return ctrl;
+    }
+
+    /**
+     * Getter for SHIFT.
+     *
+     * @return shift value
+     */
+    public boolean isShift() {
+        return shift;
     }
 
     /**
@@ -275,7 +345,9 @@ public final class TMouseEvent extends TInputEvent {
      */
     public TMouseEvent dup() {
         TMouseEvent mouse = new TMouseEvent(type, x, y, absoluteX, absoluteY,
-            mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown);
+            mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown,
+            alt, ctrl, shift);
+
         return mouse;
     }
 
@@ -286,7 +358,7 @@ public final class TMouseEvent extends TInputEvent {
      */
     @Override
     public String toString() {
-        return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s",
+        return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s ALT %s CTRL %s SHIFT %s",
             type,
             x, y,
             absoluteX, absoluteY,
@@ -294,7 +366,8 @@ public final class TMouseEvent extends TInputEvent {
             mouse2,
             mouse3,
             mouseWheelUp,
-            mouseWheelDown);
+            mouseWheelDown,
+            alt, ctrl, shift);
     }
 
 }