From: Kevin Lamonte Date: Wed, 31 Jul 2019 00:18:44 +0000 (-0500) Subject: fix typos and submenu mnemonic bug X-Git-Tag: fanfix-swing-0.0.1~12^2~13^2~137 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=382bc294dd88b71639fdd6c73216d2519635a080;p=fanfix-swing.git fix typos and submenu mnemonic bug --- diff --git a/src/jexer/TComboBox.java b/src/jexer/TComboBox.java index 0814177d..1ef6bcd4 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 1a9aa9e6..bc827b70 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 a4a54a91..86b0d6d6 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 1b78fc8b..6b00f4a6 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 ba45f6a6..47484869 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 ad96543d..984e660f 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 9af0bb83..c89e70ec 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 59bc9f0f..87798fb3 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 8a8ec6be..d102f791 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));