📄 pagelayouter.java
字号:
* in the last ReportEvent received, or null, if no event occurred here.
*
* @return the report.
*/
public ReportDefinition getReport()
{
if (getCurrentEvent() == null)
{
throw new IllegalStateException("No Current Event available.");
}
return getCurrentEvent().getReport();
}
/**
* Returns the current report event.
*
* @return the event.
*/
protected ReportEvent getCurrentEvent()
{
return currentEvent;
}
/**
* Sets the current event (also updates the report reference).
*
* @param currentEvent event.
*/
protected void setCurrentEvent(final ReportEvent currentEvent)
{
if (currentEvent == null)
{
throw new NullPointerException();
}
this.currentEvent = currentEvent;
}
/**
* Clears the current event.
*/
protected void clearCurrentEvent()
{
if (currentEvent == null)
{
Log.error ("Failed to clear current event; we don't have an event set!",
new IllegalStateException("stacktrace generated:"));
}
this.currentEvent = null;
}
/**
* Ends a page. During the process, an PageFinished event is generated and
* the state advances to the next page. The Layoutmanager-State is saved and
* the logical page is closed.
* <p>
* While this method is executed, the FinishingPage flag is set to true.
* <p>
* You are not able to print on the logical page after the page is finished.
*
* @throws IllegalStateException if the page end is requested a second time
* @throws ReportProcessingException if the page end is requested while the page
* is restarted.
*/
protected void endPage() throws ReportProcessingException
{
// this can be dangerous if a band spans multiple pages.
// rethink that.
if (isRestartingPage())
{
throw new ReportProcessingException("Report does not proceed (PageEnd during RestartPage)");
}
// cannot finish
if (isFinishingPage())
{
throw new IllegalStateException("Page is currently finishing");
}
setFinishingPage(true);
final ReportEvent cEvent = getCurrentEvent();
clearCurrentEvent();
cEvent.getState().firePageFinishedEvent();
cEvent.getState().nextPage();
setCurrentEvent(cEvent);
setFinishingPage(false);
// save the state after the PageFinished event is fired to
// gather as many information as possible
// log // no cloning save the orignal state
layoutManagerState = saveCurrentState();
setGeneratedPageEmpty(getLogicalPage().isEmpty());
getLogicalPage().close();
}
/**
* Restarts the current page. The logical page is opened again and the
* PageStartedEvent is fired. While this method is executed, the RestartingPage
* flag is set to true.
*/
protected void startPage()
{
if (isPageRestartDone() == true)
{
throw new IllegalStateException("Page already started");
}
final ReportEvent event = getCurrentEvent();
if (event == null)
{
throw new NullPointerException("PageLayouter.startPage(...): state is null.");
}
// remove the old event binding ....
clearCurrentEvent();
setRestartingPage(true);
event.getState().firePageStartedEvent(event.getType());
// restore the saved original event ...
setCurrentEvent(event);
setRestartingPage(false);
setPageRestartDone(true);
}
/**
* Checks whether this page has ended. If this method returns true, no
* printing to the logical page is allowed.
*
* @return true, if the logical page is closed and no printing is allowed
*/
public boolean isPageEnded()
{
return getLogicalPage().isOpen() == 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 abstract boolean isNewPageStarted();
/**
* Save the current state into the LayoutManagerState object. The concrete
* implementation is responsible to save all required information so that the
* printing can be continued after the pagebreak is done.
*
* @return a valid beginTransaction, never null
*/
protected abstract LayoutManagerState saveCurrentState();
/**
* Return the last stored LayoutManager state or null if there is no state
* stored.
* @return the last LayoutManagerState.
*/
public LayoutManagerState getLayoutManagerState()
{
return layoutManagerState;
}
/**
* Restores the layoutmanager state by using this state as new base for
* processing. This state must be a clone of the last report state for
* the previous page or the original last report state - or the processing
* will print stupid things.
*
* @param state the report state.
*
* @throws ReportProcessingException if there is a problem processing the report.
public abstract void restoreSaveState (ReportState state)
throws ReportProcessingException;
*/
/**
* Clear the beginTransaction. This should be called after the beginTransaction has been
* restored.
*/
protected void clearSaveState()
{
layoutManagerState = null;
}
/**
* Return a self-reference. This backdoor is used to extract the current
* PageLayoutManager instance from the DataRow. Please don't use it in your functions,
* it is required for the PageableReportProcessor.
*
* @return this PageLayouter.
*/
public Object getValue()
{
return this;
}
/**
* The dependency level defines the level of execution for this function. Higher dependency
* functions are executed before lower dependency functions. For ordinary functions and
* expressions, the range for dependencies is defined to start from 0 (lowest dependency
* possible) to 2^31 (upper limit of int).
* <p>
* PageLayouter functions override the default behaviour an place them self at depency level -1,
* an so before any userdefined function.
*
* @return the level.
*/
public int getDependencyLevel()
{
return depLevel;
}
/**
* Overrides the depency level. Should be lower than any other function depency.
* @param deplevel the new depency level.
*/
public void setDependencyLevel(final int deplevel)
{
this.depLevel = deplevel;
}
/**
* Returns a clone of the PageLayouter.
* <P>
* Be aware, this does not create a deep copy. If you have complex
* structures contained in objects, you have to overwrite this function.
*
* @return a clone of the function.
*
* @throws CloneNotSupportedException this should never happen.
*/
public Object clone() throws CloneNotSupportedException
{
final PageLayouter l = (PageLayouter) super.clone();
l.currentEvent = null;
return l;
}
/**
* Restores the state.
*
* @param ancestor 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 ancestor)
throws ReportProcessingException
{
final Object state = getLayoutManagerState();
// reset the report finished flag...
//setStartNewPage(false);
setGeneratedPageEmpty(true);
setPageRestartDone(false);
if (state == null)
{
if (ancestor.getCurrentPage() != ReportState.BEFORE_FIRST_PAGE)
{
throw new IllegalStateException("State is null, but this is not the first page."
+ ancestor.getCurrentPage());
}
}
// open the logical page ...
getLogicalPage().open();
}
/**
* Receives notification that a page was canceled by the ReportProcessor.
* This method is called, when a page was removed from the report after
* it was generated.
*
* @param event The event.
*/
public void pageCanceled(final ReportEvent event)
{
// does nothing, we dont care about canceled pages by default..
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -