KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > command > FormatCommandEqualsSpaceV


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * FormatCommandEqualsSpaceV.java
28  *
29  * Created on 9 mei 2005, 21:36
30  *
31  */

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 JavaDoc;
39 import java.util.Enumeration JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.util.Vector JavaDoc;
42
43
44 /**
45  *
46  *
47  */

48 public class FormatCommandEqualsSpaceV extends FormatCommand {
49     int actualY;
50     int interDistance;
51     Band activeBand ;
52     ReportElement fardestElement;
53     Vector JavaDoc 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 JavaDoc 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 JavaDoc h = bands.iterator(); h.hasNext(); ) {
82             Band b = (Band) h.next();
83             Vector JavaDoc 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                 // the highest element in the band doesn't have to be moved
91
bandElements.removeElement(re);
92                 
93                 // remove bottom element as well if this band is the active band
94
if (b == activeBand) {
95                     bandElements.remove( bandElements.indexOf(fardestElement) );
96                 }
97                 
98                 processElements(bandElements.elements());
99             }
100             
101         }
102         
103     }
104     
105     /*
106      * Calculate available height
107      */

108     void preparation() {
109         
110         // calculate the average interdistance of the selected elements in the active Band
111
// The active Band is the band with the first selected element.
112
// The active band is set in the preCondition() method.
113

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 JavaDoc 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; // fardestElement of active Band
141
}
142                 }
143             }
144         }
145         
146         interDistance = ( maxY - minY - usedSize )/ (counter - 1);
147         
148     }
149     
150     public void modify() {
151         re.setPosition(new Point JavaDoc(re.getPosition().x, actualY) );
152         actualY += re.getHeight() + interDistance;
153     }
154     
155 }
156
Popular Tags