KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > undo > CrosstabRowDraggedOperation


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  * CrosstabRowDraggedOperation.java
28  *
29  * Created on 19 giugno 2003, 23.23
30  *
31  */

32
33 package it.businesslogic.ireport.undo;
34 import it.businesslogic.ireport.gui.event.*;
35 import it.businesslogic.ireport.*;
36 import it.businesslogic.ireport.crosstab.CrosstabCell;
37 import it.businesslogic.ireport.crosstab.CrosstabGroup;
38 import it.businesslogic.ireport.crosstab.gui.CrosstabEditorPanel;
39 import it.businesslogic.ireport.gui.*;
40 import it.businesslogic.ireport.gui.event.CrosstabLayoutChangedEvent;
41 import java.awt.*;
42
43 import java.util.*;
44
45 /**
46  * This class handle the band dragged operation.
47  * As all operations, the costructor take the JReportFrame (owner of the element)
48  * The ReportElement is not cloned, this can be a problem if not all undo operations
49  * are correctly logged and handled.
50  * This undo operation contains the band dragged and all elements that was repositioned
51  * after the draging.
52  * It reuse a lot of code of TransformElementsOperation.
53  * @author Giulio Toffoli
54  */

55 public class CrosstabRowDraggedOperation implements it.businesslogic.ireport.UndoOperation {
56     private int delta = 0;
57     
58     private CrosstabEditorPanel editor = null;
59     private CrosstabReportElement crosstabElement;
60     private int draggedLineIndex = 0;
61     
62     /** Creates a new instance of InsertElementOperation */
63     public CrosstabRowDraggedOperation(CrosstabEditorPanel editor, CrosstabReportElement element, int draggedLineIndex,int delta) {
64         this.setEditor(editor);
65         this.setCrosstabElement(element);
66         this.setDraggedLineIndex(draggedLineIndex);
67         this.setDelta(delta);
68     }
69     
70     public void redo()
71     {
72         if (editor == null) return;
73
74         int readyToDragCellVertically = draggedLineIndex;
75         // Save relative position for all elements...
76
for (int j=0; j<getCrosstabElement().getElements().size(); ++j)
77         {
78             ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j);
79             re.setRelativePosition(new Point( re.getPosition().x - re.getCell().getLeft() - 10, re.getPosition().y - re.getCell().getTop() - 10 ));
80         }
81
82         // Modify hight of all cell in band readyToDragCellVertically...
83
Vector cells = (Vector)getEditor().getRowBands().elementAt(readyToDragCellVertically-1);
84         for (int i=0; i<cells.size(); ++i)
85         {
86             CrosstabCell cell = (CrosstabCell)cells.elementAt(i);
87             cell.setHeight(cell.getHeight() + delta );
88         }
89         for (int j=readyToDragCellVertically; j<getEditor().getRowBands().size(); ++j)
90         {
91             cells = (Vector)getEditor().getRowBands().elementAt(j);
92             for (int i=0; i<cells.size(); ++i)
93             {
94                 CrosstabCell cell = (CrosstabCell)cells.elementAt(i);
95                 if (cell.getTopIndex() >= readyToDragCellVertically)
96                 {
97                     cell.setTop(cell.getTop() + delta );
98                 }
99                 else
100                 {
101                     cell.setHeight(cell.getHeight() + delta );
102                 }
103             }
104         }
105
106         // Adjust size value of all groups...
107
for (int i=0; i< getCrosstabElement().getColumnGroups().size(); ++i)
108         {
109             CrosstabGroup group = (CrosstabGroup)getCrosstabElement().getColumnGroups().elementAt(i);
110             group.setSize( group.getHeaderCell().getHeight() );
111         }
112
113         // Adjust all elements position with new cell positions...
114
for (int j=0; j<getCrosstabElement().getElements().size(); ++j)
115         {
116             ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j);
117             re.getPosition().x = re.getRelativePosition().x + re.getCell().getLeft()+10;
118             re.getPosition().y = re.getRelativePosition().y + re.getCell().getTop()+10;
119
120             re.setPosition(re.position);
121             re.trasform(new java.awt.Point JavaDoc(0,0),TransformationType.TRANSFORMATION_RESIZE_SE);
122         }
123
124
125         for (int i=readyToDragCellVertically; i<getEditor().getRows().size(); ++i)
126         {
127             int rowPosition = ((Integer JavaDoc)getEditor().getRows().get(i)).intValue() + delta;
128             getEditor().getRows().set(i, new Integer JavaDoc(rowPosition));
129         }
130             
131         MainFrame.getMainInstance().getActiveReportFrame().setIsDocDirty(true);
132         getCrosstabElement().fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(this, this.getCrosstabElement()));
133     }
134     
135     public void undo()
136     {
137         if (editor == null) return;
138         
139         delta *= -1;
140
141         this.redo();
142             
143         delta *= -1;
144
145     }
146     
147     
148     public String JavaDoc toString()
149     {
150         return "row resize";
151     }
152
153     public int getDelta() {
154         return delta;
155     }
156
157     public void setDelta(int delta) {
158         this.delta = delta;
159     }
160
161     public int getDraggedLineIndex() {
162         return draggedLineIndex;
163     }
164
165     public void setDraggedLineIndex(int draggedLineIndex) {
166         this.draggedLineIndex = draggedLineIndex;
167     }
168
169     public CrosstabReportElement getCrosstabElement() {
170         return crosstabElement;
171     }
172
173     public void setCrosstabElement(CrosstabReportElement crosstabElement) {
174         this.crosstabElement = crosstabElement;
175     }
176
177     public CrosstabEditorPanel getEditor() {
178         return editor;
179     }
180
181     public void setEditor(CrosstabEditorPanel editor) {
182         this.editor = editor;
183     }
184     
185         
186 }
187
188
Popular Tags