aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at/knowcenter
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-10-06 11:48:51 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-10-06 11:48:51 +0200
commit271f249c0ff24b593bcc83c86edfeb236a551be5 (patch)
treeb141259d69a91486553048f9dddb7dbd168c045d /pdf-as-lib/src/main/java/at/knowcenter
parenta1faffc1987ee9a523b2736b7df5d6cb2fb5ca42 (diff)
downloadpdf-as-4-271f249c0ff24b593bcc83c86edfeb236a551be5.tar.gz
pdf-as-4-271f249c0ff24b593bcc83c86edfeb236a551be5.tar.bz2
pdf-as-4-271f249c0ff24b593bcc83c86edfeb236a551be5.zip
Colum span handling corrected. #38
Diffstat (limited to 'pdf-as-lib/src/main/java/at/knowcenter')
-rw-r--r--pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java78
1 files changed, 72 insertions, 6 deletions
diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java
index 6db7ff3a..12d0e2ee 100644
--- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java
+++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java
@@ -49,9 +49,12 @@
package at.knowcenter.wag.egov.egiz.table;
import java.io.Serializable;
-import java.util.Map;
-import java.util.HashMap;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
/**
* This class implements an abstract table definition. The table contains table
@@ -216,12 +219,75 @@ public class Table implements Serializable
public void addRow(String rowNumber, ArrayList<Entry> row)
{
rows_.put(rowNumber, row);
- if (row.size() > maxCols_)
- {
- maxCols_ = row.size();
- }
+ calculateMaxCols(row);
}
+ private void calculateMaxCols(ArrayList<Entry> newrow) {
+ int colCount = calculateRowSize(newrow);
+ if (colCount > maxCols_)
+ {
+ maxCols_ = colCount;
+ }
+ }
+
+ private int calculateRowSize(ArrayList<Entry> newrow) {
+ int colCount = 0;
+ for(int i = 0; i < newrow.size(); i++) {
+ colCount += newrow.get(i).getColSpan();
+ }
+ return colCount;
+ }
+
+ private void recalculateMaxCol() {
+ Iterator<ArrayList<Entry>> rowIt = getRows().iterator();
+ while(rowIt.hasNext()) {
+ ArrayList<Entry> row = rowIt.next();
+ calculateMaxCols(row);
+ }
+ }
+
+ private boolean recursiveNorm = false;
+
+ /**
+ * Expands the last cell of each column to fill the table
+ * @throws PdfAsSettingsException
+ */
+ public void normalize() throws PdfAsSettingsException {
+ Iterator<ArrayList<Entry>> rowIt = getRows().iterator();
+ while(rowIt.hasNext()) {
+ ArrayList<Entry> row = rowIt.next();
+
+ // This row fits just fine
+ if(row.size() == maxCols_) {
+ continue;
+ }
+
+ int rowSize = calculateRowSize(row);
+
+ // This row fits just fine including row spans
+ if(rowSize == maxCols_) {
+ continue;
+ }
+
+ int missingColumns = maxCols_ - rowSize;
+
+ if(missingColumns < 0) {
+ // wrong max Col value!
+ // recalculate the maximum Columns and normalize again!
+ if(recursiveNorm) {
+ throw new PdfAsSettingsException("Failed to build virtual model of signatur block table.");
+ }
+ recalculateMaxCol();
+ recursiveNorm = true;
+ normalize();
+ recursiveNorm = false;
+ break;
+ } else {
+ row.get(row.size() - 1).setColSpan(row.get(row.size() - 1).getColSpan() + missingColumns);
+ }
+ }
+ }
+
/**
* The toString method, used for tests or debugging.
*/