-
Notifications
You must be signed in to change notification settings - Fork 47
/
KeyStrokeSpec.kt
58 lines (44 loc) · 1.42 KB
/
KeyStrokeSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package jetbrains.datalore.base.event
class KeyStrokeSpec {
private val myKeyStrokes: Array<KeyStroke>
val keyStrokes: Iterable<KeyStroke>
get() = listOf(*myKeyStrokes)
val isEmpty: Boolean
get() = myKeyStrokes.isEmpty()
constructor(key: Key, vararg modifiers: ModifierKey) {
myKeyStrokes = arrayOf(KeyStroke(key, *modifiers))
}
constructor(keyStrokes: Collection<KeyStroke>) {
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<KeyStroke>()
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()
}
}