| Method from org.jfree.report.modules.output.pageable.base.pagelayout.SimplePageLayouter Detail: |
protected void clearSaveState() {
super.clearSaveState();
state = null;
}
|
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;
}
|
protected void createSaveState(Band b) {
if (b == null)
{
state = new SimpleLayoutManagerState(null);
}
else
{
state = new SimpleLayoutManagerState(b.getTreeLock());
}
}
Records state information. |
protected Rectangle2D doLayout(Band band,
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;
}
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. |
protected boolean doPrint(Rectangle2D bounds,
Band band,
boolean spool,
boolean watermark,
float position) 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;
}
if (position != -1)
{
throw new ReportProcessingException("Band does not fit into given position!");
}
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);
}
}
|
protected boolean endPage(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;
}
}
|
protected SimplePageLayoutCursor getCursor() {
if (cursor == null)
{
throw new IllegalStateException("No cursor, no OutputTarget: " + hashCode());
}
return cursor;
}
|
public float getCursorPosition() {
if (getCursor() == null)
{
throw new IllegalStateException("Cursor is not initialized.");
}
return getCursor().getY();
}
Returns the current position of the cursor. |
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;
}
Return a completly separated copy of this function. The copy does no
longer share any changeable objects with the original function. |
public float getReservedSpace() {
if (getCursor() == null)
{
throw new IllegalStateException("Cursor is not initialized.");
}
return getCursor().getReservedSpace();
}
Returns the reserved space on the current page. |
public float getTopContentPosition() {
if (getCursor() == null)
{
throw new IllegalStateException("Cursor is not initialized.");
}
return getCursor().getPageTop();
}
Returns the position of the first content. |
public void groupFinished(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 group has finished.
Prints the GroupFooter. |
public void groupStarted(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 started.
Prints the GroupHeader |
public boolean isNewPageStarted() {
return startNewPage;
}
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. |
public boolean isPageEmpty() {
return getLogicalPage().isEmpty();
}
Checks, whether the current page is empty. |
public boolean isSpaceFor(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);
}
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. |
public boolean isWatermarkSupported() {
return getReport().getReportConfiguration().getConfigProperty
(WATERMARK_PRINTED_KEY, "true").equals("true");
}
|
public void itemsAdvanced(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();
}
}
Receives notification that a row of data is being processed.
prints the ItemBand. |
public void itemsFinished(ReportEvent event) {
setCurrentEvent(event);
delegate.itemsFinished(event);
clearCurrentEvent();
}
Receives notification that a group of item bands has been completed.
The itemBand is finished, the report starts to close open groups. |
public void itemsStarted(ReportEvent event) {
setCurrentEvent(event);
delegate.itemsStarted(event);
clearCurrentEvent();
}
|
public void pageFinished(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 a page has ended.
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.
|
public void pageStarted(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 started.
This prints the PageHeader. If this is the first page, the header is not
printed if the pageheader style-flag DISPLAY_ON_FIRSTPAGE is set to false.
If this event is known to be the last pageStarted event, the DISPLAY_ON_LASTPAGE
is evaluated and the header is printed only if this flag is set to TRUE.
If there is an active repeating GroupHeader, print the last one. The GroupHeader
is searched for the current group and all parent groups, starting at the
current group and ascending to the parents. The first goupheader that has the
StyleFlag REPEAT_HEADER set to TRUE is printed.
The PageHeader and the repeating GroupHeader are spooled until the first real
content is printed. This way, the LogicalPage remains empty until an other band
is printed. |
public void prepareEvent(ReportEvent event) {
setCurrentEvent(event);
try
{
restartPage();
}
catch (Exception e)
{
throw new FunctionProcessingException("prepareEvent", e);
}
finally
{
clearCurrentEvent();
}
}
Receives notification of a prepare event. |
public boolean print(Band b,
boolean spool,
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;
}
final Float f = (Float)
b.getStyle().getStyleProperty(BandStyleSheet.FIXED_POSITION);
final float position;
if (f == null)
{
position = -1;
}
else
{
position = f.floatValue();
if ((position >= getCursor().getPageBottom()) ||
(position < 0))
{
throw new IndexOutOfBoundsException("Given position is invalid");
}
}
if ((handlePagebreak &&
b.getStyle().getBooleanStyleProperty(BandStyleSheet.PAGEBREAK_BEFORE) == true) ||
((position != -1) && (position < getCursorPosition())))
{
// 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;
if (position == -1)
{
y = getCursor().getY();
}
else
{
y = position;
}
// 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, position);
return retval;
}
|
public boolean printBottom(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, -1);
}
Prints a band at the bottom of the page. |
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, -1);
return retval;
}
|
public void reportDone(ReportEvent event) {
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException("AssertationFailed: Page ended.");
}
try
{
setCurrentEvent(event);
restartPage();
createSaveState(null);
saveCurrentState();
endPage(ENDPAGE_FORCED);
}
catch (Exception e)
{
throw new FunctionProcessingException("ReportDone", e);
}
finally
{
clearCurrentEvent();
}
}
Receives notification that report generation has completed, the report footer was printed,
no more output is done. This is a helper event to shut down the output service. |
public void reportFinished(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();
}
}
|
public void reportStarted(ReportEvent event) {
// activating this state after the page has ended is invalid.
if (isPageEnded())
{
throw new IllegalStateException();
}
setCurrentEvent(event);
try
{
delegate.reportStarted(event);
}
catch (FunctionProcessingException fe)
{
throw fe;
}
catch (Exception e)
{
throw new FunctionProcessingException("ReportStarted failed", e);
}
finally
{
clearCurrentEvent();
}
}
|
public void resetCursor() {
setCursor(new SimplePageLayoutCursor(getLogicalPage().getHeight()));
}
Reinitialize the cursor of the layout worker. Called when
a new page is started. |
public void restartPage() throws ReportProcessingException {
if (isPageRestartDone() || isRestartingPage() || isFinishingPage())
{
return;
}
startPage();
if (state == null)
{
// no state saved, break ...
return;
}
setRestartingPage(true);
boolean pagebreakAfter = false;
// 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());
pagebreakAfter = band.getStyle().getBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER);
band.getStyle().setBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER, false);
print(band, pagebreakAfter, PAGEBREAK_BEFORE_IGNORED);
band.getStyle().setBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER, pagebreakAfter);
}
clearSaveState();
setRestartingPage(false);
// ugly fix for the reportd-problem ..
if (pagebreakAfter)
{
createSaveState(null);
endPage(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. |
public void restoreSaveState(ReportState anchestor) throws ReportProcessingException {
super.restoreSaveState(anchestor);
isLastPageBreak = false;
}
|
protected PageLayouter.LayoutManagerState saveCurrentState() {
if (state == null)
{
throw new NullPointerException();
}
return state;
}
Returns the current state. The state was previously recorded using the
createSaveState(Band b) method. |
protected void setCursor(SimplePageLayoutCursor cursor) {
if (cursor == null)
{
throw new NullPointerException("SimplePageLayouter.setCursor(...): cursor is null.");
}
this.cursor = cursor;
}
|
public void setLogicalPage(LogicalPage logicalPage) {
super.setLogicalPage(logicalPage);
setCursor(new SimplePageLayoutCursor(getLogicalPage().getHeight()));
}
Sets the logical page and adjust the cursor. |
public void setReservedSpace(float reserved) {
if (getCursor() == null)
{
throw new IllegalStateException("Cursor is not initialized.");
}
getCursor().setReservedSpace(reserved);
}
Defines the reserved space on the current page. |
public void setStartNewPage(boolean startNewPage) {
this.startNewPage = 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. |
public void setTopPageContentPosition(float topContentPosition) {
if (getCursor() == null)
{
throw new IllegalStateException("Cursor is not initialized.");
}
getCursor().setPageTop(topContentPosition);
}
|