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: * CrosstabRowDraggedOperation.java
028: *
029: * Created on 19 giugno 2003, 23.23
030: *
031: */
032:
033: package it.businesslogic.ireport.undo;
034:
035: import it.businesslogic.ireport.gui.event.*;
036: import it.businesslogic.ireport.*;
037: import it.businesslogic.ireport.crosstab.CrosstabCell;
038: import it.businesslogic.ireport.crosstab.CrosstabGroup;
039: import it.businesslogic.ireport.crosstab.gui.CrosstabEditorPanel;
040: import it.businesslogic.ireport.gui.*;
041: import it.businesslogic.ireport.gui.event.CrosstabLayoutChangedEvent;
042: import java.awt.*;
043:
044: import java.util.*;
045:
046: /**
047: * This class handle the band dragged operation.
048: * As all operations, the costructor take the JReportFrame (owner of the element)
049: * The ReportElement is not cloned, this can be a problem if not all undo operations
050: * are correctly logged and handled.
051: * This undo operation contains the band dragged and all elements that was repositioned
052: * after the draging.
053: * It reuse a lot of code of TransformElementsOperation.
054: * @author Giulio Toffoli
055: */
056: public class CrosstabRowDraggedOperation implements
057: it.businesslogic.ireport.UndoOperation {
058: private int delta = 0;
059:
060: private CrosstabEditorPanel editor = null;
061: private CrosstabReportElement crosstabElement;
062: private int draggedLineIndex = 0;
063:
064: /** Creates a new instance of InsertElementOperation */
065: public CrosstabRowDraggedOperation(CrosstabEditorPanel editor,
066: CrosstabReportElement element, int draggedLineIndex,
067: int delta) {
068: this .setEditor(editor);
069: this .setCrosstabElement(element);
070: this .setDraggedLineIndex(draggedLineIndex);
071: this .setDelta(delta);
072: }
073:
074: public void redo() {
075: if (editor == null)
076: return;
077:
078: int readyToDragCellVertically = draggedLineIndex;
079: // Save relative position for all elements...
080: for (int j = 0; j < getCrosstabElement().getElements().size(); ++j) {
081: ReportElement re = (ReportElement) getCrosstabElement()
082: .getElements().elementAt(j);
083: re.setRelativePosition(new Point(re.getPosition().x
084: - re.getCell().getLeft() - 10, re.getPosition().y
085: - re.getCell().getTop() - 10));
086: }
087:
088: // Modify hight of all cell in band readyToDragCellVertically...
089: Vector cells = (Vector) getEditor().getRowBands().elementAt(
090: readyToDragCellVertically - 1);
091: for (int i = 0; i < cells.size(); ++i) {
092: CrosstabCell cell = (CrosstabCell) cells.elementAt(i);
093: cell.setHeight(cell.getHeight() + delta);
094: }
095: for (int j = readyToDragCellVertically; j < getEditor()
096: .getRowBands().size(); ++j) {
097: cells = (Vector) getEditor().getRowBands().elementAt(j);
098: for (int i = 0; i < cells.size(); ++i) {
099: CrosstabCell cell = (CrosstabCell) cells.elementAt(i);
100: if (cell.getTopIndex() >= readyToDragCellVertically) {
101: cell.setTop(cell.getTop() + delta);
102: } else {
103: cell.setHeight(cell.getHeight() + delta);
104: }
105: }
106: }
107:
108: // Adjust size value of all groups...
109: for (int i = 0; i < getCrosstabElement().getColumnGroups()
110: .size(); ++i) {
111: CrosstabGroup group = (CrosstabGroup) getCrosstabElement()
112: .getColumnGroups().elementAt(i);
113: group.setSize(group.getHeaderCell().getHeight());
114: }
115:
116: // Adjust all elements position with new cell positions...
117: for (int j = 0; j < getCrosstabElement().getElements().size(); ++j) {
118: ReportElement re = (ReportElement) getCrosstabElement()
119: .getElements().elementAt(j);
120: re.getPosition().x = re.getRelativePosition().x
121: + re.getCell().getLeft() + 10;
122: re.getPosition().y = re.getRelativePosition().y
123: + re.getCell().getTop() + 10;
124:
125: re.setPosition(re.position);
126: re.trasform(new java.awt.Point(0, 0),
127: TransformationType.TRANSFORMATION_RESIZE_SE);
128: }
129:
130: for (int i = readyToDragCellVertically; i < getEditor()
131: .getRows().size(); ++i) {
132: int rowPosition = ((Integer) getEditor().getRows().get(i))
133: .intValue()
134: + delta;
135: getEditor().getRows().set(i, new Integer(rowPosition));
136: }
137:
138: MainFrame.getMainInstance().getActiveReportFrame()
139: .setIsDocDirty(true);
140: getCrosstabElement()
141: .fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(
142: new CrosstabLayoutChangedEvent(this , this
143: .getCrosstabElement()));
144: }
145:
146: public void undo() {
147: if (editor == null)
148: return;
149:
150: delta *= -1;
151:
152: this .redo();
153:
154: delta *= -1;
155:
156: }
157:
158: public String toString() {
159: return "row resize";
160: }
161:
162: public int getDelta() {
163: return delta;
164: }
165:
166: public void setDelta(int delta) {
167: this .delta = delta;
168: }
169:
170: public int getDraggedLineIndex() {
171: return draggedLineIndex;
172: }
173:
174: public void setDraggedLineIndex(int draggedLineIndex) {
175: this .draggedLineIndex = draggedLineIndex;
176: }
177:
178: public CrosstabReportElement getCrosstabElement() {
179: return crosstabElement;
180: }
181:
182: public void setCrosstabElement(CrosstabReportElement crosstabElement) {
183: this .crosstabElement = crosstabElement;
184: }
185:
186: public CrosstabEditorPanel getEditor() {
187: return editor;
188: }
189:
190: public void setEditor(CrosstabEditorPanel editor) {
191: this.editor = editor;
192: }
193:
194: }
|