# HG changeset patch # User Peter Hofer # Date 1325510467 -3600 # Node ID ea49d7abeb055949dbe6cbbf94147259b362b734 # Parent 79c91d220d73388d75284028805e25649aa4fb0c IdealGraphVisualizer bugfixes: * When removing graphs, ensure that the position indices in the range slider remain valid (although they might represent different graphs afterwards) * Instead of removing the last remaining graph of a group, remove the entire group. This prevents problems in some components that assume that a group always has at least one graph. diff -r 79c91d220d73 -r ea49d7abeb05 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Thu Dec 29 16:07:35 2011 -0800 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Mon Jan 02 14:21:07 2012 +0100 @@ -56,7 +56,7 @@ private FolderNode parent; private List registeredGroups; - private GraphDocument document; + private final GraphDocument document; public FolderChildren(GraphDocument document) { this.document = document; @@ -80,7 +80,7 @@ List curNodes = new ArrayList(); for (Group g : p.getRight()) { for (InputGraph graph : g.getGraphListCopy()) { - curNodes.add(new GraphNode(graph)); + curNodes.add(new GraphNode(document, graph)); } g.getChangedEvent().addListener(this); registeredGroups.add(g); diff -r 79c91d220d73 -r ea49d7abeb05 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java Thu Dec 29 16:07:35 2011 -0800 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java Mon Jan 02 14:21:07 2012 +0100 @@ -27,6 +27,7 @@ import com.sun.hotspot.igv.coordinator.actions.DiffGraphCookie; import com.sun.hotspot.igv.coordinator.actions.GraphOpenCookie; import com.sun.hotspot.igv.coordinator.actions.GraphRemoveCookie; +import com.sun.hotspot.igv.data.GraphDocument; import com.sun.hotspot.igv.data.InputGraph; import com.sun.hotspot.igv.data.Properties; import com.sun.hotspot.igv.data.services.GraphViewer; @@ -47,16 +48,18 @@ * @author Thomas Wuerthinger */ public class GraphNode extends AbstractNode { - + private final GraphDocument document; private final InputGraph graph; /** Creates a new instance of GraphNode */ - public GraphNode(InputGraph graph) { - this(graph, new InstanceContent()); + public GraphNode(GraphDocument document, InputGraph graph) { + this(document, graph, new InstanceContent()); } - private GraphNode(final InputGraph graph, InstanceContent content) { + private GraphNode(GraphDocument document, InputGraph graph, InstanceContent content) { super(Children.LEAF, new AbstractLookup(content)); + + this.document = document; this.graph = graph; this.setDisplayName(graph.getName()); content.add(graph); @@ -69,7 +72,7 @@ } // Action for removing a graph - content.add(new GraphRemoveCookie(graph)); + content.add(new GraphRemoveCookie(document, graph)); // Action for diffing to the current graph content.add(new DiffGraphCookie(graph)); diff -r 79c91d220d73 -r ea49d7abeb05 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java Thu Dec 29 16:07:35 2011 -0800 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java Mon Jan 02 14:21:07 2012 +0100 @@ -23,16 +23,18 @@ */ package com.sun.hotspot.igv.coordinator.actions; +import com.sun.hotspot.igv.data.GraphDocument; import com.sun.hotspot.igv.data.InputGraph; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; public class GraphRemoveCookie implements RemoveCookie { - + private final GraphDocument document; private final InputGraph graph; - public GraphRemoveCookie(InputGraph graph) { + public GraphRemoveCookie(GraphDocument document, InputGraph graph) { + this.document = document; this.graph = graph; } @@ -46,6 +48,11 @@ } } - graph.getGroup().removeGraph(graph); + if (graph.getGroup().getGraphsCount() > 1) { + graph.getGroup().removeGraph(graph); + } else { + // Last graph, remove the entire group + document.removeGroup(graph.getGroup()); + } } } diff -r 79c91d220d73 -r ea49d7abeb05 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Thu Dec 29 16:07:35 2011 -0800 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java Mon Jan 02 14:21:07 2012 +0100 @@ -69,17 +69,18 @@ this.colorChangedEvent = new ChangedEvent(this); setPositions(positions); } - + protected void setPositions(List positions) { this.positions = positions; - colors = new ArrayList(); - for (int i = 0; i < positions.size(); i++) { - colors.add(Color.black); - } + colors = new ArrayList(); + for (int i = 0; i < positions.size(); i++) { + colors.add(Color.black); + } + firstPosition = Math.min(firstPosition, positions.size() - 1); + secondPosition = Math.min(secondPosition, positions.size() - 1); changedEvent.fire(); colorChangedEvent.fire(); - } - + } public void setColors(List colors) { this.colors = colors; @@ -92,9 +93,7 @@ public RangeSliderModel copy() { RangeSliderModel newModel = new RangeSliderModel(positions); - newModel.firstPosition = firstPosition; - newModel.secondPosition = secondPosition; - newModel.colors = colors; + newModel.setData(this); return newModel; } diff -r 79c91d220d73 -r ea49d7abeb05 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Thu Dec 29 16:07:35 2011 -0800 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Mon Jan 02 14:21:07 2012 +0100 @@ -33,7 +33,6 @@ import com.sun.hotspot.igv.data.ChangedEvent; import com.sun.hotspot.igv.util.RangeSliderModel; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -340,13 +339,18 @@ } public InputGraph getFirstGraph() { - return group.getGraphs().get(getFirstPosition()); + List graphs = group.getGraphs(); + if (getFirstPosition() < graphs.size()) { + return graphs.get(getFirstPosition()); + } + return graphs.get(graphs.size() - 1); } public InputGraph getSecondGraph() { List graphs = group.getGraphs(); - if (graphs.size() >= getSecondPosition()) - return group.getGraphs().get(getSecondPosition()); + if (getSecondPosition() < graphs.size()) { + return graphs.get(getSecondPosition()); + } return getFirstGraph(); }