📄 simplepagelayouter.java
字号:
* content is printed. This way, the LogicalPage remains empty until an other band
* is printed.
*
* @param event Information about the event.
*/
public void pageStarted(final ReportEvent event)
{
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException();
}
setCurrentEvent(event);
try
{
delegate.pageStarted(event);
}
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
{
delegate.pageFinished(event);
}
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();
}
setCurrentEvent(event);
try
{
delegate.reportFinished(event);
}
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();
}
setCurrentEvent(event);
try
{
delegate.groupStarted(event);
}
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("AssertationFailed: Page is closed.");
}
setCurrentEvent(event);
try
{
delegate.groupFinished(event);
}
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();
}
setCurrentEvent(event);
try
{
delegate.itemsAdvanced(event);
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("ItemsAdvanced failed", e);
}
finally
{
clearCurrentEvent();
}
}
/**
* Prints a band.
*
* @param b the band.
* @param spool a flag that controls whether or not to spool.
* @param handlePagebreak a flag that controls whether to handle the
* 'pagebreak-before constraint.
* @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
*/
public boolean print(final Band b, final boolean spool, final boolean handlePagebreak)
throws ReportProcessingException
{
// create a safe state, if the page ended. This does not print the
// band. we just return.
if (isPageEnded())
{
createSaveState(b);
setStartNewPage(true);
return false;
}
if (handlePagebreak &&
b.getStyle().getBooleanStyleProperty(BandStyleSheet.PAGEBREAK_BEFORE) == true)
{
// 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
// out-of-order prints do not accept pagebreaks, so we can be sure that
// this is no pageheader or page footer or a band from there.
createSaveState(b);
if (endPage(ENDPAGE_REQUESTED) == true)
{
// a pagebreak was requested and granted, printing is delayed
setStartNewPage(true);
return false;
}
}
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, false);
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
*/
public 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, false);
}
/**
* 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 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, final boolean watermark)
throws ReportProcessingException
{
try
{
final float height = (float) bounds.getHeight();
// handle the end of the page
if (isFinishingPage())
{
if (spool)
{
final Spool newSpool = getLogicalPage().spoolBand(bounds, band);
if (spooledBand == null)
{
spooledBand = newSpool;
}
else
{
spooledBand.merge(newSpool);
}
}
else
{
final Spool newSpool = getLogicalPage().spoolBand(bounds, band);
if (newSpool.isEmpty() == false)
{
if (spooledBand != null)
{
getLogicalPage().replaySpool(spooledBand);
spooledBand = null;
}
getLogicalPage().replaySpool(newSpool);
}
}
cursor.advance(height);
return true;
}
// handle a automatic pagebreak in case there is not enough space here ...
else if ((watermark == false) && (isPageEnded() == false) && (isSpaceFor(height) == false))
{
if ((spooledBand != null) && (spool == false))
{
getLogicalPage().replaySpool(spooledBand);
spooledBand = null;
}
createSaveState(band);
endPage(ENDPAGE_FORCED);
return false;
}
else if (isPageEnded())
{
// page has ended before, that band should be printed on the next page
createSaveState(band);
return false;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -