diff --git a/platform/platform-api/src/com/intellij/ui/components/ScrollPainter.java b/platform/platform-api/src/com/intellij/ui/components/ScrollPainter.java index ae3d89324fb4..0eb212d6360b 100644 --- a/platform/platform-api/src/com/intellij/ui/components/ScrollPainter.java +++ b/platform/platform-api/src/com/intellij/ui/components/ScrollPainter.java @@ -18,11 +18,10 @@ package com.intellij.ui.components; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.Gray; +import com.intellij.ui.paint.RectanglePainter; import com.intellij.util.ui.RegionPainter; import java.awt.*; -import java.awt.geom.Path2D; -import java.awt.geom.RoundRectangle2D; import java.awt.image.*; /** @@ -132,27 +131,14 @@ class ScrollPainter extends RegionPainter.Alpha { super(offset, base, delta, fill, draw); } - @Override - protected void paint(Graphics2D g, int x, int y, int width, int height) { - Object old = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - super.paint(g, x, y, width, height); - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, old); - } - @Override protected void fill(Graphics2D g, int x, int y, int width, int height, boolean border) { - int arc = Math.min(width, height); - g.fillRoundRect(x, y, width, height, arc, arc); + RectanglePainter.FILL.paint(g, x, y, width, height, Math.min(width, height)); } @Override protected void draw(Graphics2D g, int x, int y, int width, int height) { - int arc = Math.min(width, height); - Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD); - path.append(new RoundRectangle2D.Double(x, y, width, height, arc, arc), false); - path.append(new RoundRectangle2D.Double(x + 1, y + 1, width - 2, height - 2, arc - 2, arc - 2), false); - g.fill(path); + RectanglePainter.DRAW.paint(g, x, y, width, height, Math.min(width, height)); } } diff --git a/platform/platform-api/src/com/intellij/ui/paint/RectanglePainter.java b/platform/platform-api/src/com/intellij/ui/paint/RectanglePainter.java new file mode 100644 index 000000000000..cc7b69a710eb --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/paint/RectanglePainter.java @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2016 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.util.ui.RegionPainter; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.awt.geom.RoundRectangle2D; + +/** + * @author Sergey.Malenkov + */ +public enum RectanglePainter implements RegionPainter { + DRAW { + @Override + public void paint(Graphics2D g, int x, int y, int width, int height, Integer round) { + int sw = 1; // stroke width + int dw = sw + sw; + if (width > dw && height > dw) { + int arc = round == null ? 0 : round; + if (arc > 0) { + Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD); + path.append(new RoundRectangle2D.Double(x, y, width, height, arc, arc), false); + path.append(new RoundRectangle2D.Double(x + sw, y + sw, width - dw, height - dw, arc - dw, arc - dw), false); + Object old = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.fill(path); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, old); + } + else { + Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD); + path.append(new Rectangle2D.Double(x, y, width, height), false); + path.append(new Rectangle2D.Double(x + sw, y + sw, width - dw, height - dw), false); + g.fill(path); + } + } + else { + FILL.paint(g, x, y, width, height, round); + } + } + }, + FILL { + @Override + public void paint(Graphics2D g, int x, int y, int width, int height, Integer round) { + if (width > 0 && height > 0) { + int arc = round == null ? 0 : round; + if (arc > 0) { + Object old = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.fillRoundRect(x, y, width, height, arc, arc); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, old); + } + else { + g.fillRect(x, y, width, height); + } + } + } + }; + + public static void paint(Graphics2D g, int x, int y, int width, int height, int arc, Color fill, Color draw) { + if (fill != null) { + g.setColor(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); + } + else { + FILL.paint(g, x, y, width, height, arc); + } + } + if (draw != null) { + g.setColor(draw); + DRAW.paint(g, x, y, width, height, arc); + } + } +} diff --git a/xml/openapi/src/com/intellij/xml/breadcrumbs/BreadcrumbsComponent.java b/xml/openapi/src/com/intellij/xml/breadcrumbs/BreadcrumbsComponent.java index 00804932fc5f..730ac79def27 100644 --- a/xml/openapi/src/com/intellij/xml/breadcrumbs/BreadcrumbsComponent.java +++ b/xml/openapi/src/com/intellij/xml/breadcrumbs/BreadcrumbsComponent.java @@ -22,15 +22,14 @@ import com.intellij.openapi.util.Weighted; import com.intellij.ui.ColorUtil; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; +import com.intellij.ui.paint.RectanglePainter; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.JBInsets; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.border.Border; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -340,11 +339,9 @@ public class BreadcrumbsComponent extends JComponent @Override public Dimension getPreferredSize() { - Border border = getBorder(); Graphics2D g2 = (Graphics2D)getGraphics(); Dimension dim = new Dimension(Integer.MAX_VALUE, g2 != null ? DEFAULT_PAINTER.getSize("DUMMY", g2.getFontMetrics(), Integer.MAX_VALUE).height + 1 : 1); - Insets insets = border != null ? border.getBorderInsets(this) : JBUI.emptyInsets(); - dim.height += insets.top + insets.bottom; + JBInsets.addTo(dim, getInsets()); return dim; } @@ -603,7 +600,7 @@ public class BreadcrumbsComponent extends JComponent } abstract static class PainterSettings { - private static final Color DEFAULT_FOREGROUND_COLOR = new JBColor(Gray._50, UIUtil.getListForeground()); + private static final Color DEFAULT_FOREGROUND_COLOR = new JBColor(Gray._50, Gray.xBB); @Nullable Color getBackgroundColor(@NotNull final Crumb c) { @@ -632,7 +629,7 @@ public class BreadcrumbsComponent extends JComponent private static final Color CURRENT_BG_COLOR = new JBColor(new Color(250, 250, 220), new Color(97, 97, 75)); private static final Color HOVERED_BG_COLOR = new JBColor(Gray._220, ColorUtil.shift(DEFAULT_BG_COLOR, 1.2)); - private static final Color LIGHT_TEXT_COLOR = new JBColor(Gray._170, UIUtil.getListForeground()); + private static final Color LIGHT_TEXT_COLOR = new JBColor(Gray._170, Gray.xBB); private static final Color DEFAULT_BORDER_COLOR = new JBColor(Gray._170, Gray._50); private static final Color LIGHT_BORDER_COLOR = new JBColor(Gray._200, Gray._70); @@ -717,18 +714,8 @@ public class BreadcrumbsComponent extends JComponent final Font oldFont = g2.getFont(); final int offset = c.getOffset() - pageOffset; - final Color bg = s.getBackgroundColor(c); final int width = c.getWidth(); - if (bg != null) { - g2.setColor(bg); - g2.fillRoundRect(offset + 2, 2, width - 4, height - 3, ROUND_VALUE, ROUND_VALUE); - } - - final Color borderColor = s.getBorderColor(c); - if (borderColor != null) { - g2.setColor(borderColor); - g2.drawRoundRect(offset + 2, 2, width - 4, height - 3, ROUND_VALUE, ROUND_VALUE); - } + RectanglePainter.paint(g2, offset + 2, 2, width - 4, height - 4, ROUND_VALUE + 2, s.getBackgroundColor(c), s.getBorderColor(c)); final Color textColor = s.getForegroundColor(c); if (textColor != null) {