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 39 import java.awt.Point ; 40 import java.util.Iterator ; 41 import java.util.Vector ; 42 43 44 53 public class FormatCommandEqualsSpaceH extends FormatCommand { 54 int actualX; 55 int interDistance; 56 57 Band activeBand ; 58 Vector bands = null; 59 ReportElement fardestElement; 60 61 FormatCommandEqualsSpaceH() { 62 int operationType = OperationType.EQUALS_SPACE_H; 63 } 64 65 boolean preCondition(){ 66 activeBand = (Band) ((ReportElement) this.getSelectedElements().firstElement()).getBand(); 67 int counter = 0; 68 69 for (Iterator i = this.getSelectedElements().iterator(); i.hasNext(); ) { 70 ReportElement re = (ReportElement) i.next(); 71 if (re.getBand() == activeBand) { 72 counter++; 73 } 74 } 75 return ( counter > 1 ); 76 77 } 78 79 void executeDeeper(){ 80 resetEnumeration(); 81 82 preparation(); 83 84 bands = getBands(); 85 86 for (Iterator h = bands.iterator(); h.hasNext(); ) { 87 Band b = (Band) h.next(); 88 Vector bandElements = getBandElements(b); 90 bandElements = sortXY( bandElements.elements()); 91 92 if (bandElements.size()>1) { 93 ReportElement re = (ReportElement) bandElements.firstElement(); 94 actualX = re.getPosition().x + re.getWidth() + interDistance; 95 96 bandElements.removeElement(re); 98 99 if (b == activeBand) { 101 bandElements.remove( bandElements.indexOf(fardestElement) ); 102 } 103 104 processElements(bandElements.elements()); 105 } 106 107 } 108 109 } 110 111 114 void preparation() { 115 119 Band b = activeBand; 120 121 int counter = 0; 122 int usedSize = 0; 123 int minX = 0; 124 int maxX = 0; 125 126 ReportElement re = null; 127 128 for (Iterator i = this.getSelectedElements().iterator(); i.hasNext(); ) { 129 re = (ReportElement) i.next(); 130 131 if( re.getBand() == b){ 132 counter++; 133 usedSize += re.getWidth(); 134 135 if (counter == 1) { 136 minX = re.getPosition().x; 137 maxX = re.getPosition().x + re.getWidth(); 138 fardestElement = re; 139 } else { 140 if (minX > re.getPosition().x ) { 141 minX = re.getPosition().x; 142 } 143 if (maxX < re.getPosition().x + re.getWidth()) { 144 maxX = re.getPosition().x + re.getWidth(); 145 fardestElement = re; } 147 } 148 } 149 } 150 151 interDistance = ( maxX - minX - usedSize )/ (counter - 1); 152 153 } 154 155 public void modify() { 156 re.setPosition(new Point (actualX, re.getPosition().y) ); 157 actualX += re.getWidth() + interDistance; 158 } 159 160 } 161 | Popular Tags |