IDEA-158861 changes from review #2
authorAlexey Utkin <alexey.utkin@jetbrains.com>
Wed, 10 Aug 2016 17:40:43 +0000 (20:40 +0300)
committerAlexey Utkin <alexey.utkin@jetbrains.com>
Wed, 10 Aug 2016 17:40:43 +0000 (20:40 +0300)
platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java
platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontGlobalState.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/RainbowDescriptionPanel.java
platform/platform-resources-en/src/messages/ApplicationBundle.properties

index 5c1de9b3ee9f38f977df82f840767a12dda72a48..681a42aa8310274d71e7b786af8f9f075b8721f3 100644 (file)
@@ -31,6 +31,7 @@ import com.intellij.util.BitUtil;
 import com.intellij.util.EventDispatcher;
 import com.intellij.util.FontUtil;
 import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ui.JBUI;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -87,7 +88,7 @@ public class ColorAndFontDescriptionPanel extends JPanel implements OptionsPanel
     super(new BorderLayout());
     add(myPanel, BorderLayout.CENTER);
 
-    setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 4));
+    setBorder(JBUI.Borders.empty(4, 0, 4, 4));
     myEffectsModel = new EffectsComboModel(ContainerUtil.newArrayList(myEffectsMap.keySet()));
     //noinspection unchecked
     myEffectsCombo.setModel(myEffectsModel);
index ba0a93d95bc042ceab2e3dd01986b0ed2095695a..3ef237beaf2e3f4c7acddc424fc403ea6e47514d 100644 (file)
@@ -35,6 +35,7 @@ public class ColorAndFontGlobalState {
   }
 
   public void apply() {
+    //FIXME: we need better place for per-language state storage
     RainbowHighlighter.setRainbowEnabled(isRainbowOn);
   }
 
@@ -49,6 +50,6 @@ public class ColorAndFontGlobalState {
 
   @Override
   public int hashCode() {
-    return 31 * (isRainbowOn ? 1 : 0);
+    return isRainbowOn ? 1 : 0;
   }
 }
index e32494bb4557680838626e87388b1cbceb064feb..7d2cb99f76e04b3774b9fe52631043afb50da698 100644 (file)
@@ -69,12 +69,12 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
 
   @Override
   public void resetDefault() {
-    myActive = null;
-    if (getComponentCount() != 0) {
+    if (myActive != null) {
       final PaintLocker locker = new PaintLocker(this);
       try {
-        setPreferredSize(getSize());
-        remove(0);
+        setPreferredSize(getSize());// froze [this] size
+        remove(myActive.getPanel());
+        myActive = null;
       }
       finally {
         locker.release();
@@ -84,31 +84,41 @@ class CustomizedSwitcherPanel extends JPanel implements OptionsPanelImpl.ColorDe
 
   @Override
   public void reset(@NotNull EditorSchemeAttributeDescriptor descriptor) {
-    myActive = null;
-    if (descriptor instanceof RainbowAttributeDescriptor) {
-      myActive = myRainbowPanel;
-    }
-    else if (descriptor instanceof ColorAndFontDescription) {
-      myActive = myColorAndFontPanel;
-    }
+    JComponent oldPanel = myActive == null ? null : myActive.getPanel();
+    myActive = getPanelForDescriptor(descriptor);
+    JComponent newPanel = myActive == null ? null : myActive.getPanel();
 
-    if (getComponentCount() == 0 || myActive != getComponent(0)) {
+    if (oldPanel != newPanel) {
       final PaintLocker locker = new PaintLocker(this);
       try {
-        if (getComponentCount() != 0) {
-          remove(0);
+        if (oldPanel != null) {
+          remove(oldPanel);
+        }
+        if (newPanel != null) {
+          setPreferredSize(null);// make [this] resizable
+          add(newPanel);
         }
-        setPreferredSize(null);
-        add((JPanel)myActive);
       }
       finally {
         locker.release();
       }
     }
-    myActive.reset(descriptor);
+    if (myActive != null) {
+      myActive.reset(descriptor);
+    }
     updatePreviewPanel(descriptor);
   }
 
+  protected OptionsPanelImpl.ColorDescriptionPanel getPanelForDescriptor(@NotNull EditorSchemeAttributeDescriptor descriptor) {
+    if (descriptor instanceof RainbowAttributeDescriptor) {
+      return myRainbowPanel;
+    }
+    else if (descriptor instanceof ColorAndFontDescription) {
+      return myColorAndFontPanel;
+    }
+    return null;
+  }
+
   private void addRainbowHighlighting(@NotNull DocumentEx document,
                                       @Nullable List<HighlightData> showLineData,
                                       @NotNull List<HighlightData> data,
index 6cc712de6880b61837f3ae4e046a63836f776378..d5fdb212f674abc3953c0a08a3a8b72358419654 100644 (file)
 <?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="10" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="9" column-count="3" 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="348" height="367"/>
+      <xy x="20" y="20" width="317" height="342"/>
     </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="4" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
+            <preferred-size width="202" height="66"/>
+          </grid>
         </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">
+      <component id="5556e" 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">
-            <preferred-size width="44" height="24"/>
+          <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
+            <preferred-size width="202" height="21"/>
           </grid>
         </constraints>
         <properties>
-          <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
+          <text resource-bundle="messages/ApplicationBundle" key="label.override.gradient"/>
         </properties>
       </component>
-      <component id="abc5e" class="javax.swing.JLabel">
+      <hspacer id="13e59">
         <constraints>
-          <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>
+          <grid row="1" column="2" row-span="7" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
         </constraints>
-        <properties>
-          <text value="#1"/>
-        </properties>
-      </component>
-      <component id="2ec12" class="com.intellij.ui.ColorPanel" binding="myStop1">
+      </hspacer>
+      <vspacer id="1f6f2">
         <constraints>
-          <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 row="8" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
+            <preferred-size width="202" height="14"/>
           </grid>
         </constraints>
-        <properties/>
-      </component>
-      <component id="b9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop2">
-        <constraints>
-          <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"/>
-        </properties>
-      </component>
-      <component id="bc5e" class="javax.swing.JLabel">
+      </vspacer>
+      <component id="f26f6" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop1">
         <constraints>
-          <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>
+          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <text value="#2"/>
+          <text resource-bundle="messages/ApplicationBundle" key="checkbox.stop.1"/>
         </properties>
       </component>
-      <component id="89ac3" class="com.intellij.ui.ColorPanel" binding="myStop2">
+      <component id="11363" class="com.intellij.ui.ColorPanel" binding="myStop1">
         <constraints>
-          <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>
+          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
       </component>
-      <component id="c9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop3">
+      <component id="e998a" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop2">
         <constraints>
-          <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"/>
+          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
+          <text resource-bundle="messages/ApplicationBundle" key="checkbox.stop.2"/>
         </properties>
       </component>
-      <component id="cbc5e" class="javax.swing.JLabel">
+      <component id="a303b" class="com.intellij.ui.ColorPanel" binding="myStop2">
         <constraints>
-          <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>
-        <properties>
-          <text value="#3"/>
-        </properties>
-      </component>
-      <component id="9ae84" class="com.intellij.ui.ColorPanel" binding="myStop3">
-        <constraints>
-          <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>
+          <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
       </component>
-      <component id="d9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop4">
-        <constraints>
-          <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"/>
-        </properties>
-      </component>
-      <component id="dbc5e" class="javax.swing.JLabel">
+      <component id="f929a" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop3">
         <constraints>
-          <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>
+          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <text value="#4"/>
+          <text resource-bundle="messages/ApplicationBundle" key="checkbox.stop.3"/>
         </properties>
       </component>
-      <component id="c5026" class="com.intellij.ui.ColorPanel" binding="myStop4">
+      <component id="1c10d" class="com.intellij.ui.ColorPanel" binding="myStop3">
         <constraints>
-          <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>
+          <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
       </component>
-      <component id="e9be4" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop5">
+      <component id="6dc1" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop4">
         <constraints>
-          <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"/>
+          <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
+          <text resource-bundle="messages/ApplicationBundle" key="checkbox.stop.4"/>
         </properties>
       </component>
-      <component id="ebc5e" class="javax.swing.JLabel">
+      <component id="8db13" class="com.intellij.ui.ColorPanel" binding="myStop4">
         <constraints>
-          <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>
-        <properties>
-          <text value="#5"/>
-        </properties>
-      </component>
-      <component id="18914" class="com.intellij.ui.ColorPanel" binding="myStop5">
-        <constraints>
-          <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>
+          <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
       </component>
-      <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"/>
+      <component id="bce0f" class="com.intellij.ui.components.JBCheckBox" binding="myCbStop5">
         <constraints>
-          <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"/>
+          <grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <visible value="false"/>
+          <text resource-bundle="messages/ApplicationBundle" key="checkbox.stop.5"/>
         </properties>
-        <border type="none"/>
-        <children>
-          <component id="7f4a6" class="javax.swing.JTextPane" binding="myInheritanceLabel">
-            <constraints>
-              <grid row="1" column="0" row-span="2" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
-            </constraints>
-            <properties>
-              <text value="labl"/>
-              <visible value="true"/>
-            </properties>
-          </component>
-          <component id="60bfb" class="com.intellij.ui.components.JBCheckBox" binding="myInheritAttributesBox">
-            <constraints>
-              <grid row="0" column="0" row-span="1" col-span="1" 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.inherit.attributes"/>
-              <visible value="true"/>
-            </properties>
-            <clientProperties>
-              <hideActionText class="java.lang.Boolean" value="false"/>
-            </clientProperties>
-          </component>
-        </children>
-      </grid>
-      <vspacer id="9aa06">
-        <constraints>
-          <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="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">
+      </component>
+      <component id="1b18c" class="com.intellij.ui.ColorPanel" binding="myStop5">
         <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">
-            <preferred-size width="44" height="16"/>
-          </grid>
+          <grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
-        <properties>
-          <text resource-bundle="messages/ApplicationBundle" key="label.base.color"/>
-        </properties>
+        <properties/>
       </component>
     </children>
   </grid>
index a5964959e020de046dd86c815607e22149350846..3242437eb30aac817069956a67c60b18af198b61 100644 (file)
@@ -17,12 +17,11 @@ package com.intellij.application.options.colors;
 
 import com.intellij.openapi.editor.colors.EditorColorsScheme;
 import com.intellij.openapi.editor.colors.EditorSchemeAttributeDescriptor;
-import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Pair;
 import com.intellij.ui.ColorPanel;
-import com.intellij.ui.HyperlinkAdapter;
 import com.intellij.ui.components.JBCheckBox;
 import com.intellij.util.EventDispatcher;
+import com.intellij.util.ui.JBUI;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
@@ -52,9 +51,8 @@ public class RainbowDescriptionPanel extends JPanel implements OptionsPanelImpl.
   protected ColorPanel myStop5;
   private ColorPanel[] myStops = new ColorPanel[]{myStop1, myStop2, myStop3, myStop4, myStop5};
 
-  private JTextPane myInheritanceLabel;
-
-  private JBCheckBox myInheritAttributesBox;
+  //private JTextPane myInheritanceLabel;
+  //private JBCheckBox myInheritAttributesBox;
   private JBCheckBox myRainbow;
 
   ColorAndFontGlobalState myGlobalState;
@@ -64,28 +62,29 @@ public class RainbowDescriptionPanel extends JPanel implements OptionsPanelImpl.
     myGlobalState = globalState;
     add(myPanel, BorderLayout.CENTER);
 
-    setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 4));
+    setBorder(JBUI.Borders.empty(4, 0, 4, 4));
     ActionListener actionListener = new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
         onSettingsChanged(e);
       }
     };
-    for (JBCheckBox c : new JBCheckBox[]{myRainbow, myCbStop1, myCbStop2, myCbStop3, myCbStop4, myCbStop5, myInheritAttributesBox}) {
+    for (JBCheckBox c : new JBCheckBox[]{myRainbow, myCbStop1, myCbStop2, myCbStop3, myCbStop4, myCbStop5/*, myInheritAttributesBox*/}) {
       c.addActionListener(actionListener);
     }
     for (ColorPanel c : new ColorPanel[]{myStop1, myStop2, myStop3, myStop4, myStop5}) {
       c.addActionListener(actionListener);
     }
 
-    Messages.configureMessagePaneUi(myInheritanceLabel, "<html>", null);
-    myInheritanceLabel.addHyperlinkListener(new HyperlinkAdapter() {
-      @Override
-      protected void hyperlinkActivated(HyperlinkEvent e) {
-        onHyperLinkClicked(e);
-      }
-    });
-    myInheritanceLabel.setBorder(BorderFactory.createEmptyBorder());
+    // FIXME: inherited per-language on/off
+    //Messages.configureMessagePaneUi(myInheritanceLabel, "<html>", null);
+    //myInheritanceLabel.addHyperlinkListener(new HyperlinkAdapter() {
+    //  @Override
+    //  protected void hyperlinkActivated(HyperlinkEvent e) {
+    //    onHyperLinkClicked(e);
+    //  }
+    //});
+    //myInheritanceLabel.setBorder(BorderFactory.createEmptyBorder());
   }
 
   @NotNull
index 23f73087434996d029bc4c434b04839754221f0c..7954be9723f71a1c6e20b419a0a9eda6a8e9a74c 100644 (file)
@@ -745,5 +745,9 @@ checkbox.line.comment.add.space=Add a space at comment start
 
 rainbow.option.panel.display.name=Semantic highlighting
 label.override.gradient=Override gradient:
-label.base.color=Stop
+checkbox.stop.1=Stop #1
+checkbox.stop.2=Stop #2
+checkbox.stop.3=Stop #3
+checkbox.stop.4=Stop #4
+checkbox.stop.5=Stop #5
 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