
net.sf.nervalreports.generators.HTMLTableInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of html-generator Show documentation
Show all versions of html-generator Show documentation
This is the HTML generator package of NervalReports (a lightweight report creation library),
used to generate a report directly to a HTML file format.
/** This file is part of nervalreports.
*
* nervalreports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nervalreports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nervalreports. If not, see . */
package net.sf.nervalreports.generators;
import net.sf.nervalreports.core.paper.ReportPaperFormat;
/** Table information for HTML table construction.
* @author farrer */
/* default */ class HTMLTableInfo {
/** Index of current cell counter on current row. */
private int curTableElement;
/** Width information of columns, in percentual of page's width.
* When there's no column width information available, the array will be null
. */
private float[] columnWidth;
/** Counter of header cell indexes [0, n). */
private int curTableHeaderElement;
/** Even (true
) or odd (false
) row. (Note: rowspans won't change it). */
private boolean evenRow;
/** Remaining rows for active rowspan. Obviously, the first row with rowspan must be the one with larger rowspan.
* Thus, we only need to count for it. */
private int remaningRowsForActiveRowSpans;
/** Border style to append to tds
elements. */
private final String borderStyle;
/** Default constructor.
* @param columnWidth current definition of width for columns.
* @param borderStyle current table border style.
* @param unitsToPixels conversion factor from PDF units to pixels.
* @param pageFormat current page format to use. */
public HTMLTableInfo(int[] columnWidth, String borderStyle, float unitsToPixels, ReportPaperFormat paperFormat) {
if (columnWidth != null) {
/* Create the width info, and convert it to pixel format used at html. */
this.columnWidth = new float[columnWidth.length];
for (int i = 0; i < columnWidth.length; i++) {
this.columnWidth[i] = columnWidth[i] * unitsToPixels;
}
}
clearCurTableElement();
clearCurTableHeaderElement();
remaningRowsForActiveRowSpans = 0;
/* 0 row is... even! */
evenRow = true;
this.borderStyle = borderStyle;
}
/** Decrement by one the {@link #remaningRowsForActiveRowSpans}. */
public void decRemaningRowsForActiveRowSpans() {
if (remaningRowsForActiveRowSpans > 0) {
remaningRowsForActiveRowSpans--;
}
}
/** Set {@link #remaningRowsForActiveRowSpans}. If current value is != 0, we'll keep it unchanged, (as the first one must be the larger
* one, we only need to count it).
* @param rowSpan current rowspan. */
public void setRemaningRowsForActiveRowSpans(int rowSpan) {
if (remaningRowsForActiveRowSpans == 0) {
remaningRowsForActiveRowSpans = rowSpan;
}
}
/** return {@link #remaningRowsForActiveRowSpans}. */
public int getRemaningRowsForActiveRowSpans() {
return remaningRowsForActiveRowSpans;
}
/** @return {@link #curTableElement}. */
public int getCurTableElement() {
return curTableElement;
}
/** Increment current cell index by a value
* @param n amount to increment the cell index. */
public void incCurTableElement(int n) {
curTableElement += n;
}
/** Reset current cell index, usually when starting a new row. */
public void clearCurTableElement() {
curTableElement = 0;
}
/** @return {@link #columnWidth}. */
public float[] getColumnWidth() {
return columnWidth;
}
/** @return {@link #curTableHeaderElement}. */
public int getCurTableHeaderElement() {
return curTableHeaderElement;
}
/** Increment by one a current index of table header element. */
public void incCurTableHeaderElement() {
curTableHeaderElement++;
}
/** Reset the valur of current header index. */
public void clearCurTableHeaderElement() {
curTableHeaderElement = 0;
}
/** Change current row to be even (if it was odd) or odd (if it was even). */
public void changeEvenOddRow() {
evenRow = !evenRow;
}
/** @return {@link #evenRow}. */
public boolean getEvenRow() {
return evenRow;
}
/** @return {@link #borderStyle}. */
public String getBorderStyle() {
return borderStyle;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy