X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTList.java;h=a962f7cfe9eeee9b3ed579657964765add8bc772;hb=d8dc8aea32a07a0653933700f1abadc7776b013f;hp=3aed01ed21c25131d2e70e96efdf4d4bd9039ed3;hpb=c88c4ced6e9392a53030a1c680fe114931a1a928;p=fanfix.git diff --git a/src/jexer/TList.java b/src/jexer/TList.java index 3aed01e..a962f7c 100644 --- a/src/jexer/TList.java +++ b/src/jexer/TList.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.List; import jexer.bits.CellAttributes; +import jexer.bits.StringUtils; import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; import static jexer.TKeypress.*; @@ -93,7 +94,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 +113,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 +134,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); @@ -321,8 +339,9 @@ public class TList extends TScrollableWidget { for (int i = 0; i < strings.size(); i++) { String line = strings.get(i); - if (line.length() > maxLineWidth) { - maxLineWidth = line.length(); + int lineLength = StringUtils.width(line); + if (lineLength > maxLineWidth) { + maxLineWidth = lineLength; } }