1
0
mirror of https://github.com/chylex/IntelliJ-Inspection-Lens.git synced 2025-04-23 03:15:46 +02:00

Refactor use of TextAttributes for inspection severities

This commit is contained in:
chylex 2023-05-20 10:26:21 +02:00
parent eb2faa2518
commit 44f2fa5c16
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
3 changed files with 21 additions and 6 deletions
src/main/kotlin/com/chylex/intellij/inspectionlens/editor

View File

@ -6,7 +6,6 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.util.text.StringUtil
import java.awt.Font
import java.awt.Graphics
import java.awt.Rectangle
@ -31,7 +30,7 @@ class LensRenderer(info: HighlightInfo) : HintRenderer(null) {
}
override fun getTextAttributes(editor: Editor): TextAttributes {
return ATTRIBUTES_SINGLETON.also { it.foregroundColor = severity.color }
return severity.colorAttributes
}
override fun useEditorFont(): Boolean {
@ -39,8 +38,6 @@ class LensRenderer(info: HighlightInfo) : HintRenderer(null) {
}
private companion object {
private val ATTRIBUTES_SINGLETON = TextAttributes(null, null, null, null, Font.ITALIC)
private fun getValidDescriptionText(text: String?): String {
return if (text.isNullOrBlank()) " " else addMissingPeriod(convertHtmlToText(text))
}

View File

@ -4,6 +4,7 @@ import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.ui.ColorUtil
import com.intellij.ui.JBColor
import java.awt.Color
import java.awt.Font
/**
* Determines properties of inspection lenses based on severity.
@ -16,12 +17,14 @@ enum class LensSeverity(baseColor: Color, lightThemeDarkening: Int, darkThemeBri
SERVER_PROBLEM (Color(176, 97, 0), lightThemeDarkening = 4, darkThemeBrightening = 2),
OTHER (Color(128, 128, 128), lightThemeDarkening = 1, darkThemeBrightening = 2);
val color: JBColor
val colorAttributes: LensSeverityTextAttributes
init {
val lightThemeColor = ColorUtil.saturate(ColorUtil.darker(baseColor, lightThemeDarkening), 1)
val darkThemeColor = ColorUtil.desaturate(ColorUtil.brighter(baseColor, darkThemeBrightening), 2)
color = JBColor(lightThemeColor, darkThemeColor)
val textColor = JBColor(lightThemeColor, darkThemeColor)
colorAttributes = LensSeverityTextAttributes(foregroundColor = textColor, fontStyle = Font.ITALIC)
}
companion object {

View File

@ -0,0 +1,15 @@
package com.chylex.intellij.inspectionlens.editor
import com.intellij.openapi.editor.markup.UnmodifiableTextAttributes
import com.intellij.ui.JBColor
import java.awt.Font
class LensSeverityTextAttributes(private val foregroundColor: JBColor, private val fontStyle: Int = Font.PLAIN) : UnmodifiableTextAttributes() {
override fun getForegroundColor(): JBColor {
return foregroundColor
}
override fun getFontType(): Int {
return fontStyle
}
}