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: * UnGroupEmentsOperation.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: * This class handle the Insert operation.
045: * As all operations, the costructor take the JReportFrame (owner of the element)
046: * The ReportElement is not cloned, this can be a problem if not all undo operations
047: * are correctly logged and handled.
048: * @author Giulio Toffoli
049: */
050: public class UnGroupEmentsOperation implements
051: it.businesslogic.ireport.UndoOperation {
052:
053: /*
054: * The report elements that was inserted.
055: */
056: private Vector elements = null;
057:
058: private JReportFrame jrf = null;
059:
060: public UnGroupEmentsOperation(JReportFrame jrf) {
061: this .elements = new Vector();
062: this .jrf = jrf;
063: }
064:
065: public void redo() {
066: // We must remove our element...
067: if (jrf == null)
068: return;
069: Enumeration e = this .getElements().elements();
070: while (e.hasMoreElements()) {
071: GroupPositionedElement pe = (GroupPositionedElement) e
072: .nextElement();
073: ReportElement element = pe.getElement();
074:
075: element.setElementGroup(pe.getNewElementGroup());
076:
077: // Add element....
078: jrf.getReport().getElements().remove(pe.getOldPosition());
079:
080: jrf.getReport().getElements().insertElementAt(element,
081: pe.getNewPosition());
082: jrf.addSelectedElement(element, false);
083: }
084: jrf.fireSelectionChangedEvent();
085: jrf.getReportPanel().repaint();
086: }
087:
088: public void undo() {
089: // We must add our element...
090: if (jrf == null)
091: return;
092:
093: jrf.setSelectedElement(null);
094: for (int i = this .getElements().size() - 1; i >= 0; --i) {
095: GroupPositionedElement pe = (GroupPositionedElement) this
096: .getElements().elementAt(i);
097: ReportElement element = pe.getElement();
098:
099: element.setElementGroup(pe.getOldElementGroup());
100:
101: // Add element....
102: jrf.getReport().getElements().remove(pe.getNewPosition());
103:
104: jrf.getReport().getElements().insertElementAt(element,
105: pe.getOldPosition());
106: jrf.addSelectedElement(element, false);
107: }
108: jrf.fireSelectionChangedEvent();
109: jrf.getReportPanel().repaint();
110: }
111:
112: public String toString() {
113: return "ungroup element(s)";
114: }
115:
116: /** Getter for property elements.
117: * @return Value of property elements.
118: *
119: * To add an element, use the addElement method. Don't access directly
120: * addElement from the vector elements
121: *
122: */
123: public java.util.Vector getElements() {
124: return elements;
125: }
126:
127: /** Setter for property elements.
128: * @param elements New value of property elements.
129: *
130: */
131: public void setElements(java.util.Vector elements) {
132: this .elements = elements;
133: }
134:
135: /*
136: * Add an element to the list of elements handled by this
137: * undo operation. The position is relative to the z position
138: * in the elements vector.
139: * If the undo mechanism works fine, the requested position is
140: * ever available.
141: * The position value should be retrived when the element
142: * is added.
143: */
144: public void addElement(ReportElement element, int oldPosition,
145: int newPostion, String oldElementGroup,
146: String newElementGroup) {
147:
148: GroupPositionedElement pe = new GroupPositionedElement(element,
149: oldPosition, newPostion, oldElementGroup,
150: newElementGroup);
151: getElements().add(pe);
152: }
153:
154: }
|