X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTList.java;h=f9e721621eda3a76c69f47d33c0132ca37f54722;hb=9577a9d02a8b04eaf70c26fa33ec721f6e46e9fb;hp=da60af18745737dbc5ed5ecaf7d3a9a08730f430;hpb=a69ed767c9c07cf35cf1c5f7821fc009cfe79cd2;p=fanfix.git diff --git a/src/jexer/TList.java b/src/jexer/TList.java index da60af1..f9e7216 100644 --- a/src/jexer/TList.java +++ b/src/jexer/TList.java @@ -29,7 +29,6 @@ package jexer; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import jexer.bits.CellAttributes; @@ -94,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); } /** @@ -113,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); } /** @@ -143,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); @@ -406,6 +422,16 @@ public class TList extends TScrollableWidget { selectedString = index; } + /** + * Get a selectable string by index. + * + * @param idx index into list + * @return the string at idx in the list + */ + public final String getListItem(final int idx) { + return strings.get(idx); + } + /** * Get the selected string. *