All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.jetbrains.datalore.base.event.KeyStrokeSpec.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * 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