From: Kevin Lamonte Date: Sun, 29 Mar 2015 21:28:16 +0000 (-0400) Subject: Merge branch 'master' of https://github.com/klamonte/jexer X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=8582f35a3ffb8212463076217eb89278f42331d4;hp=-c;p=fanfix.git Merge branch 'master' of https://github.com/klamonte/jexer --- 8582f35a3ffb8212463076217eb89278f42331d4 diff --combined src/jexer/TButton.java index 30e94ed,c05a4b1..fb8c08e --- a/src/jexer/TButton.java +++ b/src/jexer/TButton.java @@@ -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. * diff --combined src/jexer/TMessageBox.java index 8f55ce8,1f05038..9de90dc --- a/src/jexer/TMessageBox.java +++ b/src/jexer/TMessageBox.java @@@ -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 buttons; + /** * Message boxes have these possible results. */ @@@ -115,6 -102,7 +115,6 @@@ NO }; - /** * Which button was clicked: OK, CANCEL, YES, or NO. */ @@@ -175,10 -163,6 +175,10 @@@ // 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; @@@ -204,7 -188,7 +204,7 @@@ // The button line lineI++; - List buttons = new ArrayList(); + buttons = new ArrayList(); int buttonX = 0; @@@ -333,68 -317,4 +333,68 @@@ } } + /** + * 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); + } + } diff --combined src/jexer/bits/ColorTheme.java index 3c518ce,60f2bd3..a8c0c89 --- a/src/jexer/bits/ColorTheme.java +++ b/src/jexer/bits/ColorTheme.java @@@ -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. * diff --combined src/jexer/menu/TMenu.java index ecdb7f7,51cc343..99add70 --- a/src/jexer/menu/TMenu.java +++ b/src/jexer/menu/TMenu.java @@@ -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; } @@@ -269,7 -261,9 +269,7 @@@ return; } if (keypress.equals(kbRight)) { - if (!isSubMenu) { - getApplication().switchMenu(true); - } + getApplication().switchMenu(true); return; } if (keypress.equals(kbLeft)) { diff --combined src/jexer/menu/TSubMenu.java index a109710,167b6a5..9d415d5 --- a/src/jexer/menu/TSubMenu.java +++ b/src/jexer/menu/TSubMenu.java @@@ -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;