1 32 33 package it.businesslogic.ireport.undo; 34 import it.businesslogic.ireport.*; 35 import it.businesslogic.ireport.IReportFont; 36 import it.businesslogic.ireport.crosstab.CrosstabCell; 37 import java.awt.*; 38 39 40 55 public class ElementTransformation implements it.businesslogic.ireport.UndoOperation, ITransformation 56 { 57 public ReportElement element; 58 59 public Rectangle oldBounds; 60 public Rectangle newBounds; 61 62 public Band oldBand; 63 public Band newBand; 64 65 public CrosstabCell oldCell; 66 public CrosstabCell newCell; 67 68 private Object oldFontSize; 69 private Object newFontSize; 70 71 72 public ElementTransformation() 73 { 74 } 76 77 80 81 82 public boolean equals(Object obj) 83 { 84 boolean isEqual = false; 85 if (obj instanceof ReportElement) 86 { 87 if (this.element != null ) 88 { 89 isEqual = this.element.equals( (ReportElement) obj ); 90 } 91 } 92 93 return isEqual; 94 } 95 96 public void undo() 97 { 98 100 element.setPosition( new Point( this.oldBounds.x, this.oldBounds.y) ) ; 101 102 element.setWidth( this.oldBounds.width); 103 element.setHeight(this.oldBounds.height); 104 105 element.updateBounds(); 106 107 if ( this.oldBand != null) 109 { 110 element.setBand( this.oldBand ); 111 } 112 113 if ( this.oldCell != null) 114 { 115 element.setCell( this.oldCell ); 116 } 117 118 if (element.getCell() != null) 120 { 121 element.setRelativePosition( new Point(element.getPosition().x - element.getCell().getLeft()- 10, element.getPosition().y - element.getCell().getTop()- 10)); 122 } 123 124 if ( element instanceof TextReportElement) 126 { 127 try 128 { 129 ((TextReportElement) element).getIReportFont().setPropertyValue( IReportFont.FONT_SIZE, oldFontSize); 130 } 131 catch (Exception e ) 132 { 133 } 135 } 136 137 } 138 139 public void redo() 140 { 141 if (element == null || this.newBounds == null) return; 143 element.setPosition( new Point( this.newBounds.x, this.newBounds.y) ); 144 145 element.setWidth(this.newBounds.width); 146 element.setHeight(this.newBounds.height); 147 148 element.updateBounds( ); 149 150 if ( this.newBand != null) 152 { 153 element.setBand( this.newBand ); 154 } 155 156 if ( this.newCell != null) 157 { 158 element.setCell( this.newCell ); 159 } 160 161 if (element.getCell() != null) 163 { 164 element.setRelativePosition( new Point(element.getPosition().x - element.getCell().getLeft()- 10, element.getPosition().y - element.getCell().getTop()- 10)); 165 } 166 167 if ( element instanceof TextReportElement) 169 { 170 try 171 { 172 ((TextReportElement) element).getIReportFont().setPropertyValue( IReportFont.FONT_SIZE, newFontSize); 173 } 174 catch (Exception e ) 175 { 176 } 178 } 179 180 } 181 182 186 public void captureCurrent( Object obj) 187 { 188 ReportElement element = (ReportElement) obj; 189 this.element = element; 190 this.oldBounds = new Rectangle( element.getBounds() ); 191 this.oldBand = element.getBand(); 192 this.oldCell = element.getCell(); 193 194 if ( element instanceof TextReportElement) 195 { 196 this.oldFontSize = ((TextReportElement) element).getIReportFont().getPropertyValue( IReportFont.FONT_SIZE); 197 } 198 } 199 200 204 public void captureModified(Object obj) { 206 ReportElement element = (ReportElement) obj; 207 this.newBounds = new Rectangle( element.getBounds() ); 208 this.newBand = element.getBand(); 209 this.newCell = element.getCell(); 210 211 if ( element instanceof TextReportElement) 212 { 213 this.newFontSize = ((TextReportElement) element).getIReportFont().getPropertyValue( IReportFont.FONT_SIZE); 214 } 215 216 } 217 218 219 } 220 | Popular Tags |