Browse Source

REPORT-54998 完善代码逻辑

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

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

@ -458,20 +458,15 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
java.awt.Rectangle startRec = cs.toRectangle(); java.awt.Rectangle startRec = cs.toRectangle();
ColumnRow currentMouseCell = GridUtils.getAdjustEventColumnRow_withresolution(reportPane, evtX, evtY, resolution); ColumnRow currentMouseCell = GridUtils.getAdjustEventColumnRow_withresolution(reportPane, evtX, evtY, resolution);
if (startRec.contains(currentMouseCell.getColumn(), currentMouseCell.getRow())) { if (isOutECBlockPane(evtX, evtY)) {
grid.getDragRectangle().setBounds(startRec); return;
} else {
if (isOutECBlockPane(evtX, evtY)) {
return;
}
int xDistance = evtX - this.oldEvtX;
int yDistance = evtY - this.oldEvtY;
int dragDirection = calculateDragDirection(xDistance, yDistance);
grid.getDragRectangle().x = calculateDragRectangleX(currentMouseCell, startRec, dragDirection);
grid.getDragRectangle().y = calculateDragRectangleY(currentMouseCell, startRec, dragDirection);
grid.getDragRectangle().width = calculateDragRectangleWidth(currentMouseCell, startRec, dragDirection);
grid.getDragRectangle().height = calculateDragRectangleHeight(currentMouseCell, startRec, dragDirection);
} }
int xDistance = evtX - this.oldEvtX;
int yDistance = evtY - this.oldEvtY;
int dragDirection = calculateDragDirection(xDistance, yDistance);
ColumnRow realCell = calculateRealCell(currentMouseCell, startRec, dragDirection);
grid.getDragRectangle().setBounds(calculateDragRectangle(realCell, startRec, dragDirection));
reportPane.ensureColumnRowVisible(currentMouseCell.getColumn() + 1, currentMouseCell.getRow() + 1); reportPane.ensureColumnRowVisible(currentMouseCell.getColumn() + 1, currentMouseCell.getRow() + 1);
} }
@ -491,97 +486,90 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
} }
} }
private int calculateDragRectangleX(ColumnRow currentMouseCell, Rectangle startRec, int direction) { /**
int result = 0; * 计算当前十字标所在格子对应的真正参与计算拖拽边框的格子
* @param currentMouseCell 当前鼠标所在的格子
* @param startRec 起始格子
* @param direction 拖拽方向
* @return 当前十字标所在格子对应的真正参与计算拖拽边框的格子
*/
private ColumnRow calculateRealCell(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
ColumnRow realCell;
switch(direction) { switch(direction) {
case DIRECTION_DOWN: case DIRECTION_DOWN:
case DIRECTION_UP: case DIRECTION_UP:
case DIRECTION_RIGHT: realCell = ColumnRow.valueOf(startRec.x, currentMouseCell.row);
result = startRec.x;
break; break;
case DIRECTION_LEFT:
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) {
result = startRec.x;
} else {
result = currentMouseCell.getColumn();
}
break;
}
return result;
}
private int calculateDragRectangleY(ColumnRow currentMouseCell, Rectangle startRec, int direction) {
int result = 0;
switch(direction) {
case DIRECTION_RIGHT: case DIRECTION_RIGHT:
case DIRECTION_LEFT: case DIRECTION_LEFT:
case DIRECTION_DOWN: realCell = ColumnRow.valueOf(currentMouseCell.column, startRec.y);
result = startRec.y;
break; break;
case DIRECTION_UP: default:
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) { realCell = currentMouseCell;
result = startRec.y;
} else {
result = currentMouseCell.getRow();
}
break; break;
} }
return result; return realCell;
} }
private int calculateDragRectangleWidth(ColumnRow currentMouseCell, Rectangle startRec, int direction) { /**
int result = 0; * 计算拖拽的边框
switch(direction) { * @param realCell 当前十字标所在格子对应的真正参与计算拖拽边框的格子
case DIRECTION_DOWN: * @param startRec 起始格子
case DIRECTION_UP: * @param direction 拖拽方向
result = startRec.width; * @return 拖拽的边框
break; */
case DIRECTION_RIGHT: private Rectangle calculateDragRectangle(ColumnRow realCell, Rectangle startRec, int direction) {
result = currentMouseCell.getColumn() - startRec.x + 1; Rectangle rectangle = new Rectangle();
break; if (startRec.contains(realCell.column, realCell.row)) {
case DIRECTION_LEFT: rectangle.setBounds(startRec);
if (isInsideSelectedCell(currentMouseCell, startRec, direction)) { } else {
result = startRec.width; boolean clockWise = isClockWise(direction);
} else { int x, y, width, height;
result = startRec.x - currentMouseCell.getColumn() + startRec.width; if (clockWise) {
} x = startRec.x;
break; y = startRec.y;
width = Math.abs(realCell.column - startRec.x) + 1; // 加一是因为计算顺时针边框宽度或者高度的时候,没把realCell自身高度算进去
height = Math.abs(realCell.row - startRec.y) + 1;
} else {
x = realCell.column;
y = realCell.row;
width = Math.abs(realCell.column - startRec.x) + startRec.width;
height = Math.abs(realCell.row - startRec.y) + startRec.height;
}
// 上面的只计算了顺时针和逆时针的width,height,但是还要顺时针里面还要区分从左往右和从上往下,这里是用于修正
boolean isHorizontal = isHorizontal(direction);
if (isHorizontal) {
height = startRec.height; // 水平方向,绘制的边框肯定就等于起始格子的高度
} else {
width = startRec.width; // 垂直方向,绘制的边框肯定就等于起始给子的宽度
}
rectangle.setBounds(x, y, width, height);
} }
return result; return rectangle;
} }
private int calculateDragRectangleHeight(ColumnRow currentMouseCell, Rectangle startRec, int direction) { /**
int result = 0; * 判断拖拽方向是否是顺时针 从左往右从上往下为顺时针从右往左从下往上为逆时针
switch(direction) { * @param direction 方向
case DIRECTION_DOWN: * @return 是否是顺时针
result = currentMouseCell.getRow() - startRec.y + 1; */
break; private boolean isClockWise(int direction) {
case DIRECTION_UP: return direction == DIRECTION_DOWN || direction == DIRECTION_RIGHT;
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) { * @param direction 方向
return (evtY > reportPane.getBounds().height - ECBlockGap) || (evtX > reportPane.getBounds().width - ECBlockGap); * @return 是否为水平
} */
return true; private boolean isHorizontal(int direction) {
return direction == DIRECTION_RIGHT || direction == DIRECTION_LEFT;
} }
private boolean isInsideSelectedCell(ColumnRow currentMouseCell, Rectangle startRec, int direction) { private boolean isOutECBlockPane(int evtX, int evtY) {
return (direction == DIRECTION_UP && currentMouseCell.getRow() >= startRec.y && currentMouseCell.getRow() < startRec.y + startRec.height) || ElementCasePane reportPane = grid.getElementCasePane();
(direction == DIRECTION_LEFT && currentMouseCell.getColumn() >= startRec.x && currentMouseCell.getColumn() < startRec.x + startRec.width); return reportPane instanceof ECBlockPane && ((evtY > reportPane.getBounds().height - ECBlockGap) || (evtX > reportPane.getBounds().width - ECBlockGap));
} }
private void doShiftSelectCell(double evtX, double evtY) { private void doShiftSelectCell(double evtX, double evtY) {

Loading…
Cancel
Save