From f482ffd5fd9c357e92894f3a82065c143996ff9f Mon Sep 17 00:00:00 2001 From: liuk Date: Sat, 8 Feb 2025 16:55:23 +0800 Subject: [PATCH] refactor: Replace EmptyBorder with DPI-aware borders - Replaced all instances of EmptyBorder with JBUI.Borders for better DPI awareness. - Removed redundant calls to conversion methods and simplified color assignments. - Fixed unclear button text in light themes --- .../editor/InlineEditAction.kt | 37 +++++++++---------- .../editor/VerticalDiffBlock.kt | 20 +++++----- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index 9f314ede6..de65aa92c 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -29,7 +29,6 @@ import java.awt.geom.AffineTransform import java.awt.geom.Path2D import java.awt.geom.RoundRectangle2D import javax.swing.* -import javax.swing.border.EmptyBorder import javax.swing.event.DocumentEvent import javax.swing.event.DocumentListener import javax.swing.event.ListDataListener @@ -73,8 +72,8 @@ fun makePanel( onReject: () -> Unit ): JPanel { val topPanel = - ShadowPanel(MigLayout("wrap 1, insets 2 ${leftInset} 2 2, gap 0!")).apply { - background = JBColor(0x20888888.toInt(), 0x20888888.toInt()) + ShadowPanel(MigLayout("wrap 1, insets 2 $leftInset 2 2, gap 0!")).apply { + background = JBColor(0x20888888, 0x20888888) isOpaque = false } @@ -374,7 +373,7 @@ class CustomPanel( val closeIcon = IconLoader.getIcon("/icons/close.svg", javaClass) return JLabel(closeIcon).apply { background = Color(0, 0, 0, 0) - border = EmptyBorder(2, 6, 2, 0) + border = JBUI.Borders.empty(2, 6, 2, 0) toolTipText = "`esc` to cancel" isOpaque = false addMouseListener( @@ -406,7 +405,7 @@ class CustomPanel( background = defaultBackground foreground = Color(128, 128, 128, 200) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 12) - border = EmptyBorder(8, 8, 8, 8) + border = JBUI.Borders.empty(8) isOpaque = false isEditable = false cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) @@ -423,7 +422,7 @@ class CustomPanel( val component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) if (component is JLabel) { - component.border = EmptyBorder(4, 6, 4, 6) + component.border = JBUI.Borders.empty(4, 6) } return component } @@ -451,9 +450,9 @@ class CustomPanel( val rightButton = CustomButton("⏎ Enter") { onEnter() } .apply { - background = JBColor(0x999998.toInt(), 0x999998.toInt()) - foreground = JBColor(0xF5F5F5.toInt(), 0xF5F5F5.toInt()) - border = EmptyBorder(2, 6, 2, 6) + background = JBColor(0x999998, 0x999998) + foreground = JBColor(0xF5F5F5, 0xF5F5F5) + border = JBUI.Borders.empty(2, 6) } val rightPanel = JPanel(MigLayout("insets 0, fillx")).apply { @@ -461,7 +460,7 @@ class CustomPanel( add(rightButton, "align right") } - border = EmptyBorder(0, 0, 16, 12) + border = JBUI.Borders.empty(0, 0, 16, 12) isOpaque = false add(dropdown, "align left") @@ -477,7 +476,7 @@ class CustomPanel( val progressBar = JProgressBar().apply { isIndeterminate = true } add(progressBar, BorderLayout.CENTER) - border = BorderFactory.createEmptyBorder(0, 0, 16, 12) + border = JBUI.Borders.empty(0, 0, 16, 12) } private val subPanelC: JPanel = @@ -486,21 +485,19 @@ class CustomPanel( JLabel("Type to re-prompt").apply { foreground = Color(156, 163, 175) // text-gray-400 font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 11) - border = EmptyBorder(0, 4, 0, 0) + border = JBUI.Borders.emptyLeft(4) } val leftButton = CustomButton("Reject All (${getMetaKeyLabel()}${getShiftKeyLabel()}⌫)") { onReject() } .apply { - background = JBColor(0x30FF0000.toInt(), 0x30FF0000.toInt()) - foreground = JBColor(0xF5F5F5.toInt(), 0xF5F5F5.toInt()) + background = JBColor(0x30FF0000, 0x30FF0000) } val rightButton = CustomButton("Accept All (${getMetaKeyLabel()}${getShiftKeyLabel()}⏎)") { onAccept() } .apply { - background = JBColor(0x3000FF00.toInt(), 0x3000FF00.toInt()) - foreground = JBColor(0xF5F5F5.toInt(), 0xF5F5F5.toInt()) + background = JBColor(0x3000FF00, 0x3000FF00) } val rightPanel = @@ -508,12 +505,12 @@ class CustomPanel( isOpaque = false add(leftButton, "align right") add(rightButton, "align right") - border = EmptyBorder(0, 0, 0, 0) + border = JBUI.Borders.empty() } add(leftLabel, "align left") add(rightPanel, "align right") - border = BorderFactory.createEmptyBorder(0, 0, 16, 12) + border = JBUI.Borders.empty(0, 0, 16, 12) isOpaque = false } @@ -625,7 +622,7 @@ class CustomButton(text: String, onClick: () -> Unit) : JLabel(text, CENTER) { }) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 11) - border = EmptyBorder(2, 6, 2, 6) + border = JBUI.Borders.empty(2, 6) } override fun paintComponent(g: Graphics) { @@ -694,7 +691,7 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { } override fun getInsets(): Insets { - return JBUI.insets(0, 6, 0, 0) + return JBUI.insetsLeft(6) } override fun installUI(c: JComponent?) { diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt index 6f311c29b..e121e5687 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/VerticalDiffBlock.kt @@ -13,8 +13,8 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.TextRange import com.intellij.ui.JBColor import com.intellij.util.application +import com.intellij.util.ui.JBUI import java.awt.* -import javax.swing.BorderFactory import javax.swing.JButton import javax.swing.JTextArea import kotlin.math.min @@ -25,8 +25,8 @@ class VerticalDiffBlock( var startLine: Int, private val onAcceptReject: (VerticalDiffBlock, Boolean) -> Unit ) { - val deletedLines: MutableList = mutableListOf(); - val addedLines: MutableList = mutableListOf(); + val deletedLines: MutableList = mutableListOf() + val addedLines: MutableList = mutableListOf() private val acceptButton: JButton private val rejectButton: JButton private var deletionInlay: Disposable? = null @@ -155,10 +155,10 @@ class VerticalDiffBlock( val rejectBtn = createButton( "${getAltKeyLabel()}${getShiftKeyLabel()}N", - JBColor(0x99FF0000.toInt(), 0x99FF0000.toInt()) + JBColor(0x77FF0000, 0x77FF0000) ).apply { addActionListener { - handleReject(); + handleReject() onAcceptReject(this@VerticalDiffBlock, false) } @@ -168,10 +168,10 @@ class VerticalDiffBlock( createButton( "${getAltKeyLabel()}${ getShiftKeyLabel() - }Y", JBColor(0x7700BB00.toInt(), 0x7700BB00.toInt()) + }Y", JBColor(0x7700BB00, 0x7700BB00) ).apply { addActionListener { - handleAccept(); + handleAccept() onAcceptReject(this@VerticalDiffBlock, true) } } @@ -215,9 +215,9 @@ class VerticalDiffBlock( private fun createDeletionTextArea(text: String) = JTextArea(text).apply { isEditable = false - background = JBColor(0x30FF0000.toInt(), 0x30FF0000.toInt()) + background = JBColor(0x30FF0000, 0x30FF0000) foreground = JBColor.GRAY - border = BorderFactory.createEmptyBorder() + border = JBUI.Borders.empty() lineWrap = false wrapStyleWord = false font = editor.colorsScheme.getFont(EditorFontType.PLAIN) @@ -250,7 +250,7 @@ class VerticalDiffBlock( font = Font("Arial", Font.BOLD, 9) isContentAreaFilled = false isOpaque = false - border = BorderFactory.createEmptyBorder(4, 2, 4, 2) + border = JBUI.Borders.empty(4, 2) preferredSize = Dimension(preferredSize.width - 30, 14) cursor = Cursor(Cursor.HAND_CURSOR) }