All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.nervalreports.generators.PDFHeaderOrFooter Maven / Gradle / Ivy

Go to download

This is the PDF generator package of NervalReports (a lightweight report creation library), used to generate a report directly to a .pdf file.

There is a newer version: 1.2
Show newest version
/** 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.ReportTextAlignment;

/** Header or footer representation for {@link PDFReportGenerator}.
 * @author farrer */
/* default */ class PDFHeaderOrFooter {
	
	/** Value to make the header not just before page content (ie: avoid to be 'glued') */
	private static final int HEIGHT_DELTA_AFTER = 12;
	
	/** Value to make the footer not just after page content (ie: avoid to be 'glued') */
	private static final int HEIGHT_DELTA_BEFORE = 4;
	
	/** Amount to sum to height whe using separator line. */
	private static final int HEIGHT_DELTA_FOR_SEPARATOR_LINE = 8; 
	
	/** Its line content, with images and/or texts. */
	private final PDFLine line;
	
	/** If will use an horizontal line to separate header/footer from page content. */
	private boolean useSeparatorLine;
	
	/** If is a header or a footer. */
	private boolean isHeader;
	
	/** Default constructor.
	 * @param textAlignment text alignment to use.
	 * @param maxWidth maximum width to occupy.
	 * @parma isHeader if is header (true) or footer (false). */
	PDFHeaderOrFooter(ReportTextAlignment textAlignment, float maxWidth, boolean isHeader) {
		this.line = new PDFLine(textAlignment, maxWidth);
		this.useSeparatorLine = false;
		this.isHeader = isHeader;
	}

	/** @return {@link #line}. */
	PDFLine getLine() {
		return line;
	}
	
	/** @return needed height to draw its contents. */
	int getNeededHeight() {
		int delta = (isHeader) ? HEIGHT_DELTA_AFTER : HEIGHT_DELTA_BEFORE;
		if (useSeparatorLine) {
			return this.line.getNeededHeight() + HEIGHT_DELTA_FOR_SEPARATOR_LINE + delta;
		} else {
			return this.line.getNeededHeight() + delta;
		}
	}

	/** @return {{@link #useSeparatorLine}. */
	boolean useSeparatorLine() {
		return useSeparatorLine;
	}

	/** Define if will use an horizontal line to separate header/footer from page content. 
	 * @param useSeparatorLine {@link #useSeparatorLine}. */
	void setUseSeparatorLine(boolean useSeparatorLine) {
		this.useSeparatorLine = useSeparatorLine;
	}
	
	/** @return true if is header, false if footer. */
	boolean isHeader() {
		return isHeader;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy