📄 simplepagelayouter.java
字号:
/**
* Repeating group header are only printed while ItemElements are
* processed.
*/
// was currentEffectiveGroupIndex - 1
for (int gidx = 0; gidx < currentEffectiveGroupIndex; gidx++)
{
final Group g = getReport().getGroup(gidx);
if (g.getHeader().getStyle().getBooleanStyleProperty(BandStyleSheet.REPEAT_HEADER))
{
print(g.getHeader(), true);
}
}
// mark the current position to calculate the maxBand-Height
getCursor().setPageTop(getCursor().getY());
if (getLogicalPage().isEmpty() == false)
{
throw new IllegalStateException("Not empty after pagestart");
}
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("PageStarted failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Receives notification that a page has ended.
* <p>
* This prints the PageFooter. If this is the first page, the footer is not
* printed if the pagefooter style-flag DISPLAY_ON_FIRSTPAGE is set to false.
* If this event is known to be the last pageFinished event, the DISPLAY_ON_LASTPAGE
* is evaluated and the footer is printed only if this flag is set to TRUE.
* <p>
*
* @param event the report event.
*/
public void pageFinished(final ReportEvent event)
{
setCurrentEvent(event);
try
{
getCursor().setReservedSpace(0);
final Band b = getReport().getPageFooter();
if (event.getState().getCurrentPage() == 1)
{
if (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_FIRSTPAGE) == true)
{
printBottom(b);
}
}
else if (isLastPageBreak)
{
if (b.getStyle().getBooleanStyleProperty(BandStyleSheet.DISPLAY_ON_LASTPAGE) == true)
{
printBottom(b);
}
}
else
{
printBottom(b);
}
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("PageFinished failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Receives notification that the report has finished.
* <P>
* Prints the ReportFooter and forces the last pagebreak.
*
* @param event Information about the event.
*/
public void reportFinished(final ReportEvent event)
{
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException();
}
try
{
setCurrentEvent(event);
currentEffectiveGroupIndex -= 1;
final Object prepareRun =
event.getState().getProperty(JFreeReportConstants.REPORT_PREPARERUN_PROPERTY,
Boolean.FALSE);
if (prepareRun.equals(Boolean.TRUE))
{
setMaxPage(event.getState().getCurrentPage());
}
// force that this last pagebreak ...
isLastPageBreak = true;
final Band b = getReport().getReportFooter();
printBand(b);
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("ReportFinished failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Receives notification that a group has started.
* <P>
* Prints the GroupHeader
*
* @param event Information about the event.
*/
public void groupStarted(final ReportEvent event)
{
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException();
}
try
{
setCurrentEvent(event);
currentEffectiveGroupIndex += 1;
final int gidx = event.getState().getCurrentGroupIndex();
final Group g = getReport().getGroup(gidx);
final Band b = g.getHeader();
printBand(b);
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("GroupStarted failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Receives notification that a group has finished.
* <P>
* Prints the GroupFooter.
*
* @param event Information about the event.
*/
public void groupFinished(final ReportEvent event)
{
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException();
}
try
{
setCurrentEvent(event);
currentEffectiveGroupIndex -= 1;
final int gidx = event.getState().getCurrentGroupIndex();
final Group g = getReport().getGroup(gidx);
final Band b = g.getFooter();
printBand(b);
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("GroupFinished failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Receives notification that a row of data is being processed.
* <P>
* prints the ItemBand.
*
* @param event Information about the event.
*/
public void itemsAdvanced(final ReportEvent event)
{
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException();
}
try
{
setCurrentEvent(event);
printBand(getReport().getItemBand());
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("ItemsAdvanced failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Prints a band.
*
* @param b the band.
*
* @throws ReportProcessingException if the printing or spooling of the band failed.
* @return true, if the band was printed, false if the printing was delayed to the next page
*/
private boolean printBand(final Band b) throws ReportProcessingException
{
if (isPageEnded())
{
createSaveState(b);
setStartNewPage(true);
return false;
}
if (b.getStyle().getBooleanStyleProperty(BandStyleSheet.PAGEBREAK_BEFORE) == true)
{
createSaveState(b);
if (endPage(ENDPAGE_REQUESTED) == false)
{
// no pagebreak was done, the band was printed to an already empty page
return print(b, false);
}
// a pagebreak was requested, printing is delayed
setStartNewPage(true);
return false;
}
else
{
return print(b, false);
}
}
/**
* Prints a band.
*
* @param b the band.
* @param spool a flag that controls whether or not to spool.
* @return true, if the band was printed, and false if the printing is delayed
* until a new page gets started.
*
* @throws ReportProcessingException if the printing failed
*/
private boolean print(final Band b, final boolean spool)
throws ReportProcessingException
{
final float y = getCursor().getY();
// don't save the state if the current page is currently being finished
// or restarted; PageHeader and PageFooter are printed out of order and
// do not influence the reporting state
final Rectangle2D bounds = doLayout(b, true);
bounds.setRect(0, y, bounds.getWidth(), bounds.getHeight());
final boolean retval = doPrint(bounds, b, spool);
return retval;
}
/**
* Prints a band at the bottom of the page.
*
* @param b the band.
* @return true, if the band was printed, and false if the printing is delayed
* until a new page gets started.
*
* @throws ReportProcessingException if the printing failed
*/
private boolean printBottom(final Band b)
throws ReportProcessingException
{
// don't save the state if the current page is currently beeing finished
// or restarted; PageHeader and PageFooter are printed out of order and
// do not influence the reporting state
// if there is nothing printed, then ignore everything ...
final boolean spool = getLogicalPage().isEmpty();
final Rectangle2D bounds = doLayout(b, true);
bounds.setRect(0, getCursor().getPageBottomReserved() - bounds.getHeight(),
bounds.getWidth(), bounds.getHeight());
return doPrint(bounds, b, spool);
}
/**
* Perform the layout of a band. The height of the band is calculated according to the contents
* of the band. The width of the band will always span the complete printable width.
*
* @param band the band.
* @param fireEvent a flag to control whether or not a report event is fired.
*
* @return the dimensions of the band.
*/
protected Rectangle2D doLayout(final Band band, final boolean fireEvent)
{
final float width = getLogicalPage().getWidth();
final float height = getCursor().getPageBottomReserved() - getCursor().getPageTop();
final Rectangle2D bounds = BandLayoutManagerUtil.doLayout(band,
getLogicalPage().getOutputTarget(),
width,
height);
if (fireEvent == true)
{
final ReportEvent event = getCurrentEvent();
clearCurrentEvent();
event.getState().fireLayoutCompleteEvent(band, event.getType());
setCurrentEvent(event);
}
return bounds;
}
/**
* Prints a band.
*
* @param bounds the bounds of the band within the logical page
* @param band the band that should be printed. The internal band layouting is
* already done, all Elements contain a valid BOUNDS property.
* @param spool a flag that controls whether to print the contents directly
* or to cache the printing operation for later usage.
* @return true, if the band was printed, and false if the printing is delayed
* until a new page gets started.
* @see com.jrefinery.report.targets.pageable.LogicalPage#spoolBand
*
* @throws ReportProcessingException if the printing caused an detectable error
* while printing the band
*/
protected boolean doPrint(final Rectangle2D bounds, final Band band, final boolean spool)
throws ReportProcessingException
{
try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -