/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.util.ui;

import org.jetbrains.annotations.NotNull;

import java.awt.*;

/**
 * User: Vassiliy.Kudryashov
 */
public class TwoColorsIcon extends EmptyIcon {
  @NotNull private final Color myColor1;
  @NotNull private final Color myColor2;

  public TwoColorsIcon(int size, @NotNull Color color1, @NotNull Color color2) {
    super(size, size);
    myColor1 = color1;
    myColor2 = color2;
  }

  @Override
  public void paintIcon(final Component component, final Graphics g, final int x, final int y) {
    final int w = getIconWidth();
    final int h = getIconHeight();
    GraphicsUtil.setupAAPainting(g);
    g.setColor(myColor1);
    g.fillPolygon(new int[]{x, x + w, x}, new int[]{y, y, y + h}, 3);
    g.setColor(myColor2);
    g.fillPolygon(new int[]{x + w, x + w, x}, new int[]{y, y + h, y + h}, 3);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    if (!super.equals(o)) return false;

    TwoColorsIcon icon = (TwoColorsIcon)o;

    if (getIconWidth() != icon.getIconWidth()) return false;
    if (getIconHeight() != icon.getIconHeight()) return false;
    if (!myColor1.equals(icon.myColor1)) return false;
    if (!myColor2.equals(icon.myColor2)) return false;
    return true;
  }

  @Override
  public int hashCode() {
    int result = super.hashCode();
    result = 31 * result + myColor1.hashCode();
    result = 31 * result + myColor2.hashCode();
    return result;
  }
}

@@ -671,26 +671,106 @@
 ll;%0A
-%0Aimport java.awt.*
+import org.jetbrains.annotations.Nullable;%0A%0Aimport java.awt.*;%0Aimport java.awt.image.BufferedImage
 ;%0A%0A/
@@ -869,37 +869,37 @@
 l private final 
-Color
+Paint
  myColor1;%0A  @No
@@ -922,22 +922,764 @@
 nal 
-Color myColor2
+Paint myColor2;%0A  private static final int SQUARE_SIZE = 6;%0A  private static final BufferedImage CHESS_IMAGE = UIUtil.createImage(SQUARE_SIZE, SQUARE_SIZE, BufferedImage.TYPE_INT_RGB);%0A  static %7B%0A    Graphics2D graphics = CHESS_IMAGE.createGraphics();%0A    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);%0A    graphics.setColor(Color.LIGHT_GRAY);%0A    graphics.fillRect(0, 0, SQUARE_SIZE + 1, SQUARE_SIZE + 1);%0A    graphics.setColor(Color.GRAY);%0A    graphics.fillRect(0, 0, SQUARE_SIZE / 2, SQUARE_SIZE / 2);%0A    graphics.fillRect(SQUARE_SIZE / 2, SQUARE_SIZE / 2, SQUARE_SIZE / 2, SQUARE_SIZE / 2);%0A  %7D%0A  private TexturePaint CHESS = new TexturePaint(CHESS_IMAGE, new Rectangle(0, 0, SQUARE_SIZE, SQUARE_SIZE))
 ;%0A%0A 
@@ -1708,30 +1708,31 @@
 int size, @N
-otN
 ull
+able
  Color color
@@ -1736,22 +1736,23 @@
 lor1, @N
-otN
 ull
+able
  Color c
@@ -1808,31 +1808,81 @@
 lor1
-;%0A    myColor2 = color2
+ != null ? color1 : CHESS;%0A    myColor2 = color2 != null ? color2 : CHESS
 ;%0A  
@@ -1989,24 +1989,81 @@
 al int y) %7B%0A
+    Graphics2D g2d = (Graphics2D)g.create();%0A    try %7B%0A  
     final in
@@ -2080,24 +2080,26 @@
 conWidth();%0A
+  
     final in
@@ -2121,24 +2121,26 @@
 ight();%0A    
+  
 GraphicsUtil
@@ -2157,33 +2157,39 @@
 inting(g
+2d
 );%0A
+  
     g
+2d
 .set
-Color
+Paint
 (myColor
@@ -2192,25 +2192,29 @@
 olor1);%0A    
-g
+  g2d
 .fillPolygon
@@ -2274,18 +2274,22 @@
     
-g.setColor
+  g2d.setPaint
 (myC
@@ -2300,17 +2300,21 @@
 2);%0A    
-g
+  g2d
 .fillPol
@@ -2378,16 +2378,75 @@
 h%7D, 3);%0A
+    %7D%0A    catch (Exception e) %7B%0A      g2d.dispose();%0A    %7D%0A
   %7D%0A%0A  @

Allow nullable colors