From 382bc294dd88b71639fdd6c73216d2519635a080 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Tue, 30 Jul 2019 19:18:44 -0500 Subject: [PATCH] fix typos and submenu mnemonic bug --- src/jexer/TComboBox.java | 5 +-- src/jexer/TImage.java | 19 +++++++++ src/jexer/TImageWindow.java | 4 +- src/jexer/TPasswordField.java | 3 +- src/jexer/TSpinner.java | 2 +- src/jexer/TTableWindow.java | 2 +- src/jexer/TWidget.java | 55 +++++++++++++++++++++++++++ src/jexer/demos/DemoEditorWindow.java | 2 +- src/jexer/menu/TMenu.java | 22 ++++++++--- 9 files changed, 100 insertions(+), 14 deletions(-) diff --git a/src/jexer/TComboBox.java b/src/jexer/TComboBox.java index 0814177..1ef6bcd 100644 --- a/src/jexer/TComboBox.java +++ b/src/jexer/TComboBox.java @@ -96,13 +96,12 @@ public class TComboBox extends TWidget { this.updateAction = updateAction; - field = new TField(this, 0, 0, width - 3, false, "", - updateAction, null); + field = addField(0, 0, width - 3, false, "", updateAction, null); if (valuesIndex >= 0) { field.setText(values.get(valuesIndex)); } - list = new TList(this, values, 0, 1, width, valuesHeight, + list = addList(values, 0, 1, width, valuesHeight, new TAction() { public void DO() { field.setText(list.getSelected()); diff --git a/src/jexer/TImage.java b/src/jexer/TImage.java index 1a9aa9e..bc827b7 100644 --- a/src/jexer/TImage.java +++ b/src/jexer/TImage.java @@ -111,6 +111,25 @@ public class TImage extends TWidget { // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Public constructor. + * + * @param parent parent widget + * @param x column relative to parent + * @param y row relative to parent + * @param width number of text cells for width of the image + * @param height number of text cells for height of the image + * @param image the image to display + * @param left left column of the image. 0 is the left-most column. + * @param top top row of the image. 0 is the top-most row. + */ + public TImage(final TWidget parent, final int x, final int y, + final int width, final int height, + final BufferedImage image, final int left, final int top) { + + this(parent, x, y, width, height, image, left, top, null); + } + /** * Public constructor. * diff --git a/src/jexer/TImageWindow.java b/src/jexer/TImageWindow.java index a4a54a9..86b0d6d 100644 --- a/src/jexer/TImageWindow.java +++ b/src/jexer/TImageWindow.java @@ -104,8 +104,8 @@ public class TImageWindow extends TScrollableWindow { BufferedImage image = ImageIO.read(file); - imageField = new TImage(this, 0, 0, getWidth() - 2, getHeight() - 2, - image, 0, 0, null); + imageField = addImage(0, 0, getWidth() - 2, getHeight() - 2, + image, 0, 0); setTitle(file.getName()); setupAfterImage(); diff --git a/src/jexer/TPasswordField.java b/src/jexer/TPasswordField.java index 1b78fc8..6b00f4a 100644 --- a/src/jexer/TPasswordField.java +++ b/src/jexer/TPasswordField.java @@ -32,7 +32,8 @@ import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; /** - * TField implements an editable text field. + * TPasswordField implements an editable text field that displays + * stars/asterisks when it is not active. */ public class TPasswordField extends TField { diff --git a/src/jexer/TSpinner.java b/src/jexer/TSpinner.java index ba45f6a..4748486 100644 --- a/src/jexer/TSpinner.java +++ b/src/jexer/TSpinner.java @@ -35,7 +35,7 @@ import jexer.event.TMouseEvent; import static jexer.TKeypress.*; /** - * TSpinner implements a simple up/down spinner. Values can be numer + * TSpinner implements a simple up/down spinner. */ public class TSpinner extends TWidget { diff --git a/src/jexer/TTableWindow.java b/src/jexer/TTableWindow.java index ad96543..984e660 100644 --- a/src/jexer/TTableWindow.java +++ b/src/jexer/TTableWindow.java @@ -75,7 +75,7 @@ public class TTableWindow extends TScrollableWindow { super(parent, title, 0, 0, parent.getScreen().getWidth() / 2, parent.getScreen().getHeight() / 2 - 2, RESIZABLE | CENTERED); - tableField = new TTableWidget(this, 0, 0, getWidth() - 2, getHeight() - 2); + tableField = addTable(0, 0, getWidth() - 2, getHeight() - 2); setupAfterTable(); } diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 9af0bb8..c89e70e 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -28,6 +28,7 @@ */ package jexer; +import java.awt.image.BufferedImage; import java.io.IOException; import java.util.List; import java.util.ArrayList; @@ -2201,4 +2202,58 @@ public abstract class TWidget implements Comparable { moveAction); } + /** + * Convenience function to add an image to this container/window. + * + * @param x column relative to parent + * @param y row relative to parent + * @param width number of text cells for width of the image + * @param height number of text cells for height of the image + * @param image the image to display + * @param left left column of the image. 0 is the left-most column. + * @param top top row of the image. 0 is the top-most row. + */ + public final TImage addImage(final int x, final int y, + final int width, final int height, + final BufferedImage image, final int left, final int top) { + + return new TImage(this, x, y, width, height, image, left, top); + } + + /** + * Convenience function to add an image to this container/window. + * + * @param x column relative to parent + * @param y row relative to parent + * @param width number of text cells for width of the image + * @param height number of text cells for height of the image + * @param image the image to display + * @param left left column of the image. 0 is the left-most column. + * @param top top row of the image. 0 is the top-most row. + * @param clickAction function to call when mouse is pressed + */ + public final TImage addImage(final int x, final int y, + final int width, final int height, + final BufferedImage image, final int left, final int top, + final TAction clickAction) { + + return new TImage(this, x, y, width, height, image, left, top, + clickAction); + } + + /** + * Convenience function to add an editable 2D data table to this + * container/window. + * + * @param x column relative to parent + * @param y row relative to parent + * @param width width of widget + * @param height height of widget + */ + public TTableWidget addTable(final int x, final int y, final int width, + final int height) { + + return new TTableWidget(this, x, y, width, height); + } + } diff --git a/src/jexer/demos/DemoEditorWindow.java b/src/jexer/demos/DemoEditorWindow.java index 59bc9f0..87798fb 100644 --- a/src/jexer/demos/DemoEditorWindow.java +++ b/src/jexer/demos/DemoEditorWindow.java @@ -72,7 +72,7 @@ public class DemoEditorWindow extends TWindow { final String text) { super(parent, title, 0, 0, 44, 22, RESIZABLE); - editField = new TEditorWidget(this, text, 0, 0, 42, 20); + editField = addEditor(text, 0, 0, 42, 20); statusBar = newStatusBar(i18n.getString("statusBar")); statusBar.addShortcutKeypress(kbF1, cmHelp, diff --git a/src/jexer/menu/TMenu.java b/src/jexer/menu/TMenu.java index 8a8ec6b..d102f79 100644 --- a/src/jexer/menu/TMenu.java +++ b/src/jexer/menu/TMenu.java @@ -270,15 +270,21 @@ public class TMenu extends TWindow { /* System.err.printf("keypress: %s active child: %s\n", keypress, getActiveChild()); - */ + */ if (getActiveChild() != this) { - if ((getActiveChild() instanceof TSubMenu) - || (getActiveChild() instanceof TMenu) - ) { + if (getActiveChild() instanceof TMenu) { getActiveChild().onKeypress(keypress); return; } + + if (getActiveChild() instanceof TSubMenu) { + TSubMenu subMenu = (TSubMenu) getActiveChild(); + if (subMenu.menu.isActive()) { + subMenu.onKeypress(keypress); + return; + } + } } if (keypress.equals(kbEsc)) { @@ -310,12 +316,18 @@ public class TMenu extends TWindow { if (!keypress.getKey().isFnKey() && !keypress.getKey().isAlt() && !keypress.getKey().isCtrl()) { + + // System.err.println("Checking children for mnemonic..."); + for (TWidget widget: getChildren()) { TMenuItem item = (TMenuItem) widget; - if ((item.getMnemonic() != null) + if ((item.isEnabled() == true) + && (item.getMnemonic() != null) && (Character.toLowerCase(item.getMnemonic().getShortcut()) == Character.toLowerCase(keypress.getKey().getChar())) ) { + // System.err.println("activate: " + item); + // Send an enter keystroke to it activate(item); item.handleEvent(new TKeypressEvent(kbEnter)); -- 2.27.0