KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PageTransformation.java
28  *
29  * Created on June 5, 2005 11:31 RL
30  *
31  */

32
33 package it.businesslogic.ireport.undo;
34 import it.businesslogic.ireport.gui.JReportFrame;
35 import it.businesslogic.ireport.util.PageSize;
36 import java.awt.*;
37
38 /**
39  * @author Robert Lamping
40  * When changing the page size during an elementtransaction, (like in FormatCommandShrink),
41  * then there is a need to undo this
42  *
43  * TO DO
44  * 1. Recalc columnwidth!!!
45  */

46 public class PageTransformation implements it.businesslogic.ireport.UndoOperation, ITransformation
47 {
48     // the target in question
49
JReportFrame jrf;
50     
51     //OLD
52
private int oldWidth;
53     private int oldHeight;
54     private String JavaDoc oldReportFormat;
55     private int oldColumnWidth;
56     
57     //NEW
58
private int newWidth;
59     private int newHeight;
60     private String JavaDoc newReportFormat;
61     private int newColumnWidth;
62     
63     public PageTransformation()
64     {
65     }
66     
67     public boolean equals(Object JavaDoc obj) {
68         boolean isEqual = false;
69         if (obj instanceof JReportFrame)
70         {
71            if (this.jrf != null ) {
72             isEqual = this.jrf.equals( (JReportFrame) obj );
73            }
74         }
75         return isEqual;
76     }
77     
78     
79     // As the element will not be removed.
80
// the element should be able to undo itself
81
public void undo()
82     {
83         this.jrf.getReport().setWidth( oldWidth );
84         this.jrf.getReport().setHeight( oldHeight );
85         this.jrf.getReport().setReportFormat(oldReportFormat );
86         this.jrf.getReport().setColumnWidth( oldColumnWidth );
87     }
88     
89     public void redo()
90     {
91         this.jrf.getReport().setWidth( newWidth );
92         this.jrf.getReport().setHeight( newHeight );
93         this.jrf.getReport().setReportFormat( newReportFormat );
94         this.jrf.getReport().setColumnWidth( newColumnWidth );
95     }
96     
97     /**
98      * Let this class decide on its own which information is captures
99      * for a later redo.
100      */

101     public void captureCurrent(Object JavaDoc obj)
102     {
103         // TODO you might wish to check whether this the obj is instanceof JReportFrame
104
// or enclose with try/catch
105
this.jrf = (JReportFrame) obj;
106         oldWidth = jrf.getReport().getWidth();
107         oldHeight = jrf.getReport().getHeight();
108         oldReportFormat = jrf.getReport().getReportFormat();
109         oldColumnWidth = jrf.getReport().getColumnWidth();
110         
111     }
112     
113     /**
114      * Let this class decide on its own which information is captures
115      * for a later unddo
116      */

117     public void captureModified( Object JavaDoc obj)
118     {
119         JReportFrame jrf = (JReportFrame) obj;
120         newWidth = jrf.getReport().getWidth();
121         newHeight = jrf.getReport().getHeight();
122         newReportFormat = jrf.getReport().getReportFormat();
123         newColumnWidth = jrf.getReport().getColumnWidth();
124
125     }
126     
127 }
128
Popular Tags