Browse Source

REPORT-54998 完善一下这边的判断逻辑,使其更加清晰

zheng-1641779399395
方磊 4 years ago
parent
commit
e4fe826784
  1. 153
      designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java

153
designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java

@ -46,6 +46,10 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
private static final int TOOLTIP_X_Y_FIX = 4; private static final int TOOLTIP_X_Y_FIX = 4;
private static final double COPY_CROSS_INNER_DISTANCE = 1.5; private static final double COPY_CROSS_INNER_DISTANCE = 1.5;
private static final double COPY_CROSS_OUTER_DISTANCE = 2.5; private static final double COPY_CROSS_OUTER_DISTANCE = 2.5;
private static final int DIRECTION_UP = 1;
private static final int DIRECTION_DOWN = 2;
private static final int DIRECTION_LEFT = 3;
private static final int DIRECTION_RIGHT = 4;
/** /**
* 拖拽时候刷新时间间隔 * 拖拽时候刷新时间间隔
*/ */
@ -457,48 +461,127 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
if (cellRectangle.contains(selectedCellPoint.getColumn(), selectedCellPoint.getRow())) { if (cellRectangle.contains(selectedCellPoint.getColumn(), selectedCellPoint.getRow())) {
grid.getDragRectangle().setBounds(cellRectangle); grid.getDragRectangle().setBounds(cellRectangle);
} else { } else {
if (isOutECBlockPane(evtX, evtY)) {
return;
}
int xDistance = evtX - this.oldEvtX; int xDistance = evtX - this.oldEvtX;
int yDistance = evtY - this.oldEvtY; int yDistance = evtY - this.oldEvtY;
if (Math.abs(yDistance) > Math.abs(xDistance)) { int dragDirection = calculateDragDirection(xDistance, yDistance);
grid.getDragRectangle().x = cellRectangle.x; grid.getDragRectangle().x = calculateDragRectangleX(selectedCellPoint, cellRectangle, dragDirection);
grid.getDragRectangle().width = cellRectangle.width; grid.getDragRectangle().y = calculateDragRectangleY(selectedCellPoint, cellRectangle, dragDirection);
if (yDistance >= 0) { grid.getDragRectangle().width = calculateDragRectangleWidth(selectedCellPoint, cellRectangle, dragDirection);
// 聚合报表要求拖拽的时候要在本块的内部进行 不能无限往下拖 grid.getDragRectangle().height = calculateDragRectangleHeight(selectedCellPoint, cellRectangle, dragDirection);
if (reportPane instanceof ECBlockPane && evtY > reportPane.getBounds().height - ECBlockGap) { }
return; reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1);
} }
grid.getDragRectangle().y = cellRectangle.y;
grid.getDragRectangle().height = selectedCellPoint.getRow() - cellRectangle.y + 1; private int calculateDragDirection(int xDistance, int yDistance) {
if (Math.abs(yDistance) > Math.abs(xDistance)) {
if (yDistance >= 0) {
return DIRECTION_DOWN;
} else {
return DIRECTION_UP;
}
} else {
if (xDistance >= 0) {
return DIRECTION_RIGHT;
} else {
return DIRECTION_LEFT;
}
}
}
private int calculateDragRectangleX(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
int result = 0;
switch(direction) {
case DIRECTION_DOWN:
case DIRECTION_UP:
case DIRECTION_RIGHT:
result = startRec.x;
break;
case DIRECTION_LEFT:
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) {
result = startRec.x;
} else { } else {
if (selectedCellPoint.getRow() >= cellRectangle.y && selectedCellPoint.getRow() < cellRectangle.y + cellRectangle.height) { result = currentMouseCell.getColumn();
grid.getDragRectangle().y = cellRectangle.y;
grid.getDragRectangle().height = cellRectangle.height;
} else {
grid.getDragRectangle().y = selectedCellPoint.getRow();
grid.getDragRectangle().height = cellRectangle.y - selectedCellPoint.getRow() + cellRectangle.height;
}
} }
} else { break;
grid.getDragRectangle().y = cellRectangle.y; }
grid.getDragRectangle().height = cellRectangle.height; return result;
if (xDistance >= 0) { }
if (reportPane instanceof ECBlockPane && evtX > reportPane.getBounds().width - ECBlockGap) {
return; private int calculateDragRectangleY(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
} int result = 0;
grid.getDragRectangle().x = cellRectangle.x; switch(direction) {
grid.getDragRectangle().width = selectedCellPoint.getColumn() - cellRectangle.x + 1; case DIRECTION_RIGHT:
case DIRECTION_LEFT:
case DIRECTION_DOWN:
result = startRec.y;
break;
case DIRECTION_UP:
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) {
result = startRec.y;
} else { } else {
if (selectedCellPoint.getColumn() >= cellRectangle.x && selectedCellPoint.getColumn() < cellRectangle.x + cellRectangle.width) { result = currentMouseCell.getRow();
grid.getDragRectangle().x = cellRectangle.x;
grid.getDragRectangle().width = cellRectangle.width;
} else {
grid.getDragRectangle().x = selectedCellPoint.getColumn();
grid.getDragRectangle().width = cellRectangle.x - selectedCellPoint.getColumn() + cellRectangle.width;
}
} }
} break;
} }
reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1); return result;
}
private int calculateDragRectangleWidth(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
int result = 0;
switch(direction) {
case DIRECTION_DOWN:
case DIRECTION_UP:
result = startRec.width;
break;
case DIRECTION_RIGHT:
result = currentMouseCell.getColumn() - startRec.x + 1;
break;
case DIRECTION_LEFT:
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) {
result = startRec.width;
} else {
result = startRec.x - currentMouseCell.getColumn() + startRec.width;
}
break;
}
return result;
}
private int calculateDragRectangleHeight(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
int result = 0;
switch(direction) {
case DIRECTION_DOWN:
result = currentMouseCell.getRow() - startRec.y + 1;
break;
case DIRECTION_UP:
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) {
result = startRec.y - currentMouseCell.getRow() + startRec.height;
} else {
result = startRec.height;
}
break;
case DIRECTION_RIGHT:
case DIRECTION_LEFT:
result = startRec.height;
break;
}
return result;
}
private boolean isOutECBlockPane(int evtX, int evtY) {
ElementCasePane reportPane = grid.getElementCasePane();
if (reportPane instanceof ECBlockPane) {
return (evtY > reportPane.getBounds().height - ECBlockGap) || (evtX > reportPane.getBounds().width - ECBlockGap);
}
return true;
}
private boolean isInsideSelectedCell(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
return (direction == DIRECTION_UP && currentMouseCell.getRow() >= startRec.y && currentMouseCell.getRow() < startRec.y + startRec.height) ||
(direction == DIRECTION_LEFT && currentMouseCell.getColumn() >= startRec.x && currentMouseCell.getColumn() < startRec.x + startRec.width);
} }
private void doShiftSelectCell(double evtX, double evtY) { private void doShiftSelectCell(double evtX, double evtY) {

Loading…
Cancel
Save