/*
 * Copyright 2000-2017 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.ui.paint;

import com.intellij.ui.paint.LinePainter2D.StrokeType;
import com.intellij.util.ui.RegionPainter;
import org.jetbrains.annotations.Nullable;

import java.awt.*;

/**
 * @author Sergey.Malenkov
 */
public enum RectanglePainter implements RegionPainter<Integer> {
  DRAW {
    @Override
    public void paint(Graphics2D g, int x, int y, int width, int height, @Nullable Integer round) {
      Object valueAA = round != null && round >= 0 ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_DEFAULT;
      RectanglePainter2D.DRAW.paint(g, x, y, width, height, round == null ? null : Double.valueOf(round), StrokeType.INSIDE, 1, valueAA);
    }
  },
  FILL {
    @Override
    public void paint(Graphics2D g, int x, int y, int width, int height, @Nullable Integer round) {
      Object valueAA = round != null && round >= 0 ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_DEFAULT;
      RectanglePainter2D.FILL.paint(g, x, y, width, height, round == null ? null : Double.valueOf(round), StrokeType.INSIDE, 1, valueAA);
    }
  };

  public static void paint(Graphics2D g, int x, int y, int width, int height, int arc, @Nullable Paint fill, @Nullable Paint draw) {
    if (fill != null) {
      g.setPaint(fill);
      if (draw != null) {
        int sw = 1; // stroke width
        int dw = sw + sw;
        FILL.paint(g, x + sw, y + sw, width - dw, height - dw, arc > dw ? arc - dw : 0);
      }
      else {
        FILL.paint(g, x, y, width, height, arc);
      }
    }
    if (draw != null) {
      g.setPaint(draw);
      DRAW.paint(g, x, y, width, height, arc);
    }
  }
}

@@ -1021,137 +1021,221 @@
     
-Object valueAA = round != null && round %3E= 0 ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_DEFAULT;%0A      
+paint2D(RectanglePainter2D.DRAW, g, x, y, width, height, round);%0A    %7D%0A  %7D,%0A  FILL %7B%0A    @Override%0A    public void paint(Graphics2D g, int x, int y, int width, int height, @Nullable Integer round) %7B%0A      paint2D(
 Rect
@@ -1249,27 +1249,22 @@
 inter2D.
-DRAW.paint(
+FILL, 
 g, x, y,
@@ -1288,137 +1288,75 @@
 ound
- == null ? null : Double.valueOf(round), StrokeType.INSIDE, 1, valueAA);%0A    %7D%0A  %7D,%0A  FILL %7B%0A    @Override%0A    public void paint(
+);%0A    %7D%0A  %7D;%0A%0A  private static void paint2D(RectanglePainter2D p, 
 Grap
@@ -1437,54 +1437,113 @@
     
-  Object valueAA =
+Double arc = round == null %7C%7C
  round 
-!=
+%3C= 0 ?
  null 
-&& round %3E= 0
+: Double.valueOf(round);%0A    Object valueAA = arc != null
  ? R
@@ -1625,33 +1625,9 @@
     
-  RectanglePainter2D.FILL
+p
 .pai
@@ -1657,52 +1657,11 @@
 ht, 
-round == null ? null : Double.valueOf(round)
+arc
 , St
@@ -1688,32 +1688,25 @@
 valueAA);%0A  
-  %7D%0A  %7D;
+%7D
 %0A%0A  public s

Fix scroll thumb painting: do not paint round rectangle if arc=0