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: * ElementTransformation.java
028: *
029: * Created on 29 giugno 2003, 0.32
030: *
031: */
032:
033: package it.businesslogic.ireport.undo;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.IReportFont;
037: import it.businesslogic.ireport.crosstab.CrosstabCell;
038: import java.awt.*;
039:
040: /**
041: *
042: * @author Giulio
043: * Modified by Robert Lamping, June 3, 2005
044: * Consideration:
045: * An ElementTransformation should be able by itself to undo or redo
046: * its transformation. This is behaviour that should be encapsulated.
047: *
048: * How to inform the environment that the element has changed is another thing to
049: * research.
050: *
051: * What to capture to be able to restore the old situation should be
052: * as much as possible be the responsibility of the ElementTransformation.
053: *
054: */
055: public class ElementTransformation implements
056: it.businesslogic.ireport.UndoOperation, ITransformation {
057: public ReportElement element;
058:
059: public Rectangle oldBounds;
060: public Rectangle newBounds;
061:
062: public Band oldBand;
063: public Band newBand;
064:
065: public CrosstabCell oldCell;
066: public CrosstabCell newCell;
067:
068: private Object oldFontSize;
069: private Object newFontSize;
070:
071: public ElementTransformation() {
072: // oldBounds = newBounds = new Rectangle();
073: }
074:
075: // As the element will not be removed.
076: // the element should be able to undo itself
077:
078: public boolean equals(Object obj) {
079: boolean isEqual = false;
080: if (obj instanceof ReportElement) {
081: if (this .element != null) {
082: isEqual = this .element.equals((ReportElement) obj);
083: }
084: }
085:
086: return isEqual;
087: }
088:
089: public void undo() {
090: //System.out.println("Old bound: " + this.oldBounds);
091:
092: element.setPosition(new Point(this .oldBounds.x,
093: this .oldBounds.y));
094:
095: element.setWidth(this .oldBounds.width);
096: element.setHeight(this .oldBounds.height);
097:
098: element.updateBounds();
099:
100: // band
101: if (this .oldBand != null) {
102: element.setBand(this .oldBand);
103: }
104:
105: if (this .oldCell != null) {
106: element.setCell(this .oldCell);
107: }
108:
109: // Restore relative position...
110: if (element.getCell() != null) {
111: element.setRelativePosition(new Point(
112: element.getPosition().x
113: - element.getCell().getLeft() - 10, element
114: .getPosition().y
115: - element.getCell().getTop() - 10));
116: }
117:
118: // font
119: if (element instanceof TextReportElement) {
120: try {
121: ((TextReportElement) element).getIReportFont()
122: .setPropertyValue(IReportFont.FONT_SIZE,
123: oldFontSize);
124: } catch (Exception e) {
125: // fontsize not properly set
126: }
127: }
128:
129: }
130:
131: public void redo() {
132: // location and size
133: if (element == null || this .newBounds == null)
134: return;
135: element.setPosition(new Point(this .newBounds.x,
136: this .newBounds.y));
137:
138: element.setWidth(this .newBounds.width);
139: element.setHeight(this .newBounds.height);
140:
141: element.updateBounds();
142:
143: // band
144: if (this .newBand != null) {
145: element.setBand(this .newBand);
146: }
147:
148: if (this .newCell != null) {
149: element.setCell(this .newCell);
150: }
151:
152: // Restore relative position...
153: if (element.getCell() != null) {
154: element.setRelativePosition(new Point(
155: element.getPosition().x
156: - element.getCell().getLeft() - 10, element
157: .getPosition().y
158: - element.getCell().getTop() - 10));
159: }
160:
161: // font
162: if (element instanceof TextReportElement) {
163: try {
164: ((TextReportElement) element).getIReportFont()
165: .setPropertyValue(IReportFont.FONT_SIZE,
166: newFontSize);
167: } catch (Exception e) {
168: // fontsize not properly set
169: }
170: }
171:
172: }
173:
174: /**
175: * Let this class decide on its own which information is captures
176: * for a later redo.
177: */
178: public void captureCurrent(Object obj) {
179: ReportElement element = (ReportElement) obj;
180: this .element = element;
181: this .oldBounds = new Rectangle(element.getBounds());
182: this .oldBand = element.getBand();
183: this .oldCell = element.getCell();
184:
185: if (element instanceof TextReportElement) {
186: this .oldFontSize = ((TextReportElement) element)
187: .getIReportFont().getPropertyValue(
188: IReportFont.FONT_SIZE);
189: }
190: }
191:
192: /**
193: * Let this class decide on its own which information is captures
194: * for a later unddo
195: */
196: public void captureModified(Object obj) // implicit typecast from Object to ReportElement?? NO!!
197: {
198: ReportElement element = (ReportElement) obj;
199: this .newBounds = new Rectangle(element.getBounds());
200: this .newBand = element.getBand();
201: this .newCell = element.getCell();
202:
203: if (element instanceof TextReportElement) {
204: this .newFontSize = ((TextReportElement) element)
205: .getIReportFont().getPropertyValue(
206: IReportFont.FONT_SIZE);
207: }
208:
209: }
210:
211: }
|