diff --git a/platform/platform-impl/src/com/intellij/ui/NotificationBalloonShadowBorderProvider.java b/platform/platform-impl/src/com/intellij/ui/NotificationBalloonShadowBorderProvider.java index 9d465d2ced19..798aef0224c8 100644 --- a/platform/platform-impl/src/com/intellij/ui/NotificationBalloonShadowBorderProvider.java +++ b/platform/platform-impl/src/com/intellij/ui/NotificationBalloonShadowBorderProvider.java @@ -17,7 +17,9 @@ package com.intellij.ui; import com.intellij.icons.AllIcons.Ide.Notification.Shadow; import com.intellij.openapi.ui.popup.Balloon; +import com.intellij.openapi.util.IconLoader; import com.intellij.util.ui.JBInsets; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -71,32 +73,11 @@ public class NotificationBalloonShadowBorderProvider implements BalloonImpl.Shad int rightWidth = Shadow.Right.getIconWidth(); int rightHeight = Shadow.Right.getIconHeight(); + drawLine(component, g, Shadow.Top, width, topLeftWidth, topRightWidth, topWidth, 0, true); + drawLine(component, g, Shadow.Bottom, width, bottomLeftWidth, bottomRightWidth, bottomWidth, height - bottomHeight, true); - Rectangle clipBounds = g.getClipBounds(); - - g.setClip(topLeftWidth, 0, width - topLeftWidth - topRightWidth, Shadow.Top.getIconHeight()); - for (int x = topLeftWidth; x < width; x += topWidth) { - Shadow.Top.paintIcon(component, g, x, 0); - } - g.setClip(bottomLeftWidth, height - bottomHeight, width - bottomLeftWidth - bottomRightWidth, bottomHeight); - for (int x = bottomLeftWidth; x < width; x += bottomWidth) { - Shadow.Bottom.paintIcon(component, g, x, height - bottomHeight); - } - g.setClip(0, topLeftHeight, Shadow.Left.getIconWidth(), height - topLeftHeight - bottomLeftHeight); - for (int y = topLeftHeight; y < height; y += leftHeight) { - Shadow.Left.paintIcon(component, g, 0, y); - } - g.setClip(width - rightWidth, topRightHeight, rightWidth, height - topRightHeight - bottomRightHeight); - for (int y = topRightHeight; y < height; y += rightHeight) { - Shadow.Right.paintIcon(component, g, width - rightWidth, y); - } - - if (clipBounds == null) { - g.setClip(null); - } - else { - g.setClip(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); - } + drawLine(component, g, Shadow.Left, height, topLeftHeight, bottomLeftHeight, leftHeight, 0, false); + drawLine(component, g, Shadow.Right, height, topRightHeight, bottomRightHeight, rightHeight, width - rightWidth, false); Shadow.Top_left.paintIcon(component, g, 0, 0); Shadow.Top_right.paintIcon(component, g, width - topRightWidth, 0); @@ -104,6 +85,42 @@ public class NotificationBalloonShadowBorderProvider implements BalloonImpl.Shad Shadow.Bottom_left.paintIcon(component, g, 0, height - bottomLeftHeight); } + private static void drawLine(@NotNull JComponent component, + @NotNull Graphics g, + @NotNull Icon icon, + int fullLength, + int start, + int end, + int step, + int start2, + boolean horizontal) { + int length = fullLength - start - end; + int count = length / step; + int calcLength = step * count; + int lastValue = start + calcLength; + + if (horizontal) { + for (int i = start; i < lastValue; i += step) { + icon.paintIcon(component, g, i, start2); + } + } + else { + for (int i = start; i < lastValue; i += step) { + icon.paintIcon(component, g, start2, i); + } + } + + if (calcLength < length) { + ImageIcon imageIcon = (ImageIcon)IconLoader.getIconSnapshot(icon); + if (horizontal) { + UIUtil.drawImage(g, imageIcon.getImage(), lastValue, start2, length - calcLength, imageIcon.getIconHeight(), component); + } + else { + UIUtil.drawImage(g, imageIcon.getImage(), start2, lastValue, imageIcon.getIconWidth(), length - calcLength, component); + } + } + } + @Override public void paintBorder(@NotNull Rectangle bounds, @NotNull Graphics2D g) { g.setColor(myFillColor); diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index b05185f641be..3d42c77e426f 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -1821,6 +1821,10 @@ public class UIUtil { } public static void drawImage(Graphics g, Image image, int x, int y, ImageObserver observer) { + drawImage(g, image, x, y, -1, -1, observer); + } + + public static void drawImage(Graphics g, Image image, int x, int y, int width, int height, ImageObserver observer) { if (image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D)g.create(x, y, image.getWidth(observer), image.getHeight(observer)); newG.scale(0.5, 0.5); @@ -1828,12 +1832,21 @@ public class UIUtil { if (img == null) { img = image; } - newG.drawImage(img, 0, 0, observer); + if (width == -1 && height == -1) { + newG.drawImage(img, 0, 0, observer); + } + else { + newG.drawImage(img, 0, 0, width * 2, height * 2, 0, 0, width * 2, height * 2, observer); + } //newG.scale(1, 1); newG.dispose(); - } else { + } + else if (width == -1 && height == -1) { g.drawImage(image, x, y, observer); } + else { + g.drawImage(image, x, y, x + width, y + height, 0, 0, width, height, observer); + } } public static void drawImage(Graphics g, BufferedImage image, BufferedImageOp op, int x, int y) {