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.crosstab.CrosstabCell; 37 import it.businesslogic.ireport.crosstab.CrosstabGroup; 38 import it.businesslogic.ireport.crosstab.gui.CrosstabEditorPanel; 39 import it.businesslogic.ireport.gui.*; 40 import it.businesslogic.ireport.gui.event.CrosstabLayoutChangedEvent; 41 import java.awt.*; 42 43 import java.util.*; 44 45 55 public class CrosstabRowDraggedOperation implements it.businesslogic.ireport.UndoOperation { 56 private int delta = 0; 57 58 private CrosstabEditorPanel editor = null; 59 private CrosstabReportElement crosstabElement; 60 private int draggedLineIndex = 0; 61 62 63 public CrosstabRowDraggedOperation(CrosstabEditorPanel editor, CrosstabReportElement element, int draggedLineIndex,int delta) { 64 this.setEditor(editor); 65 this.setCrosstabElement(element); 66 this.setDraggedLineIndex(draggedLineIndex); 67 this.setDelta(delta); 68 } 69 70 public void redo() 71 { 72 if (editor == null) return; 73 74 int readyToDragCellVertically = draggedLineIndex; 75 for (int j=0; j<getCrosstabElement().getElements().size(); ++j) 77 { 78 ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j); 79 re.setRelativePosition(new Point( re.getPosition().x - re.getCell().getLeft() - 10, re.getPosition().y - re.getCell().getTop() - 10 )); 80 } 81 82 Vector cells = (Vector)getEditor().getRowBands().elementAt(readyToDragCellVertically-1); 84 for (int i=0; i<cells.size(); ++i) 85 { 86 CrosstabCell cell = (CrosstabCell)cells.elementAt(i); 87 cell.setHeight(cell.getHeight() + delta ); 88 } 89 for (int j=readyToDragCellVertically; j<getEditor().getRowBands().size(); ++j) 90 { 91 cells = (Vector)getEditor().getRowBands().elementAt(j); 92 for (int i=0; i<cells.size(); ++i) 93 { 94 CrosstabCell cell = (CrosstabCell)cells.elementAt(i); 95 if (cell.getTopIndex() >= readyToDragCellVertically) 96 { 97 cell.setTop(cell.getTop() + delta ); 98 } 99 else 100 { 101 cell.setHeight(cell.getHeight() + delta ); 102 } 103 } 104 } 105 106 for (int i=0; i< getCrosstabElement().getColumnGroups().size(); ++i) 108 { 109 CrosstabGroup group = (CrosstabGroup)getCrosstabElement().getColumnGroups().elementAt(i); 110 group.setSize( group.getHeaderCell().getHeight() ); 111 } 112 113 for (int j=0; j<getCrosstabElement().getElements().size(); ++j) 115 { 116 ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j); 117 re.getPosition().x = re.getRelativePosition().x + re.getCell().getLeft()+10; 118 re.getPosition().y = re.getRelativePosition().y + re.getCell().getTop()+10; 119 120 re.setPosition(re.position); 121 re.trasform(new java.awt.Point (0,0),TransformationType.TRANSFORMATION_RESIZE_SE); 122 } 123 124 125 for (int i=readyToDragCellVertically; i<getEditor().getRows().size(); ++i) 126 { 127 int rowPosition = ((Integer )getEditor().getRows().get(i)).intValue() + delta; 128 getEditor().getRows().set(i, new Integer (rowPosition)); 129 } 130 131 MainFrame.getMainInstance().getActiveReportFrame().setIsDocDirty(true); 132 getCrosstabElement().fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(this, this.getCrosstabElement())); 133 } 134 135 public void undo() 136 { 137 if (editor == null) return; 138 139 delta *= -1; 140 141 this.redo(); 142 143 delta *= -1; 144 145 } 146 147 148 public String toString() 149 { 150 return "row resize"; 151 } 152 153 public int getDelta() { 154 return delta; 155 } 156 157 public void setDelta(int delta) { 158 this.delta = delta; 159 } 160 161 public int getDraggedLineIndex() { 162 return draggedLineIndex; 163 } 164 165 public void setDraggedLineIndex(int draggedLineIndex) { 166 this.draggedLineIndex = draggedLineIndex; 167 } 168 169 public CrosstabReportElement getCrosstabElement() { 170 return crosstabElement; 171 } 172 173 public void setCrosstabElement(CrosstabReportElement crosstabElement) { 174 this.crosstabElement = crosstabElement; 175 } 176 177 public CrosstabEditorPanel getEditor() { 178 return editor; 179 } 180 181 public void setEditor(CrosstabEditorPanel editor) { 182 this.editor = editor; 183 } 184 185 186 } 187 188 | Popular Tags |