diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/ReviewUIUtil.kt b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/ReviewUIUtil.kt new file mode 100644 index 000000000000..c08dcd40c645 --- /dev/null +++ b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/ReviewUIUtil.kt @@ -0,0 +1,36 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.collaboration.ui.codereview.comment + +import com.intellij.collaboration.ui.CollaborationToolsUIUtil +import com.intellij.openapi.editor.colors.EditorColors +import com.intellij.openapi.editor.colors.EditorColorsManager +import com.intellij.ui.IdeBorderFactory +import com.intellij.ui.JBColor +import java.awt.BorderLayout +import java.awt.event.ComponentAdapter +import java.awt.event.ComponentEvent +import javax.swing.JComponent +import javax.swing.JPanel + +object ReviewUIUtil { + + private const val EDITOR_INLAY_PANEL_ARC = 10 + + fun createEditorInlayPanel(component: JComponent): JPanel { + val roundedLineBorder = IdeBorderFactory.createRoundedBorder(EDITOR_INLAY_PANEL_ARC) + return RoundedPanel(BorderLayout(), EDITOR_INLAY_PANEL_ARC - 2).apply { + border = roundedLineBorder + add(component) + }.also { + CollaborationToolsUIUtil.overrideUIDependentProperty(it) { + val scheme = EditorColorsManager.getInstance().globalScheme + background = scheme.defaultBackground + roundedLineBorder.setColor(scheme.getColor(EditorColors.TEARLINE_COLOR) ?: JBColor.border()) + } + component.addComponentListener(object : ComponentAdapter() { + override fun componentResized(e: ComponentEvent?) = + it.dispatchEvent(ComponentEvent(component, ComponentEvent.COMPONENT_RESIZED)) + }) + } + } +} \ No newline at end of file diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/RoundedPanel.kt b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/RoundedPanel.kt index f3c8fa2f970f..d2ebb4d3e15a 100644 --- a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/RoundedPanel.kt +++ b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/RoundedPanel.kt @@ -1,62 +1,52 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.collaboration.ui.codereview.comment -import com.intellij.openapi.editor.colors.EditorColors -import com.intellij.openapi.editor.colors.EditorColorsManager +import com.intellij.ui.IdeBorderFactory import com.intellij.util.ui.GraphicsUtil import com.intellij.util.ui.JBInsets +import org.jetbrains.annotations.ApiStatus import java.awt.* -import java.awt.event.ComponentAdapter -import java.awt.event.ComponentEvent import java.awt.geom.RoundRectangle2D -import javax.swing.JComponent import javax.swing.JPanel +import kotlin.properties.Delegates.observable -fun wrapComponentUsingRoundedPanel(component: JComponent): JComponent { - val wrapper = RoundedPanel(BorderLayout()) - wrapper.add(component) - component.addComponentListener(object : ComponentAdapter() { - override fun componentResized(e: ComponentEvent?) = - wrapper.dispatchEvent(ComponentEvent(component, ComponentEvent.COMPONENT_RESIZED)) - }) - return wrapper -} - -private class RoundedPanel(layout: LayoutManager?) : JPanel(layout) { - private var borderLineColor: Color? = null +@ApiStatus.Internal +class RoundedPanel(layout: LayoutManager?, private val arc: Int = 8) : JPanel(layout) { init { - isOpaque = false cursor = Cursor.getDefaultCursor() - updateColors() + border = IdeBorderFactory.createRoundedBorder(arc + 2) } - override fun updateUI() { - super.updateUI() - updateColors() - } - - private fun updateColors() { - val scheme = EditorColorsManager.getInstance().globalScheme - background = scheme.defaultBackground - borderLineColor = scheme.getColor(EditorColors.TEARLINE_COLOR) + override fun paintChildren(g: Graphics) { + val g2 = g.create() as Graphics2D + try { + g2.clip(getShape()) + super.paintChildren(g2) + } + finally { + g2.dispose() + } } override fun paintComponent(g: Graphics) { - GraphicsUtil.setupRoundedBorderAntialiasing(g) + val g2 = g.create() as Graphics2D + try { + GraphicsUtil.setupRoundedBorderAntialiasing(g2) + g2.clip(getShape()) + super.paintComponent(g2) + } + finally { + g2.dispose() + } + } - val g2 = g as Graphics2D + private fun getShape(): Shape { val rect = Rectangle(size) JBInsets.removeFrom(rect, insets) // 2.25 scale is a @#$!% so we adjust sizes manually - val rectangle2d = RoundRectangle2D.Float(rect.x.toFloat() + 0.5f, rect.y.toFloat() + 0.5f, - rect.width.toFloat() - 1f, rect.height.toFloat() - 1f, - 10f, 10f) - g2.color = background - g2.fill(rectangle2d) - borderLineColor?.let { - g2.color = borderLineColor - g2.draw(rectangle2d) - } + return RoundRectangle2D.Float(rect.x.toFloat() - 0.5f, rect.y.toFloat() - 0.5f, + rect.width.toFloat() + 0.5f, rect.height.toFloat() + 0.5f, + arc.toFloat(), arc.toFloat()) } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRDiffEditorReviewComponentsFactoryImpl.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRDiffEditorReviewComponentsFactoryImpl.kt index 8de707d6d4e4..66c22c31282a 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRDiffEditorReviewComponentsFactoryImpl.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/comment/ui/GHPRDiffEditorReviewComponentsFactoryImpl.kt @@ -2,7 +2,8 @@ package org.jetbrains.plugins.github.pullrequest.comment.ui import com.intellij.collaboration.async.CompletableFutureUtil.successOnEdt -import com.intellij.collaboration.ui.codereview.comment.wrapComponentUsingRoundedPanel +import com.intellij.collaboration.ui.codereview.comment.ReviewUIUtil +import com.intellij.collaboration.ui.codereview.comment.RoundedPanel import com.intellij.diff.util.Side import com.intellij.openapi.progress.EmptyProgressIndicator import com.intellij.openapi.project.Project @@ -29,7 +30,7 @@ internal constructor(private val project: Project, override fun createThreadComponent(thread: GHPRReviewThreadModel): JComponent = GHPRReviewThreadComponent.create(project, thread, reviewDataProvider, avatarIconsProvider, currentUser).apply { border = JBUI.Borders.empty(8, 8) - }.let(::wrapComponentUsingRoundedPanel) + }.let { ReviewUIUtil.createEditorInlayPanel(it) } override fun createSingleCommentComponent(side: Side, line: Int, startLine: Int, hideCallback: () -> Unit): JComponent { val textFieldModel = GHCommentTextFieldModel(project) { @@ -104,5 +105,5 @@ internal constructor(private val project: Project, hideCallback() }.apply { border = JBUI.Borders.empty(8) - }.let(::wrapComponentUsingRoundedPanel) + }.let { ReviewUIUtil.createEditorInlayPanel(it) } } \ No newline at end of file