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 CrosstabColumnDraggedOperation 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 CrosstabColumnDraggedOperation(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 readyToDragCellHorizontally = draggedLineIndex; 75 for (int j=0; j<getCrosstabElement().getElements().size(); ++j) 78 { 79 ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j); 80 re.setRelativePosition(new Point( re.getPosition().x - re.getCell().getLeft() - 10, re.getPosition().y - re.getCell().getTop() - 10 )); 81 } 82 83 Vector cells = (Vector)getEditor().getColumnBands().elementAt(readyToDragCellHorizontally-1); 85 for (int i=0; i<cells.size(); ++i) 86 { 87 CrosstabCell cell = (CrosstabCell)cells.elementAt(i); 88 cell.setWidth(cell.getWidth() + delta ); 89 } 90 for (int j=readyToDragCellHorizontally; j<getEditor().getRowBands().size(); ++j) 91 { 92 cells = (Vector)getEditor().getColumnBands().elementAt(j); 93 for (int i=0; i<cells.size(); ++i) 94 { 95 CrosstabCell cell = (CrosstabCell)cells.elementAt(i); 96 if (cell.getLeftIndex() >= readyToDragCellHorizontally) 97 { 98 cell.setLeft(cell.getLeft() + delta ); 99 } 100 else 101 { 102 cell.setWidth(cell.getWidth() + delta ); 103 } 104 } 105 } 106 107 for (int i=0; i< getCrosstabElement().getRowGroups().size(); ++i) 109 { 110 CrosstabGroup group = (CrosstabGroup)getCrosstabElement().getRowGroups().elementAt(i); 111 group.setSize( group.getHeaderCell().getWidth() ); 112 } 113 114 115 for (int j=0; j<getCrosstabElement().getElements().size(); ++j) 117 { 118 ReportElement re = (ReportElement)getCrosstabElement().getElements().elementAt(j); 119 re.getPosition().x = re.getRelativePosition().x + re.getCell().getLeft()+10; 120 re.getPosition().y = re.getRelativePosition().y + re.getCell().getTop()+10; 121 122 re.setPosition(re.position); 123 re.trasform(new java.awt.Point (0,0),TransformationType.TRANSFORMATION_RESIZE_SE); 124 } 125 126 for (int i=readyToDragCellHorizontally; i<getEditor().getColumns().size(); ++i) 127 { 128 int rowPosition = ((Integer )getEditor().getColumns().get(i)).intValue() + delta; 129 getEditor().getColumns().set(i, new Integer (rowPosition)); 130 } 131 132 MainFrame.getMainInstance().getActiveReportFrame().setIsDocDirty(true); 133 getCrosstabElement().fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(this, this.getCrosstabElement())); 134 } 135 136 public void undo() 137 { 138 if (editor == null) return; 139 140 delta *= -1; 141 142 this.redo(); 143 144 delta *= -1; 145 } 146 147 148 public String toString() 149 { 150 return "column 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 |