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: * PasteStyleOperation.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.awt.*;
040:
041: import java.util.*;
042:
043: /**
044:
045: * @author Giulio Toffoli
046: */
047: public class PasteStyleOperation implements
048: it.businesslogic.ireport.UndoOperation {
049:
050: private Vector transformations = null;
051:
052: private JReportFrame jrf = null;
053: private CrosstabReportElement crosstabReportElement = null;
054:
055: /** Creates a new instance of InsertElementOperation */
056: public PasteStyleOperation(JReportFrame jrf,
057: CrosstabReportElement crosstabReportElement) {
058: this .setCrosstabReportElement(crosstabReportElement);
059: this .transformations = new Vector();
060: this .jrf = jrf;
061: }
062:
063: /** Creates a new instance of InsertElementOperation */
064: public PasteStyleOperation(JReportFrame jrf) {
065: this (jrf, null);
066: }
067:
068: public void redo() {
069: if (jrf == null)
070: return;
071:
072: //jrf.setSelectedElement(null);
073: Enumeration e = this .getTransformations().elements();
074: while (e.hasMoreElements()) {
075: PasteStyledElementItem ri = (PasteStyledElementItem) e
076: .nextElement();
077: ReportElement element = ri.getElement();
078: JReportFrame.applyStyle(element, ri.getNewStyle());
079:
080: jrf
081: .fireReportListenerReportElementsChanged(new ReportElementChangedEvent(
082: jrf, getCrosstabReportElement(), element,
083: ReportElementChangedEvent.CHANGED));
084: //jrf.getSelectedElements().remove( element );
085: //jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.REMOVED));
086: }
087: jrf.getMainFrame().getElementPropertiesDialog()
088: .updateSelection();
089: if (getCrosstabReportElement() != null)
090: jrf.getCrosstabEditor(getCrosstabReportElement())
091: .getPanelEditor().repaint();
092: else
093: jrf.getReportPanel().repaint();
094: }
095:
096: public void undo() {
097: if (jrf == null)
098: return;
099:
100: //jrf.setSelectedElement(null);
101: Enumeration e = this .getTransformations().elements();
102: while (e.hasMoreElements()) {
103: PasteStyledElementItem ri = (PasteStyledElementItem) e
104: .nextElement();
105: ReportElement element = ri.getElement();
106: JReportFrame.applyStyle(element, ri.getOriginalStyle());
107:
108: jrf
109: .fireReportListenerReportElementsChanged(new ReportElementChangedEvent(
110: jrf, getCrosstabReportElement(), element,
111: ReportElementChangedEvent.CHANGED));
112: //jrf.getSelectedElements().remove( element );
113: //jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.REMOVED));
114: }
115: jrf.getMainFrame().getElementPropertiesDialog()
116: .updateSelection();
117: if (getCrosstabReportElement() != null)
118: jrf.getCrosstabEditor(getCrosstabReportElement())
119: .getPanelEditor().repaint();
120: else
121: jrf.getReportPanel().repaint();
122: }
123:
124: public String toString() {
125: return "paste style";
126: }
127:
128: /** Getter for property elements.
129: * @return Value of property elements.
130: *
131: * To add an element, use the addElement method. Don't access directly
132: * addElement from the vector elements
133: *
134: */
135: public java.util.Vector getTransformations() {
136: return transformations;
137: }
138:
139: /** Setter for property elements.
140: * @param elements New value of property elements.
141: *
142: */
143: public void setTransformations(java.util.Vector transformations) {
144: this .transformations = transformations;
145: }
146:
147: /*
148: * Add an element to the list of elements handled by this
149: * undo operation.
150: * You must supply the old and the new bound of you report.
151: * This make more simple the undo/redo operation...
152: *
153: */
154: public void addElement(ReportElement element,
155: ReportElement originalStyle, ReportElement newStyle) {
156:
157: PasteStyledElementItem et = new PasteStyledElementItem(element,
158: originalStyle, newStyle);
159: getTransformations().add(et);
160: }
161:
162: public CrosstabReportElement getCrosstabReportElement() {
163: return crosstabReportElement;
164: }
165:
166: public void setCrosstabReportElement(
167: CrosstabReportElement crosstabReportElement) {
168: this.crosstabReportElement = crosstabReportElement;
169: }
170:
171: }
|