changeset 3665:3c31c42c0cd3

IdealGraphPrinter: add the ability to specify edge labels in XML input
author Peter Hofer <peter.hofer@jku.at>
date Fri, 18 Nov 2011 14:24:27 +0100
parents 6e1abd79e7c8
children bb3337727ab6
files src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java
diffstat 6 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java	Thu Nov 17 19:11:55 2011 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputEdge.java	Fri Nov 18 14:24:27 2011 +0100
@@ -58,23 +58,29 @@
                 return o1.getToIndex() - o2.getToIndex();
             }
     };
-        
+
     private char toIndex;
     private char fromIndex;
     private int from;
     private int to;
     private State state;
-    
+    private String label;
+
     public InputEdge(char toIndex, int from, int to) {
-        this((char)0, toIndex, from, to);
+        this((char) 0, toIndex, from, to, null);
     }
 
     public InputEdge(char fromIndex, char toIndex, int from, int to) {
+        this(fromIndex, toIndex, from, to, null);
+    }
+
+    public InputEdge(char fromIndex, char toIndex, int from, int to, String label) {
         this.toIndex = toIndex;
         this.fromIndex = fromIndex;
         this.from = from;
         this.to = to;
         this.state = State.SAME;
+        this.label = label;
     }
 
     public State getState() {
@@ -105,6 +111,10 @@
         return to;
     }
 
+    public String getLabel() {
+        return label;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (o == null || !(o instanceof InputEdge)) {
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Thu Nov 17 19:11:55 2011 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Fri Nov 18 14:24:27 2011 +0100
@@ -85,6 +85,7 @@
     public static final String FROM_INDEX_PROPERTY = "fromIndex";
     public static final String TO_INDEX_PROPERTY = "toIndex";
     public static final String TO_INDEX_ALT_PROPERTY = "index";
+    public static final String LABEL_PROPERTY = "label";
     public static final String METHOD_ELEMENT = "method";
     public static final String INLINE_ELEMENT = "inline";
     public static final String BYTECODES_ELEMENT = "bytecodes";
@@ -379,13 +380,14 @@
             int toIndex = 0;
             int from = -1;
             int to = -1;
+            String label = null;
 
             try {
                 String fromIndexString = readAttribute(FROM_INDEX_PROPERTY);
                 if (fromIndexString != null) {
                     fromIndex = Integer.parseInt(fromIndexString);
                 }
-                
+
                 String toIndexString = readAttribute(TO_INDEX_PROPERTY);
                 if (toIndexString == null) {
                     toIndexString = readAttribute(TO_INDEX_ALT_PROPERTY);
@@ -394,13 +396,15 @@
                     toIndex = Integer.parseInt(toIndexString);
                 }
 
+                label = readAttribute(LABEL_PROPERTY);
+
                 from = lookupID(readRequiredAttribute(FROM_PROPERTY));
                 to = lookupID(readRequiredAttribute(TO_PROPERTY));
             } catch (NumberFormatException e) {
                 throw new SAXException(e);
             }
 
-            InputEdge conn = new InputEdge((char) fromIndex, (char) toIndex, from, to);
+            InputEdge conn = new InputEdge((char) fromIndex, (char) toIndex, from, to, label);
             return start(conn);
         }
 
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd	Thu Nov 17 19:11:55 2011 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd	Fri Nov 18 14:24:27 2011 +0100
@@ -105,6 +105,7 @@
     <xsd:complexType name="edgeType">
         <xsd:attribute name="from" type="xsd:int" use="required" />
         <xsd:attribute name="to" type="xsd:int" use="required" />
+        <xsd:attribute name="label" type="xsd:string" use="optional" />
         <xsd:attribute name="fromIndex" type="xsd:int" use="optional" />
         
         <!-- These are aliases and should be mutually exclusive -->
--- a/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java	Thu Nov 17 19:11:55 2011 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Filter/src/com/sun/hotspot/igv/filter/CombineFilter.java	Fri Nov 18 14:24:27 2011 +0100
@@ -30,7 +30,6 @@
 import com.sun.hotspot.igv.graph.OutputSlot;
 import com.sun.hotspot.igv.data.Properties;
 import com.sun.hotspot.igv.data.Properties.PropertyMatcher;
-import java.awt.Color;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -100,7 +99,7 @@
 
                         for (InputSlot s : f.getInputSlots()) {
                             for (Connection c : s.getConnections()) {
-                                Connection newConn = diagram.createConnection(slot, c.getOutputSlot());
+                                Connection newConn = diagram.createConnection(slot, c.getOutputSlot(), c.getLabel());
                                 newConn.setColor(c.getColor());
                                 newConn.setStyle(c.getStyle());
                             }
@@ -157,7 +156,7 @@
                                     }
                                 }
                                 for (Connection c : nextSlot.getConnections()) {
-                                    Connection newConn = diagram.createConnection(c.getInputSlot(), slot);
+                                    Connection newConn = diagram.createConnection(c.getInputSlot(), slot, c.getLabel());
                                     newConn.setColor(c.getColor());
                                     newConn.setStyle(c.getStyle());
                                 }
--- a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java	Thu Nov 17 19:11:55 2011 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Connection.java	Fri Nov 18 14:24:27 2011 +0100
@@ -49,10 +49,12 @@
     private Color color;
     private ConnectionStyle style;
     private List<Point> controlPoints;
+    private String label;
 
-    protected Connection(InputSlot inputSlot, OutputSlot outputSlot) {
+    protected Connection(InputSlot inputSlot, OutputSlot outputSlot, String label) {
         this.inputSlot = inputSlot;
         this.outputSlot = outputSlot;
+        this.label = label;
         this.inputSlot.connections.add(this);
         this.outputSlot.connections.add(this);
         controlPoints = new ArrayList<Point>();
@@ -94,6 +96,10 @@
         return source;
     }
 
+    public String getLabel() {
+        return label;
+    }
+
     public void remove() {
         inputSlot.getFigure().removePredecessor(outputSlot.getFigure());
         inputSlot.connections.remove(this);
@@ -102,12 +108,21 @@
     }
     
     public String getToolTipText() {
-        return "From " + this.getOutputSlot().getFigure().toString() + " to " + this.getInputSlot().getFigure();
+        StringBuilder builder = new StringBuilder();
+        if (label != null) {
+            builder.append(label).append(": from ");
+        } else {
+            builder.append("From ");
+        }
+        builder.append(getOutputSlot().getFigure());
+        builder.append(" to ");
+        builder.append(getInputSlot().getFigure());
+        return builder.toString();
     }
 
     @Override
     public String toString() {
-        return "Connection(" + getFrom().getVertex() + " to " + getTo().getVertex() + ")";
+        return "Connection('" + label + "', " + getFrom().getVertex() + " to " + getTo().getVertex() + ")";
     }
 
     public Port getFrom() {
--- a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java	Thu Nov 17 19:11:55 2011 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java	Fri Nov 18 14:24:27 2011 +0100
@@ -112,10 +112,10 @@
         return f;
     }
 
-    public Connection createConnection(InputSlot inputSlot, OutputSlot outputSlot) {
+    public Connection createConnection(InputSlot inputSlot, OutputSlot outputSlot, String label) {
         assert inputSlot.getFigure().getDiagram() == this;
         assert outputSlot.getFigure().getDiagram() == this;
-        return new Connection(inputSlot, outputSlot);
+        return new Connection(inputSlot, outputSlot, label);
     }
     
     public Map<InputNode, Set<Figure>> calcSourceToFigureRelation() {
@@ -176,7 +176,7 @@
             }
             InputSlot inputSlot = toFigure.getInputSlots().get(toIndex);
 
-            Connection c = d.createConnection(inputSlot, outputSlot);
+            Connection c = d.createConnection(inputSlot, outputSlot, e.getLabel());
 
             if (e.getState() == InputEdge.State.NEW) {
                 c.setStyle(Connection.ConnectionStyle.BOLD);