|
|
|
@ -463,52 +463,30 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
|
|
|
|
|
} |
|
|
|
|
int xDistance = evtX - this.oldEvtX; |
|
|
|
|
int yDistance = evtY - this.oldEvtY; |
|
|
|
|
int dragDirection = calculateDragDirection(xDistance, yDistance); |
|
|
|
|
Rectangle endRec = calculateEndRec(currentMouseCell, startRec, dragDirection); |
|
|
|
|
boolean isHorizontal = isHorizontal(xDistance, yDistance); |
|
|
|
|
Rectangle endRec = calculateEndRec(currentMouseCell, startRec, isHorizontal); |
|
|
|
|
grid.getDragRectangle().setBounds(calculateDragRectangle(startRec, endRec)); |
|
|
|
|
|
|
|
|
|
reportPane.ensureColumnRowVisible(currentMouseCell.getColumn() + 1, currentMouseCell.getRow() + 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 boolean isHorizontal(int xDistance, int yDistance) { |
|
|
|
|
return Math.abs(yDistance) <= Math.abs(xDistance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算拖拽的结尾矩形 |
|
|
|
|
* @param currentMouseCell 当前鼠标所在的格子 |
|
|
|
|
* @param startRec 起始格子 |
|
|
|
|
* @param direction 拖拽方向 |
|
|
|
|
* @param isHorizontal 拖拽方向 水平or垂直 |
|
|
|
|
* @return 计算拖拽的结尾矩形 |
|
|
|
|
*/ |
|
|
|
|
private Rectangle calculateEndRec(ColumnRow currentMouseCell, Rectangle startRec, int direction) { |
|
|
|
|
Rectangle rec; |
|
|
|
|
switch(direction) { |
|
|
|
|
case DIRECTION_DOWN: |
|
|
|
|
case DIRECTION_UP: |
|
|
|
|
rec = new Rectangle(startRec.x, currentMouseCell.row, 1, 1); |
|
|
|
|
break; |
|
|
|
|
case DIRECTION_RIGHT: |
|
|
|
|
case DIRECTION_LEFT: |
|
|
|
|
rec = new Rectangle(currentMouseCell.column, startRec.y, 1, 1); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
rec = new Rectangle(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
return rec; |
|
|
|
|
private Rectangle calculateEndRec(ColumnRow currentMouseCell, Rectangle startRec, boolean isHorizontal) { |
|
|
|
|
if (isHorizontal) { |
|
|
|
|
return new Rectangle(currentMouseCell.column, startRec.y, 1, 1); |
|
|
|
|
} else { |
|
|
|
|
return new Rectangle(startRec.x, currentMouseCell.row, 1, 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|