Prep for 2019 release
[fanfix.git] / src / jexer / menu / TMenu.java
index be4cf5dd12646bd107d7841a3dc49edd15996cd9..bfda60247a2f81ffe20afcd8599a94a06181cfe7 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"),
@@ -44,7 +44,7 @@ import static jexer.TKeypress.*;
 /**
  * TMenu is a top-level collection of TMenuItems.
  */
-public final class TMenu extends TWindow {
+public class TMenu extends TWindow {
 
     /**
      * Translated strings.
@@ -128,8 +128,8 @@ public final class TMenu extends TWindow {
      * @param x column relative to parent
      * @param y row relative to parent
      * @param label mnemonic menu title.  Label must contain a keyboard
-     * shortcut (mnemonic), denoted by prefixing a letter with "&",
-     * e.g. "&File"
+     * shortcut (mnemonic), denoted by prefixing a letter with "&",
+     * e.g. "&File"
      */
     public TMenu(final TApplication parent, final int x, final int y,
         final String label) {
@@ -161,6 +161,7 @@ public final class TMenu extends TWindow {
     @Override
     public void onMouseDown(final TMouseEvent mouse) {
         this.mouse = mouse;
+        super.onMouseDown(mouse);
 
         // Pass to children
         for (TWidget widget: getChildren()) {
@@ -341,7 +342,7 @@ public final class TMenu extends TWindow {
         hLineXY(1 + 1, getHeight() - 1, getWidth() - 4, cHSide, background);
 
         // Draw a shadow
-        getScreen().drawBoxShadow(0, 0, getWidth(), getHeight());
+        drawBoxShadow(0, 0, getWidth(), getHeight());
     }
 
     // ------------------------------------------------------------------------
@@ -387,6 +388,21 @@ public final class TMenu extends TWindow {
         return addItemInternal(id, label, null);
     }
 
+    /**
+     * Convenience function to add a menu item.
+     *
+     * @param id menu item ID.  Must be greater than 1024.
+     * @param label menu item label
+     * @param enabled default state for enabled
+     * @return the new menu item
+     */
+    public TMenuItem addItem(final int id, final String label,
+        final boolean enabled) {
+
+        assert (id >= 1024);
+        return addItemInternal(id, label, null, enabled);
+    }
+
     /**
      * Convenience function to add a custom menu item.
      *
@@ -620,7 +636,7 @@ public final class TMenu extends TWindow {
      * Convenience function to add a sub-menu.
      *
      * @param title menu title.  Title must contain a keyboard shortcut,
-     * denoted by prefixing a letter with "&", e.g. "&File"
+     * denoted by prefixing a letter with "&", e.g. "&File"
      * @return the new sub-menu
      */
     public TSubMenu addSubMenu(final String title) {