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