📄 simplepagelayouter.java
字号:
{
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;
}
/*
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);
return true;
}
// handle a automatic pagebreak in case there is not enough space here ...
else if ((isSpaceFor(height) == false) && (isPageEnded() == 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
{
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)
{
state = new SimpleLayoutManagerState(b);
}
/**
* 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.getBand() != null)
{
try
{
final Band band = (Band) state.getBand().clone();
// update the dataRow to the current dataRow instance...
ReportState state = getCurrentEvent().getState();
// todo: How to resolve this update in a clean way. How to change the
// element connection so that it is smarter and not that weird ...
ReportDefinitionImpl impl = (ReportDefinitionImpl) state.getReport();
// yes, I hate this code too...
DataRowConnector.disconnectDataSources(band, impl.getDataRowConnector());
DataRowConnector.connectDataSources(band, impl.getDataRowConnector());
print(band, false);
}
catch (CloneNotSupportedException cne)
{
throw new ReportProcessingException
("Unable to initialize the new page. Clone failed.", cne);
}
}
clearSaveState();
setRestartingPage(false);
}
/**
* 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;
}
/**
* 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();
}
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("ItemsStarted", e);
}
finally
{
clearCurrentEvent();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -