Fixed focus border for borderless ComboBox

GitOrigin-RevId: a3651f57c285c98dd4065abcbbf7c9643719a4f1
This commit is contained in:
Pavel Porvatov
2024-03-25 11:31:47 +00:00
committed by intellij-monorepo-bot
parent ab4dce1226
commit 73d53ffcde
4 changed files with 57 additions and 4 deletions
@@ -11,7 +11,8 @@ import kotlin.math.max
/**
* Paints rounded border for focusable component. Non focused border rect is inside [rect], focused/outlined border can come outside
*/
internal fun paintComponentBorder(g: Graphics, rect: Rectangle, outline: DarculaUIUtil.Outline?, focused: Boolean, enabled: Boolean) {
internal fun paintComponentBorder(g: Graphics, rect: Rectangle, outline: DarculaUIUtil.Outline?, focused: Boolean, enabled: Boolean,
bw: Int = DarculaUIUtil.BW.get()) {
val g2 = g.create() as Graphics2D
try {
@@ -20,7 +21,6 @@ internal fun paintComponentBorder(g: Graphics, rect: Rectangle, outline: Darcula
if (MacUIUtil.USE_QUARTZ) RenderingHints.VALUE_STROKE_PURE else RenderingHints.VALUE_STROKE_NORMALIZE)
val lw = DarculaUIUtil.LW.get()
val bw = DarculaUIUtil.BW.get()
val arc = DarculaUIUtil.COMPONENT_ARC.get()
when {
@@ -91,6 +91,9 @@ open class DarculaComboBoxBorder : Border, ErrorBorderCapable, UIResource {
Type.TABLE_CELL_EDITOR, Type.EMBEDDED -> {
DarculaUIUtil.paintCellEditorBorder(g2, comboBox, r, focused)
}
Type.BORDERLESS -> {
paintBorderlessBorder(g2, comboBox, r, focused)
}
else -> {
paintNormalBorder(g2, comboBox, r, focused)
}
@@ -106,6 +109,11 @@ open class DarculaComboBoxBorder : Border, ErrorBorderCapable, UIResource {
paintComponentBorder(g, r, DarculaUIUtil.getOutline(comboBox), focused, comboBox.isEnabled)
}
protected fun paintBorderlessBorder(g: Graphics2D, comboBox: JComboBox<*>, r: Rectangle, focused: Boolean) {
JBInsets.removeFrom(r, getBorderInsets(comboBox))
paintComponentBorder(g, r, DarculaUIUtil.getOutline(comboBox), focused, comboBox.isEnabled, bw = DarculaUIUtil.LW.get())
}
/**
* Returns DarculaComboBoxUI if it should be used as border instead of [DarculaComboBoxBorder] itself.
* See [DarculaComboBoxUI.isNewBorderSupported] for details
@@ -317,14 +317,14 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border, ErrorB
}
Graphics2D g2 = (Graphics2D)g.create();
Rectangle r = new Rectangle(c.getSize());
JBInsets.removeFrom(r, myBorderCompensation);
if (comboBox.getBorder() instanceof DarculaComboBoxBorder comboBoxBorder && isNewBorderSupported(comboBox)) {
comboBoxBorder.paintComboBoxBackground(g2, comboBox, getBackgroundColor());
}
else {
try {
Rectangle r = new Rectangle(c.getSize());
JBInsets.removeFrom(r, myBorderCompensation);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
g2.translate(r.x, r.y);
@@ -47,6 +47,51 @@ internal class JComboBoxPanel : UISandboxPanel {
}
}
group("IS_EMBEDDED_PROPERTY") {
withStateLabel {
comboBox(items).applyToComponent {
putClientProperty(ComboBox.IS_EMBEDDED_PROPERTY, true)
}
}
withStateLabel {
comboBox(items)
.enabled(false)
.applyToComponent {
putClientProperty(ComboBox.IS_EMBEDDED_PROPERTY, true)
}
}
}
group("IS_BORDERLESS_PROPERTY") {
withStateLabel {
comboBox(items).applyToComponent {
putClientProperty(ComboBox.IS_BORDERLESS_PROPERTY, true)
}
}
withStateLabel {
comboBox(items)
.enabled(false)
.applyToComponent {
putClientProperty(ComboBox.IS_BORDERLESS_PROPERTY, true)
}
}
}
group("IS_TABLE_CELL_EDITOR_PROPERTY") {
withStateLabel {
comboBox(items).applyToComponent {
putClientProperty(ComboBox.IS_TABLE_CELL_EDITOR_PROPERTY, true)
}
}
withStateLabel {
comboBox(items)
.enabled(false)
.applyToComponent {
putClientProperty(ComboBox.IS_TABLE_CELL_EDITOR_PROPERTY, true)
}
}
}
group("Validation") {
withStateLabel("Error") {
comboBox(items).validationOnInput {