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

net.sf.dynamicreports.report.builder.component.TextFieldBuilder Maven / Gradle / Ivy

Go to download

DynamicReports is an open source Java reporting library based on JasperReports. It allows to create dynamic report designs and it doesn't need a visual report designer. You can very quickly create reports and produce documents that can be displayed, printed or exported into many popular formats such as PDF, Excel, Word and others.

There is a newer version: 6.20.1
Show newest version
/**
 * DynamicReports - Free Java reporting library for creating reports dynamically
 *
 * Copyright (C) 2010 - 2016 Ricardo Mariaca
 * http://www.dynamicreports.org
 *
 * This file is part of DynamicReports.
 *
 * DynamicReports 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.
 *
 * DynamicReports 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 DynamicReports. If not, see .
 */

package net.sf.dynamicreports.report.builder.component;

import java.util.Date;

import org.apache.commons.lang3.Validate;

import net.sf.dynamicreports.report.base.component.DRTextField;
import net.sf.dynamicreports.report.builder.FieldBuilder;
import net.sf.dynamicreports.report.builder.VariableBuilder;
import net.sf.dynamicreports.report.builder.expression.Expressions;
import net.sf.dynamicreports.report.builder.group.GroupBuilder;
import net.sf.dynamicreports.report.constant.ComponentDimensionType;
import net.sf.dynamicreports.report.constant.Constants;
import net.sf.dynamicreports.report.constant.Evaluation;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.constant.HorizontalTextAlignment;
import net.sf.dynamicreports.report.constant.Markup;
import net.sf.dynamicreports.report.definition.DRIField;
import net.sf.dynamicreports.report.definition.datatype.DRIDataType;
import net.sf.dynamicreports.report.definition.expression.DRIExpression;
import net.sf.dynamicreports.report.definition.expression.DRIValueFormatter;

/**
 * @author Ricardo Mariaca ([email protected])
 */
@SuppressWarnings("deprecation")
public class TextFieldBuilder extends HyperLinkComponentBuilder, DRTextField> {
	private static final long serialVersionUID = Constants.SERIAL_VERSION_UID;

	protected TextFieldBuilder() {
		super(new DRTextField());
	}

	public TextFieldBuilder setText(VariableBuilder variable) {
		Validate.notNull(variable, "variable must not be null");
		getObject().setValueExpression(variable.getVariable());
		return this;
	}

	public TextFieldBuilder setText(FieldBuilder field) {
		Validate.notNull(field, "field must not be null");
		getObject().setValueExpression(field.getField());
		if (getObject().getDataType() == null) {
			getObject().setDataType(field.getField().getDataType());
		}
		return this;
	}

	public TextFieldBuilder setText(DRIExpression textExpression) {
		getObject().setValueExpression(textExpression);
		if (textExpression instanceof DRIField && getObject().getDataType() == null) {
			getObject().setDataType(((DRIField) textExpression).getDataType());
		}
		return this;
	}

	@SuppressWarnings("unchecked")
	public TextFieldBuilder setText(String text) {
		getObject().setValueExpression((DRIExpression) Expressions.text(text));
		return this;
	}

	@SuppressWarnings("unchecked")
	public TextFieldBuilder setText(Number number) {
		getObject().setValueExpression((DRIExpression) Expressions.number(number));
		return this;
	}

	@SuppressWarnings("unchecked")
	public TextFieldBuilder setText(Date date) {
		getObject().setValueExpression((DRIExpression) Expressions.date(date));
		return this;
	}

	public TextFieldBuilder setPattern(String pattern) {
		getObject().setPattern(pattern);
		return this;
	}

	public TextFieldBuilder setPattern(DRIExpression patternExpression) {
		getObject().setPatternExpression(patternExpression);
		return this;
	}

	/**
	 * @deprecated use setHorizontalTextAlignment instead
	 */
	@Deprecated
	public TextFieldBuilder setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
		if (horizontalAlignment != null) {
			getObject().setHorizontalTextAlignment(HorizontalTextAlignment.valueOf(horizontalAlignment.name()));
		}
		else {
			getObject().setHorizontalTextAlignment(null);
		}
		return this;
	}

	public TextFieldBuilder setHorizontalTextAlignment(HorizontalTextAlignment horizontalTextAlignment) {
		getObject().setHorizontalTextAlignment(horizontalTextAlignment);
		return this;
	}

	public TextFieldBuilder setValueFormatter(DRIValueFormatter valueFormatter) {
		getObject().setValueFormatter(valueFormatter);
		return this;
	}

	public TextFieldBuilder setDataType(DRIDataType dataType) {
		getObject().setDataType(dataType);
		return this;
	}

  /**
   * This method is used to define the preferred width of a textField.
   * The width is set to the columns multiplied by width of the
   * character m for the font used
   *
   * @param columns the number of preferred columns >= 0
   * @exception IllegalArgumentException if columns is < 0
   */
	public TextFieldBuilder setColumns(Integer columns) {
		getObject().setColumns(columns);
		return this;
	}

  /**
   * This method is used to define the fixed width of a textField.
   * The width is set to the columns multiplied by width of the
   * character m for the font used
   *
   * @param columns the number of fixed columns >= 0
   * @exception IllegalArgumentException if columns is < 0
   */
	public TextFieldBuilder setFixedColumns(Integer columns) {
		getObject().setColumns(columns);
		getObject().setWidthType(ComponentDimensionType.FIXED);
		return this;
	}

  /**
   * This method is used to define the minimum width of a textField.
   * The width is set to the columns multiplied by width of the
   * character m for the font used
   *
   * @param columns the number of minimum columns >= 0
   * @exception IllegalArgumentException if columns is < 0
   */
	public TextFieldBuilder setMinColumns(Integer columns) {
		getObject().setColumns(columns);
		getObject().setWidthType(ComponentDimensionType.EXPAND);
		return this;
	}

  /**
   * This method is used to define the preferred height of a textField.
   * The height is set to the rows multiplied by height of the font
   *
   * @param rows the number of preferred rows >= 0
   * @exception IllegalArgumentException if rows is < 0
   */
	public TextFieldBuilder setRows(Integer rows) {
		getObject().setRows(rows);
		return this;
	}

  /**
   * This method is used to define the fixed height of a textField.
   * The height is set to the rows multiplied by height of the font
   *
   * @param rows the number of fixed rows >= 0
   * @exception IllegalArgumentException if rows is < 0
   */
	public TextFieldBuilder setFixedRows(Integer rows) {
		getObject().setRows(rows);
		getObject().setHeightType(ComponentDimensionType.FIXED);
		return this;
	}

  /**
   * This method is used to define the minimum height of a textField.
   * The height is set to the rows multiplied by height of the font
   *
   * @param rows the number of minimum rows >= 0
   * @exception IllegalArgumentException if rows is < 0
   */
	public TextFieldBuilder setMinRows(Integer rows) {
		getObject().setRows(rows);
		getObject().setHeightType(ComponentDimensionType.EXPAND);
		return this;
	}

	public TextFieldBuilder setEvaluationTime(Evaluation evaluationTime) {
		getObject().setEvaluationTime(evaluationTime);
		return this;
	}

	public TextFieldBuilder setEvaluationGroup(GroupBuilder evaluationGroup) {
		Validate.notNull(evaluationGroup, "evaluationGroup must not be null");
		getObject().setEvaluationGroup(evaluationGroup.build());
		getObject().setEvaluationTime(Evaluation.GROUP);
		return this;
	}

	public TextFieldBuilder setMarkup(Markup markup) {
		getObject().setMarkup(markup);
		return this;
	}

	public TextFieldBuilder setStretchWithOverflow(Boolean stretchWithOverflow) {
		getObject().setStretchWithOverflow(stretchWithOverflow);
		return this;
	}

	public TextFieldBuilder setPrintRepeatedValues(Boolean printRepeatedValues) {
		getObject().setPrintRepeatedValues(printRepeatedValues);
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy