|
|
@ -79,6 +79,9 @@ public class EditingMouseListener extends MouseInputAdapter { |
|
|
|
//备份开始拖动的位置和大小
|
|
|
|
//备份开始拖动的位置和大小
|
|
|
|
private Rectangle dragBackupBounds; |
|
|
|
private Rectangle dragBackupBounds; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int pressX; |
|
|
|
|
|
|
|
private int pressY; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取最小移动距离 |
|
|
|
* 获取最小移动距离 |
|
|
|
* |
|
|
|
* |
|
|
@ -141,6 +144,8 @@ public class EditingMouseListener extends MouseInputAdapter { |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
int oldX = e.getX(); |
|
|
|
int oldX = e.getX(); |
|
|
|
int oldY = e.getY(); |
|
|
|
int oldY = e.getY(); |
|
|
|
|
|
|
|
pressX = oldX; |
|
|
|
|
|
|
|
pressY = oldY; |
|
|
|
offsetEventPoint(e); |
|
|
|
offsetEventPoint(e); |
|
|
|
if (!stopEditing()) { |
|
|
|
if (!stopEditing()) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -189,6 +194,7 @@ public class EditingMouseListener extends MouseInputAdapter { |
|
|
|
* @param e 鼠标事件 |
|
|
|
* @param e 鼠标事件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
|
|
|
MouseEvent transEvent = new MouseEvent(e.getComponent(), MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton()); |
|
|
|
int oldX = e.getX(); |
|
|
|
int oldX = e.getX(); |
|
|
|
int oldY = e.getY(); |
|
|
|
int oldY = e.getY(); |
|
|
|
offsetEventPoint(e); |
|
|
|
offsetEventPoint(e); |
|
|
@ -213,6 +219,12 @@ public class EditingMouseListener extends MouseInputAdapter { |
|
|
|
lastPressEvent = null; |
|
|
|
lastPressEvent = null; |
|
|
|
lastXCreator = null; |
|
|
|
lastXCreator = null; |
|
|
|
e.translatePoint(oldX - e.getX(), oldY - e.getY()); |
|
|
|
e.translatePoint(oldX - e.getX(), oldY - e.getY()); |
|
|
|
|
|
|
|
if (pressX != oldX || pressY != oldY) { |
|
|
|
|
|
|
|
// click只有在mouseReleased和mousePressed前后x/y坐标相等时才会被触发在mouseReleased之后
|
|
|
|
|
|
|
|
// 但是当使用者来回点击切换时 存在mouseReleased和mousePressed前后x/y坐标不相等的情况 即鼠标按下去的位置和鼠标释放的位置不相等 存在偏移
|
|
|
|
|
|
|
|
// 当这种偏移很小时 看起来就好像是点击了 实际上是手抖了或者鼠标轻微滑动了 所以这里对这种情况要有容错处理
|
|
|
|
|
|
|
|
mouseClicked(transEvent); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void mouseDraggingRelease(MouseEvent e) { |
|
|
|
private void mouseDraggingRelease(MouseEvent e) { |
|
|
|