X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTText.java;h=c57e8846ace8b8ee160d250147333bd63723ab76;hb=85c07c5e6db3a5e74f5ba2bd6e7ee2656d5b63a0;hp=21c2f1f1445ed826106061bb47e25e14c3251664;hpb=7657ad8c9c48bdde0c7d693859e942bd2186b1f7;p=fanfix.git diff --git a/src/jexer/TText.java b/src/jexer/TText.java index 21c2f1f..c57e884 100644 --- a/src/jexer/TText.java +++ b/src/jexer/TText.java @@ -48,7 +48,7 @@ import jexer.event.TMouseEvent; * TText implements a simple scrollable text area. It reflows automatically on * resize. */ -public final class TText extends TWidget { +public final class TText extends TScrollableWidget { /** * Available text justifications. @@ -96,24 +96,33 @@ public final class TText extends TWidget { private String colorKey; /** - * Vertical scrollbar. + * Maximum width of a single line. */ - private TVScroller vScroller; + private int maxLineWidth; /** - * Horizontal scrollbar. + * Number of lines between each paragraph. */ - private THScroller hScroller; + private int lineSpacing = 1; /** - * Maximum width of a single line. + * Set the text. + * + * @param text new text to display */ - private int maxLineWidth; + public void setText(final String text) { + this.text = text; + reflowData(); + } /** - * Number of lines between each paragraph. + * Get the text. + * + * @return the text */ - private int lineSpacing = 1; + public String getText() { + return text; + } /** * Convenience method used by TWindowLoggerOutput. @@ -127,7 +136,7 @@ public final class TText extends TWidget { text += "\n\n"; text += line; } - reflow(); + reflowData(); } /** @@ -141,6 +150,7 @@ public final class TText extends TWidget { } } + vScroller.setTopValue(0); vScroller.setBottomValue((lines.size() - getHeight()) + 1); if (vScroller.getBottomValue() < 0) { vScroller.setBottomValue(0); @@ -149,6 +159,7 @@ public final class TText extends TWidget { vScroller.setValue(vScroller.getBottomValue()); } + hScroller.setLeftValue(0); hScroller.setRightValue((maxLineWidth - getWidth()) + 1); if (hScroller.getRightValue() < 0) { hScroller.setRightValue(0); @@ -165,7 +176,7 @@ public final class TText extends TWidget { */ public void setJustification(final Justification justification) { this.justification = justification; - reflow(); + reflowData(); } /** @@ -173,7 +184,7 @@ public final class TText extends TWidget { */ public void leftJustify() { justification = Justification.LEFT; - reflow(); + reflowData(); } /** @@ -181,7 +192,7 @@ public final class TText extends TWidget { */ public void centerJustify() { justification = Justification.CENTER; - reflow(); + reflowData(); } /** @@ -189,7 +200,7 @@ public final class TText extends TWidget { */ public void rightJustify() { justification = Justification.RIGHT; - reflow(); + reflowData(); } /** @@ -197,13 +208,14 @@ public final class TText extends TWidget { */ public void fullJustify() { justification = Justification.FULL; - reflow(); + reflowData(); } /** * Resize text and scrollbars for a new width/height. */ - public void reflow() { + @Override + public void reflowData() { // Reset the lines lines.clear(); @@ -233,29 +245,6 @@ public final class TText extends TWidget { lines.add(""); } } - - // Start at the top - if (vScroller == null) { - vScroller = new TVScroller(this, getWidth() - 1, 0, getHeight() - 1); - vScroller.setTopValue(0); - vScroller.setValue(0); - } else { - vScroller.setX(getWidth() - 1); - vScroller.setHeight(getHeight() - 1); - } - vScroller.setBigChange(getHeight() - 1); - - // Start at the left - if (hScroller == null) { - hScroller = new THScroller(this, 0, getHeight() - 1, getWidth() - 1); - hScroller.setLeftValue(0); - hScroller.setValue(0); - } else { - hScroller.setY(getHeight() - 1); - hScroller.setWidth(getWidth() - 1); - } - hScroller.setBigChange(getWidth() - 1); - computeBounds(); } @@ -299,7 +288,9 @@ public final class TText extends TWidget { lines = new LinkedList(); - reflow(); + vScroller = new TVScroller(this, getWidth() - 1, 0, getHeight() - 1); + hScroller = new THScroller(this, 0, getHeight() - 1, getWidth() - 1); + reflowData(); } /**