diff --git a/platform/lang-impl/src/com/intellij/ui/tabs/FileColorsConfigurable.kt b/platform/lang-impl/src/com/intellij/ui/tabs/FileColorsConfigurable.kt index 7f2c6fb2330c..a5db1eaa77ac 100644 --- a/platform/lang-impl/src/com/intellij/ui/tabs/FileColorsConfigurable.kt +++ b/platform/lang-impl/src/com/intellij/ui/tabs/FileColorsConfigurable.kt @@ -39,7 +39,8 @@ import com.intellij.ui.table.JBTable import com.intellij.util.ui.EditableModel import com.intellij.util.ui.JBInsets import com.intellij.util.ui.JBUI.Borders -import com.intellij.util.ui.PaintIcon +import com.intellij.util.ui.RegionPaintIcon +import com.intellij.util.ui.RegionPainter import org.jetbrains.annotations.Nls import java.awt.* import javax.swing.* @@ -395,10 +396,19 @@ private class FileColorsTableModel(val manager: FileColorManagerImpl) : Abstract // renderers +private class ColorPainter(val color: Color) : RegionPainter { + fun asIcon(): Icon = RegionPaintIcon(36, 12, this).withIconPreScaled(false) + + override fun paint(g: Graphics2D, x: Int, y: Int, width: Int, height: Int, c: Component?) { + g.color = color + g.fillRect(x, y, width, height) + } +} + private fun updateColorRenderer(renderer: JLabel, selected: Boolean, background: Color?): JLabel { if (!selected) renderer.background = background renderer.horizontalTextPosition = SwingConstants.LEFT - renderer.icon = background?.let { if (selected) PaintIcon(36, 12, it).withIconPreScaled(false) else null } + renderer.icon = background?.let { if (selected) ColorPainter(it).asIcon() else null } return renderer } diff --git a/platform/util/ui/src/com/intellij/util/ui/PaintIcon.kt b/platform/util/ui/src/com/intellij/util/ui/PaintIcon.kt deleted file mode 100644 index ff225298c5cb..000000000000 --- a/platform/util/ui/src/com/intellij/util/ui/PaintIcon.kt +++ /dev/null @@ -1,43 +0,0 @@ -// 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.util.ui - -import java.awt.Component -import java.awt.Graphics -import java.awt.Graphics2D -import java.awt.Paint -import javax.swing.border.Border -import kotlin.math.ceil - -open class PaintIcon(private val width: Int, private val height: Int, private val painter: RegionPainter) - : JBCachingScalableIcon() { - - constructor(size: Int, painter: RegionPainter) : this(size, size, painter) - constructor(size: Int, paint: Paint) : this(size, size, paint) - constructor(width: Int, height: Int, paint: Paint) : this(width, height, Painter(paint)) - constructor(icon: PaintIcon) : this(icon.width, icon.height, icon.painter) { - isIconPreScaled = icon.isIconPreScaled - border = icon.border - } - - var border: Border? = null - - override fun copy() = PaintIcon(this) - - override fun equals(other: Any?) = other === this - override fun hashCode() = System.identityHashCode(this) - - override fun getIconWidth() = ceil(scaleVal(width.toDouble())).toInt() - override fun getIconHeight() = ceil(scaleVal(height.toDouble())).toInt() - override fun paintIcon(component: Component, g: Graphics, x: Int, y: Int) { - (g as? Graphics2D)?.let { painter.paint(it, x, y, iconWidth, iconHeight, component) } - border?.paintBorder(component, g, x, y, iconWidth, iconHeight) - } -} - - -private class Painter(private val paint: Paint) : RegionPainter { - override fun paint(g: Graphics2D, x: Int, y: Int, width: Int, height: Int, component: Component?) { - g.paint = paint - g.fillRect(x, y, width, height) - } -} diff --git a/platform/util/ui/src/com/intellij/util/ui/RegionIcon.kt b/platform/util/ui/src/com/intellij/util/ui/RegionPaintIcon.kt similarity index 69% rename from platform/util/ui/src/com/intellij/util/ui/RegionIcon.kt rename to platform/util/ui/src/com/intellij/util/ui/RegionPaintIcon.kt index a041295e36ab..eb9ebaa59610 100644 --- a/platform/util/ui/src/com/intellij/util/ui/RegionIcon.kt +++ b/platform/util/ui/src/com/intellij/util/ui/RegionPaintIcon.kt @@ -1,22 +1,23 @@ // 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.util.ui +import com.intellij.ui.scale.DerivedScaleType.PIX_SCALE import java.awt.Component import java.awt.Graphics import java.awt.Graphics2D import java.util.Objects import kotlin.math.ceil -class RegionIcon( +class RegionPaintIcon( private val width: Int, private val height: Int, private val painter: RegionPainter -) : JBCachingScalableIcon() { +) : JBCachingScalableIcon() { constructor(size: Int, painter: RegionPainter) : this(size, size, painter) - override fun copy(): RegionIcon { - val icon = RegionIcon(width, height, painter) + override fun copy(): RegionPaintIcon { + val icon = RegionPaintIcon(width, height, painter) icon.updateContextFrom(this) return icon } @@ -39,13 +40,19 @@ class RegionIcon( override fun getIconHeight() = ceil(scaleVal(height.toDouble())).toInt() + private fun getPixWidth() = scaleVal(width.toDouble(), PIX_SCALE) + + private fun getPixHeight() = scaleVal(height.toDouble(), PIX_SCALE) + override fun toString() = painter.toString() override fun hashCode(): Int = Objects.hash(width, height, painter) override fun equals(other: Any?): Boolean { if (other === this) return true - val icon = other as? RegionIcon ?: return false - return icon.width == width && icon.height == height && icon.painter == painter + val icon = other as? RegionPaintIcon ?: return false + return icon.getPixWidth() == getPixWidth() && + icon.getPixHeight() == getPixHeight() && + icon.painter == painter } }