📄 reportstate.java
字号:
/**
* Returns the report properties.
*
* @return the report properties.
*/
public ReportProperties getProperties()
{
return reportProperties;
}
/**
* Returns a flag indicating whether this is the 'prepare' run.
* <p>
* This run is used to do repagination, and is only done when the pageformat changes.
*
* @return true, if this is a prepare run of the report engine.
*/
public boolean isPrepareRun()
{
final Boolean bool = (Boolean) getProperty(JFreeReport.REPORT_PREPARERUN_PROPERTY,
Boolean.FALSE);
return bool.booleanValue();
}
/**
* Creates a shallow clone. Handle with care. This is a relativly cheap operation,
* so we have a copy to check whether some progress was made, without having to
* pay for the complete (deep) cloning.
* <p>
* Don't use that function to store/copy a report state for a longer storage time.
* The next few advances may render the reportstate copy invalid.
*
* @param progress a carrier for the result.
*
* @return a progress object of this state.
*/
public ReportStateProgress createStateProgress(ReportStateProgress progress)
{
if (progress == null)
{
progress = new ReportStateProgress();
}
progress.setCurrentDataItem(getCurrentDataItem());
progress.setCurrentGroupIndex(getCurrentGroupIndex());
progress.setCurrentPage(getCurrentPage());
progress.setStateClass(this.getClass());
return progress;
}
/**
* Clones the report state.
*
* @return a clone.
*
* @throws CloneNotSupportedException if there is a cloning problem.
*/
public Object clone() throws CloneNotSupportedException
{
final ReportState result = (ReportState) super.clone();
result.report = (ReportDefinitionImpl) report.clone();
result.dataRow = (DataRowBackend) dataRow.clone();
result.report.getDataRowConnector().setDataRowBackend(result.dataRow);
return result;
}
/**
* This is a helper function used to detect infinite loops on report
* processing. Returns true, if the report did proceed over at least one element.
* <p>
* If this method returns false, we need to bail out of processing the report because there is
* some problem.
*
* @param oldstate the previous state.
*
* @return true if some progress has been made, false otherwise.
*/
public boolean isProceeding(final ReportStateProgress oldstate)
{
// a state is proceeding if it changed its group
if (getCurrentGroupIndex() != oldstate.getCurrentGroupIndex())
{
return true;
}
// a state is proceeding if it changed the current row in the datamodel
if (getCurrentDataItem() > oldstate.getCurrentDataItem())
{
return true;
}
// a state proceeds if it is an other class than the old state
if (this.getClass().equals(oldstate.getStateClass()) == false)
{
// Log.debug (new StateProceedMessage(this, oldstate,
// "State did proceed: In Group: "));
return true;
}
// Log.debug (new StateProceedMessage(this, oldstate,
// "State did not proceed: In Group: "));
return false;
}
// /**
// * LogHelper. The Message is created when the toString() method is called.
// * If logging is disabled, no toString() gets called and no resources are wasted.
// */
// private static class StateProceedMessage
// {
// /** The current state. */
// private ReportState currentState;
//
// /** The old state. */
// private ReportStateProgress oldState;
//
// /** The message. */
// private String message;
//
// /**
// * Creates a new message.
// *
// * @param currentState the current state.
// * @param oldState the old state.
// * @param message the message.
// */
// public StateProceedMessage(final ReportState currentState, final ReportStateProgress oldState,
// final String message)
// {
// this.currentState = currentState;
// this.oldState = oldState;
// this.message = message;
// }
//
// /**
// * Returns a string representation of the object.
// *
// * @return the string.
// */
// public String toString()
// {
// return message + currentState.getCurrentGroupIndex() + ", DataItem: "
// + currentState.getCurrentDataItem() + ",Page: "
// + currentState.getCurrentPage() + " Class: "
// + currentState.getClass() + "\n"
// + "Old State: " + oldState.getCurrentGroupIndex() + ", DataItem: "
// + oldState.getCurrentDataItem() + ",Page: "
// + oldState.getCurrentPage() + " Class: "
// + oldState.getClass() + "\n";
// }
// }
/**
* Advances the current page by one.
*/
public void nextPage()
{
setCurrentPage(getCurrentPage() + 1);
}
/**
* Tests whether this state is a defined starting point for report generation.
*
* @return false (subclasses may override).
*/
public boolean isStart()
{
return false;
}
/**
* Tests whether this state is a defined ending point for report generation.
*
* @return false (subclasses may override).
*/
public boolean isFinish()
{
return false;
}
/**
* Activates the next group by incrementing the current group index. The outer-most group is
* given an index of zero, and this increases for each subgroup that is defined.
*/
public void enterGroup()
{
setCurrentGroupIndex(getCurrentGroupIndex() + 1);
}
/**
* Deactivates the current group by decrementing the current group index.
*/
public void leaveGroup()
{
setCurrentGroupIndex(getCurrentGroupIndex() - 1);
}
/**
* Advances the active data row to the next line.
*/
public void advanceItem()
{
setCurrentItem(getCurrentDataItem() + 1);
getDataRowBackend().setCurrentRow(getCurrentDisplayItem());
}
/**
* Fires a 'report-started' event.
*/
public void fireReportInitializedEvent()
{
getFunctions().reportInitialized(new ReportEvent(this, ReportEvent.REPORT_INITIALIZED));
}
/**
* Fires a 'report-started' event.
*/
public void fireReportStartedEvent()
{
getFunctions().reportStarted(new ReportEvent(this, ReportEvent.REPORT_STARTED));
}
/**
* Fires a 'prepare' event.
*
* @param type the event type of the event that should be prepared.
*/
public void firePrepareEvent(final int type)
{
getFunctions().firePrepareEvent(new ReportEvent(this, (ReportEvent.PREPARE_EVENT | type)));
}
/**
* Fires a 'report-finished' event.
*/
public void fireReportFinishedEvent()
{
getFunctions().reportFinished(new ReportEvent(this, ReportEvent.REPORT_FINISHED));
}
/**
* Fires a 'report-finished' event.
*/
public void fireReportDoneEvent()
{
getFunctions().reportDone(new ReportEvent(this, ReportEvent.REPORT_DONE));
}
/**
* Fires a 'page-started' event.
*
* @param baseEvent the type of the base event which caused the page start to be
* triggered.
*/
public void firePageStartedEvent(final int baseEvent)
{
getFunctions().pageStarted(new ReportEvent(this, ReportEvent.PAGE_STARTED | baseEvent));
}
/**
* Fires a '<code>page-finished</code>' event. The <code>pageFinished(...)</code> method is
* called for every report function.
*/
public void firePageFinishedEvent()
{
getFunctions().pageFinished(new ReportEvent(this, ReportEvent.PAGE_FINISHED));
}
/**
* Fires a '<code>page-canceled</code>' event. The <code>pageCanceled(...)</code> method is
* called for every report function that implements the PageListener interface.
*/
public void firePageCanceledEvent()
{
getFunctions().pageCanceled(new ReportEvent(this, ReportEvent.PAGE_CANCELED));
}
/**
* Fires a '<code>group-started</code>' event. The <code>groupStarted(...)</code> method is
* called for every report function.
*/
public void fireGroupStartedEvent()
{
getFunctions().groupStarted(new ReportEvent(this, ReportEvent.GROUP_STARTED));
}
/**
* Fires a 'group-finished' event.
*/
public void fireGroupFinishedEvent()
{
getFunctions().groupFinished(new ReportEvent(this, ReportEvent.GROUP_FINISHED));
}
/**
* Fires an 'items-started' event.
*/
public void fireItemsStartedEvent()
{
getFunctions().itemsStarted(new ReportEvent(this, ReportEvent.ITEMS_STARTED));
}
/**
* Fires an 'items-finished' event.
*/
public void fireItemsFinishedEvent()
{
getFunctions().itemsFinished(new ReportEvent(this, ReportEvent.ITEMS_FINISHED));
}
/**
* Fires an 'items-advanced' event.
*/
public void fireItemsAdvancedEvent()
{
getFunctions().itemsAdvanced(new ReportEvent(this, ReportEvent.ITEMS_ADVANCED));
}
/**
* Fires an 'layout-complete' event.
*
* @param band the band, that completed layouting.
* @param type the type of the base event fireing the laout complete event.
*/
public void fireLayoutCompleteEvent(final Band band, final int type)
{
getFunctions().layoutComplete(new LayoutEvent(this, band, LayoutEvent.LAYOUT_EVENT | type));
}
/**
* Returns the current function level.
*
* @return the function level.
*/
public int getLevel()
{
return getFunctions().getLevel();
}
/**
* Returns an iterator over the function levels.
*
* @return an iterator.
*/
public Iterator getLevels()
{
return getFunctions().getLevelsDescending();
}
/**
* Returns the ancestor hash code.
*
* @return the ancestor hash code.
*/
public int getAncestorHashcode()
{
return ancestorHashcode;
}
/**
* Sets the ancestor hash code.
*
* @param ancestorHashcode the ancestor hash code.
*/
protected void setAncestorHashcode(final int ancestorHashcode)
{
this.ancestorHashcode = ancestorHashcode;
}
/**
* Returns <code>true</code> if a state is an ancestor of this state, and <code>false</code>
* otherwise.
*
* @param state the state.
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean isAncestor(final ReportState state)
{
return (state.getAncestorHashcode() == getAncestorHashcode());
}
/**
* Returns the errors that occured during the last event dispatching. This list
* gets cleared when the next event gets dispatched.
*
* @return the error list.
*/
public List getErrors()
{
return getFunctions().getErrors();
}
/**
* Checks, whether the last report event caused errors.
*
* @return true, if there were errors recorded, false otherwise.
*/
public boolean isErrorOccured()
{
return getFunctions().hasErrors();
}
/**
* Returns true if this is the last item in the group, and false otherwise.
*
* @param g the group that should be checked.
* @param currentDataRow the current data row.
* @param nextDataRow the next data row, or null, if this is the last datarow.
*
* @return A flag indicating whether or not the current item is the last in its group.
*/
public static boolean isLastItemInGroup
(final Group g, final DataRowBackend currentDataRow, final DataRowBackend nextDataRow)
{
// return true if this is the last row in the model.
if (currentDataRow.isLastRow() || nextDataRow == null)
{
return true;
}
else
{
// compare item and item+1, if any field differs, then item==last in group
final String[] fieldsCached = g.getFieldsArray();
for (int i = 0; i < fieldsCached.length; i++)
{
final String field = fieldsCached[i];
final int column1 = currentDataRow.findColumn(field);
if (column1 == -1)
{
// Log.debug ("Unable to find column in base dataset: " + field);
continue;
}
final int column2 = nextDataRow.findColumn(field);
if (column2 == -1)
{
// Log.debug ("Unable to find column in next dataset: " + field);
continue;
}
final Object item1 = currentDataRow.get(column1);
final Object item2 = nextDataRow.get(column2);
if (ObjectUtils.equal(item1, item2) == false)
{
return true;
}
}
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -