Merge branch 'master' of https://github.com/klamonte/jexer
authorKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 29 Mar 2015 21:28:16 +0000 (17:28 -0400)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 29 Mar 2015 21:28:16 +0000 (17:28 -0400)
1  2 
src/jexer/TButton.java
src/jexer/TMessageBox.java
src/jexer/bits/ColorTheme.java
src/jexer/menu/TMenu.java
src/jexer/menu/TSubMenu.java

diff --combined src/jexer/TButton.java
index 30e94edc45339c067dbcb23231de6e445956ec09,c05a4b1025be40ec9bf7e76c858a9c0bba404c78..fb8c08e35c4c3a48b6361036837d308c7eb3b9cc
@@@ -1,4 -1,4 +1,4 @@@
- /**
+ /*
   * Jexer - Java Text User Interface
   *
   * License: LGPLv3 or later
@@@ -75,16 -75,6 +75,16 @@@ public final class TButton extends TWid
       */
      private TAction action;
  
 +    /**
 +     * Act as though the button was pressed.  This is useful for other UI
 +     * elements to get the same action as if the user clicked the button.
 +     */
 +    public void dispatch() {
 +        if (action != null) {
 +            action.DO();
 +        }
 +    }
 +
      /**
       * Private constructor.
       *
index 8f55ce8cea191036ffd4d2f7856fab7bab501ae5,1f05038cf5c7f14a185ef2e42147b7ea7e971384..9de90dcdf4c2197aba6fb40a8c45e344bc4d983c
@@@ -1,4 -1,4 +1,4 @@@
- /**
+ /*
   * Jexer - Java Text User Interface
   *
   * License: LGPLv3 or later
@@@ -33,9 -33,6 +33,9 @@@ package jexer
  import java.util.ArrayList;
  import java.util.List;
  
 +import jexer.event.TKeypressEvent;
 +import static jexer.TKeypress.*;
 +
  /**
   * TMessageBox is a system-modal dialog with buttons for OK, Cancel, Yes, or
   * No.  Call it like:
@@@ -80,16 -77,6 +80,16 @@@ public class TMessageBox extends TWindo
          YESNOCANCEL
      };
  
 +    /**
 +     * The type of this message box.
 +     */
 +    private Type type;
 +
 +    /**
 +     * My buttons.
 +     */
 +    List<TButton> buttons;
 +
      /**
       * Message boxes have these possible results.
       */
          NO
      };
  
 -
      /**
       * Which button was clicked: OK, CANCEL, YES, or NO.
       */
          // Start as 50x50 at (1, 1).  These will be changed later.
          super(application, title, 1, 1, 100, 100, CENTERED | MODAL);
  
 +        // Hang onto type so that we can provide more convenience in
 +        // onKeypress().
 +        this.type = type;
 +
          // Determine width and height
          String [] lines = caption.split("\n");
          int width = title.length() + 12;
  
          // The button line
          lineI++;
 -        List<TButton> buttons = new ArrayList<TButton>();
 +        buttons = new ArrayList<TButton>();
  
          int buttonX = 0;
  
          }
      }
  
 +    /**
 +     * Handle keystrokes.
 +     *
 +     * @param keypress keystroke event
 +     */
 +    @Override
 +    public void onKeypress(final TKeypressEvent keypress) {
 +
 +        if (this instanceof TInputBox) {
 +            super.onKeypress(keypress);
 +            return;
 +        }
 +
 +        // Some convenience for message boxes: Alt won't be needed for the
 +        // buttons.
 +        switch (type) {
 +
 +        case OK:
 +            if (keypress.equals(kbO)) {
 +                buttons.get(0).dispatch();
 +                return;
 +            }
 +            break;
 +
 +        case OKCANCEL:
 +            if (keypress.equals(kbO)) {
 +                buttons.get(0).dispatch();
 +                return;
 +            } else if (keypress.equals(kbC)) {
 +                buttons.get(1).dispatch();
 +                return;
 +            }
 +            break;
 +
 +        case YESNO:
 +            if (keypress.equals(kbY)) {
 +                buttons.get(0).dispatch();
 +                return;
 +            } else if (keypress.equals(kbN)) {
 +                buttons.get(1).dispatch();
 +                return;
 +            }
 +            break;
 +
 +        case YESNOCANCEL:
 +            if (keypress.equals(kbY)) {
 +                buttons.get(0).dispatch();
 +                return;
 +            } else if (keypress.equals(kbN)) {
 +                buttons.get(1).dispatch();
 +                return;
 +            } else if (keypress.equals(kbC)) {
 +                buttons.get(2).dispatch();
 +                return;
 +            }
 +            break;
 +
 +        default:
 +            throw new IllegalArgumentException("Invalid message box type: " + type);
 +        }
 +
 +        super.onKeypress(keypress);
 +    }
 +
  }
index 3c518ceed214eb84378de114492117d85de05d49,60f2bd36c7bb0ccce1caaede6ea5e2d007ed4edb..a8c0c899ce32f27ff038f3cbabe3b3a344617c2e
@@@ -1,4 -1,4 +1,4 @@@
- /**
+ /*
   * Jexer - Java Text User Interface
   *
   * License: LGPLv3 or later
@@@ -68,17 -68,6 +68,17 @@@ public final class ColorTheme 
          return attr;
      }
  
 +    /**
 +     * Set the color for a named theme color.
 +     *
 +     * @param name theme color name, e.g. "twindow.border"
 +     * @param color the new color to associate with name, e.g. bold yellow on
 +     * blue
 +     */
 +    public void setColor(final String name, final CellAttributes color) {
 +        colors.put(name, color);
 +    }
 +
      /**
       * Save the color theme mappings to an ASCII file.
       *
index ecdb7f7cd03f1bb9e54b3d23f216cdaa71b3e93f,51cc343e8606164291af84a252e561fec695625b..99add703c18fe2d9e59d241bb325b549c16638f1
@@@ -1,4 -1,4 +1,4 @@@
- /**
+ /*
   * Jexer - Java Text User Interface
   *
   * License: LGPLv3 or later
@@@ -241,16 -241,8 +241,16 @@@ public final class TMenu extends TWindo
       */
      @Override
      public void onKeypress(final TKeypressEvent keypress) {
 -        if (getActiveChild() != null) {
 -            if (getActiveChild() instanceof TSubMenu) {
 +
 +        /*
 +        System.err.printf("keypress: %s active child: %s\n", keypress,
 +            getActiveChild());
 +         */
 +
 +        if (getActiveChild() != this) {
 +            if ((getActiveChild() instanceof TSubMenu)
 +                || (getActiveChild() instanceof TMenu)
 +            ) {
                  getActiveChild().onKeypress(keypress);
                  return;
              }
              return;
          }
          if (keypress.equals(kbRight)) {
 -            if (!isSubMenu) {
 -                getApplication().switchMenu(true);
 -            }
 +            getApplication().switchMenu(true);
              return;
          }
          if (keypress.equals(kbLeft)) {
index a109710b78174d7ce5b7cd87797bfd5b52ff4451,167b6a5b11fc7d656c912b36bac62ff5d8412587..9d415d5559322d5871bc9d4e6445eb7177efd190
@@@ -1,4 -1,4 +1,4 @@@
- /**
+ /*
   * Jexer - Java Text User Interface
   *
   * License: LGPLv3 or later
@@@ -100,18 -100,6 +100,18 @@@ public final class TSubMenu extends TMe
      @Override
      public void onKeypress(final TKeypressEvent keypress) {
  
 +        // Open me if they hit my mnemonic.
 +        if (!keypress.getKey().isFnKey()
 +            && !keypress.getKey().isAlt()
 +            && !keypress.getKey().isCtrl()
 +            && (getMnemonic() != null)
 +            && (Character.toLowerCase(getMnemonic().getShortcut())
 +                == Character.toLowerCase(keypress.getKey().getChar()))
 +        ) {
 +            dispatch();
 +            return;
 +        }
 +
          if (menu.isActive()) {
              menu.onKeypress(keypress);
              return;