Skip to content

Commit

Permalink
fix ui glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX committed Feb 20, 2024
1 parent f155c56 commit 6c52afb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import com.cycode.plugin.components.toolWindow.components.treeView.nodes.*
import com.cycode.plugin.icons.PluginIcons
import com.cycode.plugin.services.scanResults
import com.intellij.openapi.project.Project
import com.intellij.ui.JBColor
import com.intellij.ui.JBSplitter
import com.intellij.ui.SideBorder
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.treeStructure.Tree
import java.awt.Component
import java.awt.Dimension
import java.awt.GridLayout
import java.io.File
import javax.swing.Icon
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JSplitPane
import javax.swing.event.TreeSelectionEvent
import javax.swing.event.TreeSelectionListener
import javax.swing.tree.DefaultMutableTreeNode
Expand All @@ -28,15 +30,15 @@ import javax.swing.tree.TreeSelectionModel
const val DIFFERENCE_BETWEEN_SCA_LINE_NUMBERS = 1

class TreeView(
val project: Project, defaultRightPane: Component? = null
val project: Project, defaultRightPane: JComponent? = null
) : JPanel(GridLayout(1, 0)), TreeSelectionListener {
private val tree: Tree

// dummyRootNode is a workaround to allow us to hide the root node of the tree
private val dummyRootNode = createNode(DummyNode())
private val rootNodes: RootNodes = RootNodes()

private val splitPane: JSplitPane = JSplitPane(JSplitPane.HORIZONTAL_SPLIT)
private val splitPane: JBSplitter = JBSplitter()

private val scanResults = scanResults(project)

Expand All @@ -50,17 +52,18 @@ class TreeView(
tree.selectionModel.selectionMode = TreeSelectionModel.SINGLE_TREE_SELECTION
tree.addTreeSelectionListener(this) // we want to listen for when the user selects a node

val treeView = JBScrollPane(tree)

flattenJSplitPane(splitPane)
splitPane.leftComponent = treeView
splitPane.resizeWeight = 0.5

val minimumSize = Dimension(400, 100)

val treeView = JBScrollPane(tree)
treeView.border = SideBorder(JBColor.GRAY, SideBorder.RIGHT)
treeView.minimumSize = minimumSize

splitPane.firstComponent = treeView
splitPane.isShowDividerControls = true
splitPane.isShowDividerIcon = true

if (defaultRightPane != null) {
splitPane.rightComponent = defaultRightPane
splitPane.secondComponent = defaultRightPane
defaultRightPane.minimumSize = minimumSize
}

Expand Down Expand Up @@ -175,8 +178,8 @@ class TreeView(
createDetectionNodes(CliScanType.Sca, scaDetections.result, ::createScaDetectionNode)
}

fun replaceRightPanel(newRightPanel: Component): TreeView {
splitPane.rightComponent = newRightPanel
fun replaceRightPanel(newRightPanel: JComponent): TreeView {
splitPane.secondComponent = newRightPanel
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,7 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.LocalFileSystem
import java.io.File
import javax.swing.BorderFactory
import javax.swing.JSplitPane
import javax.swing.border.Border
import javax.swing.plaf.basic.BasicSplitPaneDivider
import javax.swing.plaf.basic.BasicSplitPaneUI

/**
* Makes a split pane invisible. Only contained components are shown.
*
* Ref: https://stackoverflow.com/a/12799814/8032027
*
* @param splitPane
*/
fun flattenJSplitPane(splitPane: JSplitPane) {
splitPane.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1))
val flatDividerSplitPaneUI: BasicSplitPaneUI = object : BasicSplitPaneUI() {
override fun createDefaultDivider(): BasicSplitPaneDivider {
return object : BasicSplitPaneDivider(this) {
override fun setBorder(b: Border?) {}
}
}
}
splitPane.setUI(flatDividerSplitPaneUI)
splitPane.setBorder(null)
}

fun openFileInEditor(project: Project, filePath: String, lineNumber: Int) {
val file = File(filePath)
Expand Down

0 comments on commit 6c52afb

Please sign in to comment.