+ /**
+ * Resize text and scrollbars for a new width/height.
+ */
+ @Override
+ public void reflowData() {
+ // Reset the lines
+ lines.clear();
+
+ // Break up text into paragraphs
+ String[] paragraphs = text.split("\n\n");
+ for (String p : paragraphs) {
+ switch (justification) {
+ case NONE:
+ lines.addAll(Arrays.asList(p.split("\n")));
+ break;
+ case LEFT:
+ lines.addAll(jexer.bits.StringUtils.left(p,
+ getWidth() - 1));
+ break;
+ case CENTER:
+ lines.addAll(jexer.bits.StringUtils.center(p,
+ getWidth() - 1));
+ break;
+ case RIGHT:
+ lines.addAll(jexer.bits.StringUtils.right(p,
+ getWidth() - 1));
+ break;
+ case FULL:
+ lines.addAll(jexer.bits.StringUtils.full(p,
+ getWidth() - 1));
+ break;
+ }
+
+ for (int i = 0; i < lineSpacing; i++) {
+ lines.add("");
+ }
+ }
+ computeBounds();
+ }
+
+ // ------------------------------------------------------------------------
+ // TText ------------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Set the text.
+ *
+ * @param text new text to display
+ */
+ public void setText(final String text) {
+ this.text = text;
+ reflowData();
+ }
+
+ /**
+ * Get the text.
+ *
+ * @return the text
+ */
+ public String getText() {
+ return text;
+ }
+
+ /**
+ * Convenience method used by TWindowLoggerOutput.
+ *
+ * @param line new line to add
+ */
+ public void addLine(final String line) {
+ if (StringUtils.width(text) == 0) {
+ text = line;
+ } else {
+ text += "\n\n";
+ text += line;
+ }
+ reflowData();
+ }
+
+ /**
+ * Recompute the bounds for the scrollbars.
+ */
+ private void computeBounds() {
+ maxLineWidth = 0;
+ for (String line : lines) {
+ if (StringUtils.width(line) > maxLineWidth) {
+ maxLineWidth = StringUtils.width(line);
+ }
+ }
+
+ vScroller.setTopValue(0);
+ vScroller.setBottomValue((lines.size() - getHeight()) + 1);
+ if (vScroller.getBottomValue() < 0) {
+ vScroller.setBottomValue(0);
+ }
+ if (vScroller.getValue() > vScroller.getBottomValue()) {
+ vScroller.setValue(vScroller.getBottomValue());
+ }
+
+ hScroller.setLeftValue(0);
+ hScroller.setRightValue((maxLineWidth - getWidth()) + 1);
+ if (hScroller.getRightValue() < 0) {
+ hScroller.setRightValue(0);
+ }
+ if (hScroller.getValue() > hScroller.getRightValue()) {
+ hScroller.setValue(hScroller.getRightValue());
+ }
+ }
+
+ /**
+ * Set justification.
+ *
+ * @param justification NONE, LEFT, CENTER, RIGHT, or FULL
+ */
+ public void setJustification(final Justification justification) {
+ this.justification = justification;
+ reflowData();
+ }
+
+ /**
+ * Left-justify the text.
+ */
+ public void leftJustify() {
+ justification = Justification.LEFT;
+ reflowData();
+ }
+
+ /**
+ * Center-justify the text.
+ */
+ public void centerJustify() {
+ justification = Justification.CENTER;
+ reflowData();
+ }
+
+ /**
+ * Right-justify the text.
+ */
+ public void rightJustify() {
+ justification = Justification.RIGHT;
+ reflowData();
+ }
+
+ /**
+ * Fully-justify the text.
+ */
+ public void fullJustify() {
+ justification = Justification.FULL;
+ reflowData();
+ }
+
+ /**
+ * Un-justify the text.
+ */
+ public void unJustify() {
+ justification = Justification.NONE;
+ reflowData();
+ }
+