⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 band.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (C) Copyright 2000-2003, by Object Refinery 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.
 *
 * ---------
 * Band.java
 * ---------
 * (C)opyright 2000-2003, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   Thomas Morgner;
 *
 * $Id: Band.java,v 1.11 2003/11/07 18:33:47 taqua Exp $
 *
 * Changes (from 8-Feb-2002)
 * -------------------------
 * 08-Feb-2002 : Updated code to work with latest version of the JCommon class library (DG);
 * 18-Feb-2002 : Changed band height from Number --> float (DG);
 * 05-Mar-2002 : Changed the constructors from public --> protected (DG);
 * 10-May-2002 : Declared Abstract, Removed complex constructors
 * 11-May-2002 : Bug: when adding multiple data fields referencing to the same column in the
 *               data model only the first field was filled with data on populateElements.
 * 20-May-2002 : Changed to support new drawing scheme. The state of the OutputTarget is stored
 *               before any element starts to draw and restored afterwards. This will greatly
 *               reduce sideeffects from changed fonts or paints which are not restored by the
 *               element.
 * 26-May-2002 : Elements are now stored ordered. Updated drawing to reflect new element property
 *               "Visible".
 * 04-Jun-2002 : Public methods throw exceptions on illegal values. Documentation update.
 * 04-Jul-2002 : Serializable and Cloneable
 * 08-Aug-2002 : Band visibility support added. Bands can be hidden using the visible-property
 * 22-Aug-2002 : Height contains now a special value (-100) to adjust the band to fit the available
 *               pageheight.  This is a temporary fix and gets reomved with the next layout update.
 * 31-Aug-2002 : Removed separate stoage of Function and ReportDataSource elements. This stuff was
 *               no longer in use.
 * 05-Sep-2002 : Documentation
 * 13-Sep-2002 : Ran checkstyle and fixed reported issues
 * 05-Nov-2002 : BugFixes I: dynamic feature Q&D fixes
 * 20-Nov-2002 : BugFixed II: more dynamic feature Q&D fixes
 * 02-Dec-2002 : Removed the drawing and changed Band to use StyleSheets. Band is now an Element-
 *               descentend. No more dynamic fixes, as it is not handled here anymore :)
 * 06-Dec-2002 : Documentation update.
 * 03-Jan-2002 : More Javadocs (DG);
 * 23-Jan-2003 : Bug in the clone() method, element parent was not updated.
 * 04-Feb-2003 : fixed composition operations (add element (int idx, Element e))
 */

package org.jfree.report;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.jfree.report.layout.BandLayoutManager;
import org.jfree.report.layout.StaticLayoutManager;
import org.jfree.report.style.BandDefaultStyleSheet;
import org.jfree.report.style.BandStyleSheet;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.style.InvalidStyleSheetCollectionException;
import org.jfree.report.style.StyleSheetCollection;

/**
 * A report band is a collection which can contain other Report-Elements.
 * A band contains a list of elements to be displayed, and represents one section of a
 * report (the report header or footer, the page header or footer, the group header or footer,
 * or the items within a group).
 * <P>
 * The elements in a report band can contain fixed values, field values from the dataset, or
 * function values. The elements are not required to have unique names.
 * <p>
 * This implementation is not synchronized, to take care that you externally synchronize
 * it when using multiple threads.
 * <p>
 * A band's contents should not be modified after the report processing starts,
 * so don't add Elements to the band's contained in or aquired from an report-state.
 * <p>
 * Bands contain a master stylesheet for all element contained in that band. This
 * StyleSheet is registered in the child when the element is added to the band.
 * <p>
 * Bands now extend the Element-class, so it is possible to stack bands into another
 * band. Trying to add a parent of an band as child to the band, will result in an
 * exception.
 *
 * @author David Gilbert
 * @author Thomas Morgner
 */
public class Band extends Element implements Serializable, Cloneable
{
  /**
   * the defined content type for the band. The content type is used when selecting
   * the correct display-method for an element.
   */
  public static final String CONTENT_TYPE = "X-container";

  /** All the elements for this band, stored by name. */
  private ArrayList allElements;

  /** Cached elements. */
  private transient Element[] allElementsCached;

  /** The default style-sheet for the elements contained in the band. */
  private ElementStyleSheet bandDefaults;

  /** The prefix for anonymous bands, bands without an userdefined name. */
  public static final String ANONYMOUS_BAND_PREFIX = "anonymousBand@";

  /**
   * Constructs a new band (initially empty).
   */
  public Band()
  {
    getStyle().addDefaultParent(BandDefaultStyleSheet.getBandDefaultStyle());

    final BandLayoutManager layout = new StaticLayoutManager();
    getStyle().setStyleProperty(BandLayoutManager.LAYOUTMANAGER, layout);

    setName(ANONYMOUS_BAND_PREFIX + super.hashCode());
    allElements = new ArrayList();

    // band style sheets are not accessed by names. Names are important
    // for the xml-parser when stacking the stylesheets together.
    bandDefaults = new BandStyleSheet("band-default");
    bandDefaults.setAllowCaching(true);
  }

  /**
   * Constructs a new band with the given pagebreak attributes. Pagebreak
   * attributes have no effect on subbands.
   * 
   * @param pagebreakAfter defines, whether a pagebreak should be done
   * after that band was printed.
   * @param pagebreakBefore defines, whether a pagebreak should be done
   * before that band gets printed.
   */
  public Band(final boolean pagebreakBefore, final boolean pagebreakAfter)
  {
    this();
    setPagebreakBeforePrint(pagebreakBefore);
    setPagebreakAfterPrint(pagebreakAfter);
  }

  /**
   * Returns the layout manager for the band.
   *
   * @return The layout manager.
   */
  public BandLayoutManager getLayout()
  {
    return (BandLayoutManager) getStyle().getStyleProperty(BandLayoutManager.LAYOUTMANAGER);
  }

  /**
   * Sets the band layout manager.
   *
   * @param layoutManager  the layout manager.
   */
  public void setLayout(final BandLayoutManager layoutManager)
  {
    getStyle().setStyleProperty(BandLayoutManager.LAYOUTMANAGER, layoutManager);
  }

  /**
   * Returns the default style sheet for all children of this band. This style sheet
   * is used to define a set of base (or default) properties for all elements.
   *
   * @return the default style sheet.
   */
  public ElementStyleSheet getBandDefaults()
  {
    return bandDefaults;
  }

  /**
   * Adds a report element to the band.
   *
   * @param element  the element (<code>null</code> not permitted).
   *
   * @throws NullPointerException if the element is <code>null</code> or contains <code>null</code>
   *                              values.
   */
  public synchronized void addElement(final Element element)
  {
    addElement(allElements.size(), element);
  }

  /**
   * Adds a report element to the band. The element will be inserted on the specified position.
   *
   * @param position  the position where to insert the element
   * @param element  the element that should be added
   *
   * @throws NullPointerException if the given element is null
   * @throws IllegalArgumentException if the position is invalid, either negative or
   * greater than the number of elements in this band.
   */
  public synchronized void addElement(final int position, final Element element)
  {
    if (position < 0)
    {
      throw new IllegalArgumentException("Position < 0");
    }
    if (position > allElements.size())
    {
      throw new IllegalArgumentException("Position < 0");
    }
    if (element == null)
    {
      throw new NullPointerException("Band.addElement(...): element is null.");
    }

    // check for component loops ...
    if (element instanceof Band)
    {
      Band band = this;
      while (band != null)
      {
        if (band == element)
        {
          throw new IllegalArgumentException("adding container's parent to itself");
        }
        band = band.getParent();
      }
    }

    // remove the element from its old parent ..
    // this is the default AWT behaviour when adding Components to Container
    if (element.getParent() != null)
    {
      if (element.getParent() == this)
      {
        // already a child, wont add twice ...
        return;
      }

      element.getParent().removeElement(element);
    }

    // add the element, update the childs Parent and the childs stylesheet.
    allElements.add(position, element);
    allElementsCached = null;

    // then add the parents, or the band's parent will be unregistered ..
    element.getStyle().addDefaultParent(getBandDefaults());
    element.setParent(this);

    // first register the element with the collection ...
    if (getStyleSheetCollection() != null)
    {
      element.registerStyleSheetCollection(getStyleSheetCollection());
    }
    invalidateLayout();
  }

  /**
   * Adds a collection of elements to the band.
   *
   * @param elements  the element collection.
   *
   * @throws NullPointerException if the collection given is <code>null</code> or
   * the collection contains <code>null</code> elements.
   */
  public synchronized void addElements(final Collection elements)
  {
    if (elements == null)
    {
      throw new NullPointerException("Band.addElements(...): collection is null.");
    }

    final Iterator iterator = elements.iterator();
    while (iterator.hasNext())
    {
      final Element element = (Element) iterator.next();
      addElement(element);
    }
  }

  /**
   * Returns the first element in the list that is registered by the given name.
   *
   * @param name  the element name.
   *
   * @return the first element with the specified name, or <code>null</code> if there is no
   *         such element.
   *
   * @throws NullPointerException if the given name is null.
   */
  public Element getElement(final String name)
  {
    if (name == null)
    {
      throw new NullPointerException("Band.getElement(...): name is null.");
    }

    final Iterator it = allElements.iterator();
    while (it.hasNext())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -