KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CrosstabColumnDraggedOperation.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 CrosstabColumnDraggedOperation 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 CrosstabColumnDraggedOperation(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 readyToDragCellHorizontally = draggedLineIndex;
75         // Save relative position for all elements...
76
// Save relative position for all elements...
77
for (int j=0; j<getCrosstabElement().getElements().size(); ++j)
78         {
79             ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j);
80             re.setRelativePosition(new Point( re.getPosition().x - re.getCell().getLeft() - 10, re.getPosition().y - re.getCell().getTop() - 10 ));
81         }
82
83         // Modify hight of all cell in band readyToDragCellVertically...
84
Vector cells = (Vector)getEditor().getColumnBands().elementAt(readyToDragCellHorizontally-1);
85         for (int i=0; i<cells.size(); ++i)
86         {
87             CrosstabCell cell = (CrosstabCell)cells.elementAt(i);
88             cell.setWidth(cell.getWidth() + delta );
89         }
90         for (int j=readyToDragCellHorizontally; j<getEditor().getRowBands().size(); ++j)
91         {
92             cells = (Vector)getEditor().getColumnBands().elementAt(j);
93             for (int i=0; i<cells.size(); ++i)
94             {
95                 CrosstabCell cell = (CrosstabCell)cells.elementAt(i);
96                 if (cell.getLeftIndex() >= readyToDragCellHorizontally)
97                 {
98                     cell.setLeft(cell.getLeft() + delta );
99                 }
100                 else
101                 {
102                     cell.setWidth(cell.getWidth() + delta );
103                 }
104             }
105         }
106
107         // Adjust size value of all groups...
108
for (int i=0; i< getCrosstabElement().getRowGroups().size(); ++i)
109         {
110             CrosstabGroup group = (CrosstabGroup)getCrosstabElement().getRowGroups().elementAt(i);
111             group.setSize( group.getHeaderCell().getWidth() );
112         }
113
114
115         // Adjust all elements position with new cell positions...
116
for (int j=0; j<getCrosstabElement().getElements().size(); ++j)
117         {
118             ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j);
119             re.getPosition().x = re.getRelativePosition().x + re.getCell().getLeft()+10;
120             re.getPosition().y = re.getRelativePosition().y + re.getCell().getTop()+10;
121
122             re.setPosition(re.position);
123             re.trasform(new java.awt.Point JavaDoc(0,0),TransformationType.TRANSFORMATION_RESIZE_SE);
124         }
125
126         for (int i=readyToDragCellHorizontally; i<getEditor().getColumns().size(); ++i)
127         {
128             int rowPosition = ((Integer JavaDoc)getEditor().getColumns().get(i)).intValue() + delta;
129             getEditor().getColumns().set(i, new Integer JavaDoc(rowPosition));
130         }
131
132         MainFrame.getMainInstance().getActiveReportFrame().setIsDocDirty(true);
133         getCrosstabElement().fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(this, this.getCrosstabElement()));
134     }
135     
136     public void undo()
137     {
138         if (editor == null) return;
139         
140         delta *= -1;
141
142         this.redo();
143             
144         delta *= -1;
145     }
146     
147     
148     public String JavaDoc toString()
149     {
150         return "column 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