📄 paginator.java
字号:
package textViewer;import java.util.Vector;public class Paginator extends Object { private final int TEXT_CHUNK_LENGTH = 80; // TODO: constant public Paginator() {} public int indexToPage(int index) { return (index / getTextChunkLength()) + 1; } public int getTextChunkLength() { return TEXT_CHUNK_LENGTH; } public Vector paginate(String text) { return paginateByChars(text, getTextChunkLength()); // TODO: constant } private Vector paginateByChars(String text, int charsPerPage) { Vector pages = new Vector(); // pages.addElement("mem test"); // pages.addElement(text); int pageCount = text.length() / charsPerPage + 1; //pages.addElement(Integer.toString(text.length())); try { int curPos = 0; int nextPos = curPos + charsPerPage; for(int curPage = 1; curPage <= (pageCount - 1); curPage++) { pages.addElement(text.substring(curPos,nextPos)); curPos += charsPerPage; nextPos += charsPerPage; } // the last page is special because we don't want to read past the end of the string pages.addElement(text.substring(curPos,text.length())); } catch (IndexOutOfBoundsException e) { //TODO: error handle pages.addElement("IndexOutOfBoundsException " + e.toString() + " stopped us here"); } // System.gc(); return pages; } // TODO: move the rest of pagination to here }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -