fix javadoc header
[fanfix.git] / src / jexer / menu / TSubMenu.java
index 24cc67d6739290c7803f42f356a906fa8d6914f4..167b6a5b11fc7d656c912b36bac62ff5d8412587 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Jexer - Java Text User Interface
  *
  * License: LGPLv3 or later
@@ -30,6 +30,7 @@
  */
 package jexer.menu;
 
+import jexer.TKeypress;
 import jexer.TWidget;
 import jexer.bits.CellAttributes;
 import jexer.bits.GraphicsChars;
@@ -39,7 +40,7 @@ import static jexer.TKeypress.*;
 /**
  * TSubMenu is a special case menu item that wraps another TMenu.
  */
-public class TSubMenu extends TMenuItem {
+public final class TSubMenu extends TMenuItem {
 
     /**
      * The menu window.  Note package private access.
@@ -75,19 +76,14 @@ public class TSubMenu extends TMenuItem {
     public void draw() {
         super.draw();
 
-        CellAttributes background = getTheme().getColor("tmenu");
         CellAttributes menuColor;
-        CellAttributes menuMnemonicColor;
-        if (getAbsoluteActive()) {
+        if (isAbsoluteActive()) {
             menuColor = getTheme().getColor("tmenu.highlighted");
-            menuMnemonicColor = getTheme().getColor("tmenu.mnemonic.highlighted");
         } else {
-            if (getEnabled()) {
+            if (isEnabled()) {
                 menuColor = getTheme().getColor("tmenu");
-                menuMnemonicColor = getTheme().getColor("tmenu.mnemonic");
             } else {
                 menuColor = getTheme().getColor("tmenu.disabled");
-                menuMnemonicColor = getTheme().getColor("tmenu.disabled");
             }
         }
 
@@ -104,7 +100,7 @@ public class TSubMenu extends TMenuItem {
     @Override
     public void onKeypress(final TKeypressEvent keypress) {
 
-        if (menu.getActive()) {
+        if (menu.isActive()) {
             menu.onKeypress(keypress);
             return;
         }
@@ -150,9 +146,9 @@ public class TSubMenu extends TMenuItem {
      */
     @Override
     public void dispatch() {
-        assert (getEnabled());
-        if (getAbsoluteActive()) {
-            if (!menu.getActive()) {
+        assert (isEnabled());
+        if (isAbsoluteActive()) {
+            if (!menu.isActive()) {
                 getApplication().addSubMenu(menu);
                 menu.setActive(true);
             }
@@ -166,11 +162,66 @@ public class TSubMenu extends TMenuItem {
      */
     @Override
     public TWidget getActiveChild() {
-        if (menu.getActive()) {
+        if (menu.isActive()) {
             return menu;
         }
         // Menu not active, return me
         return this;
     }
 
+    /**
+     * Convenience function to add a custom menu item.
+     *
+     * @param id menu item ID.  Must be greater than 1024.
+     * @param label menu item label
+     * @param key global keyboard accelerator
+     * @return the new menu item
+     */
+    public TMenuItem addItem(final int id, final String label,
+        final TKeypress key) {
+
+        return menu.addItem(id, label, key);
+    }
+
+    /**
+     * Convenience function to add a menu item.
+     *
+     * @param id menu item ID.  Must be greater than 1024.
+     * @param label menu item label
+     * @return the new menu item
+     */
+    public TMenuItem addItem(final int id, final String label) {
+        return menu.addItem(id, label);
+    }
+
+    /**
+     * Convenience function to add one of the default menu items.
+     *
+     * @param id menu item ID.  Must be between 0 (inclusive) and 1023
+     * (inclusive).
+     * @return the new menu item
+     */
+    public TMenuItem addDefaultItem(final int id) {
+        return menu.addDefaultItem(id);
+    }
+
+    /**
+     * Convenience function to add a menu separator.
+     */
+    public void addSeparator() {
+        menu.addSeparator();
+    }
+
+    /**
+     * 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"
+     * @return the new sub-menu
+     */
+    public TSubMenu addSubMenu(final String title) {
+        return menu.addSubMenu(title);
+    }
+
+
 }