Tree drop target started looking weird

Answered

I'm using com.intellij.ui.treeStructure.Tree with drag and drop enabled.
Earlier (211 build and earlier versions) dragging the tree node looked beautiful and was with a neat underline of the drag target (see drop_target_211_build.webm in 2022_05_24_LQABDsoNHJ7N7Jf9 ).
Now it looks so weird, and besides, the drop place is no longer underlined correctly. (see drop_target_221_build.webm in 2022_05_24_LQABDsoNHJ7N7Jf9 ).

If you have some problem with uploaded files see https://intellij-support.jetbrains.com/hc/en-us/requests/4058804  

In the provided example with screencast I used the same tree implementation, the only thing I have changed is intellij version in build.gradle:

intellij {
    version = '221.5080.210'//'211.7628.21'
}

And as you can see - the result so different.
Here is the code of my tree on Kotlin:

val root = DefaultMutableTreeNode("Main")
val child1 = DefaultMutableTreeNode("Child1")
child1.add(DefaultMutableTreeNode("Child1_1"))
child1.add(DefaultMutableTreeNode("Child1_2"))
child1.add(DefaultMutableTreeNode("Child1_3"))
root.add(child1)
root.add(DefaultMutableTreeNode("Child2"))
root.add(DefaultMutableTreeNode("Child3"))

val tree = Tree(root)
tree.dragEnabled = true
tree.dropMode = DropMode.ON_OR_INSERT
tree.cellRenderer = object : ColoredTreeCellRenderer() {
override fun customizeCellRenderer(
tree: JTree,
value: Any?,
selected: Boolean,
expanded: Boolean,
leaf: Boolean,
row: Int,
hasFocus: Boolean
) {
val node = value as? DefaultMutableTreeNode ?: return
append(node.userObject.toString())
}
}
tree.transferHandler = object : TransferHandler() {
override fun getSourceActions(c: JComponent): Int = MOVE
override fun canImport(support: TransferSupport?): Boolean {
return true
}
override fun createTransferable(c: JComponent?): Transferable {
val myTree = c as JTree
val path = myTree.selectionPaths?.firstOrNull()
val node = path?.lastPathComponent as? DefaultMutableTreeNode
return TextTransferable(node?.userObject as? String)
}
}

Could you let me know if there is a way to make the tree look like it used to? If there is, so how? If not, how can I make the place of the drop is drawn normally without UI glitches?

6 comments
Comment actions Permalink

Hi,

Do I understand correctly, that drop target is rendered differently depending on the IDE version you run it in? Or does it look different in the same IDE version depending on the platform version you compile the project against?

0
Comment actions Permalink

Hi!
If I understand you correctly, the first is correct.

I created a test project with my own plugin that adds a tree to the right side of the code editor and then successively run a gradle "runIde" task to compile it using two different IDE versions ( '221.5080.210' and '211.7628.21').
No matter which platform I used (Windows, Linux...) - drop target is rendered differently.

0
Comment actions Permalink

Hi,

I'm sorry, but I don't see what can be the issue in your code. I suggest taking a look at DnDAwareTree which seems to be used in similar platform components and doesn't cause issues.

0
Comment actions Permalink

Hi! Thank you for help, but unfortunately it works the same way(

I noticed that there is no examples among platform components, because no one use javax.swing.DropMode#ON_OR_INSERT.

The problem is relevant when you need to move a node both inside another node and between other nodes. In the first case we need to draw rectangle for the drop target and in the second case we need to draw a line between nodes as a drop target .

Unfortunately, from a 2021.1+ version of the IDEA, lines for drop target no longer draw normally and stable (sometimes it seems that the line appears, but it looks strange, not like in previous versions).

If there is a way to return previous implementation of drop target rendering it will be really nice)

0
Comment actions Permalink

Hi!

Ok thanks, I'll keep an eye on the ticket

0

Please sign in to leave a comment.