summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/ioutils/ReportWriter.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-09-17 16:20:21 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-09-17 16:20:21 -0300
commitecbe7abdde7198adcd13034f110dd675fa096a63 (patch)
tree112ef4a01009c4b16f16eb430dcf794740680ac4 /base/src/main/java/bjc/utils/ioutils/ReportWriter.java
parent72186c677da15390cf63e65270e918524a2c6107 (diff)
Add more features to ReportWriter
This adds both an ability to get the column at which the indent ended, as well as some basic page control.
Diffstat (limited to 'base/src/main/java/bjc/utils/ioutils/ReportWriter.java')
-rw-r--r--base/src/main/java/bjc/utils/ioutils/ReportWriter.java84
1 files changed, 68 insertions, 16 deletions
diff --git a/base/src/main/java/bjc/utils/ioutils/ReportWriter.java b/base/src/main/java/bjc/utils/ioutils/ReportWriter.java
index 01f4a34..a9a2eae 100644
--- a/base/src/main/java/bjc/utils/ioutils/ReportWriter.java
+++ b/base/src/main/java/bjc/utils/ioutils/ReportWriter.java
@@ -19,7 +19,8 @@ public class ReportWriter extends Writer {
private Writer contained;
// # of character positions indentStr occupies
- private int indentLevel;
+ private int indentLevel;
+ private int indentPos = 0;
private DefaultList<IndentVal> iVals;
private IndentVal defIVal;
@@ -29,6 +30,10 @@ public class ReportWriter extends Writer {
private int linesWritten = 0;
private int linePos = 0;
+ private int pageLine = 0;
+ private int pageNum = 0;
+ private int linesPerPage = 20;
+
private boolean printTabsAsSpaces;
private boolean lastCharWasNL;
@@ -40,6 +45,22 @@ public class ReportWriter extends Writer {
return indentLevel;
}
+ public int getPageLine() {
+ return pageLine;
+ }
+
+ public int getPageNum() {
+ return pageNum;
+ }
+
+ public int getLinesPerPage() {
+ return linesPerPage;
+ }
+
+ public int getIndentPos() {
+ return indentPos;
+ }
+
public String getString() {
return defIVal.indentStr;
}
@@ -83,6 +104,14 @@ public class ReportWriter extends Writer {
refreshIndents(-1);
}
+ public void setLinesPerPage(int lines) {
+ linesPerPage = lines;
+
+ while (pageLine > linesPerPage) {
+ writePage();
+ }
+ }
+
public void setLevel(int level) {
indentLevel = level;
}
@@ -158,6 +187,7 @@ public class ReportWriter extends Writer {
rw.defIVal = defIVal;
rw.indentLevel = indentLevel;
+ rw.indentPos = indentPos;
rw.tabEqv = tabEqv;
@@ -166,6 +196,10 @@ public class ReportWriter extends Writer {
rw.printTabsAsSpaces = printTabsAsSpaces;
+ rw.pageLine = pageLine;
+ rw.pageNum = pageNum;
+ rw.linesPerPage = linesPerPage;
+
// @NOTE 9/5/18
//
// Not sure if the lastChar* properties are things we should
@@ -218,6 +252,36 @@ public class ReportWriter extends Writer {
sb.delete(0, sb.length());
}
+ // @NOTE 9/17/18
+ //
+ // Need to make some decision about how to handle doing a new page, and
+ // whether we want to simulate it with simply newlines until we hit the
+ // next page, or just printing the actual form-feed and hoping whatever
+ // reading software handles it properly
+ private void writePage() {
+ pageNum += 1;
+ pageLine -= linesPerPage;
+ }
+
+ private void writeNL(char c) {
+ // Count lines written
+ if(c == '\r' || (c == '\n' && lastChar != '\r') || c == '\f') {
+ linesWritten += 1;
+ pageLine += 1;
+
+ if (pageLine > linesPerPage || c == '\f') {
+ writePage();
+ }
+ }
+
+ lastCharWasNL = true;
+
+ contained.write(c);
+
+ linePos = 0;
+ indentPos = 0;
+ }
+
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
// Skip empty writes
@@ -236,21 +300,8 @@ public class ReportWriter extends Writer {
char c = cbuf[idx];
if(c == '\n' || c == '\r') {
- // Count lines written
- if(c == '\r') linesWritten++;
- if(c == '\n' && lastChar != '\r') linesWritten++;
-
- lastCharWasNL = true;
-
- contained.write(c);
-
- linePos = 0;
+ writeNL(c);
} else {
- // @CopyPaste from above.
- //
- // No real point in pulling it out to a method
- // yet, but if :IndentStr happens, it might
- // warrant it.
if(lastCharWasNL) {
lastCharWasNL = false;
@@ -280,7 +331,8 @@ public class ReportWriter extends Writer {
if (printTabsAsSpaces) contained.write(ival.indentStrSpacedTabs);
else contained.write(ival.indentStr);
- linePos += ival.indentStrPos;
+ linePos += ival.indentStrPos;
+ indentPos += ival.indentStrPos;
}
}