double-click support
[fanfix.git] / src / jexer / TList.java
index 71600485fe2b9cb1646a8df8a3c0fa5c7af5755d..e47d7512e48cd175e480298daa6488824c84335b 100644 (file)
@@ -81,6 +81,15 @@ public class TList extends TScrollableWidget {
         return null;
     }
 
+    /**
+     * Get the maximum selection index value.
+     *
+     * @return -1 if the list is empty
+     */
+    public final int getMaxSelectedIndex() {
+        return strings.size() - 1;
+    }
+
     /**
      * Set the new list of strings to display.
      *
@@ -295,7 +304,6 @@ public class TList extends TScrollableWidget {
             && (mouse.getY() < getHeight() - 1)) {
             if (getVerticalValue() + mouse.getY() < strings.size()) {
                 selectedString = getVerticalValue() + mouse.getY();
-                dispatchEnter();
             }
             return;
         }
@@ -304,6 +312,26 @@ public class TList extends TScrollableWidget {
         super.onMouseDown(mouse);
     }
 
+    /**
+     * Handle mouse double click.
+     *
+     * @param mouse mouse double click event
+     */
+    @Override
+    public void onMouseDoubleClick(final TMouseEvent mouse) {
+        if ((mouse.getX() < getWidth() - 1)
+            && (mouse.getY() < getHeight() - 1)) {
+            if (getVerticalValue() + mouse.getY() < strings.size()) {
+                selectedString = getVerticalValue() + mouse.getY();
+                dispatchEnter();
+            }
+            return;
+        }
+
+        // Pass to children
+        super.onMouseDoubleClick(mouse);
+    }
+
     /**
      * Handle keystrokes.
      *