commonMain.jetbrains.datalore.base.event.KeyStrokeSpec.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.base.event
class KeyStrokeSpec {
private val myKeyStrokes: Array
val keyStrokes: Iterable
get() = listOf(*myKeyStrokes)
val isEmpty: Boolean
get() = myKeyStrokes.isEmpty()
constructor(key: Key, vararg modifiers: ModifierKey) {
myKeyStrokes = arrayOf(KeyStroke(key, *modifiers))
}
constructor(keyStrokes: Collection) {
myKeyStrokes = keyStrokes.toTypedArray()
}
constructor(vararg keyStrokes: KeyStroke) {
myKeyStrokes = arrayOf(*keyStrokes)
}
fun matches(keyStroke: KeyStroke): Boolean {
for (spec in myKeyStrokes) {
if (spec.matches(keyStroke)) {
return true
}
}
return false
}
fun with(key: ModifierKey): KeyStrokeSpec {
val modified = ArrayList()
for (keyStroke in myKeyStrokes) {
modified.add(keyStroke.with(key))
}
return KeyStrokeSpec(modified)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
val that = other as KeyStrokeSpec?
return keyStrokes == that!!.keyStrokes
}
override fun hashCode(): Int {
return keyStrokes.hashCode()
}
override fun toString(): String {
return keyStrokes.toString()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy