1 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 38 import java.util.*; 39 40 52 public class TransformElementsOperation implements it.businesslogic.ireport.UndoOperation 53 { 54 55 58 private Vector transformations = null; 59 60 private JReportFrame jrf = null; 61 private CrosstabReportElement crosstabReportElement = null; 62 63 64 public TransformElementsOperation(JReportFrame jrf) 65 { 66 this.transformations = new Vector(); 67 this.jrf = jrf; 68 } 69 70 71 public TransformElementsOperation(JReportFrame jrf, CrosstabReportElement crosstabReportElement) 72 { 73 this.transformations = new Vector(); 74 this.crosstabReportElement = crosstabReportElement; 75 this.jrf = jrf; 76 } 77 78 public void redo() 79 { 80 if (jrf == null) return; 81 82 if (crosstabReportElement != null) 83 { 84 jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().setSelectedElement(null); 85 } 86 else 87 { 88 jrf.setSelectedElement(null); 89 } 90 91 Vector changed_elements = new Vector(); 92 93 for (int i= 0; i < this.getTransformations().size(); ++i) 94 { 95 ( (UndoOperation) (getTransformations().get(i))).redo(); 96 97 if ( getTransformations().get(i) instanceof ElementTransformation ) 98 { 99 ElementTransformation pe = (ElementTransformation) getTransformations().get(i); 100 ReportElement element = pe.element; 101 if (crosstabReportElement != null) 103 { 104 jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().addSelectedElement( element, false ); 105 } 106 else 107 { 108 jrf.addSelectedElement( element, false ); 109 } 110 111 changed_elements.add( element ) ; 112 } 113 114 } 115 116 117 jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, crosstabReportElement, changed_elements , ReportElementChangedEvent.CHANGED)); 118 jrf.getMainFrame().getElementPropertiesDialog().updateSelection(); 119 120 if (crosstabReportElement != null) 121 { 122 jrf.getReportPanel().repaint(); 123 } 124 } 125 126 public void undo() 127 { 128 129 if (jrf == null) return; 130 131 if (crosstabReportElement != null) 132 { 133 jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().setSelectedElement(null); 134 } 135 else 136 { 137 jrf.setSelectedElement(null); 138 } 139 Vector changed_elements = new Vector(); 140 141 for (int i= 0; i < this.getTransformations().size(); ++i) 142 { 143 150 ( (UndoOperation) (getTransformations().get(i))).undo(); 151 152 if ( getTransformations().get(i) instanceof ElementTransformation ) 153 { 154 ElementTransformation pe = (ElementTransformation)getTransformations().get(i); 155 ReportElement element = pe.element; 156 158 if (crosstabReportElement != null) 159 { 160 jrf.getCrosstabEditor(crosstabReportElement).getPanelEditor().addSelectedElement( element, false ); 161 } 162 else 163 { 164 jrf.addSelectedElement( element, false ); 165 } 166 167 changed_elements.add( element ) ; 168 } 169 170 } 171 172 jrf.fireReportListenerReportElementsChanged(new ReportElementChangedEvent(jrf, crosstabReportElement, changed_elements , ReportElementChangedEvent.CHANGED)); 173 jrf.getMainFrame().getElementPropertiesDialog().updateSelection(); 174 175 if (crosstabReportElement != null) 176 { 177 jrf.getReportPanel().repaint(); 178 } 179 } 180 181 public String toString() 182 { 183 return "transformation"; 184 } 185 186 193 public java.util.Vector getTransformations() 194 { 195 return transformations; 196 } 197 198 202 public void setTransformations(java.util.Vector transformations) 203 { 204 this.transformations = transformations; 205 } 206 207 214 215 public void addElement(Object object) 216 { 217 ITransformation et = null; 218 219 224 if (object instanceof ReportElement) 225 { 226 et = new ElementTransformation(); 227 } 228 else if (object instanceof JReportFrame) 229 { 230 et = new PageTransformation(); 231 } 232 233 try 235 { 236 this.getTransformations().add(et); 237 et.captureCurrent( object ); 238 } 239 catch (Exception ex) 240 { 241 } 245 } 246 247 public void captureUniqueModified(Object obj) 248 { 249 int pos = findTransformationElement( obj ); 250 try 251 { 252 ((ITransformation) getTransformations().elementAt( pos ) ).captureModified( obj); 253 } 254 catch ( Exception e ) 255 { 256 257 } 258 } 259 260 private int findTransformationElement( Object object) 261 { 262 int pos = -1; 264 for (int i= 0; i < this.getTransformations().size(); ++i) 265 { 266 if ( ((ITransformation) getTransformations().get(i)).equals(object) ) 267 { 268 pos = i; 269 break; 270 } 271 } 272 return pos; 273 } 274 275 } 276 277 | Popular Tags |