1
16package org.tp23.antinstaller.renderer.text;
17
18import java.io.PrintStream;
19
20
21
30public class Pager {
31
32 private char[] text;
33 private int linesPerPage = 20;
34 private int charsPerLine = 80;
35 private int stringIndex = 0;
36
37 public Pager(String text) {
38 this.text = text.toCharArray();
39 }
40 public Pager(){
41 }
42
43 public String getText() {
44 return new String(text);
45 }
46
47 public void setText(String text) {
48 this.text = text.toCharArray();
49 }
50
53 public void rest(PrintStream out){
54 while(next(out));
55}
56
61 public boolean next(PrintStream out){
62 int lineChars = 0;
63 int lastSpace = -1;
64 char[] lineBuffer = new char[charsPerLine+1];
66 for (int lines = 0; lines < linesPerPage;) {
67 if(stringIndex >= text.length){
68 return false;
69 }
70 lineBuffer[lineChars] = text[stringIndex];
71 if(text[stringIndex] == ' '){
72 lastSpace = lineChars;
73 }
74 if(text[stringIndex] == '\n'){
75 String tmp = new String(lineBuffer, 0, lineChars + 1);
76 out.print(tmp);
77 lines++;
78 lineChars = 0;
79 lastSpace = -1;
80 }
81 else if(lineChars == charsPerLine){
82 if(lastSpace != -1){
84 out.println(new String(lineBuffer, 0, lastSpace));
85 stringIndex = stringIndex - (charsPerLine - lastSpace);
86 }
87 else {
88 out.println(new String(lineBuffer, 0, lineChars));
89 }
90 lines++;
91 lineChars = 0;
92 lastSpace = -1;
93 }
94 else{
95 lineChars++;
96 }
97 stringIndex++;
98 }
99 return true;
00 }
01}
02