- /**
- * Convenience method used by TWindowLoggerOutput.
- *
- * @param line new line to add
- */
- public void addLine(final String line) {
- if (text.length() == 0) {
- text = line;
- } else {
- text += "\n\n";
- text += line;
- }
- reflow();
- }
-
- /**
- * Recompute the bounds for the scrollbars.
- */
- private void computeBounds() {
- maxLineWidth = 0;
- for (String line : lines) {
- if (line.length() > maxLineWidth) {
- maxLineWidth = line.length();
- }
- }
-
- vScroller.setBottomValue((lines.size() - getHeight()) + 1);
- if (vScroller.getBottomValue() < 0) {
- vScroller.setBottomValue(0);
- }
- if (vScroller.getValue() > vScroller.getBottomValue()) {
- vScroller.setValue(vScroller.getBottomValue());
- }
-
- 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 LEFT, CENTER, RIGHT, or FULL
- */
- public void setJustification(final Justification justification) {
- this.justification = justification;
- reflow();
- }
-
- /**
- * Left-justify the text.
- */
- public void leftJustify() {
- justification = Justification.LEFT;
- reflow();
- }
-
- /**
- * Center-justify the text.
- */
- public void centerJustify() {
- justification = Justification.CENTER;
- reflow();
- }
-
- /**
- * Right-justify the text.
- */
- public void rightJustify() {
- justification = Justification.RIGHT;
- reflow();
- }
-
- /**
- * Fully-justify the text.
- */
- public void fullJustify() {
- justification = Justification.FULL;
- reflow();
- }
-
- /**
- * Resize text and scrollbars for a new width/height.
- */
- public void reflow() {
- // Reset the lines
- lines.clear();
-
- // Break up text into paragraphs
- String[] paragraphs = text.split("\n\n");
- for (String p : paragraphs) {
- switch (justification) {
- case LEFT:
- lines.addAll(jexer.bits.StringJustifier.left(p,
- getWidth() - 1));
- break;
- case CENTER:
- lines.addAll(jexer.bits.StringJustifier.center(p,
- getWidth() - 1));
- break;
- case RIGHT:
- lines.addAll(jexer.bits.StringJustifier.right(p,
- getWidth() - 1));
- break;
- case FULL:
- lines.addAll(jexer.bits.StringJustifier.full(p,
- getWidth() - 1));
- break;
- }
-
- for (int i = 0; i < lineSpacing; i++) {
- 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();
- }