diff --git a/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElement.java b/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElement.java index 1ea58c57dd..3795d54205 100644 --- a/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElement.java +++ b/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElement.java @@ -192,7 +192,7 @@ protected JRFillElement( printElementOriginator = filler.assignElementId(this); - /* */ + /* */ printWhenGroupChanges = factory.getGroup(element.getPrintWhenGroupChanges()); elementGroup = (JRFillElementGroup)factory.getVisitResult(element.getElementGroup()); @@ -232,7 +232,7 @@ protected JRFillElement(JRFillElement element, JRFillCloneFactory factory) printElementOriginator = element.printElementOriginator; - /* */ + /* */ printWhenGroupChanges = element.printWhenGroupChanges; elementGroup = (JRFillElementGroup) factory.getClone((JRFillElementGroup) element.getElementGroup()); @@ -681,7 +681,7 @@ protected void setCollapsedHeightAbove(int collapsedHeightAbove) this.collapsedHeightAbove = collapsedHeightAbove; } - /** + /** * */ protected int getCollapsedHeightBelow() @@ -839,7 +839,7 @@ protected void evaluateStyle( { throw new JRRuntimeException( - JRFillObjectFactory.EXCEPTION_MESSAGE_KEY_STYLE_NOT_FOUND, + JRFillObjectFactory.EXCEPTION_MESSAGE_KEY_STYLE_NOT_FOUND, new Object[]{styleName} ); } @@ -989,7 +989,7 @@ protected boolean prepare( if ( isPrintWhenExpressionNull() || ( !isPrintWhenExpressionNull() && - isPrintWhenTrue() ) + isPrintWhenTrue() ) ) { setToPrint(true); @@ -1185,23 +1185,14 @@ protected void _moveDependantElements() /** * */ - protected void moveDependantElements() - { + protected void moveDependantElements() { Collection elements = getDependantElements(); - if (elements != null && elements.size() > 0) - { - for (JRFillElement element : elements) - { - int newRelativeY = - getRelativeY() + getStretchHeight() //pusher element current bottom edge - + (element.getY() - (getY() + getHeight())) //design time distance between elements; difference between float element top edge and pusher element bottom edge - - (element.getCollapsedHeightAbove() - getCollapsedHeightAbove()); //difference in collapsedY amount, meaning the elements could only have become closer together due to blank element removal - - if (newRelativeY > element.getRelativeY()) - { + if (elements != null && !elements.isEmpty()) { + int offset = getRelativeY() + getStretchHeight() - getY() - getHeight() + getCollapsedHeightAbove(); + for (JRFillElement element : elements) { + int newRelativeY = offset + element.getY() - element.getCollapsedHeightAbove(); + if (newRelativeY > element.getRelativeY()) { element.setRelativeY(newRelativeY); - - element.moveDependantElements(); } } } @@ -1297,7 +1288,7 @@ public final Object evaluateExpression(JRExpression expression, byte evaluation) * Decides whether the value for this element is repeating. *

* Dynamic elements should call {@link #setValueRepeating(boolean) setValueRepeating(boolean)} on - * {@link #evaluate(byte) evaluate(byte)}. Static elements don't have to do anything, this method + * {@link #evaluate(byte) evaluate(byte)}. Static elements don't have to do anything, this method * will return true by default. * * @return whether the value for this element is repeating @@ -2006,7 +1997,7 @@ public static Integer getBookmarkLevel(Object value) throws JRException { throw new JRException( - EXCEPTION_MESSAGE_KEY_INVALID_BOOKMARK_LEVEL, + EXCEPTION_MESSAGE_KEY_INVALID_BOOKMARK_LEVEL, new Object[] {value} ); } diff --git a/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElementContainer.java b/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElementContainer.java index 9a00a196a6..4c5dbfc498 100644 --- a/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElementContainer.java +++ b/jasperreports/src/net/sf/jasperreports/engine/fill/JRFillElementContainer.java @@ -211,25 +211,25 @@ protected final void _initElements() } } - /* */ + /* */ Collections.sort(sortedElemsList, new JRYComparator()); ySortedElements = new JRFillElement[elements.length]; sortedElemsList.toArray(ySortedElements); - /* */ + /* */ stretchElements = new JRFillElement[stretchElemsList.size()]; stretchElemsList.toArray(stretchElements); - /* */ + /* */ bandBottomElements = new JRFillElement[bandBottomElemsList.size()]; bandBottomElemsList.toArray(bandBottomElements); - /* */ + /* */ removableElements = new JRFillElement[removableElemsList.size()]; removableElemsList.toArray(removableElements); } - /* */ + /* */ setDependentElements(); } @@ -251,7 +251,7 @@ protected final void initElements() JRYComparator yComparator = new JRYComparator(); - /* */ + /* */ ySortedElements = Arrays.copyOf(elements, elements.length); Arrays.sort(ySortedElements, yComparator); @@ -301,60 +301,52 @@ protected final void initElements() } } - /* */ + /* */ stretchElements = new JRFillElement[stretchElemsList.size()]; stretchElemsList.toArray(stretchElements); - /* */ + /* */ bandBottomElements = new JRFillElement[bandBottomElemsList.size()]; bandBottomElemsList.toArray(bandBottomElements); - /* */ + /* */ removableElements = new JRFillElement[removableElemsList.size()]; removableElemsList.toArray(removableElements); } - /* */ + /* */ setDependentElements(); } /** * */ - private void setDependentElements() - { - if (ySortedElements != null && ySortedElements.length > 0) - { - for(int i = 0; i < ySortedElements.length - 1; i++) - { + private void setDependentElements() { + if (ySortedElements != null && ySortedElements.length > 0) { + outerLoop: + for (int i = 0; i < ySortedElements.length - 1; i++) { JRFillElement iElem = ySortedElements[i]; boolean isBreakElem = iElem instanceof JRFillBreak; - - for(int j = i + 1; j < ySortedElements.length; j++) - { + int iElemX = iElem.getX(); + int iElemWidth = iElem.getWidth(); + int iElemRight = iElemX + iElemWidth; + int iElemBottom = iElem.getY() + iElem.getHeight(); + for (int j = i + 1; j < ySortedElements.length; j++) { JRFillElement jElem = ySortedElements[j]; - - int left = Math.min(iElem.getX(), jElem.getX()); - int right = Math.max(iElem.getX() + iElem.getWidth(), jElem.getX() + jElem.getWidth()); - - if ( - ((isBreakElem && jElem.getPositionTypeValue() == PositionTypeEnum.FIX_RELATIVE_TO_TOP) || jElem.getPositionTypeValue() == PositionTypeEnum.FLOAT) && - iElem.getY() + iElem.getHeight() <= jElem.getY() && - iElem.getWidth() + jElem.getWidth() > right - left // FIXME band bottom elements should not have dependent elements - ) - { + int jElemX = jElem.getX(); + int jElemWidth = jElem.getWidth(); + int jElemRight = jElemX + jElemWidth; + PositionTypeEnum positionType = jElem.getPositionTypeValue(); + if (((isBreakElem && positionType == PositionTypeEnum.FIX_RELATIVE_TO_TOP) + || positionType == PositionTypeEnum.FLOAT) + && iElemBottom <= jElem.getY() + && iElemWidth + jElemWidth > Math.max(iElemRight, jElemRight) - Math.min(iElemX, jElemX)) { iElem.addDependantElement(jElem); + if (jElemX <= iElemX && jElemRight >= iElemRight) { + continue outerLoop; + } } } - - /* - if (iElem.getParent().getElementGroup() != null) //parent might be null - { - iElem.setGroupElements( - iElem.getParent().getElementGroup().getElements() - ); - } - */ } } } @@ -538,6 +530,9 @@ protected void prepareElements( { for (JRFillElement element : ySortedElements) { + if (currentOverflowWithElements && isOverflowAllowed && element.getY() > firstY + availableHeight) { + break; + } currentOverflowWithElements = element.prepare( availableHeight + getElementFirstY(element),