Browse Source

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

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

133
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;
int dragDirection = calculateDragDirection(xDistance, yDistance);
grid.getDragRectangle().x = calculateDragRectangleX(selectedCellPoint, cellRectangle, dragDirection);
grid.getDragRectangle().y = calculateDragRectangleY(selectedCellPoint, cellRectangle, dragDirection);
grid.getDragRectangle().width = calculateDragRectangleWidth(selectedCellPoint, cellRectangle, dragDirection);
grid.getDragRectangle().height = calculateDragRectangleHeight(selectedCellPoint, cellRectangle, dragDirection);
}
reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1);
}
private int calculateDragDirection(int xDistance, int yDistance) {
if (Math.abs(yDistance) > Math.abs(xDistance)) { if (Math.abs(yDistance) > Math.abs(xDistance)) {
grid.getDragRectangle().x = cellRectangle.x;
grid.getDragRectangle().width = cellRectangle.width;
if (yDistance >= 0) { if (yDistance >= 0) {
// 聚合报表要求拖拽的时候要在本块的内部进行 不能无限往下拖 return DIRECTION_DOWN;
if (reportPane instanceof ECBlockPane && evtY > reportPane.getBounds().height - ECBlockGap) { } else {
return; return DIRECTION_UP;
} }
grid.getDragRectangle().y = cellRectangle.y;
grid.getDragRectangle().height = selectedCellPoint.getRow() - cellRectangle.y + 1;
} else { } else {
if (selectedCellPoint.getRow() >= cellRectangle.y && selectedCellPoint.getRow() < cellRectangle.y + cellRectangle.height) { if (xDistance >= 0) {
grid.getDragRectangle().y = cellRectangle.y; return DIRECTION_RIGHT;
grid.getDragRectangle().height = cellRectangle.height;
} else { } else {
grid.getDragRectangle().y = selectedCellPoint.getRow(); return DIRECTION_LEFT;
grid.getDragRectangle().height = cellRectangle.y - selectedCellPoint.getRow() + cellRectangle.height; }
} }
} }
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 {
grid.getDragRectangle().y = cellRectangle.y; result = currentMouseCell.getColumn();
grid.getDragRectangle().height = cellRectangle.height;
if (xDistance >= 0) {
if (reportPane instanceof ECBlockPane && evtX > reportPane.getBounds().width - ECBlockGap) {
return;
} }
grid.getDragRectangle().x = cellRectangle.x; break;
grid.getDragRectangle().width = selectedCellPoint.getColumn() - cellRectangle.x + 1; }
return result;
}
private int calculateDragRectangleY(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
int result = 0;
switch(direction) {
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; break;
}
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 { } else {
grid.getDragRectangle().x = selectedCellPoint.getColumn(); result = startRec.x - currentMouseCell.getColumn() + startRec.width;
grid.getDragRectangle().width = cellRectangle.x - selectedCellPoint.getColumn() + cellRectangle.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;
} }
reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1); 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