Skip to content

Commit

Permalink
fix CPU issue
Browse files Browse the repository at this point in the history
  • Loading branch information
adam varsano committed Apr 11, 2024
1 parent 7b02844 commit 82f8e3b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
47 changes: 23 additions & 24 deletions src/main/kotlin/com/bridgecrew/ui/buttons/SeverityFilterButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,47 @@ import com.bridgecrew.ui.actions.SeverityFilterActions
import com.bridgecrew.utils.isDarkMode
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.util.ui.UIUtil
import java.awt.*
import javax.swing.JButton
import javax.swing.JComponent
import javax.swing.plaf.basic.BasicButtonUI

class SeverityFilterButton(val project: Project, text: String, val severity: Severity): JButton(text) {
class SeverityFilterButton(val project: Project, text: String, val severity: Severity, isActive: Boolean): JButton(text) {
private var isActive = false

init {
addActionListener(SeverityFilterActions(project))
this.isActive = isActive
preferredSize = Dimension(22, 22)
border = null
isOpaque = true
val boldFont = Font(font.fontName, Font.BOLD, font.size)
font = boldFont

updateButtonAppearance()
// Add an ActionListener to change the text when the button is toggled
addActionListener {
updateButtonAppearance()
}
addActionListener(SeverityFilterActions(project))

isEnabled = shouldBeEnabled(severity, project)

ui = object: BasicButtonUI() {
override fun paint(g: Graphics?, c: JComponent?) {
val g2d = g?.create() as Graphics2D
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
g2d.color = getFilterColor()
c?.height?.let { g2d.fillRect(0,0, c.width, it) }
val boldFont = Font(font.fontName, Font.BOLD, font.size)
font = boldFont
super.paint(g, c)
g2d.dispose()
if (c is SeverityFilterButton) {
super.paint(g, c)
}
}
}

isEnabled = shouldBeEnabled(severity, project)
}

private fun getFilterColor(): Color {
var bgColor: Color = UIUtil.getEditorPaneBackground()
if(shouldBeEnabled(severity, project) && isClicked()) {
private fun updateButtonAppearance() {
background = if (isActive) {
val color = if(isDarkMode()) Color.decode("#5C6164") else Color.decode("#CFCFCF")
bgColor = Color(color.red, color.green, color.blue, 102)
Color(color.red, color.green, color.blue, 102)
} else {
null
}
return bgColor
}

private fun isClicked(): Boolean {
return SeverityFilterActions.severityFilterState[text] == true
}

private fun shouldBeEnabled(severity: Severity, project: Project): Boolean {
Expand All @@ -60,12 +61,10 @@ class SeverityFilterButton(val project: Project, text: String, val severity: Sev
return false
}


if (!SeverityFilterActions.enabledSeverities.contains(severity)) {
return false
}

return true
}

}
20 changes: 11 additions & 9 deletions src/main/kotlin/com/bridgecrew/ui/topPanel/CheckovTopPanel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bridgecrew.ui.topPanel

import com.bridgecrew.results.Severity
import com.bridgecrew.ui.actions.SeverityFilterActions
import com.bridgecrew.ui.buttons.SeverityFilterButton
import com.bridgecrew.utils.*
import com.intellij.openapi.Disposable
Expand Down Expand Up @@ -50,16 +51,17 @@ class CheckovTopPanel(val project: Project) : SimpleToolWindowPanel(true, true),
actionToolbarPanel.add(Box.createRigidArea(Dimension(5, 20)))
}

private fun addFilterActions(actionToolbarPanel: JPanel) {
actionToolbarPanel.add(SeverityFilterButton(project, "I", Severity.INFO))
actionToolbarPanel.add(Box.createRigidArea(Dimension(3, 0)))
actionToolbarPanel.add(SeverityFilterButton(project,"L", Severity.LOW))
actionToolbarPanel.add(Box.createRigidArea(Dimension(3, 0)))
actionToolbarPanel.add(SeverityFilterButton(project,"M", Severity.MEDIUM))
actionToolbarPanel.add(Box.createRigidArea(Dimension(3, 0)))
actionToolbarPanel.add(SeverityFilterButton(project,"H", Severity.HIGH))
private fun createSeverityFilterButton(actionToolbarPanel: JPanel, text: String, severity: Severity) {
actionToolbarPanel.add(SeverityFilterButton(project, text, severity, SeverityFilterActions.severityFilterState[text] == true))
actionToolbarPanel.add(Box.createRigidArea(Dimension(3, 0)))
actionToolbarPanel.add(SeverityFilterButton(project,"C", Severity.CRITICAL))
}

private fun addFilterActions(actionToolbarPanel: JPanel) {
createSeverityFilterButton(actionToolbarPanel, "I", Severity.INFO)
createSeverityFilterButton(actionToolbarPanel, "L", Severity.LOW)
createSeverityFilterButton(actionToolbarPanel, "M", Severity.MEDIUM)
createSeverityFilterButton(actionToolbarPanel, "H", Severity.HIGH)
createSeverityFilterButton(actionToolbarPanel, "C", Severity.CRITICAL)
}

override fun dispose() = Unit
Expand Down

0 comments on commit 82f8e3b

Please sign in to comment.