projects
/
sixth-3d.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improved code readability
[sixth-3d.git]
/
src
/
main
/
java
/
eu
/
svjatoslav
/
sixth
/
e3d
/
gui
/
textEditorComponent
/
Page.java
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
4ccacb2
..
0f60618
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Page.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/gui/textEditorComponent/Page.java
@@
-1,51
+1,84
@@
/*
* Sixth 3D engine. Author: Svjatoslav Agejenko.
* This project is released under Creative Commons Zero (CC0) license.
/*
* Sixth 3D engine. Author: Svjatoslav Agejenko.
* This project is released under Creative Commons Zero (CC0) license.
- *
-*
*/
*/
-
package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
import java.util.ArrayList;
import java.util.List;
package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
import java.util.ArrayList;
import java.util.List;
+/**
+ * A page in a text editor.
+ */
public class Page {
public class Page {
- public List<TextLine> lines = new ArrayList<>();
+ /**
+ * The text lines.
+ */
+ public List<TextLine> rows = new ArrayList<>();
public void ensureMaxTextLine(final int row) {
public void ensureMaxTextLine(final int row) {
- while (
line
s.size() <= row)
-
line
s.add(new TextLine());
+ while (
row
s.size() <= row)
+
row
s.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) {
public char getChar(final int row, final int column) {
- if (
line
s.size() <= row)
+ if (
row
s.size() <= row)
return ' ';
return ' ';
- return
line
s.get(row).getCharForLocation(column);
+ return
row
s.get(row).getCharForLocation(column);
}
}
+ /**
+ * Returns the specified line.
+ *
+ * @param row
+ * The line number.
+ * @return The line.
+ */
public TextLine getLine(final int row) {
ensureMaxTextLine(row);
public TextLine getLine(final int row) {
ensureMaxTextLine(row);
- return
line
s.get(row);
+ return
row
s.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) {
public int getLineLength(final int row) {
- if (
line
s.size() <= row)
+ if (
row
s.size() <= row)
return 0;
return 0;
- return
line
s.get(row).getLength();
+ return
row
s.get(row).getLength();
}
}
+ /**
+ * Returns the number of lines in the page.
+ *
+ * @return The number of lines in the page.
+ */
public int getLinesCount() {
pack();
public int getLinesCount() {
pack();
- return
line
s.size();
+ return
row
s.size();
}
}
+ /**
+ * Returns the text of the page.
+ *
+ * @return The text of the page.
+ */
public String getText() {
pack();
final StringBuilder result = new StringBuilder();
public String getText() {
pack();
final StringBuilder result = new StringBuilder();
- for (final TextLine textLine :
line
s) {
+ for (final TextLine textLine :
row
s) {
if (result.length() > 0)
result.append("\n");
result.append(textLine.toString());
if (result.length() > 0)
result.append("\n");
result.append(textLine.toString());
@@
-58,34
+91,51
@@
public class Page {
}
public void insertLine(final int row, final TextLine textLine) {
}
public void insertLine(final int row, final TextLine textLine) {
-
line
s.add(row, textLine);
+
row
s.add(row, textLine);
}
}
+ /**
+ * Removes empty lines from the end of the page.
+ */
private void pack() {
int newLength = 0;
private void pack() {
int newLength = 0;
- for (int i =
line
s.size() - 1; i >= 0; i--)
- if (!
line
s.get(i).isEmpty()) {
+ for (int i =
row
s.size() - 1; i >= 0; i--)
+ if (!
row
s.get(i).isEmpty()) {
newLength = i + 1;
break;
}
newLength = i + 1;
break;
}
- if (newLength ==
line
s.size())
+ if (newLength ==
row
s.size())
return;
return;
-
lines = line
s.subList(0, newLength);
+
rows = row
s.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) {
public void removeCharacter(final int row, final int col) {
- if (
line
s.size() <= row)
+ if (
row
s.size() <= row)
return;
getLine(row).removeCharacter(col);
}
return;
getLine(row).removeCharacter(col);
}
+ /**
+ * Removes the specified line from the page.
+ *
+ * @param row
+ * The line number.
+ */
public void removeLine(final int row) {
public void removeLine(final int row) {
- if (
line
s.size() <= row)
+ if (
row
s.size() <= row)
return;
return;
-
line
s.remove(row);
+
row
s.remove(row);
}
}
}
}