KickJava   Java API By Example, From Geeks To Geeks.

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


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

49 public class FormatCommandJoinRight extends FormatCommand {
50     int actual_x;
51     
52     {
53         operationType = OperationType.JOIN_RIGHT;
54     }
55     
56     public void executeDeeper() {
57         // 1 Check which bands to treat:
58
Vector JavaDoc used_bands = new Vector JavaDoc();
59         
60         for (Iterator JavaDoc h = this.getSelectedElements().iterator(); h.hasNext(); ) {
61             ReportElement bandRe = (ReportElement) h.next();
62
63             if (!used_bands.contains(bandRe.getBand())) {
64                    used_bands.add( bandRe.getBand());
65             } else {
66                  continue;
67             }
68
69             
70             //Band b = (Band)bands_enum.nextElement();
71
Band b = bandRe.getBand();
72             
73             Vector JavaDoc myElements = new Vector JavaDoc();
74             Enumeration JavaDoc enum2 = this.getSelectedElements().elements();
75             
76             while (enum2.hasMoreElements()) {
77                 ReportElement re = (ReportElement)enum2.nextElement();
78                 if (re.getBand() == b) {
79                     // insert this element in the right position...
80
if (myElements.size() == 0) {
81                         myElements.add(re);
82                     } else {
83                         boolean inserted=false;
84                         for (int i=0; i<myElements.size(); ++i) {
85                             ReportElement re2 = (ReportElement)myElements.elementAt(i);
86                             if (re.getPosition().x > re2.getPosition().x) {
87                                 myElements.insertElementAt(re, i);
88                                 inserted = true;
89                                 break;
90                             }
91                         }
92                         if (!inserted){
93                             myElements.addElement(re);
94                         }
95                         
96                     }
97                 }
98             }
99             
100             // Repositioning elements...
101
ReportElement re = (ReportElement) myElements.elementAt(0);
102             actual_x = re.getPosition().x + re.getWidth();
103             
104             // use myELements instead of jrf.getElements()
105
processElements( myElements.elements() );
106         }
107     }
108     
109     public void modify() {
110         
111         re.setPosition( new Point JavaDoc(actual_x - re.getWidth(), re.getPosition().y) );
112         actual_x -= re.getWidth();
113     }
114     
115 }
116
Popular Tags