Skip to content

Commit

Permalink
take custom tag priority into account
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Oct 31, 2018
1 parent 360e25c commit 868b7ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/main/kotlin/org/acejump/config/AceConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ object AceConfig : Configurable, PersistentStateComponent<AceSettings> {

override fun isModified() =
panel.allowedChars != settings.allowedChars ||
panel.keyboardChars != settings.keyboardChars ||
panel.jumpModeColor != settings.jumpModeColor ||
panel.targetModeColor != settings.targetModeColor ||
panel.textHighlightColor != settings.textHighlightColor ||
panel.tagForegroundColor != settings.tagForegroundColor ||
panel.tagBackgroundColor != settings.tagBackgroundColor

override fun apply() {
settings.allowedChars = panel.allowedChars.toList().distinct().run {
if (isEmpty()) Pattern.defaultChars else filter { it.isLetterOrDigit() }
}.joinToString("")
private fun String.distinctAlphanumerics() = toList().distinct().run {
if (isEmpty()) Pattern.defaultChars else filter { it.isLetterOrDigit() }
}.joinToString("")

override fun apply() {
settings.allowedChars = panel.allowedChars.distinctAlphanumerics()
settings.keyboardChars = panel.keyboardChars.distinctAlphanumerics()
panel.jumpModeColor?.let { settings.jumpModeRGB = it.rgb }
panel.targetModeColor?.let { settings.targetModeRGB = it.rgb }
panel.textHighlightColor?.let { settings.textHighlightRGB = it.rgb }
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/acejump/config/AceSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.awt.Color.*
import kotlin.reflect.KProperty

data class AceSettings(var allowedChars: String = Pattern.defaultChars.joinToString(""),
var keyboardChars: String = Pattern.keyboardKeys,
// These must be primitives in order to be serializable
internal var jumpModeRGB: Int = BLUE.rgb,
internal var targetModeRGB: Int = RED.rgb,
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/org/acejump/config/AceSettingsPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.acejump.search.aceString
import java.awt.Color
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JTextArea
import javax.swing.JTextField
import kotlin.reflect.KProperty

Expand All @@ -19,13 +20,16 @@ class AceSettingsPanel {
private var textHighlightColorWheel = ColorPanel()
private var tagForegroundColorWheel = ColorPanel()
private var tagBackgroundColorWheel = ColorPanel()
private var keyboardCharsLayout = JTextArea()

internal val rootPanel: JPanel = panel {
fun Cell.short(component: JComponent) = component(growPolicy = SHORT_TEXT)
fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)

noteRow(aceString("tagCharsToBeUsedHeading"))
row(aceString("tagCharsToBeUsedLabel")) { medium(tagCharactersField) }
noteRow("Alphanumeric Keyboard Characters from top to bottom")
row("Keyboard keys") { medium(keyboardCharsLayout) }
noteRow(aceString("colorsToBeUsedHeading"))
row(aceString("jumpModeColorLabel")) { short(jumpModeColorWheel) }
row(aceString("tagBackgroundColorLabel")) { short(tagBackgroundColorWheel) }
Expand All @@ -38,6 +42,10 @@ class AceSettingsPanel {
get() = tagCharactersField.text.toLowerCase()
set(value) = tagCharactersField.setText(value)

internal var keyboardChars: String
get() = keyboardCharsLayout.text.toLowerCase()
set(value) = keyboardCharsLayout.setText(value)

internal var jumpModeColor by jumpModeColorWheel
internal var targetModeColor by targetModeColorWheel
internal var textHighlightColor by textHighlightColorWheel
Expand All @@ -46,6 +54,7 @@ class AceSettingsPanel {

fun reset(settings: AceSettings) {
allowedChars = settings.allowedChars
keyboardChars = settings.keyboardChars
jumpModeColor = settings.jumpModeColor
targetModeColor = settings.targetModeColor
textHighlightColor = settings.textHighlightColor
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/org/acejump/label/Pattern.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum class Pattern(val string: String) {
ALL_WORDS("(?<=[^a-zA-Z0-9_])[a-zA-Z0-9_]");

companion object {
fun distance(fromKey: Char, toKey: Char) = nearby[fromKey]!![toKey]
private fun distance(fromKey: Char, toKey: Char) = nearby[fromKey]!![toKey]

fun priority(char: Char) = priority[char]

Expand All @@ -31,7 +31,16 @@ enum class Pattern(val string: String) {
var NUM_CHARS: Int = 36
get() = AceConfig.settings.allowedChars.length

val defaultChars = ('a'..'z').plus('0'..'9')
private val priority: Map<Char, Int> =
"fjghdkslavncmbxzrutyeiwoqp5849673210".mapIndices()

val defaultChars = ('a'..'z').plus('0'..'9').sortedBy { priority[it] }
val keyboardKeys = """
12345890
qwertyuiop
asdfghjkl
zxcvbnm
""".trimIndent()

val defaultOrder: Comparator<String> = compareBy(
{ it[0].isDigit() || it[1].isDigit() },
Expand All @@ -54,9 +63,6 @@ enum class Pattern(val string: String) {
"zxcvbnm"
)

private val priority: Map<Char, Int> =
"fjghdkslavncmbxzrutyeiwoqp5849673210".mapIndices()

private val nearby: Map<Char, Map<Char, Int>> = mapOf(
// Values are QWERTY keys sorted by physical proximity to the map key
'j' to "jikmnhuolbgypvftcdrxsezawq8796054321",
Expand Down

0 comments on commit 868b7ba

Please sign in to comment.