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: * CrosstabColumnDraggedOperation.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 CrosstabColumnDraggedOperation 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 CrosstabColumnDraggedOperation(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 readyToDragCellHorizontally = draggedLineIndex;
079: // Save relative position for all elements...
080: // Save relative position for all elements...
081: for (int j = 0; j < getCrosstabElement().getElements().size(); ++j) {
082: ReportElement re = (ReportElement) getCrosstabElement()
083: .getElements().elementAt(j);
084: re.setRelativePosition(new Point(re.getPosition().x
085: - re.getCell().getLeft() - 10, re.getPosition().y
086: - re.getCell().getTop() - 10));
087: }
088:
089: // Modify hight of all cell in band readyToDragCellVertically...
090: Vector cells = (Vector) getEditor().getColumnBands().elementAt(
091: readyToDragCellHorizontally - 1);
092: for (int i = 0; i < cells.size(); ++i) {
093: CrosstabCell cell = (CrosstabCell) cells.elementAt(i);
094: cell.setWidth(cell.getWidth() + delta);
095: }
096: for (int j = readyToDragCellHorizontally; j < getEditor()
097: .getRowBands().size(); ++j) {
098: cells = (Vector) getEditor().getColumnBands().elementAt(j);
099: for (int i = 0; i < cells.size(); ++i) {
100: CrosstabCell cell = (CrosstabCell) cells.elementAt(i);
101: if (cell.getLeftIndex() >= readyToDragCellHorizontally) {
102: cell.setLeft(cell.getLeft() + delta);
103: } else {
104: cell.setWidth(cell.getWidth() + delta);
105: }
106: }
107: }
108:
109: // Adjust size value of all groups...
110: for (int i = 0; i < getCrosstabElement().getRowGroups().size(); ++i) {
111: CrosstabGroup group = (CrosstabGroup) getCrosstabElement()
112: .getRowGroups().elementAt(i);
113: group.setSize(group.getHeaderCell().getWidth());
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 = readyToDragCellHorizontally; i < getEditor()
131: .getColumns().size(); ++i) {
132: int rowPosition = ((Integer) getEditor().getColumns()
133: .get(i)).intValue()
134: + delta;
135: getEditor().getColumns().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: public String toString() {
158: return "column resize";
159: }
160:
161: public int getDelta() {
162: return delta;
163: }
164:
165: public void setDelta(int delta) {
166: this .delta = delta;
167: }
168:
169: public int getDraggedLineIndex() {
170: return draggedLineIndex;
171: }
172:
173: public void setDraggedLineIndex(int draggedLineIndex) {
174: this .draggedLineIndex = draggedLineIndex;
175: }
176:
177: public CrosstabReportElement getCrosstabElement() {
178: return crosstabElement;
179: }
180:
181: public void setCrosstabElement(CrosstabReportElement crosstabElement) {
182: this .crosstabElement = crosstabElement;
183: }
184:
185: public CrosstabEditorPanel getEditor() {
186: return editor;
187: }
188:
189: public void setEditor(CrosstabEditorPanel editor) {
190: this.editor = editor;
191: }
192:
193: }
|