Skip to content

Commit

Permalink
8295934: IGV: keep node selection when changing view or graph
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, rcastanedalo
  • Loading branch information
tobiasholenstein committed Nov 15, 2022
1 parent 9adb728 commit 6f467cd
Show file tree
Hide file tree
Showing 17 changed files with 509 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ protected void performAction(Node[] activatedNodes) {
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
if (p != null) {
p.clearSelectedNodes();
p.addSelectedNodes(c.getNodes());
p.addSelectedNodes(c.getNodes(), true);
p.centerSelectedNodes();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public void setGraph(InputGraph g) {
removeEdge(e);
}

edgeLayer.removeChildren();
mainLayer.removeChildren();

for (InputBlock b : g.getBlocks()) {
addNode(b);
}
Expand All @@ -118,33 +121,34 @@ public void setGraph(InputGraph g) {
validate();
}

public void clearSelection() {
private void clearSelection() {
for (BlockWidget w : selection) {
w.setState(w.getState().deriveSelected(false));
}
selection.clear();
selectionChanged();
}

public void selectionChanged() {
private void selectionChanged() {
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
if (p != null) {
Set<InputNode> inputNodes = new HashSet<>();
for (BlockWidget w : selection) {
inputNodes.addAll(w.getBlock().getNodes());
}
p.clearSelectedNodes();
p.addSelectedNodes(inputNodes);
p.addSelectedNodes(inputNodes, true);
p.centerSelectedNodes();
}
}

public void addToSelection(BlockWidget widget) {
private void addToSelection(BlockWidget widget) {
widget.setState(widget.getState().deriveSelected(true));
selection.add(widget);
selectionChanged();
}

public void removeFromSelection(BlockWidget widget) {
private void removeFromSelection(BlockWidget widget) {
widget.setState(widget.getState().deriveSelected(false));
selection.remove(widget);
selectionChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sun.hotspot.igv.util.LookupHistory;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
Expand Down Expand Up @@ -102,14 +103,16 @@ public void componentClosed() {

@Override
public void changed(InputGraphProvider lastProvider) {
if (lastProvider != null) {
InputGraph graph = lastProvider.getGraph();
if (graph != null) {
scene.setGraph(graph);
return;
SwingUtilities.invokeLater(() -> {
if (lastProvider != null) {
InputGraph graph = lastProvider.getGraph();
if (graph != null) {
scene.setGraph(graph);
return;
}
}
}
scene.setGraph(new InputGraph(""));
scene.setGraph(new InputGraph(""));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ public String getDisplayName() {
}

public int getIndex() {
return getGroup().getGraphs().indexOf(this);
Group group = getGroup();
if (group != null) {
return group.getGraphs().indexOf(this);
} else {
return -1;
}
}

public Collection<InputNode> getNodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public interface InputGraphProvider {

InputGraph getGraph();

void addSelectedNodes(Collection<InputNode> nodes);
void centerSelectedNodes();

void clearSelectedNodes();
void addSelectedNodes(Collection<InputNode> nodes, boolean showIfHidden);

void clearSelectedNodes();

/**
* @return an iterator walking forward through the {@link InputGraph}s following the {@link #getGraph()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package com.sun.hotspot.igv.graph;

import com.sun.hotspot.igv.data.*;
import com.sun.hotspot.igv.data.Properties;
import com.sun.hotspot.igv.data.*;
import java.awt.Font;
import java.util.*;

Expand Down Expand Up @@ -268,4 +268,14 @@ public int compare(Figure a, Figure b) {

System.out.println("=============================================================");
}

public Figure getRootFigure() {
Properties.PropertySelector<Figure> selector = new Properties.PropertySelector<>(figures);
Figure root = selector.selectSingle(new Properties.StringPropertyMatcher("name", "Root"));
if (root == null) {
root = selector.selectSingle(new Properties.StringPropertyMatcher("name", "Start"));
}
return root;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public class RangeSliderModel implements ChangedEventProvider<RangeSliderModel>
private int secondPosition;
private List<Color> colors;

public RangeSliderModel(List<String> positions) {
assert positions.size() > 0;
this.changedEvent = new ChangedEvent<>(this);
this.colorChangedEvent = new ChangedEvent<>(this);
setPositions(positions);
public RangeSliderModel() {
changedEvent = new ChangedEvent<>(this);
colorChangedEvent = new ChangedEvent<>(this);
positions = new ArrayList<>();
colors = new ArrayList<>();
}

protected void setPositions(List<String> positions) {
Expand Down Expand Up @@ -88,10 +88,12 @@ public int getSecondPosition() {
public void setPositions(int fp, int sp) {
assert fp >= 0 && fp < positions.size();
assert sp >= 0 && sp < positions.size();
firstPosition = fp;
secondPosition = sp;
ensureOrder();
changedEvent.fire();
if (firstPosition != fp || secondPosition != sp) {
firstPosition = fp;
secondPosition = sp;
ensureOrder();
changedEvent.fire();
}
}

private void ensureOrder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void evaluate(SearchRequest request, SearchResponse response) {
}
editor.clearSelectedNodes();
editor.addSelectedNodes(b.getNodes(), true);
editor.centerSelectedNodes();
editor.requestActive();
},
"B" + b.getName() + (theGraph != null ? " in " + theGraph.getName() : ""))) {
Expand Down
Loading

1 comment on commit 6f467cd

@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.