📄 samplereport1.java
字号:
new BasicStroke(0),
new Rectangle2D.Float(0, 0, -100, -100), false, true
)
);
items.addElement(
ItemFactory.createLineShapeElement(
"top",
Color.decode("#DFDFDF"),
new BasicStroke(0.1f),
new Line2D.Float(0, 0, 0, 0)
)
);
items.addElement(
ItemFactory.createLineShapeElement(
"bottom",
Color.decode("#DFDFDF"),
new BasicStroke(0.1f),
new Line2D.Float(0, 10, 0, 10)
)
);
items.addElement(
ItemFactory.createStringElement(
"Code Element",
new Rectangle2D.Float(0, 0, 176, 8),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"<null>",
"Country"
)
);
items.addElement(
ItemFactory.createStringElement(
"Code Element",
new Rectangle2D.Float(180, 0, 76, 8),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"<null>",
"ISO Code"
)
);
items.addElement(
ItemFactory.createNumberElement(
"Population Element",
new Rectangle2D.Float(260, 0, 76, 8),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"<null>",
"#,##0",
"Population"
)
);
return items;
}
/**
* Creates the function collection. The xml definition for this construct:
*
<pre>
<functions>
<function name="sum" class="com.jrefinery.report.function.ItemSumFunction">
<properties>
<property name="field">Population</property>
<property name="group">Continent Group</property>
</properties>
</function>
<function name="backgroundTrigger"
class="com.jrefinery.report.function.ElementVisibilitySwitchFunction">
<properties>
<property name="element">background</property>
</properties>
</function>
</functions>
</pre>
*
* @return the functions.
*
* @throws FunctionInitializeException if there is a problem initialising the functions.
*/
private ExpressionCollection createFunctions() throws FunctionInitializeException
{
final ExpressionCollection functions = new ExpressionCollection();
final ItemSumFunction sum = new ItemSumFunction();
sum.setName("sum");
sum.setProperty("field", "Population");
sum.setProperty("group", "Continent Group");
functions.add(sum);
final ElementVisibilitySwitchFunction backgroundTrigger = new ElementVisibilitySwitchFunction();
backgroundTrigger.setName("backgroundTrigger");
backgroundTrigger.setProperty("element", "background");
functions.add(backgroundTrigger);
return functions;
}
/**
<pre>
<groups>
... create the groups and add them to the list ...
</groups>
</pre>
*
* @return the groups.
*/
private GroupList createGroups()
{
final GroupList list = new GroupList();
list.add(createContinentGroup());
return list;
}
/**
<pre>
<group name="Continent Group">
<groupheader height="18" fontname="Monospaced" fontstyle="bold" fontsize="9" pagebreak="false">
<label name="Label 5" x="0" y="1" width="76" height="9" alignment="left">CONTINENT:</label>
<string-field name="Continent Element" x="96" y="1" width="76" height="9" alignment="left"
fieldname="Continent"/>
<line name="line1" x1="0" y1="12" x2="0" y2="12" weight="0.5"/>
</groupheader>
<groupfooter height="18" fontname="Monospaced" fontstyle="bold" fontsize="9">
<label name="Label 6" x="0" y="0" width="450" height="12" alignment="left"
baseline="10">Population:</label>
<number-function x="260" y="0" width="76" height="12" alignment="right" baseline="10"
format="#,##0" function="sum"/>
</groupfooter>
<fields>
<field>Continent</field>
</fields>
</group>
</pre>
*
* @return the continent group.
*/
private Group createContinentGroup()
{
final Group continentGroup = new Group();
continentGroup.setName("Continent Group");
continentGroup.addField("Continent");
final GroupHeader header = (GroupHeader)
ItemFactory.createGroupHeader(18, new Font("Monospaced", Font.BOLD, 9), null, false);
header.addElement(
ItemFactory.createLabelElement(
"Label 5",
new Rectangle2D.Float(0, 1, 76, 9),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"CONTINENT:"
)
);
header.addElement(
ItemFactory.createStringElement(
"Continent Element",
new Rectangle2D.Float(96, 1, 76, 9),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"<null>",
"Continent"
)
);
header.addElement(
ItemFactory.createLineShapeElement(
"line1",
null,
new BasicStroke(0.5f),
new Line2D.Float(0, 12, 0, 12)
)
);
continentGroup.setHeader(header);
final GroupFooter footer = (GroupFooter)
ItemFactory.createGroupFooter(18, new Font("Monospaced", Font.BOLD, 9), null);
footer.addElement(
ItemFactory.createLabelElement(
"Label 6",
new Rectangle2D.Float(0, 0, -100, 12),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"Population:"
)
);
footer.addElement(
ItemFactory.createNumberElement(
"anonymous",
new Rectangle2D.Float(260, 0, 76, 12),
null,
ElementAlignment.LEFT.getOldAlignment(),
ElementAlignment.MIDDLE.getOldAlignment(),
null,
"<null>",
"#,##0",
"sum"
)
);
continentGroup.setFooter(footer);
return continentGroup;
}
/**
* Creates the report.
*
* @return the constructed report.
*
* @throws FunctionInitializeException if there was a problem initialising any of the functions.
*/
public JFreeReport createReport() throws FunctionInitializeException
{
final JFreeReport report = new JFreeReport();
report.setName("Sample Report 1");
report.setReportFooter(createReportFooter());
report.setReportHeader(createReportHeader());
report.setPageFooter(createPageFooter());
report.setPageHeader(createPageHeader());
report.setGroups(createGroups());
report.setItemBand(createItemBand());
report.setFunctions(createFunctions());
report.setPropertyMarked("report.date", true);
return report;
}
/**
* Default constructor.
*/
public SampleReport1()
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -