KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BandDraggedOperation.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.gui.*;
37 import it.businesslogic.ireport.util.*;
38 import java.awt.*;
39
40 import java.util.*;
41
42 /**
43  * This class handle the band dragged operation.
44  * As all operations, the costructor take the JReportFrame (owner of the element)
45  * The ReportElement is not cloned, this can be a problem if not all undo operations
46  * are correctly logged and handled.
47  * This undo operation contains the band dragged and all elements that was repositioned
48  * after the draging.
49  * It reuse a lot of code of TransformElementsOperation.
50  * @author Giulio Toffoli
51  */

52 public class BandDraggedOperation implements it.businesslogic.ireport.UndoOperation {
53     
54     /*
55      * The report elements that was inserted.
56      */

57     private Vector transformations = null;
58     private int bandDelta = 0;
59     
60     private JReportFrame jrf = null;
61     
62     private Band band;
63     
64     /** Creates a new instance of InsertElementOperation */
65     public BandDraggedOperation(JReportFrame jrf, Band band) {
66         this.transformations = new Vector();
67         this.band = band;
68         this.jrf = jrf;
69     }
70     
71     public void redo()
72     {
73         if (jrf == null) return;
74
75         band.setHeight( band.getHeight() + bandDelta);
76         
77         //jrf.setSelectedElement(null);
78
Enumeration e = this.getTransformations().elements();
79         while ( e.hasMoreElements() )
80         {
81             ElementTransformation pe = (ElementTransformation)e.nextElement();
82             ReportElement element = pe.element;
83             // Add element....
84
//jrf.addSelectedElement( element );
85

86             element.getPosition().x = pe.newBounds.x;
87             element.getPosition().y = pe.newBounds.y;
88             element.setWidth(pe.newBounds.width);
89             element.setHeight(pe.newBounds.height);
90             
91             element.updateBounds();
92             jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.CHANGED));
93             //jrf.getSelectedElements().remove( element );
94
//jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.REMOVED));
95
}
96         jrf.setIsDocDirty(true);
97         jrf.getReportPanel().repaint();
98     }
99     
100     public void undo()
101     {
102         if (jrf == null) return;
103
104         band.setHeight( band.getHeight() - bandDelta );
105         
106         //jrf.setSelectedElement(null);
107
for (int i= this.getTransformations().size()-1; i>=0; --i)
108         {
109             ElementTransformation pe = (ElementTransformation)getTransformations().get(i);
110             ReportElement element = pe.element;
111             // Add element....
112
//jrf.addSelectedElement( element );
113

114             element.getPosition().x = pe.oldBounds.x;
115             element.getPosition().y = pe.oldBounds.y;
116             element.setWidth(pe.oldBounds.width);
117             element.setHeight(pe.oldBounds.height);
118             
119             element.updateBounds();
120             jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.CHANGED));
121             //jrf.getSelectedElements().remove( element );
122
//jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.REMOVED));
123
}
124         jrf.setIsDocDirty(true);
125         jrf.getReportPanel().repaint();
126     }
127     
128     public String JavaDoc toString()
129     {
130         return "band resize";
131     }
132     
133     /** Getter for property elements.
134      * @return Value of property elements.
135      *
136      * To add an element, use the addElement method. Don't access directly
137      * addElement from the vector elements
138      *
139      */

140     public java.util.Vector JavaDoc getTransformations() {
141         return transformations;
142     }
143     
144     /** Setter for property elements.
145      * @param elements New value of property elements.
146      *
147      */

148     public void setTransformations(java.util.Vector JavaDoc transformations) {
149         this.transformations = transformations;
150     }
151     
152     /*
153      * Add an element to the list of elements handled by this
154      * undo operation.
155      * You must supply the old and the new bound of you report.
156      * This make more simple the undo/redo operation...
157      *
158      */

159      public void addElement(ReportElement element, Rectangle oldBounds, Rectangle newBounds) {
160          
161         ElementTransformation et = new ElementTransformation();
162         et.element = element;
163         et.oldBounds = oldBounds;
164         et.newBounds = newBounds;
165         getTransformations().add(et);
166     }
167     
168      /** Getter for property band.
169       * @return Value of property band.
170       *
171       */

172      public it.businesslogic.ireport.Band getBand() {
173          return band;
174      }
175      
176      /** Setter for property band.
177       * @param band New value of property band.
178       *
179       */

180      public void setBand(it.businesslogic.ireport.Band band) {
181          this.band = band;
182      }
183      
184      /** Getter for property bandDelta.
185       * @return Value of property bandDelta.
186       *
187       */

188      public int getBandDelta() {
189          return bandDelta;
190      }
191      
192      /** Setter for property bandDelta.
193       * @param bandDelta New value of property bandDelta.
194       *
195       */

196      public void setBandDelta(int bandDelta) {
197          this.bandDelta = bandDelta;
198      }
199      
200 }
201
202
Popular Tags