jasperDesign.setPageWidth(height);
for (int i = 0; i < properties.length; i++)
{
JRDesignField field = new JRDesignField();
field.setName(properties[i].getName());
field.setValueClass(properties[i].getType());
try
{
jasperDesign.addField(field);
}
catch (Exception e)
{
log.warn(e);
}
}
if (exportType == ExportType.PDF)
{
// add title
JRDesignStaticText sText = new JRDesignStaticText();
sText.setX(0);
sText.setY(0);
sText.setWidth(jasperDesign.getPageHeight());
sText.setHeight(50);
sText.setText(jasperDesign.getName());
sText.setFontSize(16);
sText.setBold(true);
JRDesignBand band = new JRDesignBand();
band.setHeight(50);
band.addElement(sText);
jasperDesign.setTitle(band);
// add page footer for page numbers
band = new JRDesignBand();
band.setHeight(15);
sText = new JRDesignStaticText();
sText.setX(0);
sText.setY(0);
sText.setHeight(15);
sText.setWidth(40);
sText.setText("Page:");
band.addElement(sText);
JRDesignExpression exp = new JRDesignExpression();
exp.addVariableChunk("PAGE_NUMBER");
exp.setValueClass(Integer.class);
JRDesignTextField txt = new JRDesignTextField();
txt.setExpression(exp);
txt.setX(40);
txt.setY(0);
txt.setHeight(15);
txt.setWidth(100);
band.addElement(txt);
jasperDesign.setPageFooter(band);
}
JRDesignBand emptyBand = new JRDesignBand();
emptyBand.setHeight(0);
jasperDesign.setPageHeader(emptyBand);
jasperDesign.setColumnFooter(emptyBand);
jasperDesign.setSummary(emptyBand);
JRField[] fields = jasperDesign.getFields();
// add column header and detail bands
JRDesignBand bandDetail = new JRDesignBand();
bandDetail.setHeight(20);
JRDesignBand bandHeader = new JRDesignBand();
bandHeader.setHeight(20);
int fieldWidth = (jasperDesign.getPageWidth() - jasperDesign.getLeftMargin()
- jasperDesign.getRightMargin() - (fields.length - 1) * jasperDesign.getColumnSpacing())
/ fields.length;
for (int i = 0; i < fields.length; i++)
{
try
{
JRField field = fields[i];
JRDesignExpression exp = new JRDesignExpression();
exp.addFieldChunk(field.getName());
if (field.getValueClassName().equals("java.sql.Date"))
{
// JasperReports does not support java.sql.Date in text field expression
exp.setValueClass(java.util.Date.class);
}
else
{
exp.setValueClass(field.getValueClass());
}
JRDesignTextField txt = new JRDesignTextField();
txt.setExpression(exp);
txt.setX(i * fieldWidth);
txt.setY(0);
txt.setHeight(20);
txt.setWidth(fieldWidth);
if (field.getValueClass().equals(Double.class))
{
txt.setPattern("0.00");
}
bandDetail.addElement(txt);
JRDesignStaticText sText = new JRDesignStaticText();
sText.setX(i * fieldWidth);
sText.setY(0);
sText.setHeight(20);
sText.setWidth(fieldWidth);
sText.setText(field.getName());
sText.setUnderline(true);
bandHeader.addElement(sText);
}
catch (Exception e)