From 4fc43445c55cadd0894de52fcab08de9c0b1d345 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Tue, 2 Feb 2016 12:13:26 +0300 Subject: [PATCH] IDEA-149395 catch possible exceptions (IDEA-151088) --- .../intellij/ui/components/JBScrollPane.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java index bbccbc3d195e..13a713488258 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java @@ -40,9 +40,8 @@ import java.awt.image.*; public class JBScrollPane extends JScrollPane { public static final RegionPainter TRACK_PAINTER = new AlphaPainter(.0f, .1f); - public static final RegionPainter THUMB_PAINTER = SystemInfo.isWindows // others do not support custom composites - ? new SubtractThumbPainter(.20f, .15f, Gray.x91) - : new ThumbPainter(.35f, .25f, Gray.x6E); + public static final RegionPainter THUMB_PAINTER = new ProtectedPainter(new SubtractThumbPainter(.20f, .15f, Gray.x91), + new ThumbPainter(.35f, .25f, Gray.x6E)); public static final RegionPainter THUMB_DARK_PAINTER = new ThumbPainter(.35f, .25f, Gray.x94); private int myViewportBorderWidth = -1; @@ -703,6 +702,34 @@ public class JBScrollPane extends JScrollPane { } } + private static class ProtectedPainter implements RegionPainter { + private RegionPainter myPainter; + private RegionPainter myFallback; + + public ProtectedPainter(RegionPainter painter, RegionPainter fallback) { + myPainter = painter; + myFallback = fallback; + } + + @Override + public void paint(Graphics2D g, int x, int y, int width, int height, Float value) { + RegionPainter painter = myFallback; + if (myPainter != null) { + try { + myPainter.paint(g, x, y, width, height, value); + return; + } + catch (Exception exception) { + // do not try to use myPainter again on other systems + if (!SystemInfo.isWindows) myPainter = null; + } + } + if (painter != null) { + painter.paint(g, x, y, width, height, value); + } + } + } + private static class AlphaPainter implements RegionPainter { private final float myBase; private final float myDelta; @@ -747,8 +774,7 @@ public class JBScrollPane extends JScrollPane { @Override void paint(Graphics2D g, int x, int y, int width, int height) { - super.paint(g, x, y, width, height); - g.fillRect(x + 1, y + 1, width - 2, height - 2); + super.paint(g, x + 1, y + 1, width - 2, height - 2); g.setColor(myColor); if (Registry.is("ide.scroll.thumb.border.rounded")) { g.drawLine(x + 1, y, x + width - 2, y);