mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-81363 'triangular' logic doesn't work if one initially moves mouse over the menu item in 'wrong' direction. After that submenu would disappear quickly and not user-friendly.
This commit is contained in:
@@ -359,6 +359,10 @@ public final class ActionMenu extends JMenu {
|
||||
private SingleAlarm myCallbackAlarm;
|
||||
private MouseEvent myEventToRedispatch;
|
||||
|
||||
private long myLastEventTime = 0L;
|
||||
private boolean myInBounds = false;
|
||||
private SingleAlarm myCheckAlarm;
|
||||
|
||||
private UsabilityHelper(Component component) {
|
||||
myCallbackAlarm = new SingleAlarm(new Runnable() {
|
||||
@Override
|
||||
@@ -370,6 +374,17 @@ public final class ActionMenu extends JMenu {
|
||||
}
|
||||
}
|
||||
}, 50, this);
|
||||
myCheckAlarm = new SingleAlarm(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myLastEventTime > 0 && System.currentTimeMillis() - myLastEventTime > 1500) {
|
||||
if (!myInBounds && myCallbackAlarm != null && !myCallbackAlarm.isDisposed()) {
|
||||
myCallbackAlarm.request();
|
||||
}
|
||||
}
|
||||
myCheckAlarm.request();
|
||||
}
|
||||
}, 100, this);
|
||||
myComponent = component;
|
||||
PointerInfo info = MouseInfo.getPointerInfo();
|
||||
myLastMousePoint = info != null ? info.getLocation() : null;
|
||||
@@ -410,17 +425,19 @@ public final class ActionMenu extends JMenu {
|
||||
Point point = ((MouseEvent)e).getLocationOnScreen();
|
||||
Rectangle bounds = myComponent.getBounds();
|
||||
bounds.setLocation(myComponent.getLocationOnScreen());
|
||||
|
||||
myCallbackAlarm.cancel();
|
||||
boolean isMouseMovingTowardsSubmenu = bounds.contains(point) || new Polygon(
|
||||
myInBounds = bounds.contains(point);
|
||||
boolean isMouseMovingTowardsSubmenu = myInBounds || new Polygon(
|
||||
new int[]{myLastMousePoint.x, myUpperTargetPoint.x, myLowerTargetPoint.x},
|
||||
new int[]{myLastMousePoint.y, myUpperTargetPoint.y, myLowerTargetPoint.y},
|
||||
3).contains(point);
|
||||
|
||||
myEventToRedispatch = (MouseEvent)e;
|
||||
myLastEventTime = System.currentTimeMillis();
|
||||
|
||||
if (!isMouseMovingTowardsSubmenu) {
|
||||
myCallbackAlarm.request();
|
||||
} else {
|
||||
myCallbackAlarm.cancel();
|
||||
}
|
||||
myLastMousePoint = point;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user