Skip to content

Commit 604a115

Browse files
8290016: IGV: Fix graph panning when mouse dragged outside of window
Reviewed-by: kvn, thartmann
1 parent 59e495e commit 604a115

File tree

2 files changed

+64
-65
lines changed

2 files changed

+64
-65
lines changed

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import com.sun.hotspot.igv.hierarchicallayout.HierarchicalLayoutManager;
3838
import com.sun.hotspot.igv.layout.LayoutGraph;
3939
import com.sun.hotspot.igv.layout.Link;
40-
import com.sun.hotspot.igv.selectioncoordinator.*;
40+
import com.sun.hotspot.igv.selectioncoordinator.SelectionCoordinator;
4141
import com.sun.hotspot.igv.util.ColorIcon;
4242
import com.sun.hotspot.igv.util.CustomSelectAction;
4343
import com.sun.hotspot.igv.util.DoubleClickAction;
@@ -91,7 +91,6 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
9191
private Widget bottomRight;
9292
private DiagramViewModel model;
9393
private DiagramViewModel modelCopy;
94-
private WidgetAction zoomAction;
9594
private boolean rebuilding;
9695

9796
/**
@@ -267,16 +266,6 @@ public void performSelection(Rectangle rectangle) {
267266
}
268267
};
269268

270-
private MouseWheelListener mouseWheelListener = new MouseWheelListener() {
271-
272-
@Override
273-
public void mouseWheelMoved(MouseWheelEvent e) {
274-
if (e.isControlDown()) {
275-
DiagramScene.this.relayoutWithoutLayout(null);
276-
}
277-
}
278-
};
279-
280269
public Point getScrollPosition() {
281270
return getScrollPane().getViewport().getViewPosition();
282271
}
@@ -406,7 +395,7 @@ public DiagramScene(Action[] actions, Action[] actionsWithSelection, DiagramView
406395
// This panAction handles the event only when the left mouse button is
407396
// pressed without any modifier keys, otherwise it will not consume it
408397
// and the selection action (below) will handle the event
409-
panAction = new CustomizablePanAction(~0, MouseEvent.BUTTON1_DOWN_MASK);
398+
panAction = new CustomizablePanAction(MouseEvent.BUTTON1_DOWN_MASK);
410399
this.getActions().addAction(panAction);
411400

412401
selectAction = new CustomSelectAction(new SelectProvider() {
@@ -455,17 +444,10 @@ public void select(Widget widget, Point localLocation, boolean invertSelection)
455444
bottomRight.setPreferredLocation(new Point(-BORDER_SIZE, -BORDER_SIZE));
456445
this.addChild(bottomRight);
457446

458-
LayerWidget selectionLayer = new LayerWidget(this);
459-
this.addChild(selectionLayer);
460-
461447
this.setLayout(LayoutFactory.createAbsoluteLayout());
462-
463448
this.getInputBindings().setZoomActionModifiers(Utilities.isMac() ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK);
464-
zoomAction = ActionFactory.createMouseCenteredZoomAction(1.2);
465-
this.getActions().addAction(zoomAction);
466-
this.getView().addMouseWheelListener(mouseWheelListener);
449+
this.getActions().addAction(ActionFactory.createMouseCenteredZoomAction(1.1));
467450
this.getActions().addAction(ActionFactory.createPopupMenuAction(popupMenuProvider));
468-
469451
this.getActions().addAction(ActionFactory.createWheelPanAction());
470452

471453
LayerWidget selectLayer = new LayerWidget(this);

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/CustomizablePanAction.java

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 1997, 2015, 2022, Oracle and/or its affiliates. All rights reserved.
55
*
66
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
77
* Other names may be trademarks of their respective owners.
@@ -50,6 +50,7 @@
5050
import javax.swing.JComponent;
5151
import javax.swing.JScrollPane;
5252
import javax.swing.SwingUtilities;
53+
import javax.swing.JScrollBar;
5354
import org.netbeans.api.visual.action.WidgetAction;
5455
import org.netbeans.api.visual.action.WidgetAction.State;
5556
import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent;
@@ -62,16 +63,15 @@
6263
*/
6364
public class CustomizablePanAction extends WidgetAction.LockedAdapter {
6465
private boolean enabled = true;
66+
private boolean active = true;
6567

6668
private Scene scene;
6769
private JScrollPane scrollPane;
6870
private Point lastLocation;
69-
70-
private final int modifiersExMask;
71+
private Rectangle rectangle;
7172
private final int modifiersEx;
7273

73-
public CustomizablePanAction(int modifiersExMask, int modifiersEx) {
74-
this.modifiersExMask = modifiersExMask;
74+
public CustomizablePanAction(int modifiersEx) {
7575
this.modifiersEx = modifiersEx;
7676
}
7777

@@ -80,72 +80,89 @@ protected boolean isLocked() {
8080
return scrollPane != null;
8181
}
8282

83+
private void lock() {
84+
scrollPane = findScrollPane(scene.getView());
85+
}
86+
87+
private void unlock() {
88+
scrollPane = null;
89+
}
90+
8391
public void setEnabled(boolean enabled) {
8492
if (this.enabled != enabled) {
85-
if (isLocked())
93+
if (this.isLocked()) {
8694
throw new IllegalStateException();
87-
95+
}
8896
this.enabled = enabled;
8997
}
9098
}
9199

92100
@Override
93-
public State mousePressed (Widget widget, WidgetMouseEvent event) {
101+
public State mouseEntered(Widget widget, WidgetMouseEvent event) {
102+
active = true;
103+
return super.mouseEntered(widget, event);
104+
}
105+
106+
@Override
107+
public State mouseExited(Widget widget, WidgetMouseEvent event) {
108+
active = false;
109+
return super.mouseExited(widget, event);
110+
}
111+
112+
@Override
113+
public State mousePressed(Widget widget, WidgetMouseEvent event) {
94114
EditorTopComponent editor = EditorTopComponent.getActive();
95115
if (editor != null) {
96116
editor.requestActive();
97117
}
98-
if (isLocked ())
99-
return State.createLocked (widget, this);
100-
if (enabled && (event.getModifiersEx() & modifiersExMask) == modifiersEx) {
101-
scene = widget.getScene ();
102-
scrollPane = findScrollPane (scene.getView ());
103-
if (scrollPane != null) {
104-
lastLocation = scene.convertSceneToView (widget.convertLocalToScene (event.getPoint ()));
105-
SwingUtilities.convertPointToScreen (lastLocation, scene.getView ());
106-
return State.createLocked (widget, this);
118+
if (!this.isLocked() && active && enabled && (event.getModifiersEx() == modifiersEx)) {
119+
scene = widget.getScene();
120+
this.lock();
121+
if (this.isLocked()) {
122+
lastLocation = scene.convertSceneToView(widget.convertLocalToScene(event.getPoint()));
123+
SwingUtilities.convertPointToScreen(lastLocation, scene.getView());
124+
rectangle = scene.getView().getVisibleRect();
107125
}
108126
}
109-
return State.REJECTED;
127+
return super.mousePressed(widget, event);
110128
}
111129

112-
private JScrollPane findScrollPane (JComponent component) {
130+
private JScrollPane findScrollPane(JComponent component) {
113131
for (;;) {
114-
if (component == null)
132+
if (component == null) {
115133
return null;
116-
if (component instanceof JScrollPane)
134+
}
135+
if (component instanceof JScrollPane) {
117136
return ((JScrollPane) component);
118-
Container parent = component.getParent ();
119-
if (! (parent instanceof JComponent))
137+
}
138+
Container parent = component.getParent();
139+
if (!(parent instanceof JComponent)) {
120140
return null;
141+
}
121142
component = (JComponent) parent;
122143
}
123144
}
124145

125146
@Override
126-
public State mouseReleased (Widget widget, WidgetMouseEvent event) {
127-
boolean state = pan (widget, event.getPoint ());
128-
if (state)
129-
scrollPane = null;
130-
return state ? State.createLocked (widget, this) : State.REJECTED;
147+
public State mouseReleased(Widget widget, WidgetMouseEvent event) {
148+
if (this.isLocked() && scene == widget.getScene()) {
149+
this.unlock();
150+
}
151+
return super.mouseReleased(widget, event);
131152
}
132153

133154
@Override
134-
public State mouseDragged (Widget widget, WidgetMouseEvent event) {
135-
return pan (widget, event.getPoint ()) ? State.createLocked (widget, this) : State.REJECTED;
136-
}
137-
138-
private boolean pan (Widget widget, Point newLocation) {
139-
if (scrollPane == null || scene != widget.getScene ())
140-
return false;
141-
newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation));
142-
SwingUtilities.convertPointToScreen (newLocation, scene.getView ());
143-
JComponent view = scene.getView ();
144-
Rectangle rectangle = view.getVisibleRect ();
145-
rectangle.x += lastLocation.x - newLocation.x;
146-
rectangle.y += lastLocation.y - newLocation.y;
147-
view.scrollRectToVisible (rectangle);
148-
lastLocation = newLocation;
149-
return true;
155+
public State mouseDragged(Widget widget, WidgetMouseEvent event) {
156+
if (active && this.isLocked() && scene == widget.getScene()) {
157+
Point newLocation = event.getPoint();
158+
newLocation = scene.convertSceneToView(widget.convertLocalToScene(newLocation));
159+
SwingUtilities.convertPointToScreen(newLocation, scene.getView());
160+
rectangle.x += lastLocation.x - newLocation.x;
161+
rectangle.y += lastLocation.y - newLocation.y;
162+
scene.getView().scrollRectToVisible(rectangle);
163+
lastLocation = newLocation;
164+
return State.createLocked(widget, this);
165+
}
166+
return State.REJECTED;
150167
}
151168
}

0 commit comments

Comments
 (0)