IDEA-135734 Tabs: more contrast between selected and not selected
authorVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Mon, 2 Feb 2015 19:53:04 +0000 (22:53 +0300)
committerVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Mon, 2 Feb 2015 19:54:16 +0000 (22:54 +0300)
platform/platform-api/src/com/intellij/ui/tabs/impl/DarculaEditorTabsPainter.java
platform/platform-api/src/com/intellij/ui/tabs/impl/DefaultEditorTabsPainter.java
platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java
platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/CompressibleSingleRowLayout.java
platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorWindow.java

index 412da4bb95365c9e7b6f98aff64e7bb65eee5bfc..e626dab1eccda7415f4b6f8aea8f744f298a77d5 100644 (file)
  */
 package com.intellij.ui.tabs.impl;
 
-import com.intellij.ui.Gray;
-import com.intellij.util.ui.UIUtil;
+import com.intellij.ui.ColorUtil;
 
 import java.awt.*;
 
 /**
  * @author Konstantin Bulenkov
  */
-class DarculaEditorTabsPainter extends JBEditorTabsPainter {
-  @Override
-  public void doPaintInactive(Graphics2D g2d,
-                              Rectangle effectiveBounds,
-                              int x,
-                              int y,
-                              int w,
-                              int h,
-                              Color tabColor,
-                              int row,
-                              int column,
-                              boolean vertical) {
-    if (tabColor != null) {
-      g2d.setColor(tabColor);
-      g2d.fillRect(x, y, w, h);
-    } else {
-      g2d.setPaint(UIUtil.getControlColor());
-      g2d.fillRect(x, y, w, h);
-    }
+@SuppressWarnings("UseJBColor")
+class DarculaEditorTabsPainter extends DefaultEditorTabsPainter {
 
-    g2d.setColor(Gray._0.withAlpha(10));
-    g2d.drawRect(x, y, w - 1, h - 1);
+  @Override
+  protected Color getDefaultTabColor() {
+    return new Color(0x515658);
   }
 
   @Override
-  public void doPaintBackground(Graphics2D g, Rectangle clip, boolean vertical, Rectangle rectangle) {
-    g.setColor(UIUtil.getPanelBackground());
-    g.fill(clip);
-
-    g.setColor(Gray._0.withAlpha(80));
-    g.fill(clip);
-
-    final int x = rectangle.x;
-    final int y = rectangle.y;
-    final int h = rectangle.height;
-    g.setPaint(UIUtil.getGradientPaint(x, y, Gray._78.withAlpha(160), x, y + h, Gray._78.withAlpha(120)));
-    final int w = rectangle.width;
-    g.fillRect(x, rectangle.y, w, h + (vertical ? 1 : 0));
-
-    if (!vertical) {
-      g.setColor(Gray._78);
-      g.drawLine(x, rectangle.y, x + w, rectangle.y);
-    }
+  public Color getBackgroundColor() {
+    return new Color(0x353536);
   }
 
-
-  public void fillSelectionAndBorder(Graphics2D g, JBTabsImpl.ShapeInfo selectedShape, Color tabColor, int x, int y, int height) {
-    if (tabColor != null) {
-      g.setColor(tabColor);
-      g.fill(selectedShape.fillPath.getShape());
-
-      g.setPaint(UIUtil.getGradientPaint(x, y, Gray._255.withAlpha(50), x, y + height, Gray._255.withAlpha(0)));
-    } else {
-      g.setPaint(UIUtil.getGradientPaint(x, y, Gray._85, x, y + height, Gray._60));
-    }
-
-    g.fill(selectedShape.fillPath.getShape());
-
-    g.setColor(Gray._135.withAlpha(90));
-    g.draw(selectedShape.fillPath.getShape());
-
-    // fix right side due to swing stupidity (fill & draw will occupy different shapes)
-    g.draw(selectedShape.labelPath
-               .transformLine(selectedShape.labelPath.getMaxX() - selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getY() +
-                                                                                                     selectedShape.labelPath.deltaY(1),
-                              selectedShape.labelPath.getMaxX() - selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getMaxY() -
-                                                                                                     selectedShape.labelPath.deltaY(4)));
+  @Override
+  protected Color getInactiveMaskColor() {
+    return ColorUtil.withAlpha(new Color(0x262626), .5);
   }
 
   @Override
-  public Color getBackgroundColor() {
-    //noinspection UseJBColor
-    return new Color(0x3C3F41);
+  protected Color getShadowBaseColor() {
+    return new Color(0x242627);
   }
 }
index c2bf919b8dd57422cf0fa6b16963e4e867945ebd..c6d1ab21a758931c64fca64cfd7ae0cf5788e623 100644 (file)
  */
 package com.intellij.ui.tabs.impl;
 
+import com.intellij.openapi.editor.colors.EditorColorsManager;
 import com.intellij.ui.ColorUtil;
 import com.intellij.ui.Gray;
-import com.intellij.util.ui.UIUtil;
 
 import java.awt.*;
 
 /**
  * @author Konstantin Bulenkov
  */
+@SuppressWarnings("UseJBColor")
 public class DefaultEditorTabsPainter extends JBEditorTabsPainter {
 
-  private static final int ACTIVE_TAB_SHADOW_HEIGHT = 3;
-
   @Override
   public void doPaintInactive(Graphics2D g2d,
                               Rectangle effectiveBounds,
@@ -39,92 +38,53 @@ public class DefaultEditorTabsPainter extends JBEditorTabsPainter {
                               int row,
                               int column,
                               boolean vertical) {
-    if (tabColor != null) {
-      g2d.setPaint(UIUtil.getGradientPaint(x, y, Gray._200, x, y + effectiveBounds.height, Gray._130));
-      g2d.fillRect(x, y, w, h);
-
-      g2d.setColor(ColorUtil.toAlpha(tabColor, 150));
-      g2d.fillRect(x, y, w, h);
-    } else {
-      g2d.setPaint(UIUtil.getGradientPaint(x, y, Gray._255.withAlpha(180), x, y + effectiveBounds.height, Gray._255.withAlpha(100)));
-      g2d.fillRect(x, y, w, h);
-    }
-
-
-    // Push top row under the navbar or toolbar and have a blink over previous row shadow for 2nd and subsequent rows.
-    if (row == 0) {
-      g2d.setColor(Gray._200.withAlpha(200));
-    }
-    else {
-      g2d.setColor(Gray._255.withAlpha(100));
-    }
-
-    g2d.drawLine(x, y, x + w - 1, y);
+    ;
+    g2d.setColor(tabColor != null ? tabColor : getDefaultTabColor());
+    g2d.fillRect(x, y, w, h);
+    g2d.setColor(getInactiveMaskColor());
+    g2d.fillRect(x, y, w, h);
 
     if (!vertical) {
-      drawShadow(g2d, x, w, y + h);
+      drawShadowLines(g2d, x, y, w);
     }
   }
 
-  private static void drawShadow(Graphics2D g, int x, int w, int shadowBottom) {
-    int shadowTop = shadowBottom - ACTIVE_TAB_SHADOW_HEIGHT;
-    g.setPaint(UIUtil.getGradientPaint(x, shadowTop, Gray.TRANSPARENT,
-                                   x, shadowBottom, Gray._0.withAlpha(30)));
-    g.fillRect(x, shadowTop, w, ACTIVE_TAB_SHADOW_HEIGHT);
-  }
-
   @Override
   public void doPaintBackground(Graphics2D g, Rectangle clip, boolean vertical, Rectangle rectangle) {
-    g.setColor(UIUtil.getPanelBackground());
+    g.setColor(getBackgroundColor());
     g.fill(clip);
-
-    g.setColor(Gray._0.withAlpha(80));
-    g.fill(clip);
-
-    final int x = rectangle.x;
-    final int y = rectangle.y;
-    g.setPaint(UIUtil.getGradientPaint(x, y, Gray._255.withAlpha(160),
-                                 x, rectangle.y + rectangle.height, Gray._255.withAlpha(120)));
-    g.fillRect(x, rectangle.y, rectangle.width, rectangle.height + (vertical ? 1 : 0));
-
     if (!vertical) {
-      g.setColor(Gray._210);
-      g.drawLine(x, rectangle.y, x + rectangle.width, rectangle.y);
-
-      drawShadow(g, rectangle.x, rectangle.width, rectangle.y + rectangle.height);
+      drawShadowLines(g, rectangle.x, rectangle.y, rectangle.width);
     }
   }
 
-  private static Color multiplyColor(Color c) {
-    //noinspection UseJBColor
-    return new Color(c.getRed() * c.getRed() / 255, c.getGreen() * c.getGreen() / 255, c.getBlue() * c.getBlue() / 255);
+  private void drawShadowLines(Graphics g, int x, int y, int width) {
+    g.setColor(ColorUtil.withAlpha(getShadowBaseColor(), .5));
+    g.drawLine(x, y, x + width, y);
+    g.setColor(ColorUtil.withAlpha(getShadowBaseColor(), .2));
+    g.drawLine(x, y+1, x + width, y+1);
   }
 
   public void fillSelectionAndBorder(Graphics2D g, JBTabsImpl.ShapeInfo selectedShape, Color tabColor, int x, int y, int height) {
-    if (tabColor != null) {
-      g.setColor(multiplyColor(tabColor));
-      g.fill(selectedShape.fillPath.getShape());
-
-      g.setPaint(UIUtil.getGradientPaint(x, y, Gray._255.withAlpha(150), x, y + height, Gray._255.withAlpha(0)));
-    } else {
-      g.setPaint(UIUtil.getGradientPaint(x, y, Gray._255, x, y + height, Gray._230));
-    }
-
+    g.setColor(tabColor != null ? tabColor : getDefaultTabColor());
     g.fill(selectedShape.fillPath.getShape());
-
-    g.setColor(Gray._255.withAlpha(180));
     g.draw(selectedShape.fillPath.getShape());
-
-    // fix right side due to swing stupidity (fill & draw will occupy different shapes)
-    g.draw(selectedShape.labelPath
-               .transformLine(selectedShape.labelPath.getMaxX() - selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getY() +
-                                                                                                     selectedShape.labelPath.deltaY(1),
-                              selectedShape.labelPath.getMaxX() - selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getMaxY() -
-                                                                                                     selectedShape.labelPath.deltaY(4)));
   }
 
   @Override
   public Color getBackgroundColor() {
-    return Gray._142;
+    return Gray._177;
+  }
+
+  protected Color getDefaultTabColor() {
+    return EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground();
+  }
+
+  protected Color getInactiveMaskColor() {
+    return ColorUtil.withAlpha(new Color(0x262626), .2);
+  }
+
+  protected Color getShadowBaseColor() {
+    return new Color(0xbababa);
   }
 }
index 5ebaa0f366d4daf4a5855783b519ce7bba24fcd5..c79632f4df01ead3ae177fff280a0b5f561a10b8 100644 (file)
@@ -136,8 +136,8 @@ public class TabLabel extends JPanel {
           super.doPaint(g);
           return;
         }
-        int dimSize = 20;
-        int dimStep = 1;
+        int dimSize = 30;
+        int dimStep = 2;
         Composite oldComposite = g.getComposite();
         Shape oldClip = g.getClip();
         try {
@@ -146,8 +146,7 @@ public class TabLabel extends JPanel {
 
           for (int x = clip.x + clip.width - dimSize; x < clip.x + clip.width; x+=dimStep) {
             g.setClip(x, clip.y, dimStep, clip.height);
-            float linear = 1 - ((float)x - (clip.x + clip.width - dimSize)) / dimSize;
-            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)(1 - Math.cos(Math.PI * linear)) / 2));
+            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1 - ((float)x - (clip.x + clip.width - dimSize)) / dimSize));
             super.doPaint(g);
           }
         } finally {
@@ -169,14 +168,14 @@ public class TabLabel extends JPanel {
   public Insets getInsets() {
     Insets insets = super.getInsets();
     if (myTabs.isEditorTabs()) {
-      int right = insets.right;
       if (!Registry.is("editor.use.compressible.tabs")) {
-        if (UISettings.getInstance().SHOW_CLOSE_BUTTON) right = 3;
+        if (UISettings.getInstance().SHOW_CLOSE_BUTTON) insets.right = 3;
       }
       else {
-        right = (UISettings.getInstance().SHOW_CLOSE_BUTTON || !UISettings.getInstance().MARK_MODIFIED_TABS_WITH_ASTERISK) ? 3 : 6;
+        insets.right = (UISettings.getInstance().SHOW_CLOSE_BUTTON || !UISettings.getInstance().MARK_MODIFIED_TABS_WITH_ASTERISK) ? 3 : 6;
+        insets.left = 5;
       }
-      return new Insets(insets.top, insets.left, insets.bottom, right);
+      return new Insets(insets.top, insets.left, insets.bottom, insets.right);
     }
 
     return insets;
index f921d12c28d427da9d5c462a331f90502bc627dc..9d9fcafa3458292ce8e31be55e7c07462da08dc7 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.ui.tabs.TabInfo;
 import com.intellij.ui.tabs.impl.JBTabsImpl;
 import com.intellij.ui.tabs.impl.LayoutPassInfo;
 import com.intellij.ui.tabs.impl.TabLabel;
+import com.intellij.util.ui.GraphicsUtil;
 
 import java.awt.*;
 import java.util.Iterator;
@@ -39,7 +40,7 @@ public class CompressibleSingleRowLayout extends SingleRowLayout {
       if (firstLabel != null && lastLabel != null) {
         data.tabRectangle.x = firstLabel.getBounds().x;
         data.tabRectangle.y = firstLabel.getBounds().y;
-        data.tabRectangle.width = data.requiredLength;//(int)lastLabel.getBounds().getMaxX() - data.tabRectangle.x;
+        data.tabRectangle.width = data.requiredLength;
         data.tabRectangle.height = (int)lastLabel.getBounds().getMaxY() - data.tabRectangle.y;
       }
     }
@@ -56,17 +57,24 @@ public class CompressibleSingleRowLayout extends SingleRowLayout {
 
   @Override
   protected void layoutLabelsAndGhosts(SingleRowPassInfo data) {
+    if (myTabs.getPresentation().getTabsPosition() != JBTabsPosition.top
+        && myTabs.getPresentation().getTabsPosition() != JBTabsPosition.bottom) {
+      super.layoutLabelsAndGhosts(data);
+      return;
+    }
+
+    int tabWidth = 0;
     boolean layoutStopped = false;
     int lengthEstimation = 0;
-    boolean needCompression = false;
-    if (myTabs.getPresentation().getTabsPosition() == JBTabsPosition.top
-        || myTabs.getPresentation().getTabsPosition() == JBTabsPosition.bottom) {
-      for (TabInfo eachInfo : data.toLayout) {
-        final TabLabel label = myTabs.myInfo2Label.get(eachInfo);
-        lengthEstimation += getStrategy().getLengthIncrement(label.getPreferredSize());
+    for (TabInfo eachInfo : data.toLayout) {
+      final TabLabel label = myTabs.myInfo2Label.get(eachInfo);
+      if (tabWidth == 0) {
+        tabWidth = GraphicsUtil.stringWidth("m", label.getLabelComponent().getFont()) * 15;
       }
-      needCompression = lengthEstimation > data.toFitLength;
+      lengthEstimation += tabWidth;
     }
+    double compressionFactor = (double)lengthEstimation / data.toFitLength;
+
     int spentLength = 0;
     for (Iterator<TabInfo> iterator = data.toLayout.iterator(); iterator.hasNext(); ) {
       TabInfo eachInfo = iterator.next();
@@ -79,16 +87,15 @@ public class CompressibleSingleRowLayout extends SingleRowLayout {
       }
 
       label.setActionPanelVisible(true);
-      final Dimension eachSize = label.getPreferredSize();
 
       int length;
-      if (needCompression) {
-        length = iterator.hasNext() ? (int)(getStrategy().getLengthIncrement(label.getPreferredSize()) * (float)data.toFitLength / lengthEstimation)
+      if (compressionFactor > 1) {
+        length = iterator.hasNext() ? (int)(tabWidth * (float)data.toFitLength / lengthEstimation)
                                     : data.toFitLength - spentLength - data.toLayout.size() / 2;
         spentLength += length;
       }
       else {
-        length = getStrategy().getLengthIncrement(eachSize);
+        length = tabWidth;
       }
       boolean continueLayout = applyTabLayout(data, label, length, 0);
 
@@ -104,4 +111,11 @@ public class CompressibleSingleRowLayout extends SingleRowLayout {
       JBTabsImpl.resetLayout(myTabs.myInfo2Label.get(eachInfo));
     }
   }
+
+  @Override
+  protected boolean applyTabLayout(SingleRowPassInfo data, TabLabel label, int length, int deltaToFit) {
+    boolean result = super.applyTabLayout(data, label, length, deltaToFit);
+    label.setAlignmentToCenter(false);
+    return result;
+  }
 }
index 6bdb103ce4172f0e1a06a8524a9943da9e48fa7d..e2e7a2a4482648a2e7e1f24990328e2ad648454a 100644 (file)
@@ -979,7 +979,7 @@ public class EditorWindow {
     }
 
     final Icon modifiedIcon;
-    if (UISettings.getInstance().MARK_MODIFIED_TABS_WITH_ASTERISK) {
+    if (UISettings.getInstance().MARK_MODIFIED_TABS_WITH_ASTERISK || Registry.is("editor.use.compressible.tabs")) {
       modifiedIcon = composite != null && composite.isModified() ? MODIFIED_ICON : GAP_ICON;
       count++;
     }