📄 abstractbandlayoutmanager.java
字号:
(Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE), parentDim, null
);
Dimension2D prefSize
= (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
if (prefSize != null)
{
prefSize = correctDimension(prefSize, parentDim, null);
}
// the width is the limiting element in the calculation, height is considered
// infinitive ...
maxSize.setSize(Math.min(parentDim.getWidth(), maxSize.getWidth()),
maxSize.getHeight());
final ElementLayoutInformation eli
= new ElementLayoutInformation(new Point2D.Float(), minSize, maxSize, prefSize);
return eli;
}
/**
* Creates layout information for the minimum size.
*
* @param e the element.
* @param containerBounds the bounds of the container.
*
* @return layout information.
*/
protected strictfp ElementLayoutInformation
createLayoutInformationForMinimumSize(final Element e, final Dimension2D containerBounds)
{
// the preferred size of an band can be a relative value. Then this value is
// relative to the container bounds
final Dimension2D minSize = correctDimension((Dimension2D)
e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE), containerBounds, null);
// now take the maximum limit defined for that band into account.
final Dimension2D maxSize = correctDimension((Dimension2D)
e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE), containerBounds, null);
final float maxW = (float) Math.min(maxSize.getWidth(), containerBounds.getWidth());
final float maxH = (float) Math.min(maxSize.getHeight(), containerBounds.getHeight());
// the bounds inherited from the parent, cut down to the maximum size defined
// for this elements.
maxSize.setSize(maxW, maxH);
return new ElementLayoutInformation(new Point2D.Float(), minSize, maxSize);
}
/**
* Creates layout information for the preferred size.
*
* @param e the element.
* @param containerDims the dimensions of the container.
*
* @return layout information.
*/
protected strictfp ElementLayoutInformation
createLayoutInformationForPreferredSize(final Element e, final Dimension2D containerDims)
{
float height = 0;
float width = 0;
// the preferred size of an band can be a relative value. Then this value is
// relative to the container bounds
final Dimension2D prefSize
= (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
final Dimension2D minSize = correctDimension((Dimension2D)
e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE), containerDims, null);
final Dimension2D maxSize = correctDimension((Dimension2D)
e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE), containerDims, null);
// there is a preferredSize defined, don't calculate one...
if (prefSize != null)
{
height = Math.max(height,
correctRelativeValue((float) prefSize.getHeight(), (float) containerDims.getHeight()));
width = Math.max(width,
correctRelativeValue((float) prefSize.getWidth(), (float) containerDims.getWidth()));
}
// check for an minimum size and take that into account
height = (float) Math.max(height, minSize.getHeight());
width = (float) Math.max(width, minSize.getWidth());
// now take the maximum limit defined for that band into account.
final float maxW = (float) Math.min(maxSize.getWidth(), containerDims.getWidth());
final float maxH = (float) Math.min(maxSize.getHeight(), containerDims.getHeight());
// the bounds inherited from the parent, cut down to the maximum size defined
// for this elements.
// maxSize defines the bounds of the parent and the maximum size we defined.
// whatever is smaller gets used ...
maxSize.setSize(maxW, maxH);
// minSize is our defined Size (we use at least regardless whether there is
// some more content ...
minSize.setSize(width, height);
return new ElementLayoutInformation(new Point2D.Float(), minSize, maxSize, prefSize);
}
/**
* Returns <code>true</code> if the element has a static width, and <code>false</code> otherwise.
*
* @param e the element.
*
* @return <code>true</code> or </code>false</code>.
*/
protected boolean isElementStaticWidth(final Element e)
{
Dimension2D size
= (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE);
if (size.getWidth() < 0)
{
return false;
}
size = (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE);
if (size.getWidth() < 0)
{
return false;
}
size = (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
if (size != null)
{
if (size.getWidth() < 0)
{
return false;
}
}
return true;
}
/**
* Returns true if the element has a static height, and false otherwise.
*
* @param e the element.
*
* @return true or false.
*/
protected boolean isElementStaticHeight(final Element e)
{
Dimension2D size
= (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE);
if (size.getHeight() < 0)
{
return false;
}
size = (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.MAXIMUMSIZE);
if (size.getWidth() < 0)
{
return false;
}
size = (Dimension2D) e.getStyle().getStyleProperty(ElementStyleSheet.PREFERREDSIZE);
if (size != null)
{
if (size.getHeight() < 0)
{
return false;
}
}
return true;
}
/**
* Corrects the relative (proportional) values. The values are given
* in the range from -100 (= 100%) to 0 (0%) and are resolved to the
* base values.
*
* @param dim the dimension that should be corrected.
* @param base the base to define the 100% limit.
* @param retval the return value.
*
* @return the corrected dimension.
*/
protected static strictfp Dimension2D correctDimension
(final Dimension2D dim, final Dimension2D base, final Dimension2D retval)
{
float newWidth = (float) dim.getWidth();
if (dim.getWidth() < 0)
{
newWidth = (float) (dim.getWidth() * base.getWidth() / -100);
}
float newHeight = (float) dim.getHeight();
if (dim.getHeight() < 0)
{
newHeight = (float) (dim.getHeight() * base.getHeight() / -100);
}
if (retval == null)
{
return new FloatDimension(newWidth, newHeight);
}
else
{
retval.setSize(newWidth, newHeight);
return retval;
}
}
/**
* Corrects a single value.
* @param dim the dimensions value
* @param base the base value (the containers value)
* @return the corrected value if necessary or the dim value unchanged.
*/
protected static strictfp float correctRelativeValue (final float dim, final float base)
{
if (dim < 0)
{
return (dim * base / -100f);
}
return dim;
}
/**
* Corrects the relative (proportional) values. The values are given
* in the range from -100 (= 100%) to 0 (0%) and are resolved to the
* base values.
*
* @param dim the point that should be corrected.
* @param base the base to define the 100% limit.
* @param retval the return value.
*
* @return the corrected point.
*/
protected static strictfp Point2D correctPoint
(final Point2D dim, final Dimension2D base, final Point2D retval)
{
double x = dim.getX();
double y = dim.getY();
if (x < 0)
{
x = (dim.getX() * base.getWidth() / -100);
}
if (y < 0)
{
y = (dim.getY() * base.getHeight() / -100);
}
if (retval == null)
{
return new Point2D.Float((float) x, (float) y);
}
else
{
retval.setLocation(x, y);
return retval;
}
}
/**
* Aligns the given value to the boundary. This is used to align
* the content to an grid, in case that the output target needs
* all coordinates aligned.
*
* @param value the value.
* @param boundary the boundary.
*
* @return The aligned value.
*/
protected static strictfp float align(final float value, final float boundary)
{
if (boundary == 0)
{
return value;
}
return (float) Math.floor(value / boundary) * boundary;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -