X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgui%2FtextEditorComponent%2FPage.java;h=0f606186bb5882d1a9a821ec01ed5a85fb8c17e4;hb=8aa50f568d2edcfe974ceed4192158951e7f3215;hp=c52fbd7e2a5c201e8481927a4a630d02a4e62eb4;hpb=9d03f0af97129ee791c0b1a33703fe1e34e9c050;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Page.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Page.java index c52fbd7..0f60618 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Page.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Page.java @@ -7,8 +7,14 @@ package eu.svjatoslav.sixth.e3d.gui.textEditorComponent; import java.util.ArrayList; import java.util.List; +/** + * A page in a text editor. + */ public class Page { + /** + * The text lines. + */ public List rows = new ArrayList<>(); public void ensureMaxTextLine(final int row) { @@ -16,28 +22,58 @@ public class Page { rows.add(new TextLine()); } + /** + * Returns the character at the specified location. + * If the location is out of bounds, returns a space. + * + * @return The character at the specified location. + */ public char getChar(final int row, final int column) { if (rows.size() <= row) return ' '; return rows.get(row).getCharForLocation(column); } + /** + * Returns the specified line. + * + * @param row + * The line number. + * @return The line. + */ public TextLine getLine(final int row) { ensureMaxTextLine(row); return rows.get(row); } + /** + * Returns the length of the specified line. + * + * @param row + * The line number. + * @return The length of the line. + */ public int getLineLength(final int row) { if (rows.size() <= row) return 0; return rows.get(row).getLength(); } + /** + * Returns the number of lines in the page. + * + * @return The number of lines in the page. + */ public int getLinesCount() { pack(); return rows.size(); } + /** + * Returns the text of the page. + * + * @return The text of the page. + */ public String getText() { pack(); @@ -58,6 +94,9 @@ public class Page { rows.add(row, textLine); } + /** + * Removes empty lines from the end of the page. + */ private void pack() { int newLength = 0; @@ -73,12 +112,26 @@ public class Page { rows = rows.subList(0, newLength); } + /** + * Removes the specified character from the page. + * + * @param row + * The line number. + * @param col + * The character number. + */ public void removeCharacter(final int row, final int col) { if (rows.size() <= row) return; getLine(row).removeCharacter(col); } + /** + * Removes the specified line from the page. + * + * @param row + * The line number. + */ public void removeLine(final int row) { if (rows.size() <= row) return;