001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * FormatCommandEqualsSpaceV.java
028: *
029: * Created on 9 mei 2005, 21:36
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.command;
034:
035: import it.businesslogic.ireport.Band;
036: import it.businesslogic.ireport.OperationType;
037: import it.businesslogic.ireport.ReportElement;
038: import java.awt.Point;
039: import java.util.Enumeration;
040: import java.util.Iterator;
041: import java.util.Vector;
042:
043: /**
044: *
045: *
046: */
047: public class FormatCommandEqualsSpaceV extends FormatCommand {
048: int actualY;
049: int interDistance;
050: Band activeBand;
051: ReportElement fardestElement;
052: Vector bands = null;
053:
054: {
055: operationType = OperationType.EQUALS_SPACE_V;
056: }
057:
058: boolean preCondition() {
059: activeBand = (Band) ((ReportElement) this .getSelectedElements()
060: .firstElement()).getBand();
061: int counter = 0;
062:
063: for (Iterator i = this .getSelectedElements().iterator(); i
064: .hasNext();) {
065: ReportElement re = (ReportElement) i.next();
066: if (re.getBand() == activeBand) {
067: counter++;
068: }
069: }
070: return (counter > 1);
071:
072: }
073:
074: void executeDeeper() {
075:
076: resetEnumeration();
077:
078: preparation();
079:
080: bands = getBands();
081:
082: for (Iterator h = bands.iterator(); h.hasNext();) {
083: Band b = (Band) h.next();
084: Vector bandElements = getBandElements(b);
085: bandElements = sortYX(bandElements.elements());
086:
087: if (bandElements.size() > 1) {
088: ReportElement re = (ReportElement) bandElements
089: .firstElement();
090: actualY = re.getPosition().y + re.getHeight()
091: + interDistance;
092:
093: // the highest element in the band doesn't have to be moved
094: bandElements.removeElement(re);
095:
096: // remove bottom element as well if this band is the active band
097: if (b == activeBand) {
098: bandElements.remove(bandElements
099: .indexOf(fardestElement));
100: }
101:
102: processElements(bandElements.elements());
103: }
104:
105: }
106:
107: }
108:
109: /*
110: * Calculate available height
111: */
112: void preparation() {
113:
114: // calculate the average interdistance of the selected elements in the active Band
115: // The active Band is the band with the first selected element.
116: // The active band is set in the preCondition() method.
117:
118: Band b = activeBand;
119:
120: int counter = 0;
121: int usedSize = 0;
122: int minY = 0;
123: int maxY = 0;
124:
125: ReportElement re = null;
126:
127: for (Iterator i = this .getSelectedElements().iterator(); i
128: .hasNext();) {
129: re = (ReportElement) i.next();
130:
131: if (re.getBand() == b) {
132: counter++;
133: usedSize += re.getHeight();
134:
135: if (counter == 1) {
136: minY = re.getPosition().y;
137: maxY = re.getPosition().y + re.getHeight();
138: fardestElement = re;
139: } else {
140: if (minY > re.getPosition().y) {
141: minY = re.getPosition().y;
142: }
143: if (maxY < re.getPosition().y + re.getHeight()) {
144: maxY = re.getPosition().y + re.getHeight();
145: fardestElement = re; // fardestElement of active Band
146: }
147: }
148: }
149: }
150:
151: interDistance = (maxY - minY - usedSize) / (counter - 1);
152:
153: }
154:
155: public void modify() {
156: re.setPosition(new Point(re.getPosition().x, actualY));
157: actualY += re.getHeight() + interDistance;
158: }
159:
160: }
|