KickJava   Java API By Example, From Geeks To Geeks.

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


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  * UnGroupEmentsOperation.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  * This class handle the Insert operation.
44  * As all operations, the costructor take the JReportFrame (owner of the element)
45  * The ReportElement is not cloned, this can be a problem if not all undo operations
46  * are correctly logged and handled.
47  * @author Giulio Toffoli
48  */

49 public class UnGroupEmentsOperation implements it.businesslogic.ireport.UndoOperation {
50     
51     /*
52      * The report elements that was inserted.
53      */

54     private Vector elements = null;
55     
56     private JReportFrame jrf = null;
57         
58     public UnGroupEmentsOperation(JReportFrame jrf) {
59          this.elements = new Vector();
60         this.jrf = jrf;
61     }
62     
63     public void redo()
64     {
65         // We must remove our element...
66
if (jrf == null) return;
67         Enumeration e = this.getElements().elements();
68         while ( e.hasMoreElements() )
69         {
70             GroupPositionedElement pe = (GroupPositionedElement)e.nextElement();
71             ReportElement element = pe.getElement();
72             
73             element.setElementGroup( pe.getNewElementGroup() );
74             
75             // Add element....
76
jrf.getReport().getElements().remove( pe.getOldPosition() );
77             
78             jrf.getReport().getElements().insertElementAt(element, pe.getNewPosition());
79             jrf.addSelectedElement( element , false);
80         }
81         jrf.fireSelectionChangedEvent();
82         jrf.getReportPanel().repaint();
83     }
84     
85     public void undo()
86     {
87         // We must add our element...
88
if (jrf == null) return;
89         
90         jrf.setSelectedElement(null);
91         for (int i= this.getElements().size()-1; i>=0; --i)
92         {
93             GroupPositionedElement pe = (GroupPositionedElement)this.getElements().elementAt(i);
94             ReportElement element = pe.getElement();
95             
96             element.setElementGroup( pe.getOldElementGroup() );
97             
98             // Add element....
99
jrf.getReport().getElements().remove( pe.getNewPosition() );
100             
101             jrf.getReport().getElements().insertElementAt(element, pe.getOldPosition());
102             jrf.addSelectedElement( element , false);
103         }
104         jrf.fireSelectionChangedEvent();
105         jrf.getReportPanel().repaint();
106     }
107     
108     public String JavaDoc toString()
109     {
110         return "ungroup element(s)";
111     }
112     
113     /** Getter for property elements.
114      * @return Value of property elements.
115      *
116      * To add an element, use the addElement method. Don't access directly
117      * addElement from the vector elements
118      *
119      */

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

128     public void setElements(java.util.Vector JavaDoc elements) {
129         this.elements = elements;
130     }
131     
132     /*
133      * Add an element to the list of elements handled by this
134      * undo operation. The position is relative to the z position
135      * in the elements vector.
136      * If the undo mechanism works fine, the requested position is
137      * ever available.
138      * The position value should be retrived when the element
139      * is added.
140      */

141      public void addElement(ReportElement element, int oldPosition, int newPostion, String JavaDoc oldElementGroup, String JavaDoc newElementGroup) {
142          
143         GroupPositionedElement pe = new GroupPositionedElement(element, oldPosition, newPostion,oldElementGroup, newElementGroup);
144         getElements().add(pe);
145     }
146     
147 }
148
149
Popular Tags