Skip to content

Commit

Permalink
improv: Clear selection when clicking empty section in inclusions-list
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Sep 20, 2023
1 parent f08ca16 commit 758a097
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@ import de.griefed.serverpackcreator.api.ApiWrapper
import de.griefed.serverpackcreator.api.InclusionSpecification
import de.griefed.serverpackcreator.gui.GuiProps
import de.griefed.serverpackcreator.gui.components.BalloonTipButton
import de.griefed.serverpackcreator.gui.window.configs.ConfigEditor
import de.griefed.serverpackcreator.gui.components.DocumentChangeListener
import de.griefed.serverpackcreator.gui.components.ElementLabel
import de.griefed.serverpackcreator.gui.components.ScrollTextField
import de.griefed.serverpackcreator.gui.window.configs.ConfigEditor
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import net.miginfocom.swing.MigLayout
import org.apache.logging.log4j.kotlin.cachedLoggerOf
import java.awt.BorderLayout
import java.awt.Dimension
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.io.File
import java.util.regex.PatternSyntaxException
import javax.swing.*
import javax.swing.event.DocumentEvent
import javax.swing.event.ListSelectionEvent


/**
* Editor for [InclusionSpecification] for a given server pack. This editor allows you to specify the
* * source
Expand Down Expand Up @@ -184,6 +187,31 @@ class InclusionsEditor(
timer.stop()
timer.delay = delay
timer.isRepeats = false

list.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
super.mouseClicked(e)
clearselection(e)
}

override fun mousePressed(e: MouseEvent) {
super.mousePressed(e)
clearselection(e)
}

override fun mouseReleased(e: MouseEvent) {
super.mouseReleased(e)
clearselection(e)
}

fun clearselection(e: MouseEvent) {
val index = list.locationToIndex(e.point)
val bounds = list.getCellBounds(index, index)
if (bounds == null || !bounds.contains(e.point)) {
list.clearSelection()
}
}
})
}

/**
Expand Down

0 comments on commit 758a097

Please sign in to comment.