📄 group.java
字号:
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner;
*
* (C) Copyright 2000-2003, 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.
*
* ----------
* Group.java
* ----------
* (C)opyright 2000-2003, by Simba Management Limited and Contributors.
*
* Original Author: David Gilbert (for Simba Management Limited);
* Contributor(s): Thomas Morgner;
*
* $Id: Group.java,v 1.30.2.2 2003/08/24 14:17:59 taqua Exp $
*
* Changes (from 8-Feb-2002)
* -------------------------
* 08-Feb-2002 : Updated code to work with latest version of the JCommon class library (DG);
* 11-May-2002 : Fields are now in a list, order is important for comparision. The field list
* not modifyable outside this list. Header and footer are no longer allowed to
* contain null values. Is lastItemInGroup returns always true, if the end of the
* data had been reached.
* 03-Jul-2002 : Serializable and cloneable, replaces own ReadOnlyList with standard implementation
* 26-Jul-2002 : Introduced DataRowBackend as replacement for the raw data access
* 05-Sep-2002 : Documentation
* 09-Sep-2002 : Removed log messages
* 13-Sep-2002 : Ran checkstyle against the source
* 02-Dec-2002 : Removed To-Do item, caching of field-name to index pos is done.
* 06-Dec-2002 : Updated changelog, removed Iterator-usage for performance reasons
* 10-Dec-2002 : Updated Javadocs (DG);
*
*/
package com.jrefinery.report;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import com.jrefinery.report.targets.style.StyleSheetCollection;
import com.jrefinery.report.targets.style.StyleSheetCollectionHelper;
/**
* A report group. Reports can contain any number of (nested) groups.
* The order of the fields is important. If the group does not contain
* any fields, the group spans the whole report from the first to the last
* row.
* <p>
* The group's field list should not be modified after the group was added
* to the group list, or the results are undefined.
*
* @see GroupList
*
* @author David Gilbert
* @author Thomas Morgner
*/
public class Group implements Serializable, Cloneable, Comparable
{
/**
* Internal helper class to handle the style sheet collection properly.
*/
private static class GroupStyleSheetCollectionHelper extends StyleSheetCollectionHelper
{
/** The group for which we handle the stylesheet collection. */
private Group group;
/**
* Creates a new helper for the given group.
*
* @param group the group whose stylesheet collection should be managed.
*/
public GroupStyleSheetCollectionHelper(final Group group)
{
this.group = group;
}
/**
* Handles the stylesheet collection registration for the group and
* all group bands.
*/
protected void handleRegisterStyleSheetCollection()
{
group.getFooter().registerStyleSheetCollection(this.getStyleSheetCollection());
group.getHeader().registerStyleSheetCollection(this.getStyleSheetCollection());
}
/**
* Handles the stylesheet collection unregistration for the group and
* all group bands.
*/
protected void handleUnregisterStyleSheetCollection()
{
group.getFooter().unregisterStyleSheetCollection(this.getStyleSheetCollection());
group.getHeader().unregisterStyleSheetCollection(this.getStyleSheetCollection());
}
}
/** The name of the group. */
private String name;
/** The fields that define the group (can be empty). */
private TreeSet fields;
/** Cached fields. */
private transient String[] fieldsCached;
/** The group header (optional). */
private GroupHeader header;
/** The group footer (optional). */
private GroupFooter footer;
/** The helper implementation that manages the stylesheet collection. */
private GroupStyleSheetCollectionHelper styleSheetCollectionHelper;
/**
* Constructs a group with no fields, and an empty header and footer.
*/
public Group()
{
name = "anonymousGroup@" + super.hashCode();
fields = new TreeSet();
this.styleSheetCollectionHelper = new GroupStyleSheetCollectionHelper(this);
this.footer = new GroupFooter();
this.header = new GroupHeader();
}
/**
* Defines the name for this group. The name must not be empty and must be unique within
* the GroupList.
*
* @param name the group name (null not permitted).
*/
public void setName(final String name)
{
if (name == null)
{
throw new NullPointerException("Name must not be null");
}
this.name = name;
}
/**
* Returns the name of the group.
*
* @return the group name.
*/
public String getName()
{
return this.name;
}
/**
* Returns the group header.
* <P>
* The group header is a report band that contains elements that should be printed at the
* start of a group.
*
* @return the group header.
*/
public GroupHeader getHeader()
{
return header;
}
/**
* Sets the header for the group.
*
* @param header the header (null not permitted).
*
* @throws NullPointerException if the given header is null
*/
public void setHeader(final GroupHeader header)
{
if (header == null)
{
throw new NullPointerException("Header must not be null");
}
if (getStyleSheetCollection() != null)
{
this.header.unregisterStyleSheetCollection(getStyleSheetCollection());
}
this.header = header;
if (getStyleSheetCollection() != null)
{
this.header.registerStyleSheetCollection(getStyleSheetCollection());
}
}
/**
* Returns the group footer.
*
* @return the footer.
*/
public GroupFooter getFooter()
{
return footer;
}
/**
* Sets the footer for the group.
*
* @param footer the footer (null not permitted).
* @throws NullPointerException if the given footer is null.
*/
public void setFooter(final GroupFooter footer)
{
if (footer == null)
{
throw new NullPointerException("The footer must not be null");
}
if (getStyleSheetCollection() != null)
{
this.footer.unregisterStyleSheetCollection(getStyleSheetCollection());
}
this.footer = footer;
if (getStyleSheetCollection() != null)
{
this.footer.registerStyleSheetCollection(getStyleSheetCollection());
}
}
/**
* Sets the fields for this group. The given list must contain Strings defining the
* needed fields from the DataRow. Don't reference Function-Fields here, functions are
* not supported in th groupfield definition.
*
* @param c the list containing strings.
*
* @throws NullPointerException if the given list is null or the list contains null-values.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -