📄 abstractbandlayoutmanager.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.
*
* ------------------------------
* 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.15.2.1 2003/08/24 14:18:12 taqua Exp $
*
* Changes
* -------
* 24.03.2003 : Initial version
*/
package com.jrefinery.report.targets.base.bandlayout;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import com.jrefinery.report.Band;
import com.jrefinery.report.Element;
import com.jrefinery.report.targets.base.ElementLayoutInformation;
import com.jrefinery.report.targets.base.content.Content;
import com.jrefinery.report.targets.base.content.ContentFactory;
import com.jrefinery.report.targets.base.layout.LayoutSupport;
import com.jrefinery.report.targets.style.ElementStyleSheet;
import com.jrefinery.report.util.Log;
import org.jfree.ui.FloatDimension;
/**
* An abstract band layout manager.
*
* @author Thomas Morgner.
*/
public abstract class AbstractBandLayoutManager implements BandLayoutManager
{
/** Layout support. */
private LayoutSupport support;
/**
* Default constructor.
*/
protected AbstractBandLayoutManager()
{
}
/**
* Returns the minimum size for an element.
*
* @param e the element.
* @param containerBounds the bounds of the elements parents.
*
* @return the minimum size.
*/
protected Dimension2D getMinimumSize(final Element e, final Dimension2D containerBounds)
{
Dimension2D retval;
// if this is a band, then try to calculate the min-size
if (e instanceof Band)
{
final BandLayoutManager lm = BandLayoutManagerUtil.getLayoutManager(e, getLayoutSupport());
retval = lm.minimumLayoutSize((Band) e, containerBounds);
}
else
{
// return the minimum size as fallback
final Dimension2D dim = (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE);
retval = correctDimension(dim, containerBounds, null);
}
// docmark: minimum size also checks the dynamic height.
if (e.getStyle().getBooleanStyleProperty(ElementStyleSheet.DYNAMIC_HEIGHT))
{
retval = getElementContentBounds(retval, e, containerBounds);
}
// 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()));
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, getMinimumSize 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.
*
* @return the preferred size of the element.
*/
protected Dimension2D getPreferredSize(final Element e, final Dimension2D containerBounds)
{
Dimension2D retval;
//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, getLayoutSupport());
retval = lm.preferredLayoutSize((Band) e, containerBounds);
}
else
{
// if prefsize is defined, return it
final Dimension2D d = (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
if (d != null)
{
retval = correctDimension(d, containerBounds, null);
}
else
{
// return the absolute dimension as fallback
retval = correctDimension((Dimension2D)
e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE), containerBounds, null);
}
}
if (e.getStyle().getBooleanStyleProperty(ElementStyleSheet.DYNAMIC_HEIGHT))
{
retval = getElementContentBounds(retval, e, containerBounds);
}
// 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()));
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, getPreferredSize returned 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.
* todo redefine the context creation process, height or width can be dynamic
*
* @param bounds the bounds of the element calculated so far.
* @param e the element.
* @param conBounds the bounds of the surrounding container.
*
* @return the new elements dimension.
*/
protected Dimension2D getElementContentBounds(final Dimension2D bounds,
final Element e,
final Dimension2D conBounds)
{
// check if we can handle the content before doing anything...
// ...
// bounds can be null, if no absolute dim was defined.
final ContentFactory contentFactory = getLayoutSupport().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, getLayoutSupport());
if (content == null)
{
return new FloatDimension();
}
final Rectangle2D contentBounds = content.getMinimumContentSize();
if (contentBounds == null)
{
return new FloatDimension();
}
return new FloatDimension((float) Math.max(minSize.getWidth(), contentBounds.getWidth()),
(float) Math.max(minSize.getHeight(), contentBounds.getHeight()));
}
catch (Exception ex)
{
Log.debug("Exception: ", ex);
return new FloatDimension((float) Math.max(minSize.getWidth(), bounds.getWidth()),
(float) Math.max(minSize.getHeight(), bounds.getHeight()));
}
}
/**
* 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 ElementLayoutInformation createLayoutInfoForDynamics(final Element e, final Dimension2D parentDim)
{
final Dimension2D maxSize = correctDimension(
(Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE), parentDim, null
);
final Dimension2D minSize = correctDimension(
(Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE), parentDim, null
);
Dimension2D prefSize
= (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
if (prefSize != null)
{
prefSize = correctDimension(prefSize, parentDim, null);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -