From 9577a9d02a8b04eaf70c26fa33ec721f6e46e9fb Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Fri, 2 Aug 2019 14:25:14 -0500 Subject: [PATCH] update colors on single click on list --- src/jexer/TEditColorThemeWindow.java | 6 +++++ src/jexer/TList.java | 39 ++++++++++++++++++++-------- src/jexer/TWidget.java | 25 ++++++++++++++++++ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/jexer/TEditColorThemeWindow.java b/src/jexer/TEditColorThemeWindow.java index 5d1c0412..668309d5 100644 --- a/src/jexer/TEditColorThemeWindow.java +++ b/src/jexer/TEditColorThemeWindow.java @@ -653,6 +653,12 @@ public class TEditColorThemeWindow extends TWindow { refreshFromTheme(colorNames.getSelected()); } }, + new TAction() { + // When the user navigates with keyboard + public void DO() { + refreshFromTheme(colorNames.getSelected()); + } + }, new TAction() { // When the user navigates with keyboard public void DO() { diff --git a/src/jexer/TList.java b/src/jexer/TList.java index 3aed01ed..f9e72162 100644 --- a/src/jexer/TList.java +++ b/src/jexer/TList.java @@ -93,7 +93,7 @@ public class TList extends TScrollableWidget { public TList(final TWidget parent, final List strings, final int x, final int y, final int width, final int height) { - this(parent, strings, x, y, width, height, null); + this(parent, strings, x, y, width, height, null, null, null); } /** @@ -112,16 +112,7 @@ public class TList extends TScrollableWidget { final int y, final int width, final int height, final TAction enterAction) { - super(parent, x, y, width, height); - this.enterAction = enterAction; - this.strings = new ArrayList(); - if (strings != null) { - this.strings.addAll(strings); - } - - hScroller = new THScroller(this, 0, getHeight() - 1, getWidth() - 1); - vScroller = new TVScroller(this, getWidth() - 1, 0, getHeight() - 1); - reflowData(); + this(parent, strings, x, y, width, height, enterAction, null, null); } /** @@ -142,9 +133,35 @@ public class TList extends TScrollableWidget { final int y, final int width, final int height, final TAction enterAction, final TAction moveAction) { + this(parent, strings, x, y, width, height, enterAction, moveAction, + null); + } + + /** + * Public constructor. + * + * @param parent parent widget + * @param strings list of strings to show. This is allowed to be null + * and set later with setList() or by subclasses. + * @param x column relative to parent + * @param y row relative to parent + * @param width width of text area + * @param height height of text area + * @param enterAction action to perform when an item is selected + * @param moveAction action to perform when the user navigates to a new + * item with arrow/page keys + * @param singleClickAction action to perform when the user clicks on an + * item + */ + public TList(final TWidget parent, final List strings, final int x, + final int y, final int width, final int height, + final TAction enterAction, final TAction moveAction, + final TAction singleClickAction) { + super(parent, x, y, width, height); this.enterAction = enterAction; this.moveAction = moveAction; + this.singleClickAction = singleClickAction; this.strings = new ArrayList(); if (strings != null) { this.strings.addAll(strings); diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 9e026137..633b1495 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -2334,6 +2334,31 @@ public abstract class TWidget implements Comparable { moveAction); } + /** + * Convenience function to add a list to this container/window. + * + * @param strings list of strings to show. This is allowed to be null + * and set later with setList() or by subclasses. + * @param x column relative to parent + * @param y row relative to parent + * @param width width of text area + * @param height height of text area + * @param enterAction action to perform when an item is selected + * @param moveAction action to perform when the user navigates to a new + * item with arrow/page keys + * @param singleClickAction action to perform when the user clicks on an + * item + */ + public TList addList(final List strings, final int x, + final int y, final int width, final int height, + final TAction enterAction, final TAction moveAction, + final TAction singleClickAction) { + + return new TList(this, strings, x, y, width, height, enterAction, + moveAction, singleClickAction); + } + + /** * Convenience function to add an image to this container/window. * -- 2.27.0