*/
package jexer;
-import static jexer.TKeypress.kbDown;
-import static jexer.TKeypress.kbEnd;
-import static jexer.TKeypress.kbHome;
-import static jexer.TKeypress.kbLeft;
-import static jexer.TKeypress.kbPgDn;
-import static jexer.TKeypress.kbPgUp;
-import static jexer.TKeypress.kbRight;
-import static jexer.TKeypress.kbUp;
-
import java.util.LinkedList;
import java.util.List;
import jexer.bits.CellAttributes;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
+import static jexer.TKeypress.*;
/**
* 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.
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.
text += "\n\n";
text += line;
}
- reflow();
+ reflowData();
}
/**
}
}
+ vScroller.setTopValue(0);
vScroller.setBottomValue((lines.size() - getHeight()) + 1);
if (vScroller.getBottomValue() < 0) {
vScroller.setBottomValue(0);
vScroller.setValue(vScroller.getBottomValue());
}
+ hScroller.setLeftValue(0);
hScroller.setRightValue((maxLineWidth - getWidth()) + 1);
if (hScroller.getRightValue() < 0) {
hScroller.setRightValue(0);
*/
public void setJustification(final Justification justification) {
this.justification = justification;
- reflow();
+ reflowData();
}
/**
*/
public void leftJustify() {
justification = Justification.LEFT;
- reflow();
+ reflowData();
}
/**
*/
public void centerJustify() {
justification = Justification.CENTER;
- reflow();
+ reflowData();
}
/**
*/
public void rightJustify() {
justification = Justification.RIGHT;
- reflow();
+ reflowData();
}
/**
*/
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();
for (String p : paragraphs) {
switch (justification) {
case LEFT:
- lines.addAll(jexer.bits.StringJustifier.left(p,
+ lines.addAll(jexer.bits.StringUtils.left(p,
getWidth() - 1));
break;
case CENTER:
- lines.addAll(jexer.bits.StringJustifier.center(p,
+ lines.addAll(jexer.bits.StringUtils.center(p,
getWidth() - 1));
break;
case RIGHT:
- lines.addAll(jexer.bits.StringJustifier.right(p,
+ lines.addAll(jexer.bits.StringUtils.right(p,
getWidth() - 1));
break;
case FULL:
- lines.addAll(jexer.bits.StringJustifier.full(p,
+ lines.addAll(jexer.bits.StringUtils.full(p,
getWidth() - 1));
break;
}
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();
}
lines = new LinkedList<String>();
- reflow();
+ vScroller = new TVScroller(this, getWidth() - 1, 0, getHeight() - 1);
+ hScroller = new THScroller(this, 0, getHeight() - 1, getWidth() - 1);
+ reflowData();
}
/**