📄 simplepagelayouter.java
字号:
if (spool)
{
final Spool newSpool = getLogicalPage().spoolBand(bounds, band);
if (spooledBand == null)
{
spooledBand = newSpool;
}
else
{
spooledBand.merge(newSpool);
}
cursor.advance(height);
return true;
}
else
{
final Spool newSpool = getLogicalPage().spoolBand(bounds, band);
if (newSpool.isEmpty() == false)
{
if (spooledBand != null)
{
getLogicalPage().replaySpool(spooledBand);
spooledBand = null;
}
/*
PhysicalOperation [] pop = newSpool.getOperations();
Log.debug ("--->" + band.getClass());
for (int i = 0; i < pop.length; i++)
{
Log.debug (pop[i]);
}
*/
getLogicalPage().replaySpool(newSpool);
}
cursor.advance(height);
if (band.getStyle().getBooleanStyleProperty(BandStyleSheet.PAGEBREAK_AFTER) == true)
{
createSaveState(null);
endPage(ENDPAGE_REQUESTED);
}
return true;
}
}
}
catch (ReportProcessingException rpe)
{
throw rpe;
}
catch (OutputTargetException ote)
{
throw new FunctionProcessingException("Failed to print", ote);
}
}
/**
* Determines whether or not there is space remaining on the page for a band of the specified
* height. Perform layouting for the pageFooter to guess the height.
*
* @param height the height (in Java2D user space units).
*
* @return true or false.
*/
public boolean isSpaceFor(final float height)
{
if (isLastPageBreak && (getReport().getPageFooter().isDisplayOnLastPage() == false))
{
getCursor().setReservedSpace(0);
}
else
{
final Band b = getReport().getPageFooter();
// perform layout, but do not fire the event, as we don't print the band ...
final Rectangle2D rect = doLayout(b, false);
getCursor().setReservedSpace((float) rect.getHeight());
}
return getCursor().isSpaceFor(height);
}
/**
* Returns the cursor.
*
* @return the cursor.
* @throws IllegalStateException if a cursor is requested but no OutputTarget is set.
*/
protected SimplePageLayoutCursor getCursor()
{
if (cursor == null)
{
throw new IllegalStateException("No cursor, no OutputTarget: " + hashCode());
}
return cursor;
}
/**
* Sets the cursor.
*
* @param cursor the cursor (null not permitted).
* @throws NullPointerException if the given cursor is null
*/
protected void setCursor(final SimplePageLayoutCursor cursor)
{
if (cursor == null)
{
throw new NullPointerException("SimplePageLayouter.setCursor(...): cursor is null.");
}
this.cursor = cursor;
}
/**
* Records state information.
*
* @param b the band.
*/
protected void createSaveState(final Band b)
{
if (b == null)
{
state = new SimpleLayoutManagerState(null);
}
else
{
state = new SimpleLayoutManagerState(b.getTreeLock());
}
}
/**
* Returns the current state. The state was previously recorded using the
* <code>createSaveState(Band b)</code> method.
*
* @return the current state, never null
*/
protected PageLayouter.LayoutManagerState saveCurrentState()
{
if (state == null)
{
throw new NullPointerException();
}
return state;
}
/**
* Restores the state.
*
* @param anchestor the ancestor state.
*
* @throws ReportProcessingException if the printing failed or a pagebreak is
* requested while the page is restored.
* @throws IllegalStateException if there is no SavedState but this is not the
* first page.
*/
public void restoreSaveState(final ReportState anchestor)
throws ReportProcessingException
{
super.restoreSaveState(anchestor);
isLastPageBreak = false;
}
/**
* Handles the restarting of the page. Fires the pageStarted event and prints
* the pageheader. Restarting the page is done once after the PageLayouterState
* was restored.
*
* @throws ReportProcessingException if restarting the page failed.
*/
public void restartPage() throws ReportProcessingException
{
if (isPageRestartDone() || isRestartingPage() || isFinishingPage())
{
return;
}
startPage();
if (state == null)
{
// no state saved, break ...
return;
}
setRestartingPage(true);
// if there was a pagebreak_after_print, there is no band to print for now
if (state.getBandID() != null)
{
final ReportState reportstate = getCurrentEvent().getState();
final ReportDefinition impl = reportstate.getReport();
final Band band = getBandForID(impl, state.getBandID());
print(band, BAND_PRINTED, PAGEBREAK_BEFORE_IGNORED);
}
clearSaveState();
setRestartingPage(false);
}
private Band getBandForID (ReportDefinition def, Object id)
{
if (def.getReportHeader().getTreeLock() == id)
{
return def.getReportHeader();
}
if (def.getReportFooter().getTreeLock() == id)
{
return def.getReportFooter();
}
if (def.getPageHeader().getTreeLock() == id)
{
return def.getPageHeader();
}
if (def.getPageFooter().getTreeLock() == id)
{
return def.getPageFooter();
}
if (def.getItemBand().getTreeLock() == id)
{
return def.getItemBand();
}
for (int i = 0; i < def.getGroupCount(); i++)
{
Group g = def.getGroup(i);
if (g.getHeader().getTreeLock() == id)
{
return g.getHeader();
}
if (g.getFooter().getTreeLock() == id)
{
return g.getFooter();
}
}
return null;
}
/**
* Clears the layout state.
*/
protected void clearSaveState()
{
super.clearSaveState();
state = null;
}
/**
* Sets the logical page and adjust the cursor.
*
* @param logicalPage the logical page.
*/
public void setLogicalPage(final LogicalPage logicalPage)
{
super.setLogicalPage(logicalPage);
setCursor(new SimplePageLayoutCursor(getLogicalPage().getHeight()));
}
/**
* Ends the page.
*
* @param force set to true, to skip the test whether the logical page is empty and
* to enforce an pagebreak. This is a requirement when an completly empty report
* (no bands or elements printed) should be finished.
*
* @return true if the pageBreak is done, false otherwise.
*
* @throws ReportProcessingException if finishing the page failed.
*/
protected boolean endPage(final boolean force) throws ReportProcessingException
{
if (getLogicalPage().isEmpty() == false || force)
{
if (spooledBand != null)
{
// getLogicalPage().replaySpool(spooledBand);
// Log.warn ("Spool contained data, this data is lost now ...!");
spooledBand = null;
}
super.endPage();
return true;
}
else
{
return false;
}
}
/**
* Returns true, if the PageLayouter has successfully started a new page. The
* start of the new page is delayed, until the first content is printed.
*
* @return true, if a new page has already been started, false otherwise.
*/
public boolean isNewPageStarted()
{
return startNewPage;
}
/**
* Defines whether the PageLayouter has successfully started a new page. The
* start of the new page is delayed, until the first content is printed, this
* flag is used to keep track of the page initialization state.
*
* @param startNewPage true, if a new page has already been started, false otherwise.
*/
public void setStartNewPage(final boolean startNewPage)
{
this.startNewPage = startNewPage;
}
/**
* Return a completly separated copy of this function. The copy does no
* longer share any changeable objects with the original function.
*
* @return a copy of this function.
*/
public Expression getInstance()
{
final SimplePageLayouter sl = (SimplePageLayouter) super.getInstance();
sl.spooledBand = null;
sl.delegate = new SimplePageLayoutDelegate(sl);
sl.cursor = null;
sl.isLastPageBreak = false;
sl.state = null;
return sl;
}
/**
* Clones the layouter.
*
* @return the clone.
*
* @throws CloneNotSupportedException if there is a problem cloning.
*/
public Object clone() throws CloneNotSupportedException
{
final SimplePageLayouter sl = (SimplePageLayouter) super.clone();
if (spooledBand != null)
{
sl.spooledBand = (Spool) spooledBand.clone();
}
sl.delegate = (SimplePageLayoutDelegate) delegate.clone();
sl.delegate.setWorker(sl);
return sl;
}
/**
* Receives notification of a prepare event.
*
* @param event the event.
*/
public void prepareEvent(final ReportEvent event)
{
try
{
setCurrentEvent(event);
restartPage();
}
catch (Exception e)
{
throw new FunctionProcessingException("prepareEvent", e);
}
finally
{
clearCurrentEvent();
}
}
public boolean isWatermarkSupported()
{
return true;
}
public boolean printWatermark(Band watermark) throws ReportProcessingException
{
final LogicalPage logPage = getLogicalPage();
final Rectangle2D bounds = BandLayoutManagerUtil.doFixedLayout
(watermark, logPage.getOutputTarget(), logPage.getWidth(), logPage.getHeight());
final boolean retval = doPrint(bounds, watermark, true, true);
return retval;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -