From c161c346778ec7f98bdadf3bc44e876edce5bb77 Mon Sep 17 00:00:00 2001 From: Dmitry Krasilschikov Date: Fri, 6 Sep 2024 10:55:22 +0300 Subject: [PATCH] LLM-3705 Refactor RoundedLineBorder implementation Moved RoundedLineBorder to a new file and renamed it to RoundedLineBorderWithBackground. Let's use this rounded border for In-Editor generation popup GitOrigin-RevId: b4365f7cefe24eca1e77d83c1f329e069788b226 --- .../RoundedLineBorderWithBackground.kt | 38 +++++++++++++++++++ .../builder/components/ValidationTooltip.kt | 37 +----------------- 2 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ui/dsl/builder/components/RoundedLineBorderWithBackground.kt diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/RoundedLineBorderWithBackground.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/RoundedLineBorderWithBackground.kt new file mode 100644 index 000000000000..1a8100fa7147 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/RoundedLineBorderWithBackground.kt @@ -0,0 +1,38 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.ui.dsl.builder.components + +import com.intellij.util.ui.JBUI +import java.awt.* +import javax.swing.border.LineBorder + +class RoundedLineBorderWithBackground( + color: Color, + private val bgColor: Color, + private val arcSize: Int = JBUI.scale(10), + thickness: Int = JBUI.scale(1), +) : LineBorder(color, thickness) { + + override fun paintBorder(c: Component, g: Graphics, x: Int, y: Int, width: Int, height: Int) { + val g2 = g as Graphics2D + + val oldAntialiasing = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) + val oldColor = g2.color + + g2.color = bgColor + g2.fillRoundRect(x + thickness - 1, y + thickness - 1, + width - thickness - thickness + 1, + height - thickness - thickness + 1, + arcSize, arcSize) + + g2.color = lineColor + for (i in 0 until thickness) { + g2.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i - 1, arcSize, arcSize) + } + + g2.color = oldColor + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAntialiasing) + } + + override fun getBorderInsets(c: Component, insets: Insets) = JBUI.emptyInsets() +} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/ValidationTooltip.kt b/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/ValidationTooltip.kt index 727d5cc6e368..6e4fcbb8261f 100644 --- a/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/ValidationTooltip.kt +++ b/platform/platform-impl/src/com/intellij/ui/dsl/builder/components/ValidationTooltip.kt @@ -12,50 +12,15 @@ import com.intellij.ui.dsl.builder.Cell import com.intellij.ui.dsl.builder.Row import com.intellij.ui.dsl.builder.bindText import com.intellij.ui.dsl.gridLayout.UnscaledGaps -import com.intellij.util.ui.JBUI import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.Nls -import java.awt.* import javax.swing.JPanel -import javax.swing.border.LineBorder @ApiStatus.Experimental enum class ValidationType { ERROR, WARNING } -private class RoundedLineBorder(color: Color, - private val bgColor: Color, - private val arcSize: Int = JBUI.scale(10), - thickness: Int = JBUI.scale(1)) : LineBorder(color, thickness) { - - override fun paintBorder(c: Component, g: Graphics, x: Int, y: Int, width: Int, height: Int) { - val g2 = g as Graphics2D - - val oldAntialiasing = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) - val oldColor = g2.color - - g2.color = bgColor - g2.fillRoundRect(x + thickness - 1, y + thickness - 1, - width - thickness - thickness + 1, - height - thickness - thickness + 1, - arcSize, arcSize) - - g2.color = lineColor - for (i in 0 until thickness) { - g2.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i - 1, arcSize, arcSize) - } - - g2.color = oldColor - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAntialiasing) - } - - override fun getBorderInsets(c: Component, insets: Insets): Insets { - return Insets(0, 0, 0, 0) - } -} - fun Row.validationTooltip(@Nls message: String, firstActionLink: ActionLink? = null, secondActionLink: ActionLink? = null, @@ -141,5 +106,5 @@ fun Row.validationTooltip( } }) .customize(UnscaledGaps(top = 4, bottom = 4)) - .applyToComponent { border = RoundedLineBorder(borderColor, backgroundColor) } + .applyToComponent { border = RoundedLineBorderWithBackground(borderColor, backgroundColor) } } \ No newline at end of file