📄 levelledexpressionlist.java
字号:
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner;
*
* (C) Copyright 2000-2002, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* --------------------------
* LevelledExpressionList.java
* --------------------------
* (C)opyright 2000-2002, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: LevelledExpressionList.java,v 1.18.2.4 2003/08/24 14:18:08 taqua Exp $
*
* Changes
* -------
* 05-Dec-2002 : Updates Javadocs (DG);
*
*/
package com.jrefinery.report.function;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import com.jrefinery.report.DataRow;
import com.jrefinery.report.event.LayoutEvent;
import com.jrefinery.report.event.LayoutListener;
import com.jrefinery.report.event.PageEventListener;
import com.jrefinery.report.event.PrepareEventListener;
import com.jrefinery.report.event.ReportEvent;
import com.jrefinery.report.event.ReportListener;
import com.jrefinery.report.util.LevelList;
import com.jrefinery.report.util.Log;
/**
* A list of expressions/functions and associated levels. This class listens for report events,
* then passes these events on to the expressions and functions in *descending* level order.
*
* @author Thomas Morgner
*/
public final class LevelledExpressionList implements ReportListener,
Cloneable, LayoutListener, PageEventListener
{
/** A list of expressions and associated levels. */
private LevelList expressionList;
/** error list stores the errors that occur during the event dispatching. */
private ArrayList errorList;
/** The level. */
private int level;
/** The levels. */
private int[] levels;
/** The dataRow for all functions. */
private DataRow dataRow;
/**
* DefaultConstructor.
*/
protected LevelledExpressionList()
{
expressionList = new LevelList();
errorList = new ArrayList();
levels = new int[0];
}
/**
* Creates a new list.
*
* @param ec the expressions.
* @param fc the functions.
*/
public LevelledExpressionList(final ExpressionCollection ec, final ExpressionCollection fc)
{
this();
initializeExpressions(ec);
initializeFunctions(fc);
this.levels = buildLevels();
}
private int[] buildLevels ()
{
// copy all levels from the collections to the cache ...
// we assume, that the collections do not change anymore!
final ArrayList al = new ArrayList();
final Iterator it = expressionList.getLevelsDescending();
while (it.hasNext())
{
final Integer level = (Integer) it.next();
al.add(level);
}
int[] levels = new int[al.size()];
for (int i = 0; i < levels.length; i++)
{
final Integer level = (Integer) al.get(i);
levels[i] = level.intValue();
}
return levels;
}
/**
* Receives notification that report generation has started.
* <P>
* The event carries a ReportState.Started state.
* Use this to prepare the report header.
*
* @param event the event.
*/
public void reportStarted(final ReportEvent event)
{
// clearError(); is done in the prepare event ...
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function)
{
final Function f = (Function) e;
try
{
f.reportStarted(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that report generation has started.
* <P>
* The event carries a ReportState.Started state. Use this to initialize the report.
*
* @param event the event.
*/
public void reportInitialized(final ReportEvent event)
{
clearError(); // has no prepare event ...
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
Object next = itLevel.next();
if (next instanceof Expression == false)
{
throw new ClassCastException(next.getClass().toString());
}
final Expression e = (Expression) next;
if (e instanceof Function)
{
final Function f = (Function) e;
try
{
f.reportInitialized(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that report generation has finished (the last record is read and all
* groups are closed).
*
* @param event the event.
*/
public void reportFinished(final ReportEvent event)
{
// clearError(); done in the prepare event ...
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function)
{
final Function f = (Function) e;
try
{
f.reportFinished(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that a new page is being started.
*
* @param event the event.
*/
public void pageStarted(final ReportEvent event)
{
// this is an internal event, don't fire prepare or clear the errors.
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function) // todo 0.8.5 limit event to PageEventListeners
{
final Function f = (Function) e;
try
{
f.pageStarted(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that a new page is being started.
*
* @param event the event.
*/
public void pageCanceled(final ReportEvent event)
{
// this is an internal event, don't fire prepare or clear the errors.
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof PageEventListener)
{
final PageEventListener f = (PageEventListener) e;
try
{
f.pageCanceled(event);
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that a page is completed.
*
* @param event the event.
*/
public void pageFinished(final ReportEvent event)
{
// this is an internal event, don't fire prepare or clear the errors.
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function) // todo 0.8.5 limit event to PageEventListeners
{
final Function f = (Function) e;
try
{
f.pageFinished(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that a new group has started.
* <P>
* The group can be determined by the report state's getCurrentGroup() function.
*
* @param event the event.
*/
public void groupStarted(final ReportEvent event)
{
// clearError(); done in the prepare event ...
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function)
{
final Function f = (Function) e;
try
{
f.groupStarted(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that a group is finished.
* <P>
* The group can be determined by the report state's getCurrentGroup() function.
*
* @param event the event.
*/
public void groupFinished(final ReportEvent event)
{
// clearError(); done in the prepare event ...
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function)
{
final Function f = (Function) e;
try
{
f.groupFinished(event);
}
catch (Exception ex)
{
addError(ex);
}
}
else
{
try
{
if (e.isActive())
{
e.getValue();
}
}
catch (Exception ex)
{
addError(ex);
}
}
}
}
}
/**
* Receives notification that a group of item bands is about to be processed.
* <P>
* The next events will be itemsAdvanced events until the itemsFinished event is raised.
*
* @param event the event.
*/
public void itemsStarted(final ReportEvent event)
{
// clearError(); done in the prepare event ...
for (int i = 0; i < levels.length; i++)
{
final int level = levels[i];
if (level < getLevel())
{
break;
}
final Iterator itLevel = expressionList.getElementsForLevel(level);
while (itLevel.hasNext())
{
final Expression e = (Expression) itLevel.next();
if (e instanceof Function)
{
final Function f = (Function) e;
try
{
f.itemsStarted(event);
}
catch (Exception ex)
{
addError(ex);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -