/*
 * Copyright 2013-2016 consulo.io
 *
 * 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 consulo.ide.ui.laf.modern;

import com.intellij.openapi.actionSystem.ActionButtonComponent;
import com.intellij.openapi.actionSystem.impl.ActionButton;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.ui.ColorUtil;
import com.intellij.util.ui.GraphicsUtil;
import com.intellij.util.ui.JBUI;
import consulo.ide.ui.laf.intellij.ActionButtonUI;

import javax.swing.*;
import java.awt.*;

/**
 * @author VISTALL
 * @since 27-Nov-16.
 */
public class ModernActionButtonUI extends ActionButtonUI {
  public static ModernActionButtonUI createUI(JComponent c) {
    return new ModernActionButtonUI();
  }

  @Override
  protected void paintBorder(ActionButton button, Graphics g, Dimension size, int state) {
    if (state == ActionButtonComponent.NORMAL && !button.isBackgroundSet()) return;

    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    g.setColor(state == ActionButtonComponent.POPPED || state == ActionButtonComponent.PUSHED
               ? ModernUIUtil.getSelectionBackground()
               : ModernUIUtil.getBorderColor(button));
    g.drawRect(0, 0, size.width - JBUI.scale(1), size.height - JBUI.scale(1));
    config.restore();
  }

  @Override
  protected void paintBackground(ActionButton button, Graphics g, Dimension size, int state) {
    if (state == ActionButtonComponent.PUSHED) {
      g.setColor(ColorUtil.toAlpha(ModernUIUtil.getSelectionBackground(), 100));
      g.fillRect(JBUI.scale(1), JBUI.scale(1), size.width - JBUI.scale(2), size.height - JBUI.scale(2));
    }
  }
}

@@ -854,27 +854,34 @@
 ij.u
-til.ui.GraphicsUtil
+i.paint.RectanglePainter2D
 ;%0Aim
@@ -906,20 +906,28 @@
 util.ui.
-JBUI
+GraphicsUtil
 ;%0Aimport
@@ -1694,58 +1694,81 @@
     
-g.drawRect(0, 0, size.width - JBUI.scale(1
+RectanglePainter2D.DRAW.paint((Graphics2D)g, 0, 0, size.getWidth(
 ), size.
 heig
@@ -1767,29 +1767,18 @@
 ize.
-h
+getH
 eight
- - JBUI.scale(1
+(
 ));%0A
@@ -2051,82 +2051,81 @@
     
-g.fillRect(JBUI.scale(1), JBUI.scale(1), size.width - JBUI.scale(2
+RectanglePainter2D.FILL.paint((Graphics2D)g, 0, 0, size.getWidth(
 ), size.
 heig
@@ -2124,29 +2124,18 @@
 ize.
-h
+getH
 eight
- - JBUI.scale(2
+(
 ));%0A

fix bug with wrong rectangle paint at action button