changeset 4175:ea49d7abeb05

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.
author Peter Hofer <peter.hofer@jku.at>
date Mon, 02 Jan 2012 14:21:07 +0100
parents 79c91d220d73
children a428df0139f3
files src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphNode.java src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/GraphRemoveCookie.java src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSliderModel.java src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java
diffstat 5 files changed, 37 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- 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<Group> registeredGroups;
-        private GraphDocument document;
+        private final GraphDocument document;
 
         public FolderChildren(GraphDocument document) {
             this.document = document;
@@ -80,7 +80,7 @@
                 List<Node> curNodes = new ArrayList<Node>();
                 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);
--- 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));
--- 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());
+        }
     }
 }
--- 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<RangeSliderModel>(this);
         setPositions(positions);
     }
-    
+
     protected void setPositions(List<String> positions) {
         this.positions = positions;
-         colors = new ArrayList<Color>();
-         for (int i = 0; i < positions.size(); i++) {
-             colors.add(Color.black);
-         }
+        colors = new ArrayList<Color>();
+        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<Color> 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;
     }
 
--- 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<InputGraph> graphs = group.getGraphs();
+        if (getFirstPosition() < graphs.size()) {
+            return graphs.get(getFirstPosition());
+        }
+        return graphs.get(graphs.size() - 1);
     }
 
     public InputGraph getSecondGraph() {
         List<InputGraph> graphs = group.getGraphs();
-        if (graphs.size() >= getSecondPosition())
-            return group.getGraphs().get(getSecondPosition());
+        if (getSecondPosition() < graphs.size()) {
+            return graphs.get(getSecondPosition());
+        }
         return getFirstGraph();
     }