8265441: IGV: select block nodes by clicking on it
Reviewed-by: rcastanedalo, thartmann
This commit is contained in:
parent
78454b69da
commit
3135914362
@ -41,7 +41,8 @@ public final class SelectBytecodesAction extends CookieAction {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,8 @@ public class ControlFlowScene extends GraphScene<InputBlock, InputBlockEdge> imp
|
||||
for (BlockWidget w : selection) {
|
||||
inputNodes.addAll(w.getBlock().getNodes());
|
||||
}
|
||||
p.setSelectedNodes(inputNodes);
|
||||
p.clearSelectedNodes();
|
||||
p.addSelectedNodes(inputNodes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ package com.sun.hotspot.igv.data.services;
|
||||
|
||||
import com.sun.hotspot.igv.data.InputGraph;
|
||||
import com.sun.hotspot.igv.data.InputNode;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -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()}
|
||||
|
@ -58,7 +58,6 @@ public class SplitFilter extends AbstractFilter {
|
||||
OutputSlot os = c.getOutputSlot();
|
||||
if (f.getInputNode() != null) {
|
||||
os.getSource().addSourceNode(f.getInputNode());
|
||||
os.setAssociatedNode(f.getInputNode());
|
||||
os.setColor(f.getColor());
|
||||
}
|
||||
|
||||
@ -75,7 +74,6 @@ public class SplitFilter extends AbstractFilter {
|
||||
InputSlot is = c.getInputSlot();
|
||||
if (f.getInputNode() != null) {
|
||||
is.getSource().addSourceNode(f.getInputNode());
|
||||
is.setAssociatedNode(f.getInputNode());
|
||||
is.setColor(f.getColor());
|
||||
}
|
||||
|
||||
|
@ -87,13 +87,14 @@ public class BlockQuickSearch implements SearchProvider {
|
||||
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;
|
||||
|
@ -32,9 +32,7 @@ import com.sun.hotspot.igv.hierarchicallayout.HierarchicalLayoutManager;
|
||||
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;
|
||||
@ -70,7 +68,7 @@ import org.openide.util.lookup.InstanceContent;
|
||||
*
|
||||
* @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;
|
||||
@ -186,26 +184,26 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +219,15 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
|
||||
@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();
|
||||
}
|
||||
};
|
||||
@ -286,6 +292,9 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
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;
|
||||
@ -375,7 +384,12 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
@ -487,46 +501,42 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
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() {
|
||||
@ -561,7 +571,7 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
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);
|
||||
@ -588,7 +598,8 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
|
||||
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);
|
||||
@ -891,6 +902,11 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
// 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;
|
||||
@ -932,38 +948,6 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
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();
|
||||
@ -986,7 +970,7 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(Collection<Figure> list) {
|
||||
public void setFigureSelection(Set<Figure> list) {
|
||||
super.setSelectedObjects(new HashSet<>(list));
|
||||
}
|
||||
|
||||
@ -1004,10 +988,6 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
return getUndoRedoManager();
|
||||
}
|
||||
|
||||
private boolean isVisible(Figure f) {
|
||||
return !getModel().getHiddenNodes().contains(f.getInputNode().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden() {
|
||||
SelectionCoordinator.getInstance().getHighlightedChangedEvent().removeListener(highlightedCoordinatorListener);
|
||||
@ -1122,31 +1102,6 @@ public class DiagramScene extends ObjectScene implements DiagramViewer {
|
||||
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();
|
||||
|
||||
|
@ -242,14 +242,13 @@ public class DiagramViewModel extends RangeSliderModel implements ChangedListene
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
@ -31,7 +31,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.swing.JComponent;
|
||||
import org.openide.awt.UndoRedo;
|
||||
import org.openide.util.Lookup;
|
||||
@ -77,9 +77,9 @@ public interface DiagramViewer {
|
||||
|
||||
void componentShowing();
|
||||
|
||||
void setSelection(Collection<Figure> list);
|
||||
void setFigureSelection(Set<Figure> list);
|
||||
|
||||
void centerFigures(List<Figure> list);
|
||||
void centerFigures(Collection<Figure> list);
|
||||
|
||||
void setInteractionMode(InteractionMode mode);
|
||||
|
||||
|
@ -27,7 +27,7 @@ package com.sun.hotspot.igv.view;
|
||||
import com.sun.hotspot.igv.data.InputGraph;
|
||||
import com.sun.hotspot.igv.data.InputNode;
|
||||
import com.sun.hotspot.igv.data.services.InputGraphProvider;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
import org.openide.util.lookup.ServiceProvider;
|
||||
|
||||
/**
|
||||
@ -57,9 +57,16 @@ public class EditorInputGraphProvider implements InputGraphProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedNodes(Set<InputNode> nodes) {
|
||||
public void addSelectedNodes(Collection<InputNode> nodes) {
|
||||
if (editor != null && EditorTopComponent.isOpen(editor)) {
|
||||
editor.setSelectedNodes(nodes);
|
||||
editor.addSelectedNodes(nodes, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelectedNodes() {
|
||||
if (editor != null && EditorTopComponent.isOpen(editor)) {
|
||||
editor.clearSelectedNodes();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -321,33 +321,25 @@ public final class EditorTopComponent extends TopComponent {
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedFigures(List<Figure> list) {
|
||||
scene.setSelection(list);
|
||||
scene.centerFigures(list);
|
||||
}
|
||||
|
||||
public void setSelectedNodes(Set<InputNode> nodes) {
|
||||
List<Figure> list = new ArrayList<>();
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
public void addSelectedNodes(Collection<InputNode> nodes, boolean centerSelection) {
|
||||
Set<Integer> ids = new HashSet<>(getModel().getSelectedNodes());
|
||||
for (InputNode n : nodes) {
|
||||
ids.add(n.getId());
|
||||
}
|
||||
Set<Figure> selectedFigures = new HashSet<>();
|
||||
for (Figure f : getDiagram().getFigures()) {
|
||||
if (ids.contains(f.getInputNode().getId())) {
|
||||
list.add(f);
|
||||
selectedFigures.add(f);
|
||||
}
|
||||
}
|
||||
setSelectedFigures(list);
|
||||
scene.setFigureSelection(selectedFigures);
|
||||
if (centerSelection) {
|
||||
scene.centerFigures(selectedFigures);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedNodes(InputBlock b) {
|
||||
List<Figure> list = new ArrayList<>();
|
||||
for (Figure f : getDiagram().getFigures()) {
|
||||
if (f.getBlock().getInputBlock() == b) {
|
||||
list.add(f);
|
||||
}
|
||||
}
|
||||
setSelectedFigures(list);
|
||||
public void clearSelectedNodes() {
|
||||
scene.setFigureSelection(Collections.emptySet());
|
||||
}
|
||||
|
||||
public Rectangle getSceneBounds() {
|
||||
|
@ -108,24 +108,22 @@ public class NodeQuickSearch implements SearchProvider {
|
||||
}
|
||||
|
||||
if (matches != null) {
|
||||
final Set<InputNode> set = new HashSet<>(matches);
|
||||
final Set<InputNode> nodeSet = new HashSet<>(matches);
|
||||
final InputGraph theGraph = p.getGraph() != matchGraph ? matchGraph : null;
|
||||
// Show "All N matching nodes" entry only if 1) there are
|
||||
// multiple matches and 2) the query does not only contain
|
||||
// digits (it is rare to select all nodes whose id contains a
|
||||
// certain subsequence of digits).
|
||||
if (matches.size() > 1 && !rawValue.matches("\\d+")) {
|
||||
if (!response.addResult(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final EditorTopComponent comp = EditorTopComponent.getActive();
|
||||
if (comp != null) {
|
||||
if (theGraph != null) {
|
||||
comp.getModel().selectGraph(theGraph);
|
||||
}
|
||||
comp.setSelectedNodes(set);
|
||||
comp.requestActive();
|
||||
if (!response.addResult(() -> {
|
||||
final EditorTopComponent editor = EditorTopComponent.getActive();
|
||||
if (editor != null) {
|
||||
if (theGraph != null) {
|
||||
editor.getModel().selectGraph(theGraph);
|
||||
}
|
||||
editor.clearSelectedNodes();
|
||||
editor.addSelectedNodes(nodeSet, true);
|
||||
editor.requestActive();
|
||||
}
|
||||
},
|
||||
"All " + matches.size() + " matching nodes (" + name + "=" + value + ")" + (theGraph != null ? " in " + theGraph.getName() : "")
|
||||
@ -145,15 +143,16 @@ public class NodeQuickSearch implements SearchProvider {
|
||||
if (!response.addResult(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final EditorTopComponent comp = EditorTopComponent.getActive();
|
||||
if (comp != null) {
|
||||
final EditorTopComponent editor = EditorTopComponent.getActive();
|
||||
if (editor != null) {
|
||||
final Set<InputNode> tmpSet = new HashSet<>();
|
||||
tmpSet.add(n);
|
||||
if (theGraph != null) {
|
||||
comp.getModel().selectGraph(theGraph);
|
||||
editor.getModel().selectGraph(theGraph);
|
||||
}
|
||||
comp.setSelectedNodes(tmpSet);
|
||||
comp.requestActive();
|
||||
editor.clearSelectedNodes();
|
||||
editor.addSelectedNodes(tmpSet, true);
|
||||
editor.requestActive();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -38,27 +38,12 @@ abstract public class ExpandAdjacentAction extends CallableSystemAction {
|
||||
protected void expandFigures(Function<Figure, List<Figure>> getAdjacentFigures) {
|
||||
EditorTopComponent editor = EditorTopComponent.getActive();
|
||||
if (editor != null) {
|
||||
Set<Figure> oldSelection = editor.getModel().getSelectedFigures();
|
||||
Set<Figure> figures = new HashSet<>(oldSelection);
|
||||
for (Figure f : editor.getModel().getDiagram().getFigures()) {
|
||||
if (oldSelection.contains(f)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean ok = false;
|
||||
for (Figure adjFig : getAdjacentFigures.apply(f)) {
|
||||
if (oldSelection.contains(adjFig)) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
figures.add(f);
|
||||
}
|
||||
Set<Figure> selectedFigured = editor.getModel().getSelectedFigures();
|
||||
Set<Figure> expandedFigures = new HashSet<>(selectedFigured);
|
||||
for (Figure selectedFigure : selectedFigured) {
|
||||
expandedFigures.addAll(getAdjacentFigures.apply(selectedFigure));
|
||||
}
|
||||
|
||||
editor.getModel().showFigures(figures);
|
||||
editor.getModel().showFigures(expandedFigures);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public final class ExpandPredecessorsAction extends ExpandAdjacentAction {
|
||||
|
||||
@Override
|
||||
public void performAction() {
|
||||
expandFigures(Figure::getSuccessors);
|
||||
expandFigures(Figure::getPredecessors);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ public final class ExpandSuccessorsAction extends ExpandAdjacentAction {
|
||||
|
||||
@Override
|
||||
public void performAction() {
|
||||
expandFigures(Figure::getPredecessors);
|
||||
expandFigures(Figure::getSuccessors);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,24 +24,29 @@
|
||||
package com.sun.hotspot.igv.view.widgets;
|
||||
|
||||
import com.sun.hotspot.igv.data.InputBlock;
|
||||
import com.sun.hotspot.igv.graph.Diagram;
|
||||
import com.sun.hotspot.igv.data.services.InputGraphProvider;
|
||||
import com.sun.hotspot.igv.util.DoubleClickHandler;
|
||||
import com.sun.hotspot.igv.util.LookupHistory;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import org.netbeans.api.visual.action.WidgetAction;
|
||||
import org.netbeans.api.visual.widget.Scene;
|
||||
import org.netbeans.api.visual.widget.Widget;
|
||||
import org.openide.util.Utilities;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Thomas Wuerthinger
|
||||
*/
|
||||
public class BlockWidget extends Widget {
|
||||
public class BlockWidget extends Widget implements DoubleClickHandler {
|
||||
|
||||
public static final Color BACKGROUND_COLOR = new Color(235, 235, 255);
|
||||
private static final Font TITLE_FONT = new Font("Arial", Font.BOLD, 14);
|
||||
public static final Color TITLE_COLOR = new Color(42, 42, 171);
|
||||
private InputBlock blockNode;
|
||||
private final InputBlock blockNode;
|
||||
|
||||
public BlockWidget(Scene scene, Diagram d, InputBlock blockNode) {
|
||||
public BlockWidget(Scene scene, InputBlock blockNode) {
|
||||
super(scene);
|
||||
this.blockNode = blockNode;
|
||||
this.setBackground(BACKGROUND_COLOR);
|
||||
@ -71,4 +76,26 @@ public class BlockWidget extends Widget {
|
||||
g.drawString(s, r.x + 5, r.y + (int) r1.getHeight());
|
||||
g.setStroke(old);
|
||||
}
|
||||
|
||||
private void addToSelection(BlockWidget blockWidget, boolean additiveSelection) {
|
||||
InputGraphProvider graphProvider = LookupHistory.getLast(InputGraphProvider.class);
|
||||
if (graphProvider != null) {
|
||||
if (!additiveSelection) {
|
||||
graphProvider.clearSelectedNodes();
|
||||
}
|
||||
graphProvider.addSelectedNodes(blockWidget.blockNode.getNodes());
|
||||
}
|
||||
}
|
||||
|
||||
private int getModifierMask () {
|
||||
return Utilities.isMac() ? MouseEvent.META_DOWN_MASK : MouseEvent.CTRL_DOWN_MASK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDoubleClick(Widget widget, WidgetAction.WidgetMouseEvent event) {
|
||||
assert widget instanceof BlockWidget;
|
||||
BlockWidget blockWidget = (BlockWidget) widget;
|
||||
boolean additiveSelection = (event.getModifiersEx() & getModifierMask()) != 0;
|
||||
addToSelection(blockWidget, additiveSelection);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class FigureWidget extends Widget implements Properties.Provider, PopupMe
|
||||
return middleWidget.isHitAt(localLocation);
|
||||
}
|
||||
|
||||
public FigureWidget(final Figure f, WidgetAction hoverAction, WidgetAction selectAction, DiagramScene scene, Widget parent) {
|
||||
public FigureWidget(final Figure f, DiagramScene scene, Widget parent) {
|
||||
super(scene);
|
||||
|
||||
assert this.getScene() != null;
|
||||
|
Loading…
Reference in New Issue
Block a user