Skip to content

Commit 3135914

Browse files
8265441: IGV: select block nodes by clicking on it
Reviewed-by: rcastanedalo, thartmann
1 parent 78454b6 commit 3135914

File tree

16 files changed

+156
-188
lines changed

16 files changed

+156
-188
lines changed

src/utils/IdealGraphVisualizer/Bytecodes/src/main/java/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ protected void performAction(Node[] activatedNodes) {
4141
SelectBytecodesCookie c = activatedNodes[0].getCookie(SelectBytecodesCookie.class);
4242
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
4343
if (p != null) {
44-
p.setSelectedNodes(c.getNodes());
44+
p.clearSelectedNodes();
45+
p.addSelectedNodes(c.getNodes());
4546
}
4647
}
4748

src/utils/IdealGraphVisualizer/ControlFlow/src/main/java/com/sun/hotspot/igv/controlflow/ControlFlowScene.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ public void selectionChanged() {
133133
for (BlockWidget w : selection) {
134134
inputNodes.addAll(w.getBlock().getNodes());
135135
}
136-
p.setSelectedNodes(inputNodes);
136+
p.clearSelectedNodes();
137+
p.addSelectedNodes(inputNodes);
137138
}
138139
}
139140

src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/services/InputGraphProvider.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import com.sun.hotspot.igv.data.InputGraph;
2828
import com.sun.hotspot.igv.data.InputNode;
29-
import java.util.Set;
29+
import java.util.Collection;
3030

3131
/**
3232
*
@@ -36,7 +36,10 @@ public interface InputGraphProvider {
3636

3737
InputGraph getGraph();
3838

39-
void setSelectedNodes(Set<InputNode> nodes);
39+
void addSelectedNodes(Collection<InputNode> nodes);
40+
41+
void clearSelectedNodes();
42+
4043

4144
/**
4245
* @return an iterator walking forward through the {@link InputGraph}s following the {@link #getGraph()}

src/utils/IdealGraphVisualizer/Filter/src/main/java/com/sun/hotspot/igv/filter/SplitFilter.java

-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public void apply(Diagram d) {
5858
OutputSlot os = c.getOutputSlot();
5959
if (f.getInputNode() != null) {
6060
os.getSource().addSourceNode(f.getInputNode());
61-
os.setAssociatedNode(f.getInputNode());
6261
os.setColor(f.getColor());
6362
}
6463

@@ -75,7 +74,6 @@ public void apply(Diagram d) {
7574
InputSlot is = c.getInputSlot();
7675
if (f.getInputNode() != null) {
7776
is.getSource().addSourceNode(f.getInputNode());
78-
is.setAssociatedNode(f.getInputNode());
7977
is.setColor(f.getColor());
8078
}
8179

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ public void evaluate(SearchRequest request, SearchResponse response) {
8787
final InputGraph theGraph = p.getGraph() != matchGraph ? matchGraph : null;
8888
for (final InputBlock b : matches) {
8989
if (!response.addResult(() -> {
90-
final EditorTopComponent comp = EditorTopComponent.getActive();
91-
assert(comp != null);
90+
final EditorTopComponent editor = EditorTopComponent.getActive();
91+
assert(editor != null);
9292
if (theGraph != null) {
93-
comp.getModel().selectGraph(theGraph);
93+
editor.getModel().selectGraph(theGraph);
9494
}
95-
comp.setSelectedNodes(b);
96-
comp.requestActive();
95+
editor.clearSelectedNodes();
96+
editor.addSelectedNodes(b.getNodes(), true);
97+
editor.requestActive();
9798
},
9899
"B" + b.getName() + (theGraph != null ? " in " + theGraph.getName() : ""))) {
99100
return;

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

+63-108
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
import com.sun.hotspot.igv.hierarchicallayout.LinearLayoutManager;
3333
import com.sun.hotspot.igv.layout.LayoutGraph;
3434
import com.sun.hotspot.igv.selectioncoordinator.SelectionCoordinator;
35-
import com.sun.hotspot.igv.util.ColorIcon;
36-
import com.sun.hotspot.igv.util.DoubleClickAction;
37-
import com.sun.hotspot.igv.util.PropertiesSheet;
35+
import com.sun.hotspot.igv.util.*;
3836
import com.sun.hotspot.igv.view.actions.CustomSelectAction;
3937
import com.sun.hotspot.igv.view.actions.CustomizablePanAction;
4038
import com.sun.hotspot.igv.view.actions.MouseZoomAction;
@@ -70,7 +68,7 @@
7068
*
7169
* @author Thomas Wuerthinger
7270
*/
73-
public class DiagramScene extends ObjectScene implements DiagramViewer {
71+
public class DiagramScene extends ObjectScene implements DiagramViewer, DoubleClickHandler {
7472

7573
private final CustomizablePanAction panAction;
7674
private final WidgetAction hoverAction;
@@ -186,26 +184,26 @@ public ChangedEvent<DiagramViewer> getZoomChangedEvent() {
186184
}
187185

188186
@Override
189-
public void centerFigures(List<Figure> figures) {
190-
Rectangle overall = null;
187+
public void centerFigures(Collection<Figure> figures) {
191188
getModel().showFigures(figures);
192-
for (Figure f : figures) {
193-
FigureWidget fw = getWidget(f);
194-
if (fw != null) {
195-
Rectangle r = fw.getBounds();
196-
Point p = fw.getLocation();
197-
assert r != null;
198-
Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height);
199-
200-
if (overall == null) {
201-
overall = r2;
202-
} else {
203-
overall = overall.union(r2);
189+
Rectangle overallRect = null;
190+
for (Figure figure : figures) {
191+
FigureWidget figureWidget = getWidget(figure);
192+
if (figureWidget != null) {
193+
Rectangle bounds = figureWidget.getBounds();
194+
if (bounds != null) {
195+
Point location = figureWidget.getLocation();
196+
Rectangle figureRect = new Rectangle(location.x, location.y, bounds.width, bounds.height);
197+
if (overallRect == null) {
198+
overallRect = figureRect;
199+
} else {
200+
overallRect = overallRect.union(figureRect);
201+
}
204202
}
205203
}
206204
}
207-
if (overall != null) {
208-
centerRectangle(overall);
205+
if (overallRect != null) {
206+
centerRectangle(overallRect);
209207
}
210208
}
211209

@@ -221,7 +219,15 @@ public void filteredChanged(SelectionCoordinator source) {
221219

222220
@Override
223221
public void filteredChanged(SelectionCoordinator source) {
224-
gotoSelection(source.getSelectedObjects());
222+
Set<Integer> ids = source.getSelectedObjects();
223+
Set<Figure> figures = new HashSet<>();
224+
for (Figure f : getModel().getDiagram().getFigures()) {
225+
if (ids.contains(f.getInputNode().getId())) {
226+
figures.add(f);
227+
}
228+
}
229+
centerFigures(figures);
230+
setSelectedObjects(idSetToObjectSet(ids));
225231
validate();
226232
}
227233
};
@@ -286,6 +292,9 @@ public DiagramScene(Action[] actions, Action[] actionsWithSelection, DiagramView
286292
panAction = new CustomizablePanAction(MouseEvent.BUTTON1_DOWN_MASK);
287293
getActions().addAction(panAction);
288294

295+
// handle default double-click, when not handled by other DoubleClickHandler
296+
getActions().addAction(new DoubleClickAction(this));
297+
289298
selectAction = new CustomSelectAction(new SelectProvider() {
290299
public boolean isAimingAllowed(Widget widget, Point localLocation, boolean invertSelection) {
291300
return false;
@@ -375,7 +384,12 @@ public void select(Widget widget, Point localLocation, boolean invertSelection)
375384
}
376385
}
377386

378-
setSelectedObjects(selectedObjects);
387+
Set<Object> symmetricDiff = new HashSet<>(getSelectedObjects());
388+
symmetricDiff.addAll(selectedObjects);
389+
Set<Object> tmp = new HashSet<>(getSelectedObjects());
390+
tmp.retainAll(selectedObjects);
391+
symmetricDiff.removeAll(tmp);
392+
setSelectedObjects(symmetricDiff);
379393
};
380394
getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider));
381395

@@ -487,46 +501,42 @@ public boolean isAllVisible() {
487501
return getModel().getHiddenNodes().isEmpty();
488502
}
489503

490-
public Action createGotoAction(final Figure f) {
491-
final DiagramScene diagramScene = this;
492-
String name = f.getLines()[0];
493-
504+
public Action createGotoAction(final Figure figure) {
505+
String name = figure.getLines()[0];
494506
name += " (";
495-
496-
if (f.getCluster() != null) {
497-
name += "B" + f.getCluster().toString();
507+
if (figure.getCluster() != null) {
508+
name += "B" + figure.getCluster().toString();
498509
}
499-
final boolean hidden = !getWidget(f, FigureWidget.class).isVisible();
500-
if (hidden) {
501-
if (f.getCluster() != null) {
510+
boolean isHidden = !getWidget(figure, FigureWidget.class).isVisible();
511+
if (isHidden) {
512+
if (figure.getCluster() != null) {
502513
name += ", ";
503514
}
504515
name += "hidden";
505516
}
506517
name += ")";
507-
Action a = new AbstractAction(name, new ColorIcon(f.getColor())) {
508-
518+
Action action = new AbstractAction(name, new ColorIcon(figure.getColor())) {
509519
@Override
510520
public void actionPerformed(ActionEvent e) {
511-
diagramScene.gotoFigure(f);
521+
setFigureSelection(Collections.singleton(figure));
522+
centerFigures(Collections.singleton(figure));
512523
}
513524
};
514525

515-
a.setEnabled(true);
516-
return a;
526+
action.setEnabled(true);
527+
return action;
517528
}
518529

519-
public Action createGotoAction(final Block b) {
520-
final DiagramScene diagramScene = this;
521-
String name = "B" + b.getInputBlock().getName();
522-
Action a = new AbstractAction(name) {
530+
public Action createGotoAction(final Block block) {
531+
String name = "B" + block.getInputBlock().getName();
532+
Action action = new AbstractAction(name) {
523533
@Override
524534
public void actionPerformed(ActionEvent e) {
525-
diagramScene.gotoBlock(b);
535+
gotoBlock(block);
526536
}
527537
};
528-
a.setEnabled(true);
529-
return a;
538+
action.setEnabled(true);
539+
return action;
530540
}
531541

532542
private void update() {
@@ -561,7 +571,7 @@ private void update() {
561571
f.setWidth(maxWidth.get(f.getBlock().getInputBlock()));
562572
}
563573

564-
FigureWidget w = new FigureWidget(f, hoverAction, selectAction, this, mainLayer);
574+
FigureWidget w = new FigureWidget(f, this, mainLayer);
565575
w.getActions().addAction(ActionFactory.createPopupMenuAction(w));
566576
w.getActions().addAction(selectAction);
567577
w.getActions().addAction(hoverAction);
@@ -588,7 +598,8 @@ private void update() {
588598

589599
if (getModel().getShowBlocks() || getModel().getShowCFG()) {
590600
for (InputBlock bn : d.getInputBlocks()) {
591-
BlockWidget w = new BlockWidget(this, d, bn);
601+
BlockWidget w = new BlockWidget(this, bn);
602+
w.getActions().addAction(new DoubleClickAction(w));
592603
w.setVisible(false);
593604
addObject(bn, w);
594605
blockLayer.addChild(w);
@@ -891,6 +902,11 @@ public void setInteractionMode(InteractionMode mode) {
891902
// and the selection action handles it instead
892903
}
893904

905+
@Override
906+
public void handleDoubleClick(Widget w, WidgetAction.WidgetMouseEvent e) {
907+
setSelectedObjects(Collections.emptySet());
908+
}
909+
894910
private class ConnectionSet {
895911

896912
private Set<Connection> connections;
@@ -932,38 +948,6 @@ private Set<Object> idSetToObjectSet(Set<Integer> ids) {
932948
return result;
933949
}
934950

935-
private void gotoSelection(Set<Integer> ids) {
936-
937-
Rectangle overall = null;
938-
Set<Integer> hiddenNodes = new HashSet<>(getModel().getHiddenNodes());
939-
hiddenNodes.removeAll(ids);
940-
getModel().setHiddenNodes(hiddenNodes);
941-
942-
Set<Object> objects = idSetToObjectSet(ids);
943-
for (Object o : objects) {
944-
945-
Widget w = getWidget(o);
946-
if (w != null) {
947-
Rectangle r = w.getBounds();
948-
Point p = w.convertLocalToScene(new Point(0, 0));
949-
950-
assert r != null;
951-
Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height);
952-
953-
if (overall == null) {
954-
overall = r2;
955-
} else {
956-
overall = overall.union(r2);
957-
}
958-
}
959-
}
960-
if (overall != null) {
961-
centerRectangle(overall);
962-
}
963-
964-
setSelectedObjects(objects);
965-
}
966-
967951
private void centerRectangle(Rectangle r) {
968952
Rectangle rect = convertSceneToView(r);
969953
Rectangle viewRect = scrollPane.getViewport().getViewRect();
@@ -986,7 +970,7 @@ private void centerRectangle(Rectangle r) {
986970
}
987971

988972
@Override
989-
public void setSelection(Collection<Figure> list) {
973+
public void setFigureSelection(Set<Figure> list) {
990974
super.setSelectedObjects(new HashSet<>(list));
991975
}
992976

@@ -1004,10 +988,6 @@ public UndoRedo getUndoRedo() {
1004988
return getUndoRedoManager();
1005989
}
1006990

1007-
private boolean isVisible(Figure f) {
1008-
return !getModel().getHiddenNodes().contains(f.getInputNode().getId());
1009-
}
1010-
1011991
@Override
1012992
public void componentHidden() {
1013993
SelectionCoordinator.getInstance().getHighlightedChangedEvent().removeListener(highlightedCoordinatorListener);
@@ -1122,31 +1102,6 @@ private void updateHiddenNodes(Set<Integer> newHiddenNodes, boolean doRelayout)
11221102
validate();
11231103
}
11241104

1125-
private void showFigure(Figure f) {
1126-
HashSet<Integer> newHiddenNodes = new HashSet<>(getModel().getHiddenNodes());
1127-
newHiddenNodes.remove(f.getInputNode().getId());
1128-
getModel().setHiddenNodes(newHiddenNodes);
1129-
}
1130-
1131-
private void centerWidget(Widget w) {
1132-
Rectangle r = w.getBounds();
1133-
Point p = w.getLocation();
1134-
assert r != null;
1135-
centerRectangle(new Rectangle(p.x, p.y, r.width, r.height));
1136-
}
1137-
1138-
public void gotoFigure(final Figure f) {
1139-
if (!isVisible(f)) {
1140-
showFigure(f);
1141-
}
1142-
1143-
FigureWidget fw = getWidget(f);
1144-
if (fw != null) {
1145-
centerWidget(fw);
1146-
setSelection(Collections.singletonList(f));
1147-
}
1148-
}
1149-
11501105
public JPopupMenu createPopupMenu() {
11511106
JPopupMenu menu = new JPopupMenu();
11521107

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,13 @@ public void setSelectedNodes(Set<Integer> nodes) {
242242
}
243243

244244
public void showFigures(Collection<Figure> figures) {
245-
HashSet<Integer> newHiddenNodes = new HashSet<>(getHiddenNodes());
245+
HashSet<Integer> newHiddenNodes = new HashSet<>(hiddenNodes);
246246
for (Figure f : figures) {
247247
newHiddenNodes.remove(f.getInputNode().getId());
248248
}
249249
setHiddenNodes(newHiddenNodes);
250250
}
251251

252-
253252
public Set<Figure> getSelectedFigures() {
254253
Set<Figure> result = new HashSet<>();
255254
for (Figure f : diagram.getFigures()) {

0 commit comments

Comments
 (0)