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: * RemoveMarginsOperation.java
028: *
029: * Created on 19 giugno 2003, 23.23
030: *
031: */
032:
033: package it.businesslogic.ireport.undo;
034:
035: import it.businesslogic.ireport.gui.event.*;
036: import it.businesslogic.ireport.*;
037: import it.businesslogic.ireport.gui.*;
038: import it.businesslogic.ireport.util.*;
039: import java.util.*;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class RemoveMarginsOperation implements
046: it.businesslogic.ireport.UndoOperation {
047:
048: private int oldTop = 0;
049: private int oldLeft = 0;
050: private int oldBottom = 0;
051: private int oldRight = 0;
052:
053: private JReportFrame jrf = null;
054:
055: /** Creates a new instance of RemoveMarginsOperation */
056: public RemoveMarginsOperation(JReportFrame jrf, int oldTop,
057: int oldBottom, int oldLeft, int oldRight) {
058:
059: this .oldTop = oldTop;
060: this .oldBottom = oldBottom;
061: this .oldLeft = oldLeft;
062: this .oldRight = oldRight;
063:
064: this .jrf = jrf;
065: }
066:
067: public void redo() {
068: if (jrf == null)
069: return;
070:
071: jrf.getReport().setTopMargin(0);
072: jrf.getReport().setBottomMargin(0);
073: jrf.getReport().setLeftMargin(0);
074: jrf.getReport().setRightMargin(0);
075:
076: jrf.getReport().setWidth(
077: jrf.getReport().getWidth() - oldLeft - oldRight);
078:
079: if (oldTop != 0 || oldLeft != 0) {
080: Enumeration e = jrf.getReport().getElements().elements();
081: while (e.hasMoreElements()) {
082: ReportElement re = (ReportElement) e.nextElement();
083: re.trasform(new java.awt.Point(-oldLeft, -oldTop),
084: TransformationType.TRANSFORMATION_MOVE);
085: }
086: }
087:
088: jrf.setIsDocDirty(true);
089: jrf.getReportPanel().repaint();
090: }
091:
092: public void undo() {
093: if (jrf == null)
094: return;
095:
096: jrf.getReport().setTopMargin(oldTop);
097: jrf.getReport().setBottomMargin(oldBottom);
098: jrf.getReport().setLeftMargin(oldLeft);
099: jrf.getReport().setRightMargin(oldRight);
100:
101: jrf.getReport().setWidth(
102: jrf.getReport().getWidth() + oldLeft + oldRight);
103:
104: if (oldTop != 0 || oldLeft != 0) {
105: Enumeration e = jrf.getReport().getElements().elements();
106: while (e.hasMoreElements()) {
107: ReportElement re = (ReportElement) e.nextElement();
108: re.trasform(new java.awt.Point(oldLeft, oldTop),
109: TransformationType.TRANSFORMATION_MOVE);
110: }
111: }
112:
113: jrf.setIsDocDirty(true);
114: jrf.getReportPanel().repaint();
115: }
116:
117: public String toString() {
118: return "remove margins";
119: }
120: }
|