diff --git a/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputNode.java b/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputNode.java index 62b7aa4c034..48a000bf7b9 100644 --- a/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputNode.java +++ b/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputNode.java @@ -23,6 +23,7 @@ */ package com.sun.hotspot.igv.data; +import java.awt.Color; import java.util.Objects; /** @@ -67,4 +68,27 @@ public class InputNode extends Properties.Entity { public String toString() { return "Node " + id + " " + getProperties().toString(); } + + public void setCustomColor(Color color) { + if (color != null) { + String hexColor = String.format("#%08X", color.getRGB()); + getProperties().setProperty("color", hexColor); + } else { + getProperties().setProperty("color", null); + } + } + + public Color getCustomColor() { + String hexColor = getProperties().get("color"); + if (hexColor != null) { + try { + String hex = hexColor.startsWith("#") ? hexColor.substring(1) : hexColor; + int argb = (int) Long.parseLong(hex, 16); + return new Color(argb, true); + } catch (Exception ignored) { + return null; + } + } + return null; + } } diff --git a/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Diagram.java b/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Diagram.java index bb5e3358a30..b42dec7eb39 100644 --- a/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Diagram.java +++ b/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Diagram.java @@ -36,6 +36,7 @@ public class Diagram { private final Map figures; private final Map blocks; + private final InputGraph inputGraph; private final String nodeText; private final String shortNodeText; private final String tinyNodeText; @@ -66,6 +67,7 @@ public class Diagram { this.figures = new LinkedHashMap<>(); this.blocks = new LinkedHashMap<>(8); this.blockConnections = new HashSet<>(); + this.inputGraph = graph; this.cfg = false; int curId = 0; @@ -128,6 +130,10 @@ public class Diagram { } } + public InputGraph getInputGraph() { + return inputGraph; + } + public Block getBlock(InputBlock b) { assert blocks.containsKey(b); return blocks.get(b); diff --git a/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Figure.java b/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Figure.java index 23c7d136d5b..d85e102f874 100644 --- a/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Figure.java +++ b/src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Figure.java @@ -23,6 +23,7 @@ */ package com.sun.hotspot.igv.graph; +import com.sun.hotspot.igv.data.InputGraph; import com.sun.hotspot.igv.data.InputNode; import com.sun.hotspot.igv.data.Properties; import com.sun.hotspot.igv.layout.Cluster; @@ -153,7 +154,12 @@ public class Figure extends Properties.Entity implements Vertex { } public Color getColor() { - return color; + Color customColor = inputNode.getCustomColor(); + if (customColor != null) { + return customColor; + } else { + return color; + } } public void setWarning(String warning) { @@ -415,4 +421,16 @@ public class Figure extends Properties.Entity implements Vertex { public int compareTo(Vertex f) { return toString().compareTo(f.toString()); } + + public void setCustomColor(Color color) { + // Apply custom color not just to this input node but to all + // corresponding input nodes in the group. + InputGraph graph = diagram.getInputGraph(); + for (InputGraph g : graph.getGroup().getGraphs()) { + InputNode n = g.getNode(inputNode.getId()); + if (n != null) { + n.setCustomColor(color); + } + } + } } diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java index 88418338f34..90d5e0ac424 100644 --- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java +++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java @@ -230,7 +230,7 @@ public class DiagramScene extends ObjectScene implements DiagramViewer, DoubleCl public void colorSelectedFigures(Color color) { for (Figure figure : model.getSelectedFigures()) { - figure.setColor(color); + figure.setCustomColor(color); FigureWidget figureWidget = getWidget(figure); if (figureWidget != null) { figureWidget.refreshColor(); diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ColorAction.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ColorAction.java index 7a38587eb38..d0ace9f7710 100644 --- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ColorAction.java +++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/actions/ColorAction.java @@ -82,6 +82,7 @@ public final class ColorAction extends ModelAwareAction { private static final JLabel selectedColorLabel = new JLabel("Preview"); private static final JColorChooser colorChooser = new JColorChooser(Color.WHITE); + private static final Color NO_COLOR = new Color(0, 0, 0, 0); public ColorAction() { initializeComponents(); @@ -89,8 +90,8 @@ public final class ColorAction extends ModelAwareAction { private void initializeComponents() { selectedColorLabel.setPreferredSize(new Dimension(3 * 32, 32)); - selectedColorLabel.setOpaque(true); - selectedColorLabel.setBackground(Color.WHITE); + selectedColorLabel.setOpaque(false); // Allow transparency + selectedColorLabel.setBackground(NO_COLOR); // Set transparent background selectedColorLabel.setForeground(Color.BLACK); // Set text color selectedColorLabel.setHorizontalAlignment(SwingConstants.CENTER); // Center the text @@ -100,6 +101,7 @@ public final class ColorAction extends ModelAwareAction { Color selectedColor = colorChooser.getColor(); if (selectedColor != null) { selectedColorLabel.setBackground(selectedColor); + selectedColorLabel.setOpaque(selectedColor.getAlpha() != 0); selectedColorLabel.setForeground(FigureWidget.getTextColor(selectedColor)); } }); @@ -118,10 +120,27 @@ public final class ColorAction extends ModelAwareAction { colorButton.setPreferredSize(new Dimension(16, 16)); colorButton.addActionListener(e -> { selectedColorLabel.setBackground(color); + selectedColorLabel.setOpaque(color.getAlpha() != 0); selectedColorLabel.setForeground(FigureWidget.getTextColor(color)); }); colorsPanel.add(colorButton); } + + // Add "No Color" button + JButton noColorButton = new JButton("No Color"); + noColorButton.setOpaque(true); + noColorButton.setContentAreaFilled(true); + noColorButton.setBorderPainted(true); + noColorButton.setPreferredSize(new Dimension(90, 24)); + noColorButton.setFocusPainted(false); + noColorButton.addActionListener(e -> { + selectedColorLabel.setBackground(NO_COLOR); + selectedColorLabel.setOpaque(false); + selectedColorLabel.setForeground(Color.BLACK); + }); + colorsPanel.add(noColorButton); + + // Add the preview label colorsPanel.add(selectedColorLabel, 0); colorsPanel.revalidate(); colorsPanel.repaint(); @@ -148,9 +167,10 @@ public final class ColorAction extends ModelAwareAction { dialogLoc = dialogHolder[0].getLocation(); // OK button action Color selectedColor = selectedColorLabel.getBackground(); - if (selectedColor != null) { - editor.colorSelectedFigures(selectedColor); + if (selectedColor.equals(NO_COLOR)) { + selectedColor = null; } + editor.colorSelectedFigures(selectedColor); }, null // Cancel button action ); diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/widgets/FigureWidget.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/widgets/FigureWidget.java index 24780d4d7d2..5578c4505cf 100644 --- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/widgets/FigureWidget.java +++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/widgets/FigureWidget.java @@ -271,6 +271,7 @@ public class FigureWidget extends Widget implements Properties.Provider, PopupMe @Override protected void paintChildren() { + refreshColor(); Composite oldComposite = null; if (boundary) { oldComposite = getScene().getGraphics().getComposite();