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: * FormatCommandJoinRight.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:
039: import java.awt.Point;
040: import java.awt.Rectangle;
041: import java.util.Enumeration;
042: import java.util.Iterator;
043: import java.util.Vector;
044:
045: /**
046: *
047: *
048: */
049: public class FormatCommandJoinRight extends FormatCommand {
050: int actual_x;
051:
052: {
053: operationType = OperationType.JOIN_RIGHT;
054: }
055:
056: public void executeDeeper() {
057: // 1 Check which bands to treat:
058: Vector used_bands = new Vector();
059:
060: for (Iterator h = this .getSelectedElements().iterator(); h
061: .hasNext();) {
062: ReportElement bandRe = (ReportElement) h.next();
063:
064: if (!used_bands.contains(bandRe.getBand())) {
065: used_bands.add(bandRe.getBand());
066: } else {
067: continue;
068: }
069:
070: //Band b = (Band)bands_enum.nextElement();
071: Band b = bandRe.getBand();
072:
073: Vector myElements = new Vector();
074: Enumeration enum2 = this .getSelectedElements().elements();
075:
076: while (enum2.hasMoreElements()) {
077: ReportElement re = (ReportElement) enum2.nextElement();
078: if (re.getBand() == b) {
079: // insert this element in the right position...
080: if (myElements.size() == 0) {
081: myElements.add(re);
082: } else {
083: boolean inserted = false;
084: for (int i = 0; i < myElements.size(); ++i) {
085: ReportElement re2 = (ReportElement) myElements
086: .elementAt(i);
087: if (re.getPosition().x > re2.getPosition().x) {
088: myElements.insertElementAt(re, i);
089: inserted = true;
090: break;
091: }
092: }
093: if (!inserted) {
094: myElements.addElement(re);
095: }
096:
097: }
098: }
099: }
100:
101: // Repositioning elements...
102: ReportElement re = (ReportElement) myElements.elementAt(0);
103: actual_x = re.getPosition().x + re.getWidth();
104:
105: // use myELements instead of jrf.getElements()
106: processElements(myElements.elements());
107: }
108: }
109:
110: public void modify() {
111:
112: re.setPosition(new Point(actual_x - re.getWidth(), re
113: .getPosition().y));
114: actual_x -= re.getWidth();
115: }
116:
117: }
|