001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * PageTransformation.java
028: *
029: * Created on June 5, 2005 11:31 RL
030: *
031: */
032:
033: package it.businesslogic.ireport.undo;
034:
035: import it.businesslogic.ireport.gui.JReportFrame;
036: import it.businesslogic.ireport.util.PageSize;
037: import java.awt.*;
038:
039: /**
040: * @author Robert Lamping
041: * When changing the page size during an elementtransaction, (like in FormatCommandShrink),
042: * then there is a need to undo this
043: *
044: * TO DO
045: * 1. Recalc columnwidth!!!
046: */
047: public class PageTransformation implements
048: it.businesslogic.ireport.UndoOperation, ITransformation {
049: // the target in question
050: JReportFrame jrf;
051:
052: //OLD
053: private int oldWidth;
054: private int oldHeight;
055: private String oldReportFormat;
056: private int oldColumnWidth;
057:
058: //NEW
059: private int newWidth;
060: private int newHeight;
061: private String newReportFormat;
062: private int newColumnWidth;
063:
064: public PageTransformation() {
065: }
066:
067: public boolean equals(Object obj) {
068: boolean isEqual = false;
069: if (obj instanceof JReportFrame) {
070: if (this .jrf != null) {
071: isEqual = this .jrf.equals((JReportFrame) obj);
072: }
073: }
074: return isEqual;
075: }
076:
077: // As the element will not be removed.
078: // the element should be able to undo itself
079: public void undo() {
080: this .jrf.getReport().setWidth(oldWidth);
081: this .jrf.getReport().setHeight(oldHeight);
082: this .jrf.getReport().setReportFormat(oldReportFormat);
083: this .jrf.getReport().setColumnWidth(oldColumnWidth);
084: }
085:
086: public void redo() {
087: this .jrf.getReport().setWidth(newWidth);
088: this .jrf.getReport().setHeight(newHeight);
089: this .jrf.getReport().setReportFormat(newReportFormat);
090: this .jrf.getReport().setColumnWidth(newColumnWidth);
091: }
092:
093: /**
094: * Let this class decide on its own which information is captures
095: * for a later redo.
096: */
097: public void captureCurrent(Object obj) {
098: // TODO you might wish to check whether this the obj is instanceof JReportFrame
099: // or enclose with try/catch
100: this .jrf = (JReportFrame) obj;
101: oldWidth = jrf.getReport().getWidth();
102: oldHeight = jrf.getReport().getHeight();
103: oldReportFormat = jrf.getReport().getReportFormat();
104: oldColumnWidth = jrf.getReport().getColumnWidth();
105:
106: }
107:
108: /**
109: * Let this class decide on its own which information is captures
110: * for a later unddo
111: */
112: public void captureModified(Object obj) {
113: JReportFrame jrf = (JReportFrame) obj;
114: newWidth = jrf.getReport().getWidth();
115: newHeight = jrf.getReport().getHeight();
116: newReportFormat = jrf.getReport().getReportFormat();
117: newColumnWidth = jrf.getReport().getColumnWidth();
118:
119: }
120:
121: }
|