KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RemoveMarginsOperation.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.util.*;
39
40
41 /**
42  *
43  * @author Administrator
44  */

45 public class RemoveMarginsOperation implements it.businesslogic.ireport.UndoOperation {
46     
47     
48     private int oldTop = 0;
49     private int oldLeft = 0;
50     private int oldBottom = 0;
51     private int oldRight = 0;
52     
53     private JReportFrame jrf = null;
54     
55     
56     /** Creates a new instance of RemoveMarginsOperation */
57     public RemoveMarginsOperation(JReportFrame jrf, int oldTop, int oldBottom, int oldLeft, int oldRight ) {
58         
59         this.oldTop = oldTop;
60         this.oldBottom = oldBottom;
61         this.oldLeft = oldLeft;
62         this.oldRight = oldRight;
63                 
64         this.jrf = jrf;
65     }
66         
67      public void redo()
68     {
69         if (jrf == null) return;
70
71         jrf.getReport().setTopMargin( 0 );
72         jrf.getReport().setBottomMargin( 0 );
73         jrf.getReport().setLeftMargin( 0 );
74         jrf.getReport().setRightMargin( 0 );
75         
76         jrf.getReport().setWidth( jrf.getReport().getWidth() - oldLeft - oldRight );
77         
78         if (oldTop != 0 || oldLeft != 0) {
79                     Enumeration e = jrf.getReport().getElements().elements();
80                     while (e.hasMoreElements()) {
81                         ReportElement re = (ReportElement)e.nextElement();
82                         re.trasform(new java.awt.Point JavaDoc(-oldLeft,-oldTop), TransformationType.TRANSFORMATION_MOVE);
83                     }
84                 }
85                 
86         jrf.setIsDocDirty(true);
87         jrf.getReportPanel().repaint();
88     }
89     
90     public void undo()
91     {
92         if (jrf == null) return;
93
94         jrf.getReport().setTopMargin( oldTop );
95         jrf.getReport().setBottomMargin( oldBottom );
96         jrf.getReport().setLeftMargin( oldLeft );
97         jrf.getReport().setRightMargin( oldRight );
98         
99         jrf.getReport().setWidth( jrf.getReport().getWidth() + oldLeft + oldRight );
100         
101         if (oldTop != 0 || oldLeft != 0) {
102                     Enumeration e = jrf.getReport().getElements().elements();
103                     while (e.hasMoreElements()) {
104                         ReportElement re = (ReportElement)e.nextElement();
105                         re.trasform(new java.awt.Point JavaDoc(oldLeft,oldTop), TransformationType.TRANSFORMATION_MOVE);
106                     }
107                 }
108                 
109         jrf.setIsDocDirty(true);
110         jrf.getReportPanel().repaint();
111     }
112     
113     public String JavaDoc toString()
114     {
115         return "remove margins";
116     }
117 }
118
Popular Tags