/*
 * Copyright 2000-2015 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.ide.ui.laf.intellij;

import com.intellij.ide.ui.laf.darcula.DarculaLaf;

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

/**
 * @author Konstantin Bulenkov
 */
@SuppressWarnings("UnnecessaryLocalVariable")
public class MacIntelliJBorderPainter {
  private static final Icon L = DarculaLaf.loadIcon("macBorderLeft.png");
  private static final Icon R = DarculaLaf.loadIcon("macBorderRight.png");
  private static final Icon T = DarculaLaf.loadIcon("macBorderTop.png");
  private static final Icon B = DarculaLaf.loadIcon("macBorderBottom.png");
  private static final Icon TL = DarculaLaf.loadIcon("macBorderTopLeft.png");
  private static final Icon TR = DarculaLaf.loadIcon("macBorderTopRight.png");
  private static final Icon BL = DarculaLaf.loadIcon("macBorderBottomLeft.png");
  private static final Icon BR = DarculaLaf.loadIcon("macBorderBottomRight.png");

  public static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    g = g.create(x,y,width,height);
    //corners
    TL.paintIcon(c, g, x, y);
    BL.paintIcon(c, g, x, y + height - BL.getIconHeight());
    TR.paintIcon(c, g, x + width - TR.getIconWidth(), y);
    BR.paintIcon(c, g, x + width - BR.getIconWidth(), y + height - BR.getIconHeight());

    //top and bottom lines
    int xOffset = x + TL.getIconWidth();
    int stop = x + width - TR.getIconWidth();
    int top = y;
    int bottom = y + height - B.getIconHeight();
    g.setClip(xOffset, y, width - L.getIconWidth() - R.getIconWidth(), height);
    while (xOffset < stop) {
      T.paintIcon(c, g, xOffset, top);
      B.paintIcon(c, g, xOffset, bottom);
      xOffset += T.getIconWidth();
    }

    //left and right lines
    int left = x;
    int right = x + width - R.getIconWidth();
    int yOffset = y + T.getIconHeight();
    stop = y + height - B.getIconHeight();
    g.setClip(x, yOffset, width, height - T.getIconHeight() - B.getIconHeight());
    while (yOffset < stop) {
      L.paintIcon(c, g, left, yOffset);
      R.paintIcon(c, g, right, yOffset);
      yOffset += L.getIconHeight();
    }
    g.dispose();
  }
}

@@ -641,60 +641,8 @@
 j;%0A%0A
-import com.intellij.ide.ui.laf.darcula.DarculaLaf;%0A%0A
 impo
@@ -808,55 +808,149 @@
 r %7B%0A
+%0A
   p
-rivate static final Icon L = DarculaLaf.load
+ublic static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) %7B%0A    final Icon L = MacIntelliJIconCache.get
 Icon
@@ -968,32 +968,15 @@
 Left
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -983,39 +983,48 @@
 al Icon R = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon(%22macBor
@@ -1035,32 +1035,15 @@
 ight
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -1054,31 +1054,40 @@
 con T = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon(%22ma
@@ -1100,32 +1100,15 @@
 rTop
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -1119,31 +1119,40 @@
 con B = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon(%22ma
@@ -1168,32 +1168,15 @@
 ttom
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -1184,39 +1184,48 @@
 l Icon TL = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon(%22macBor
@@ -1238,32 +1238,15 @@
 Left
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -1254,39 +1254,48 @@
 l Icon TR = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon(%22macBor
@@ -1309,32 +1309,15 @@
 ight
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -1329,31 +1329,40 @@
 on BL = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon(%22ma
@@ -1382,32 +1382,15 @@
 Left
-.png
 %22);%0A  
-private static
+ 
  fin
@@ -1406,23 +1406,32 @@
 R = 
-DarculaLaf.load
+MacIntelliJIconCache.get
 Icon
@@ -1456,113 +1456,12 @@
 ight
-.png%22);%0A%0A  public static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) %7B
+%22);%0A
 %0A   

use icon cache for graphite aware painting