Skip to content

Commit

Permalink
8265441: IGV: select block nodes by clicking on it
Browse files Browse the repository at this point in the history
Reviewed-by: rcastanedalo, thartmann
  • Loading branch information
tobiasholenstein committed Oct 26, 2022
1 parent 78454b6 commit 3135914
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 188 deletions.
Expand Up @@ -41,7 +41,8 @@ protected void performAction(Node[] activatedNodes) {
SelectBytecodesCookie c = activatedNodes[0].getCookie(SelectBytecodesCookie.class);
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
if (p != null) {
p.setSelectedNodes(c.getNodes());
p.clearSelectedNodes();
p.addSelectedNodes(c.getNodes());
}
}

Expand Down
Expand Up @@ -133,7 +133,8 @@ public void selectionChanged() {
for (BlockWidget w : selection) {
inputNodes.addAll(w.getBlock().getNodes());
}
p.setSelectedNodes(inputNodes);
p.clearSelectedNodes();
p.addSelectedNodes(inputNodes);
}
}

Expand Down
Expand Up @@ -26,7 +26,7 @@

import com.sun.hotspot.igv.data.InputGraph;
import com.sun.hotspot.igv.data.InputNode;
import java.util.Set;
import java.util.Collection;

/**
*
Expand All @@ -36,7 +36,10 @@ public interface InputGraphProvider {

InputGraph getGraph();

void setSelectedNodes(Set<InputNode> nodes);
void addSelectedNodes(Collection<InputNode> nodes);

void clearSelectedNodes();


/**
* @return an iterator walking forward through the {@link InputGraph}s following the {@link #getGraph()}
Expand Down
Expand Up @@ -58,7 +58,6 @@ public void apply(Diagram d) {
OutputSlot os = c.getOutputSlot();
if (f.getInputNode() != null) {
os.getSource().addSourceNode(f.getInputNode());
os.setAssociatedNode(f.getInputNode());
os.setColor(f.getColor());
}

Expand All @@ -75,7 +74,6 @@ public void apply(Diagram d) {
InputSlot is = c.getInputSlot();
if (f.getInputNode() != null) {
is.getSource().addSourceNode(f.getInputNode());
is.setAssociatedNode(f.getInputNode());
is.setColor(f.getColor());
}

Expand Down
Expand Up @@ -87,13 +87,14 @@ public void evaluate(SearchRequest request, SearchResponse response) {
final InputGraph theGraph = p.getGraph() != matchGraph ? matchGraph : null;
for (final InputBlock b : matches) {
if (!response.addResult(() -> {
final EditorTopComponent comp = EditorTopComponent.getActive();
assert(comp != null);
final EditorTopComponent editor = EditorTopComponent.getActive();
assert(editor != null);
if (theGraph != null) {
comp.getModel().selectGraph(theGraph);
editor.getModel().selectGraph(theGraph);
}
comp.setSelectedNodes(b);
comp.requestActive();
editor.clearSelectedNodes();
editor.addSelectedNodes(b.getNodes(), true);
editor.requestActive();
},
"B" + b.getName() + (theGraph != null ? " in " + theGraph.getName() : ""))) {
return;
Expand Down
Expand Up @@ -32,9 +32,7 @@
import com.sun.hotspot.igv.hierarchicallayout.LinearLayoutManager;
import com.sun.hotspot.igv.layout.LayoutGraph;
import com.sun.hotspot.igv.selectioncoordinator.SelectionCoordinator;
import com.sun.hotspot.igv.util.ColorIcon;
import com.sun.hotspot.igv.util.DoubleClickAction;
import com.sun.hotspot.igv.util.PropertiesSheet;
import com.sun.hotspot.igv.util.*;
import com.sun.hotspot.igv.view.actions.CustomSelectAction;
import com.sun.hotspot.igv.view.actions.CustomizablePanAction;
import com.sun.hotspot.igv.view.actions.MouseZoomAction;
Expand Down Expand Up @@ -70,7 +68,7 @@
*
* @author Thomas Wuerthinger
*/
public class DiagramScene extends ObjectScene implements DiagramViewer {
public class DiagramScene extends ObjectScene implements DiagramViewer, DoubleClickHandler {

private final CustomizablePanAction panAction;
private final WidgetAction hoverAction;
Expand Down Expand Up @@ -186,26 +184,26 @@ public ChangedEvent<DiagramViewer> getZoomChangedEvent() {
}

@Override
public void centerFigures(List<Figure> figures) {
Rectangle overall = null;
public void centerFigures(Collection<Figure> figures) {
getModel().showFigures(figures);
for (Figure f : figures) {
FigureWidget fw = getWidget(f);
if (fw != null) {
Rectangle r = fw.getBounds();
Point p = fw.getLocation();
assert r != null;
Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height);

if (overall == null) {
overall = r2;
} else {
overall = overall.union(r2);
Rectangle overallRect = null;
for (Figure figure : figures) {
FigureWidget figureWidget = getWidget(figure);
if (figureWidget != null) {
Rectangle bounds = figureWidget.getBounds();
if (bounds != null) {
Point location = figureWidget.getLocation();
Rectangle figureRect = new Rectangle(location.x, location.y, bounds.width, bounds.height);
if (overallRect == null) {
overallRect = figureRect;
} else {
overallRect = overallRect.union(figureRect);
}
}
}
}
if (overall != null) {
centerRectangle(overall);
if (overallRect != null) {
centerRectangle(overallRect);
}
}

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

@Override
public void filteredChanged(SelectionCoordinator source) {
gotoSelection(source.getSelectedObjects());
Set<Integer> ids = source.getSelectedObjects();
Set<Figure> figures = new HashSet<>();
for (Figure f : getModel().getDiagram().getFigures()) {
if (ids.contains(f.getInputNode().getId())) {
figures.add(f);
}
}
centerFigures(figures);
setSelectedObjects(idSetToObjectSet(ids));
validate();
}
};
Expand Down Expand Up @@ -286,6 +292,9 @@ public DiagramScene(Action[] actions, Action[] actionsWithSelection, DiagramView
panAction = new CustomizablePanAction(MouseEvent.BUTTON1_DOWN_MASK);
getActions().addAction(panAction);

// handle default double-click, when not handled by other DoubleClickHandler
getActions().addAction(new DoubleClickAction(this));

selectAction = new CustomSelectAction(new SelectProvider() {
public boolean isAimingAllowed(Widget widget, Point localLocation, boolean invertSelection) {
return false;
Expand Down Expand Up @@ -375,7 +384,12 @@ public void select(Widget widget, Point localLocation, boolean invertSelection)
}
}

setSelectedObjects(selectedObjects);
Set<Object> symmetricDiff = new HashSet<>(getSelectedObjects());
symmetricDiff.addAll(selectedObjects);
Set<Object> tmp = new HashSet<>(getSelectedObjects());
tmp.retainAll(selectedObjects);
symmetricDiff.removeAll(tmp);
setSelectedObjects(symmetricDiff);
};
getActions().addAction(ActionFactory.createRectangularSelectAction(rectangularSelectDecorator, selectLayer, rectangularSelectProvider));

Expand Down Expand Up @@ -487,46 +501,42 @@ public boolean isAllVisible() {
return getModel().getHiddenNodes().isEmpty();
}

public Action createGotoAction(final Figure f) {
final DiagramScene diagramScene = this;
String name = f.getLines()[0];

public Action createGotoAction(final Figure figure) {
String name = figure.getLines()[0];
name += " (";

if (f.getCluster() != null) {
name += "B" + f.getCluster().toString();
if (figure.getCluster() != null) {
name += "B" + figure.getCluster().toString();
}
final boolean hidden = !getWidget(f, FigureWidget.class).isVisible();
if (hidden) {
if (f.getCluster() != null) {
boolean isHidden = !getWidget(figure, FigureWidget.class).isVisible();
if (isHidden) {
if (figure.getCluster() != null) {
name += ", ";
}
name += "hidden";
}
name += ")";
Action a = new AbstractAction(name, new ColorIcon(f.getColor())) {

Action action = new AbstractAction(name, new ColorIcon(figure.getColor())) {
@Override
public void actionPerformed(ActionEvent e) {
diagramScene.gotoFigure(f);
setFigureSelection(Collections.singleton(figure));
centerFigures(Collections.singleton(figure));
}
};

a.setEnabled(true);
return a;
action.setEnabled(true);
return action;
}

public Action createGotoAction(final Block b) {
final DiagramScene diagramScene = this;
String name = "B" + b.getInputBlock().getName();
Action a = new AbstractAction(name) {
public Action createGotoAction(final Block block) {
String name = "B" + block.getInputBlock().getName();
Action action = new AbstractAction(name) {
@Override
public void actionPerformed(ActionEvent e) {
diagramScene.gotoBlock(b);
gotoBlock(block);
}
};
a.setEnabled(true);
return a;
action.setEnabled(true);
return action;
}

private void update() {
Expand Down Expand Up @@ -561,7 +571,7 @@ private void update() {
f.setWidth(maxWidth.get(f.getBlock().getInputBlock()));
}

FigureWidget w = new FigureWidget(f, hoverAction, selectAction, this, mainLayer);
FigureWidget w = new FigureWidget(f, this, mainLayer);
w.getActions().addAction(ActionFactory.createPopupMenuAction(w));
w.getActions().addAction(selectAction);
w.getActions().addAction(hoverAction);
Expand All @@ -588,7 +598,8 @@ private void update() {

if (getModel().getShowBlocks() || getModel().getShowCFG()) {
for (InputBlock bn : d.getInputBlocks()) {
BlockWidget w = new BlockWidget(this, d, bn);
BlockWidget w = new BlockWidget(this, bn);
w.getActions().addAction(new DoubleClickAction(w));
w.setVisible(false);
addObject(bn, w);
blockLayer.addChild(w);
Expand Down Expand Up @@ -891,6 +902,11 @@ public void setInteractionMode(InteractionMode mode) {
// and the selection action handles it instead
}

@Override
public void handleDoubleClick(Widget w, WidgetAction.WidgetMouseEvent e) {
setSelectedObjects(Collections.emptySet());
}

private class ConnectionSet {

private Set<Connection> connections;
Expand Down Expand Up @@ -932,38 +948,6 @@ private Set<Object> idSetToObjectSet(Set<Integer> ids) {
return result;
}

private void gotoSelection(Set<Integer> ids) {

Rectangle overall = null;
Set<Integer> hiddenNodes = new HashSet<>(getModel().getHiddenNodes());
hiddenNodes.removeAll(ids);
getModel().setHiddenNodes(hiddenNodes);

Set<Object> objects = idSetToObjectSet(ids);
for (Object o : objects) {

Widget w = getWidget(o);
if (w != null) {
Rectangle r = w.getBounds();
Point p = w.convertLocalToScene(new Point(0, 0));

assert r != null;
Rectangle r2 = new Rectangle(p.x, p.y, r.width, r.height);

if (overall == null) {
overall = r2;
} else {
overall = overall.union(r2);
}
}
}
if (overall != null) {
centerRectangle(overall);
}

setSelectedObjects(objects);
}

private void centerRectangle(Rectangle r) {
Rectangle rect = convertSceneToView(r);
Rectangle viewRect = scrollPane.getViewport().getViewRect();
Expand All @@ -986,7 +970,7 @@ private void centerRectangle(Rectangle r) {
}

@Override
public void setSelection(Collection<Figure> list) {
public void setFigureSelection(Set<Figure> list) {
super.setSelectedObjects(new HashSet<>(list));
}

Expand All @@ -1004,10 +988,6 @@ public UndoRedo getUndoRedo() {
return getUndoRedoManager();
}

private boolean isVisible(Figure f) {
return !getModel().getHiddenNodes().contains(f.getInputNode().getId());
}

@Override
public void componentHidden() {
SelectionCoordinator.getInstance().getHighlightedChangedEvent().removeListener(highlightedCoordinatorListener);
Expand Down Expand Up @@ -1122,31 +1102,6 @@ private void updateHiddenNodes(Set<Integer> newHiddenNodes, boolean doRelayout)
validate();
}

private void showFigure(Figure f) {
HashSet<Integer> newHiddenNodes = new HashSet<>(getModel().getHiddenNodes());
newHiddenNodes.remove(f.getInputNode().getId());
getModel().setHiddenNodes(newHiddenNodes);
}

private void centerWidget(Widget w) {
Rectangle r = w.getBounds();
Point p = w.getLocation();
assert r != null;
centerRectangle(new Rectangle(p.x, p.y, r.width, r.height));
}

public void gotoFigure(final Figure f) {
if (!isVisible(f)) {
showFigure(f);
}

FigureWidget fw = getWidget(f);
if (fw != null) {
centerWidget(fw);
setSelection(Collections.singletonList(f));
}
}

public JPopupMenu createPopupMenu() {
JPopupMenu menu = new JPopupMenu();

Expand Down
Expand Up @@ -242,14 +242,13 @@ public void setSelectedNodes(Set<Integer> nodes) {
}

public void showFigures(Collection<Figure> figures) {
HashSet<Integer> newHiddenNodes = new HashSet<>(getHiddenNodes());
HashSet<Integer> newHiddenNodes = new HashSet<>(hiddenNodes);
for (Figure f : figures) {
newHiddenNodes.remove(f.getInputNode().getId());
}
setHiddenNodes(newHiddenNodes);
}


public Set<Figure> getSelectedFigures() {
Set<Figure> result = new HashSet<>();
for (Figure f : diagram.getFigures()) {
Expand Down

1 comment on commit 3135914

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.