IDEA-158861 changes from review
authorAlexey Utkin <alexey.utkin@jetbrains.com>
Wed, 10 Aug 2016 09:27:51 +0000 (12:27 +0300)
committerAlexey Utkin <alexey.utkin@jetbrains.com>
Wed, 10 Aug 2016 09:27:51 +0000 (12:27 +0300)
platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java
platform/lang-impl/src/com/intellij/application/options/colors/CustomizedSwitcherPanel.java
platform/lang-impl/src/com/intellij/application/options/colors/RainbowDescriptionPanel.form
platform/lang-impl/src/com/intellij/application/options/colors/SimpleEditorPreview.java
platform/platform-resources-en/src/messages/ApplicationBundle.properties

index c90af35acfeef0a34e5b587edec6776784f0ab28..bdd6d1c9a7dcd7ce04da1e368e1ce2007d0338eb 100644 (file)
@@ -538,26 +538,26 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
     String group = provider.getDisplayName();
     List<AttributesDescriptor> attributeDescriptors = ColorSettingsUtil.getAllAttributeDescriptors(provider);
     //todo: single point configuration?
-    //if (provider instanceof RainbowColorSettingsPage) {
-    //  descriptions.add(new RainbowAttributeDescriptor(group,
-    //                                                  ApplicationBundle.message("rainbow.option.panel.display.name"),
-    //                                                  scheme,
-    //                                                  scheme.getInitRainbowState(),
-    //                                                  scheme.getCurrentRainbowState()));
-    //}
+    if (provider instanceof RainbowColorSettingsPage) {
+      descriptions.add(new RainbowAttributeDescriptor(group,
+                                                      ApplicationBundle.message("rainbow.option.panel.display.name"),
+                                                      scheme,
+                                                      scheme.getInitRainbowState(),
+                                                      scheme.getCurrentRainbowState()));
+    }
     for (AttributesDescriptor descriptor : attributeDescriptors) {
       addSchemedDescription(descriptions, descriptor.getDisplayName(), group, descriptor.getKey(), scheme, null, null);
-      if (provider instanceof RainbowColorSettingsPage
-          && ((RainbowColorSettingsPage)provider).isRainbowType(descriptor.getKey())) {
-        //todo: joined sub-descriptor
-        descriptions.add(new RainbowAttributeDescriptor(group,
-                                                        descriptor.getDisplayName()
-                                                        + EditorSchemeAttributeDescriptorWithPath.NAME_SEPARATOR
-                                                        + ApplicationBundle.message("rainbow.option.panel.display.name"),
-                                                        scheme,
-                                                        scheme.getInitRainbowState(),
-                                                        scheme.getCurrentRainbowState()));
-      }
+    //  if (provider instanceof RainbowColorSettingsPage
+    //      && ((RainbowColorSettingsPage)provider).isRainbowType(descriptor.getKey())) {
+    //    //todo: joined sub-descriptor?
+    //    descriptions.add(new RainbowAttributeDescriptor(group,
+    //                                                    descriptor.getDisplayName()
+    //                                                    + EditorSchemeAttributeDescriptorWithPath.NAME_SEPARATOR
+    //                                                    + ApplicationBundle.message("rainbow.option.panel.display.name"),
+    //                                                    scheme,
+    //                                                    scheme.getInitRainbowState(),
+    //                                                    scheme.getCurrentRainbowState()));
+    //  }
     }
 
     ColorDescriptor[] colorDescriptors = provider.getColorDescriptors();
index babd1ad7a4648c5cbf246f9cb8a085d1d4a45325..e32494bb4557680838626e87388b1cbceb064feb 100644 (file)
@@ -17,14 +17,17 @@ package com.intellij.application.options.colors;
 
 import com.intellij.application.options.colors.highlighting.HighlightData;
 import com.intellij.codeHighlighting.RainbowHighlighter;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
 import com.intellij.openapi.editor.colors.EditorSchemeAttributeDescriptor;
 import com.intellij.openapi.editor.colors.TextAttributesKey;
 import com.intellij.openapi.editor.ex.DocumentEx;
+import com.intellij.openapi.editor.ex.EditorEx;
 import com.intellij.openapi.options.colors.ColorSettingsPage;
 import com.intellij.openapi.options.colors.RainbowColorSettingsPage;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.TextRange;
+import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -68,14 +71,13 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
   public void resetDefault() {
     myActive = null;
     if (getComponentCount() != 0) {
+      final PaintLocker locker = new PaintLocker(this);
       try {
-        setIgnoreRepaint(true);
         setPreferredSize(getSize());
         remove(0);
       }
       finally {
-        setIgnoreRepaint(false);
-        revalidate();
+        locker.release();
       }
     }
   }
@@ -91,9 +93,8 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
     }
 
     if (getComponentCount() == 0 || myActive != getComponent(0)) {
-      boolean ignoreRepaint = getIgnoreRepaint();
+      final PaintLocker locker = new PaintLocker(this);
       try {
-        setIgnoreRepaint(true);
         if (getComponentCount() != 0) {
           remove(0);
         }
@@ -101,8 +102,7 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
         add((JPanel)myActive);
       }
       finally {
-        setIgnoreRepaint(ignoreRepaint);
-        revalidate();
+        locker.release();
       }
     }
     myActive.reset(descriptor);
@@ -110,12 +110,14 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
   }
 
   private void addRainbowHighlighting(@NotNull DocumentEx document,
-                                      @NotNull List<HighlightData> showLineData,
+                                      @Nullable List<HighlightData> showLineData,
                                       @NotNull List<HighlightData> data,
                                       @NotNull RainbowHighlighter rainbowHighlighter,
                                       @NotNull List<TextAttributesKey> rainbowTempKeys) {
     if (!rainbowTempKeys.isEmpty()) {
-      List<HighlightData> newData = new ArrayList<HighlightData>(showLineData);
+      List<HighlightData> newData = new ArrayList<HighlightData>();
+      if (showLineData != null) newData.addAll(showLineData);
+
       HashMap<String, Integer> id2index = new HashMap<String, Integer>();
 
       for (HighlightData d : data) {
@@ -163,31 +165,42 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
 
   protected void updatePreviewPanel(@NotNull EditorSchemeAttributeDescriptor descriptor) {
     if (!(myPreviewPanel instanceof SimpleEditorPreview)) return;
-
-    SimpleEditorPreview simpleEditorPreview = (SimpleEditorPreview)myPreviewPanel;
-
-    if (myActive == myRainbowPanel
-        && myPage instanceof RainbowColorSettingsPage
-        && descriptor instanceof RainbowAttributeDescriptor) {
-      if (myRainbowPanel.myGlobalState.isRainbowOn) {
+    UIUtil.invokeAndWaitIfNeeded((Runnable)() -> ApplicationManager.getApplication().runWriteAction(() -> {
+      SimpleEditorPreview simpleEditorPreview = (SimpleEditorPreview)myPreviewPanel;
+      String demoText = (myPage instanceof RainbowColorSettingsPage
+                         && descriptor instanceof RainbowAttributeDescriptor)
+                        ? ((RainbowColorSettingsPage)myPage).getRainbowDemoText()
+                        : myPage.getDemoText();
+      List<HighlightData> showLineData = null;
+
+      if (myPage instanceof RainbowColorSettingsPage && myRainbowPanel.myGlobalState.isRainbowOn) {
         RainbowHighlighter highlighter = new RainbowHighlighter(descriptor.getScheme());
         List<TextAttributesKey> tempKeys = highlighter.getRainbowTempKeys();
-        Pair<String, List<HighlightData>> demo = getColorDemoLine(highlighter, tempKeys);
-        simpleEditorPreview.setDemoText(demo.first + "\n" + ((RainbowColorSettingsPage)myPage).getRainbowDemoText());
-        addRainbowHighlighting(simpleEditorPreview.getEditor().getDocument(),
-                               demo.second,
+        EditorEx editor = simpleEditorPreview.getEditor();
+        if (myActive == myRainbowPanel) {
+          Pair<String, List<HighlightData>> demo = getColorDemoLine(highlighter, tempKeys);
+          simpleEditorPreview.setDemoText(demo.first + "\n" + demoText);
+          showLineData = demo.second;
+        }
+        else {
+          simpleEditorPreview.setDemoText(demoText);
+        }
+        addRainbowHighlighting(editor.getDocument(),
+                               showLineData,
                                simpleEditorPreview.getHighlightDataForExtension(),
                                highlighter,
                                tempKeys);
       }
       else {
-        simpleEditorPreview.setDemoText(((RainbowColorSettingsPage)myPage).getRainbowDemoText());
+        simpleEditorPreview.setDemoText(demoText);
         removeRainbowHighlighting(simpleEditorPreview.getHighlightDataForExtension());
       }
-    }
-    else {
-      simpleEditorPreview.setDemoText(myPage.getDemoText());
-    }
+
+      simpleEditorPreview.updateView();
+      if (descriptor instanceof RainbowAttributeDescriptor) {
+        simpleEditorPreview.scrollHighlightInView(showLineData);
+      }
+    }));
   }
 
   @NotNull
@@ -217,4 +230,21 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
     myRainbowPanel.addListener(listener);
     myColorAndFontPanel.addListener(listener);
   }
+
+  private static class PaintLocker {
+    private Container myPaintHolder;
+    private boolean myPaintState;
+
+    public PaintLocker(@NotNull JComponent component) {
+      myPaintHolder = component.getParent();
+      myPaintState = myPaintHolder.getIgnoreRepaint();
+      myPaintHolder.setIgnoreRepaint(true);
+    }
+
+    public void release() {
+      myPaintHolder.validate();
+      myPaintHolder.setIgnoreRepaint(myPaintState);
+      myPaintHolder.repaint();
+    }
+  }
 }
index 445133c29f423c4709919e4e212f8c3797a06399..6cc712de6880b61837f3ae4e046a63836f776378 100644 (file)
@@ -1,25 +1,33 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.application.options.colors.RainbowDescriptionPanel">
-  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="9" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="10" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="10" bottom="10" right="10"/>
     <constraints>
-      <xy x="20" y="20" width="327" height="344"/>
+      <xy x="20" y="20" width="348" height="367"/>
     </constraints>
     <properties/>
     <border type="none"/>
     <children>
       <component id="fcf61" class="com.intellij.ui.components.JBCheckBox" binding="myRainbow">
         <constraints>
-          <grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="0" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
           <text resource-bundle="messages/ApplicationBundle" key="checkbox.rainbow"/>
         </properties>
       </component>
+      <component id="2aaea" class="javax.swing.JLabel">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text resource-bundle="messages/ApplicationBundle" key="label.override.gradient"/>
+        </properties>
+      </component>
       <component id="a9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop1">
         <constraints>
-          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
-            <preferred-size width="77" height="24"/>
+          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+            <preferred-size width="44" height="24"/>
           </grid>
         </constraints>
         <properties>
@@ -28,7 +36,7 @@
       </component>
       <component id="abc5e" class="javax.swing.JLabel">
         <constraints>
-          <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+          <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
             <preferred-size width="16" height="16"/>
           </grid>
         </constraints>
@@ -38,7 +46,7 @@
       </component>
       <component id="2ec12" class="com.intellij.ui.ColorPanel" binding="myStop1">
         <constraints>
-          <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
+          <grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
             <preferred-size width="57" height="21"/>
           </grid>
         </constraints>
@@ -46,7 +54,7 @@
       </component>
       <component id="b9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop2">
         <constraints>
-          <grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="3" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
           <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
@@ -54,7 +62,7 @@
       </component>
       <component id="bc5e" class="javax.swing.JLabel">
         <constraints>
-          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+          <grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
             <preferred-size width="16" height="16"/>
           </grid>
         </constraints>
@@ -64,7 +72,7 @@
       </component>
       <component id="89ac3" class="com.intellij.ui.ColorPanel" binding="myStop2">
         <constraints>
-          <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
+          <grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
             <preferred-size width="57" height="21"/>
           </grid>
         </constraints>
@@ -72,7 +80,7 @@
       </component>
       <component id="c9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop3">
         <constraints>
-          <grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="4" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
           <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
@@ -80,7 +88,7 @@
       </component>
       <component id="cbc5e" class="javax.swing.JLabel">
         <constraints>
-          <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+          <grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
             <preferred-size width="16" height="16"/>
           </grid>
         </constraints>
@@ -90,7 +98,7 @@
       </component>
       <component id="9ae84" class="com.intellij.ui.ColorPanel" binding="myStop3">
         <constraints>
-          <grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
+          <grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
             <preferred-size width="57" height="21"/>
           </grid>
         </constraints>
       </component>
       <component id="d9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop4">
         <constraints>
-          <grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="5" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
           <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
       </component>
       <component id="dbc5e" class="javax.swing.JLabel">
         <constraints>
-          <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+          <grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
             <preferred-size width="16" height="16"/>
           </grid>
         </constraints>
       </component>
       <component id="c5026" class="com.intellij.ui.ColorPanel" binding="myStop4">
         <constraints>
-          <grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
+          <grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
             <preferred-size width="57" height="21"/>
           </grid>
         </constraints>
       </component>
       <component id="e9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop5">
         <constraints>
-          <grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="6" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
           <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
       </component>
       <component id="ebc5e" class="javax.swing.JLabel">
         <constraints>
-          <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+          <grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
             <preferred-size width="16" height="16"/>
           </grid>
         </constraints>
       </component>
       <component id="18914" class="com.intellij.ui.ColorPanel" binding="myStop5">
         <constraints>
-          <grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
+          <grid row="6" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false">
             <preferred-size width="57" height="21"/>
           </grid>
         </constraints>
       <grid id="945b4" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="30" left="0" bottom="0" right="0"/>
         <constraints>
-          <grid row="6" column="0" row-span="2" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
+          <grid row="7" column="1" row-span="2" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
         </constraints>
         <properties>
           <visible value="false"/>
       </grid>
       <vspacer id="9aa06">
         <constraints>
-          <grid row="8" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+          <grid row="9" column="2" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
       </vspacer>
       <hspacer id="cde47">
         <constraints>
-          <grid row="7" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+          <grid row="8" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
         </constraints>
       </hspacer>
       <component id="853c3" class="javax.swing.JLabel">
         <constraints>
-          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
-            <preferred-size width="77" height="16"/>
+          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
+            <preferred-size width="44" height="16"/>
           </grid>
         </constraints>
         <properties>
index b257d2e90c898e14a31dda1e5637a65486839802..527b469ce6194f529eeae7638a98707589f70177 100644 (file)
@@ -18,14 +18,15 @@ package com.intellij.application.options.colors;
 
 import com.intellij.application.options.colors.highlighting.HighlightData;
 import com.intellij.application.options.colors.highlighting.HighlightsExtractor;
+import com.intellij.codeHighlighting.RainbowHighlighter;
 import com.intellij.ide.highlighter.HighlighterFactory;
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.editor.EditorFactory;
 import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.editor.ScrollType;
 import com.intellij.openapi.editor.colors.CodeInsightColors;
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
+import com.intellij.openapi.editor.colors.EditorSchemeAttributeDescriptor;
 import com.intellij.openapi.editor.colors.TextAttributesKey;
 import com.intellij.openapi.editor.event.CaretAdapter;
 import com.intellij.openapi.editor.event.CaretEvent;
@@ -36,19 +37,21 @@ import com.intellij.openapi.editor.highlighter.HighlighterIterator;
 import com.intellij.openapi.fileTypes.SyntaxHighlighter;
 import com.intellij.openapi.options.colors.ColorSettingsPage;
 import com.intellij.openapi.options.colors.EditorHighlightingProvidingColorSettingsPage;
-import com.intellij.openapi.editor.colors.EditorSchemeAttributeDescriptor;
 import com.intellij.psi.tree.IElementType;
 import com.intellij.util.Alarm;
 import com.intellij.util.EventDispatcher;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseMotionAdapter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 public class SimpleEditorPreview implements PreviewPanel {
   private final ColorSettingsPage myPage;
@@ -105,22 +108,16 @@ public class SimpleEditorPreview implements PreviewPanel {
   }
 
   public void setDemoText(final String text) {
-    UIUtil.invokeAndWaitIfNeeded( new Runnable() {
-      @Override
-      public void run() {
-        ApplicationManager.getApplication().runWriteAction(() -> {
-          try {
-            myTextIsChanging = true;
-            myHighlightData.clear();
-            String stripped = myHighlightsExtractor.extractHighlights(text, myHighlightData);
-            myEditor.getSelectionModel().removeSelection();
-            myEditor.getDocument().setText(stripped);
-          } finally {
-            myTextIsChanging = false;
-          }
-        });
-      }
-    });
+    try {
+      myTextIsChanging = true;
+      myHighlightData.clear();
+      String stripped = myHighlightsExtractor.extractHighlights(text, myHighlightData);
+      myEditor.getSelectionModel().removeSelection();
+      myEditor.getDocument().setText(stripped);
+    }
+    finally {
+      myTextIsChanging = false;
+    }
   }
 
   private void addMouseMotionListener(final Editor view,
@@ -154,7 +151,10 @@ public class SimpleEditorPreview implements PreviewPanel {
           ClickNavigator.setCursor(editor, Cursor.HAND_CURSOR);
         }
         else {
-          myDispatcher.getMulticaster().selectionInPreviewChanged(highlightData.getHighlightType());
+          myDispatcher.getMulticaster().selectionInPreviewChanged(
+            RainbowHighlighter.isRainbowTempKey(highlightData.getHighlightKey())
+            ? RainbowHighlighter.RAINBOW_TYPE
+            : highlightData.getHighlightType());
         }
         return;
       }
@@ -225,33 +225,36 @@ public class SimpleEditorPreview implements PreviewPanel {
                                                                myPage.getHighlighter(), true,
                                                                myBlinkingAlarm, BLINK_COUNT, myPage);
 
-      scrollHighlightInView(highlights, myEditor);
+      scrollHighlightInView(highlights);
     }
   }
 
-  private static void scrollHighlightInView(final List<HighlightData> highlightDatas, final Editor editor) {
+  void scrollHighlightInView(@Nullable final List<HighlightData> highlightDatas) {
+    if (highlightDatas == null) return;
+
     boolean needScroll = true;
     int minOffset = Integer.MAX_VALUE;
     for (HighlightData data : highlightDatas) {
-      if (isOffsetVisible(editor, data.getStartOffset())) {
+      if (isOffsetVisible(data.getStartOffset())) {
         needScroll = false;
         break;
       }
       minOffset = Math.min(minOffset, data.getStartOffset());
     }
     if (needScroll && minOffset != Integer.MAX_VALUE) {
-      LogicalPosition pos = editor.offsetToLogicalPosition(minOffset);
-      editor.getScrollingModel().scrollTo(pos, ScrollType.MAKE_VISIBLE);
+      LogicalPosition pos = myEditor.offsetToLogicalPosition(minOffset);
+      myEditor.getScrollingModel().scrollTo(pos, ScrollType.MAKE_VISIBLE);
     }
   }
 
-  private static boolean isOffsetVisible(final Editor editor, final int startOffset) {
-    Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
-    Point point = editor.logicalPositionToXY(editor.offsetToLogicalPosition(startOffset));
-    return point.y >= visibleArea.y && point.y < (visibleArea.y + visibleArea.height);
+  private boolean isOffsetVisible(final int startOffset) {
+    return myEditor
+      .getScrollingModel()
+      .getVisibleArea()
+      .contains(myEditor.logicalPositionToXY(myEditor.offsetToLogicalPosition(startOffset)));
   }
 
-  private void stopBlinking() {
+  public void stopBlinking() {
     myBlinkingAlarm.cancelAllRequests();
   }
 
index d035a7428c18989eda329cc5185c8c91052c7011..23f73087434996d029bc4c434b04839754221f0c 100644 (file)
@@ -744,5 +744,6 @@ remote.desktop.detected.message=Animation disabled
 checkbox.line.comment.add.space=Add a space at comment start
 
 rainbow.option.panel.display.name=Semantic highlighting
-label.base.color=Override gradient stop
-checkbox.rainbow=<html>Unique color for each<br>parameter and local variable<br><font color=gray><sub>Chosen from generated gradient</sub></font></html>
\ No newline at end of file
+label.override.gradient=Override gradient:
+label.base.color=Stop
+checkbox.rainbow=<html>Unique color for each parameter<br>and local variable<br><font color=gray><sub>Chosen from generated gradient</sub></font></html>
\ No newline at end of file