1 32 33 package it.businesslogic.ireport.gui.command; 34 35 import it.businesslogic.ireport.Band; 36 import it.businesslogic.ireport.OperationType; 37 import it.businesslogic.ireport.ReportElement; 38 import java.awt.Point ; 39 import java.util.Enumeration ; 40 import java.util.Iterator ; 41 import java.util.Vector ; 42 43 44 48 public class FormatCommandEqualsSpaceV extends FormatCommand { 49 int actualY; 50 int interDistance; 51 Band activeBand ; 52 ReportElement fardestElement; 53 Vector bands = null; 54 55 { 56 operationType = OperationType.EQUALS_SPACE_V; 57 } 58 59 boolean preCondition(){ 60 activeBand = (Band) ((ReportElement) this.getSelectedElements().firstElement()).getBand(); 61 int counter = 0; 62 63 for (Iterator i = this.getSelectedElements().iterator(); i.hasNext(); ) { 64 ReportElement re = (ReportElement) i.next(); 65 if (re.getBand() == activeBand) { 66 counter++; 67 } 68 } 69 return ( counter > 1 ); 70 71 } 72 73 void executeDeeper(){ 74 75 resetEnumeration(); 76 77 preparation(); 78 79 bands = getBands(); 80 81 for (Iterator h = bands.iterator(); h.hasNext(); ) { 82 Band b = (Band) h.next(); 83 Vector bandElements = getBandElements(b); 84 bandElements = sortYX( bandElements.elements()); 85 86 if (bandElements.size()>1) { 87 ReportElement re = (ReportElement) bandElements.firstElement(); 88 actualY = re.getPosition().y + re.getHeight() + interDistance; 89 90 bandElements.removeElement(re); 92 93 if (b == activeBand) { 95 bandElements.remove( bandElements.indexOf(fardestElement) ); 96 } 97 98 processElements(bandElements.elements()); 99 } 100 101 } 102 103 } 104 105 108 void preparation() { 109 110 114 Band b = activeBand; 115 116 int counter = 0; 117 int usedSize = 0; 118 int minY = 0; 119 int maxY = 0; 120 121 ReportElement re = null; 122 123 for (Iterator i = this.getSelectedElements().iterator(); i.hasNext(); ) { 124 re = (ReportElement) i.next(); 125 126 if( re.getBand() == b){ 127 counter++; 128 usedSize += re.getHeight(); 129 130 if (counter == 1) { 131 minY = re.getPosition().y; 132 maxY = re.getPosition().y + re.getHeight(); 133 fardestElement = re; 134 } else { 135 if (minY > re.getPosition().y ) { 136 minY = re.getPosition().y; 137 } 138 if (maxY < re.getPosition().y + re.getHeight()) { 139 maxY = re.getPosition().y + re.getHeight(); 140 fardestElement = re; } 142 } 143 } 144 } 145 146 interDistance = ( maxY - minY - usedSize )/ (counter - 1); 147 148 } 149 150 public void modify() { 151 re.setPosition(new Point (re.getPosition().x, actualY) ); 152 actualY += re.getHeight() + interDistance; 153 } 154 155 } 156 | Popular Tags |