# HG changeset patch # User Andreas Woess # Date 1429534999 -7200 # Node ID 3006db547d5f103a40f3a6075ad433d89be33fc2 # Parent de8880bbf2e10e9e061fdac9fc580ab9e2746f1d IGV: improve text contrast for partially visible nodes diff -r de8880bbf2e1 -r 3006db547d5f src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Mon Apr 20 14:22:01 2015 +0200 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java Mon Apr 20 15:03:19 2015 +0200 @@ -32,10 +32,8 @@ import com.sun.hotspot.igv.util.PropertiesSheet; import com.sun.hotspot.igv.view.DiagramScene; import java.awt.*; -import java.awt.color.ColorSpace; import java.awt.event.ActionEvent; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; import javax.swing.AbstractAction; @@ -93,7 +91,6 @@ } public FigureWidget(final Figure f, WidgetAction hoverAction, WidgetAction selectAction, DiagramScene scene, Widget parent) { - super(scene); assert this.getScene() != null; @@ -123,24 +120,13 @@ dummyTop.setMinimumSize(new Dimension(Figure.INSET / 2, 1)); middleWidget.addChild(dummyTop); - for (String cur : strings) { - - String displayString = cur; - + for (String displayString : strings) { LabelWidget lw = new LabelWidget(scene); labelWidgets.add(lw); middleWidget.addChild(lw); lw.setLabel(displayString); lw.setFont(figure.getDiagram().getFont()); - - Color bg = f.getColor(); - double brightness = bg.getRed() * 0.21 + bg.getGreen() * 0.72 + bg.getBlue() * 0.07; - if (brightness < 150) { - lw.setForeground(Color.WHITE); - } else { - lw.setForeground(Color.BLACK); - } - + lw.setForeground(getTextColor()); lw.setAlignment(LabelWidget.Alignment.CENTER); lw.setVerticalAlignment(LabelWidget.VerticalAlignment.CENTER); lw.setBorder(BorderFactory.createEmptyBorder()); @@ -209,6 +195,16 @@ return figure; } + private Color getTextColor() { + Color bg = figure.getColor(); + double brightness = bg.getRed() * 0.21 + bg.getGreen() * 0.72 + bg.getBlue() * 0.07; + if (brightness < 150) { + return Color.WHITE; + } else { + return Color.BLACK; + } + } + @Override protected void paintChildren() { Composite oldComposite = null; @@ -226,9 +222,20 @@ for (LabelWidget labelWidget : labelWidgets) { labelWidget.setVisible(true); } - } else { + Color oldColor = null; + if (boundary) { + for (LabelWidget labelWidget : labelWidgets) { + oldColor = labelWidget.getForeground(); + labelWidget.setForeground(Color.BLACK); + } + } super.paintChildren(); + if (boundary) { + for (LabelWidget labelWidget : labelWidgets) { + labelWidget.setForeground(oldColor); + } + } } if (boundary) {