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

📄 abstractbandlayoutmanager.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 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.
 *
 * ------------------------------
 * AbstractBandLayoutManager.java
 * ------------------------------
 * (C)opyright 2002, 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: AbstractBandLayoutManager.java,v 1.14 2003/11/12 22:40:03 taqua Exp $
 *
 * Changes
 * -------
 * 24.03.2003 : Initial version
 */
package org.jfree.report.layout;

import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import org.jfree.report.Band;
import org.jfree.report.Element;
import org.jfree.report.content.Content;
import org.jfree.report.content.ContentFactory;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.util.ElementLayoutInformation;
import org.jfree.report.util.Log;
import org.jfree.ui.FloatDimension;

/**
 * An abstract band layout manager.
 *
 * @author Thomas Morgner.
 */
public abstract class AbstractBandLayoutManager implements BandLayoutManager
{
  /**
   * Default constructor.
   */
  protected AbstractBandLayoutManager()
  {
  }

  /**
   * Returns the minimum size for an element.
   *
   * @param e  the element.
   * @param containerBounds the bounds of the elements parents.
   * @param retval a dimension object that should be filled, or null,
   * if a new object should be created
   * @param support the layout support used to compute sizes.
   *
   * @return the minimum size.
   */
  protected strictfp Dimension2D computeMinimumSize
    (final Element e, final Dimension2D containerBounds, 
     Dimension2D retval, final LayoutSupport support)
  {
    if (containerBounds.getWidth() < 0 || containerBounds.getHeight() < 0)
    {
      throw new IllegalArgumentException("Container bounds must be positive");
    }

    // if this is a band, then try to calculate the min-size
    if (e instanceof Band)
    {
      final BandLayoutManager lm = BandLayoutManagerUtil.getLayoutManager(e);
      retval = lm.minimumLayoutSize((Band) e, containerBounds, support);
    }
    else
    {
      // return the minimum size. The minimum size is always defined.
      final Dimension2D dim = (Dimension2D)
          e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE);
      retval = correctDimension(dim, containerBounds, retval);
    }

    final Dimension2D maxSize = correctDimension((Dimension2D)
        e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE), containerBounds, null);

    maxSize.setSize(Math.min(containerBounds.getWidth(), maxSize.getWidth()),
        Math.min(containerBounds.getHeight(), maxSize.getHeight()));

    // docmark: minimum size also checks the dynamic height.
    if (e.getStyle().getBooleanStyleProperty(ElementStyleSheet.DYNAMIC_HEIGHT))
    {
      retval = getElementContentBounds(retval, e, maxSize, support);
    }

    retval.setSize(Math.min(retval.getWidth(), maxSize.getWidth()),
        Math.min(retval.getHeight(), maxSize.getHeight()));

    //Log.debug ("-- calculate MinimumSize: " + retval);
    // layouting has failed, if negative values are returned ... !
    if (retval.getWidth() < 0 || retval.getHeight() < 0)
    {
      throw new IllegalStateException
        ("Layouting failed, computeMinimumSize returned negative values.");
    }
    return retval;
  }

  /**
   * Calculates the preferred size of an element.
   *
   * @param e  the element.
   * @param containerBounds  the bounds of the element's container.
   * @param retval a dimension object that should be filled, or null,
   * if a new object should be created
   * @param support the layout support used to compute sizes.
   *
   * @return the preferred size of the element.
   */
  protected strictfp Dimension2D computePreferredSize
      (final Element e, final Dimension2D containerBounds,
       Dimension2D retval, final LayoutSupport support)
  {
    if (containerBounds.getWidth() < 0 || containerBounds.getHeight() < 0)
    {
      throw new IllegalArgumentException("Container bounds must be positive");
    }
    //Log.debug (">> calculate PreferredSize: " + e);
    //Log.debug (">> calculate PreferredSize: " + containerBounds);

    // if e is a band, then try to calculate the preferred size
    if (e instanceof Band)
    {
      final BandLayoutManager lm = BandLayoutManagerUtil.getLayoutManager(e);
      retval = lm.preferredLayoutSize((Band) e, containerBounds, support);
    }
    else
    {
      // if prefsize is defined, return it. The preferred size is optional,
      // so it may be required to also query the minimum size.
      final Dimension2D d = (Dimension2D)
          e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
      if (d != null)
      {
        retval = correctDimension(d, containerBounds, retval);
      }
      else
      {
        // return the absolute dimension as fallback
        retval = correctDimension((Dimension2D)
            e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE), containerBounds, retval);
      }
    }

    // now apply the maximum bounds to the retval.
    // the maximum bounds are defined by the element and the elements container.
    final Dimension2D maxSize = correctDimension((Dimension2D)
        e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE), containerBounds, null);

    maxSize.setSize(Math.min(containerBounds.getWidth(), maxSize.getWidth()),
        Math.min(containerBounds.getHeight(), maxSize.getHeight()));

    if (e.getStyle().getBooleanStyleProperty(ElementStyleSheet.DYNAMIC_HEIGHT))
    {
      retval = getElementContentBounds(retval, e, maxSize, support);
    }

    retval.setSize(Math.min(retval.getWidth(), maxSize.getWidth()),
        Math.min(retval.getHeight(), maxSize.getHeight()));

    //Log.debug ("-- calculate PreferredSize: " + retval);
    // layouting has failed, if negative values are returned ... !
    if (retval.getWidth() < 0 || retval.getHeight() < 0)
    {
      throw new IllegalStateException(
          "Layouting failed, computePreferredSize returns negative values."
      );
    }

    return retval;
  }

  /**
   * Calculates the size of an element by creating the content for this element and
   * then trying to layout that content. This operation is performed for all
   * "dynamic" elements.
   * <p>
   * Calculation rules: Take the width of given bounds to calculate a height based
   * on the content. Then cut the content to a maybe defined max-value.
   *
   * @param bounds  the bounds of the element calculated so far. These bounds will be modified
   * and returned.
   * @param e  the element.
   * @param conBounds  the bounds of the surrounding container.
   * @param support the layout support used to compute sizes.
   *
   * @return the new elements dimension.
   */
  protected strictfp Dimension2D getElementContentBounds
      (final Dimension2D bounds, final Element e,
       final Dimension2D conBounds, final LayoutSupport support)
  {
    // check if we can handle the content before doing anything...
    // ...
    final ContentFactory contentFactory = support.getContentFactory();
    if (contentFactory.canHandleContent(e.getContentType()) == false)
    {
      return bounds;
    }

    final ElementLayoutInformation eli = createLayoutInfoForDynamics(e, conBounds);
    final Dimension2D minSize = eli.getMinimumSize();
    try
    {

      final Content content = contentFactory.createContentForElement(e, eli, support);
      if (content == null)
      {
        bounds.setSize(0,0);
        return bounds;
      }
      final Rectangle2D contentBounds = content.getMinimumContentSize();
      if (contentBounds == null)
      {
        bounds.setSize(0,0);
        return bounds;
      }
      bounds.setSize(Math.max(minSize.getWidth(), contentBounds.getWidth()),
                     Math.max(minSize.getHeight(), contentBounds.getHeight()));
      return bounds;
    }
    catch (Exception ex)
    {
      Log.info("Exception while layouting dynamic content: ", ex);
      bounds.setSize(Math.max(minSize.getWidth(), bounds.getWidth()),
                     Math.max(minSize.getHeight(), bounds.getHeight()));
      return bounds;
    }
  }

  /**
   * Creates a layout information object for a DynamicElement content calculation.
   * The maximum height is only limited by the elements max height, not by the parent.
   *
   * @param e the element for that the layout should be done.
   * @param parentDim the dimensions for the parent of the element
   * @return the created layout information.
   */
  protected strictfp ElementLayoutInformation createLayoutInfoForDynamics
      (final Element e, final Dimension2D parentDim)
  {
    final Dimension2D maxSize = correctDimension(
        (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE), parentDim, null
    );
    final Dimension2D minSize = correctDimension(

⌨️ 快捷键说明

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