IDEA-159243 Use the ColorGenerator class for per-variable highlighting semantic
authorAlexey Utkin <alexey.utkin@jetbrains.com>
Mon, 1 Aug 2016 08:33:42 +0000 (11:33 +0300)
committerAlexey Utkin <alexey.utkin@jetbrains.com>
Mon, 1 Aug 2016 08:40:37 +0000 (11:40 +0300)
platform/analysis-impl/src/com/intellij/codeHighlighting/ColorGenerator.java [moved from platform/vcs-impl/src/com/intellij/openapi/vcs/ui/ColorGenerator.java with 98% similarity]
platform/analysis-impl/src/com/intellij/codeHighlighting/RainbowHighlighter.java
platform/platform-tests/testSrc/com/intellij/codeHighlighting/ColorGeneratorTest.kt [moved from platform/vcs-impl/testSrc/com/intellij/openapi/vcs/ui/ColorGeneratorTest.kt with 97% similarity]
platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotationsSettings.java

similarity index 98%
rename from platform/vcs-impl/src/com/intellij/openapi/vcs/ui/ColorGenerator.java
rename to platform/analysis-impl/src/com/intellij/codeHighlighting/ColorGenerator.java
index 6d59f760ae3eefbc0422b010864710703deeee38..dff61c5a8ecb542e559a839d1a6cb46b388fda37 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.intellij.openapi.vcs.ui;
+package com.intellij.codeHighlighting;
 
 import com.intellij.ui.JBColor;
 import org.jetbrains.annotations.NotNull;
index ba50dc7dfbe37f4dcd2837c262459ab2fee4c348..8f908f393be9019118d8bf1f732c464394066b84 100644 (file)
@@ -37,11 +37,12 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import static com.intellij.util.ObjectUtils.notNull;
-
 public class RainbowHighlighter {
+  private final static int[] RAINBOW_COLORS_DEFAULT = {0x9b3b6a, 0x114d77, 0xbc8650, 0x005910, 0xbc5150};
+  private final static int[] RAINBOW_COLORS_DARK = {0x529d52, 0xbe7070, 0x3d7676, 0xbe9970, 0x9d527c};
+  private final static int RAINBOW_COLORS_BETWEEN = 4;
+  private final static List<TextAttributesKey> RAINBOW_COLOR_KEYS = new ArrayList<TextAttributesKey>(RAINBOW_COLORS_DEFAULT.length);
   private final static String UNIT_TEST_COLORS = "#000001,#000002,#000003,#000004"; // Do not modify!
-  private final static int COLOR_COUNT = 16;
 
   @NotNull private final TextAttributesScheme myColorsScheme;
   @NotNull private final List<Color> myRainbowColors;
@@ -69,25 +70,28 @@ public class RainbowHighlighter {
 
   private static List<Color> generateColorSequence(@NotNull TextAttributesScheme colorsScheme) {
     String colorDump = ApplicationManager.getApplication().isUnitTestMode()
-      ? UNIT_TEST_COLORS
-      : Registry.get("rainbow.highlighter.colors").asString();
+                       ? UNIT_TEST_COLORS
+                       : Registry.get("rainbow.highlighter.colors").asString();
 
     final List<String> registryColors = StringUtil.split(colorDump, ",");
     if (!registryColors.isEmpty()) {
-      return registryColors.stream().map((s -> ColorUtil.fromHex(s.trim()))).collect(Collectors.toList());
+      return registryColors.stream().map(s -> ColorUtil.fromHex(s.trim())).collect(Collectors.toList());
     }
 
-    List<Color> colors = new ArrayList<Color>(COLOR_COUNT);
-    TextAttributes attributes = colorsScheme.getAttributes(DefaultLanguageHighlighterColors.CONSTANT);
-    Color foregroundColor = notNull(attributes != null ? attributes.getForegroundColor() : null, JBColor.gray);
-    float[] floats = Color.RGBtoHSB(foregroundColor.getRed(), foregroundColor.getGreen(), foregroundColor.getBlue(), null);
-    for (int i = 0; i < COLOR_COUNT; ++i) {
-      float factor = ((float)i) / COLOR_COUNT;
-      Color color = Color.getHSBColor(factor, .7f, floats[2] * 1.3f);
-      //noinspection UseJBColor
-      colors.add(new Color(color.getRed()/2, color.getGreen(), color.getBlue())); // to highlight errors we reduce Red color
+    if (RAINBOW_COLOR_KEYS.isEmpty()) {
+      for (int i = 0; i < RAINBOW_COLORS_DEFAULT.length; ++i) {
+        RAINBOW_COLOR_KEYS.add(TextAttributesKey.createTextAttributesKey("RAINBOW_COLOR" + i,
+                                                                         new TextAttributes(
+                                                                           new JBColor(RAINBOW_COLORS_DEFAULT[i],
+                                                                                       RAINBOW_COLORS_DARK[i]),
+                                                                           null, null, null, Font.PLAIN)));
+      }
     }
-    return colors;
+    return ColorGenerator.generateLinearColorSequence(RAINBOW_COLOR_KEYS
+                                                        .stream()
+                                                        .map(key -> colorsScheme.getAttributes(key).getForegroundColor())
+                                                        .collect(Collectors.toList()),
+                                                      RAINBOW_COLORS_BETWEEN);
   }
 
   public HighlightInfo getInfo(int colorIndex, @Nullable PsiElement id, @Nullable TextAttributesKey colorKey) {
similarity index 97%
rename from platform/vcs-impl/testSrc/com/intellij/openapi/vcs/ui/ColorGeneratorTest.kt
rename to platform/platform-tests/testSrc/com/intellij/codeHighlighting/ColorGeneratorTest.kt
index 820f05e950a537dd316ed9b9c5453d7ed0790e1b..11fcfd23fdffef9e6f8145b897fd39c43460d2b6 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.intellij.openapi.vcs.ui
+package com.intellij.codeHighlighting
 
 import com.intellij.testFramework.UsefulTestCase
 import com.intellij.ui.Gray
 import java.awt.Color
 
-class ColorGeneratorTest : UsefulTestCase () {
+class ColorGeneratorTest : UsefulTestCase() {
   fun testLineGeneration() {
     for (count in 0..5) {
       assertEquals(count + 2, generate(Color.BLACK, Color.WHITE, count).size)
index a213c4dcd494de81f86bd63a208716d00eee0044..481adf30e140b90c49be34b940fb571e0a268d27 100644 (file)
@@ -19,7 +19,7 @@ import com.intellij.openapi.components.ServiceManager;
 import com.intellij.openapi.editor.colors.ColorKey;
 import com.intellij.openapi.editor.colors.EditorColorsManager;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
-import com.intellij.openapi.vcs.ui.ColorGenerator;
+import com.intellij.codeHighlighting.ColorGenerator;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;