KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PasteStyleOperation.java
28  *
29  * Created on 19 giugno 2003, 23.23
30  *
31  */

32
33 package it.businesslogic.ireport.undo;
34 import it.businesslogic.ireport.gui.event.*;
35 import it.businesslogic.ireport.*;
36 import it.businesslogic.ireport.gui.*;
37 import it.businesslogic.ireport.util.*;
38 import java.awt.*;
39
40 import java.util.*;
41
42 /**
43
44  * @author Giulio Toffoli
45  */

46 public class PasteStyleOperation implements it.businesslogic.ireport.UndoOperation {
47     
48     private Vector transformations = null;
49     
50     private JReportFrame jrf = null;
51     private CrosstabReportElement crosstabReportElement = null;
52     
53     /** Creates a new instance of InsertElementOperation */
54     public PasteStyleOperation(JReportFrame jrf, CrosstabReportElement crosstabReportElement) {
55         this.setCrosstabReportElement(crosstabReportElement);
56         this.transformations = new Vector();
57         this.jrf = jrf;
58     }
59     
60     /** Creates a new instance of InsertElementOperation */
61     public PasteStyleOperation(JReportFrame jrf) {
62         this(jrf, null);
63     }
64     
65     public void redo()
66     {
67         if (jrf == null) return;
68
69         //jrf.setSelectedElement(null);
70
Enumeration e = this.getTransformations().elements();
71         while ( e.hasMoreElements() )
72         {
73             PasteStyledElementItem ri = (PasteStyledElementItem)e.nextElement();
74             ReportElement element = ri.getElement();
75             JReportFrame.applyStyle( element, ri.getNewStyle() );
76
77             jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, getCrosstabReportElement(), element , ReportElementChangedEvent.CHANGED));
78             //jrf.getSelectedElements().remove( element );
79
//jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.REMOVED));
80
}
81         jrf.getMainFrame().getElementPropertiesDialog().updateSelection();
82         if (getCrosstabReportElement() != null) jrf.getCrosstabEditor(getCrosstabReportElement()).getPanelEditor().repaint();
83         else jrf.getReportPanel().repaint();
84     }
85     
86     public void undo()
87     {
88         if (jrf == null) return;
89
90         //jrf.setSelectedElement(null);
91
Enumeration e = this.getTransformations().elements();
92         while ( e.hasMoreElements() )
93         {
94             PasteStyledElementItem ri = (PasteStyledElementItem)e.nextElement();
95             ReportElement element = ri.getElement();
96             JReportFrame.applyStyle( element, ri.getOriginalStyle() );
97
98             jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, getCrosstabReportElement(), element , ReportElementChangedEvent.CHANGED));
99             //jrf.getSelectedElements().remove( element );
100
//jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, element , ReportElementChangedEvent.REMOVED));
101
}
102         jrf.getMainFrame().getElementPropertiesDialog().updateSelection();
103         if (getCrosstabReportElement() != null) jrf.getCrosstabEditor(getCrosstabReportElement()).getPanelEditor().repaint();
104         else jrf.getReportPanel().repaint();
105     }
106     
107     public String JavaDoc toString()
108     {
109         return "paste style";
110     }
111     
112     /** Getter for property elements.
113      * @return Value of property elements.
114      *
115      * To add an element, use the addElement method. Don't access directly
116      * addElement from the vector elements
117      *
118      */

119     public java.util.Vector JavaDoc getTransformations() {
120         return transformations;
121     }
122     
123     /** Setter for property elements.
124      * @param elements New value of property elements.
125      *
126      */

127     public void setTransformations(java.util.Vector JavaDoc transformations) {
128         this.transformations = transformations;
129     }
130     
131     /*
132      * Add an element to the list of elements handled by this
133      * undo operation.
134      * You must supply the old and the new bound of you report.
135      * This make more simple the undo/redo operation...
136      *
137      */

138      public void addElement(ReportElement element, ReportElement originalStyle, ReportElement newStyle) {
139          
140         PasteStyledElementItem et = new PasteStyledElementItem(element,originalStyle,newStyle);
141         getTransformations().add(et);
142     }
143
144     public CrosstabReportElement getCrosstabReportElement() {
145         return crosstabReportElement;
146     }
147
148     public void setCrosstabReportElement(CrosstabReportElement crosstabReportElement) {
149         this.crosstabReportElement = crosstabReportElement;
150     }
151     
152 }
153
154
Popular Tags