diff --git a/src/main/kotlin/com/fwdekker/randomness/affix/AffixDecoratorEditor.kt b/src/main/kotlin/com/fwdekker/randomness/affix/AffixDecoratorEditor.kt index 0af922a29..ff9887605 100644 --- a/src/main/kotlin/com/fwdekker/randomness/affix/AffixDecoratorEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/affix/AffixDecoratorEditor.kt @@ -7,7 +7,6 @@ import com.fwdekker.randomness.ui.disableMnemonic import com.fwdekker.randomness.ui.isEditable import com.fwdekker.randomness.ui.loadMnemonic import com.fwdekker.randomness.ui.withName -import com.intellij.openapi.ui.ComboBox import com.intellij.ui.dsl.builder.Cell import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.panel @@ -44,7 +43,7 @@ class AffixDecoratorEditor( .bindSelected(scheme::enabled) .also { enabledCheckBox = it } - cell(ComboBox(presets.toTypedArray())) + comboBox(presets) .enabledIf(enabledIf?.and(enabledCheckBox.selected) ?: enabledCheckBox.selected) .isEditable(true) .withName(camelConcat(namePrefix, "affixDescriptor")) diff --git a/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecorator.kt b/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecorator.kt index 4f3223358..e307919ea 100644 --- a/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecorator.kt +++ b/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecorator.kt @@ -88,7 +88,7 @@ data class ArrayDecorator( /** * The preset values for the [separator] field. */ - val PRESET_SEPARATORS = arrayOf(", ", "; ", "\\n") + val PRESET_SEPARATORS = listOf(", ", "; ", "\\n") /** * The default value of the [separator] field. diff --git a/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecoratorEditor.kt b/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecoratorEditor.kt index 1827ecac9..c29be648a 100644 --- a/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecoratorEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/array/ArrayDecoratorEditor.kt @@ -17,7 +17,6 @@ import com.fwdekker.randomness.ui.isEditable import com.fwdekker.randomness.ui.loadMnemonic import com.fwdekker.randomness.ui.withFixedWidth import com.fwdekker.randomness.ui.withName -import com.intellij.openapi.ui.ComboBox import com.intellij.ui.dsl.builder.BottomGap import com.intellij.ui.dsl.builder.Cell import com.intellij.ui.dsl.builder.bindSelected @@ -86,7 +85,7 @@ class ArrayDecoratorEditor( .bindSelected(scheme::separatorEnabled) .also { separatorEnabledCheckBox = it.component } - cell(ComboBox(PRESET_SEPARATORS)) + comboBox(PRESET_SEPARATORS) .enabledIf(isEnabled.and(separatorEnabledCheckBox.selected)) .isEditable(true) .withName("arraySeparator") diff --git a/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt b/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt index 18077046d..eaa082df9 100644 --- a/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt +++ b/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalScheme.kt @@ -129,7 +129,7 @@ data class DecimalScheme( /** * The preset values for the [decimalSeparator] field. */ - val PRESET_DECIMAL_SEPARATORS = arrayOf(",", ".") + val PRESET_DECIMAL_SEPARATORS = listOf(",", ".") /** * The default value of the [decimalSeparator] field. @@ -144,7 +144,7 @@ data class DecimalScheme( /** * The preset values for the [groupingSeparator] field. */ - val PRESET_GROUPING_SEPARATORS = arrayOf(".", ",", "_") + val PRESET_GROUPING_SEPARATORS = listOf(".", ",", "_") /** * The default value of the [groupingSeparator] field. diff --git a/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalSchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalSchemeEditor.kt index 868ddab52..10a241e99 100644 --- a/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalSchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/decimal/DecimalSchemeEditor.kt @@ -21,7 +21,6 @@ import com.fwdekker.randomness.ui.loadMnemonic import com.fwdekker.randomness.ui.withFilter import com.fwdekker.randomness.ui.withFixedWidth import com.fwdekker.randomness.ui.withName -import com.intellij.openapi.ui.ComboBox import com.intellij.ui.dsl.builder.AlignX import com.intellij.ui.dsl.builder.Cell import com.intellij.ui.dsl.builder.bindSelected @@ -79,7 +78,7 @@ class DecimalSchemeEditor(scheme: DecimalScheme = DecimalScheme()) : SchemeEdito } row(Bundle("decimal.ui.format.decimal_separator_option")) { - cell(ComboBox(PRESET_DECIMAL_SEPARATORS)) + comboBox(PRESET_DECIMAL_SEPARATORS) .isEditable(true) .withFilter(MinMaxLengthDocumentFilter(1, 1)) .withName("decimalSeparator") @@ -95,7 +94,7 @@ class DecimalSchemeEditor(scheme: DecimalScheme = DecimalScheme()) : SchemeEdito .bindSelected(scheme::groupingSeparatorEnabled) .also { groupingSeparatorEnabled = it } - cell(ComboBox(PRESET_GROUPING_SEPARATORS)) + comboBox(PRESET_GROUPING_SEPARATORS) .enabledIf(groupingSeparatorEnabled.selected) .isEditable(true) .withFilter(MinMaxLengthDocumentFilter(1, 1)) diff --git a/src/main/kotlin/com/fwdekker/randomness/integer/IntegerScheme.kt b/src/main/kotlin/com/fwdekker/randomness/integer/IntegerScheme.kt index 80fbc6384..292d9761e 100644 --- a/src/main/kotlin/com/fwdekker/randomness/integer/IntegerScheme.kt +++ b/src/main/kotlin/com/fwdekker/randomness/integer/IntegerScheme.kt @@ -152,7 +152,7 @@ data class IntegerScheme( /** * The preset values for the [groupingSeparator] descriptor. */ - val PRESET_GROUPING_SEPARATORS = arrayOf(".", ",", "_") + val PRESET_GROUPING_SEPARATORS = listOf(".", ",", "_") /** * The default value of the [groupingSeparator] field. diff --git a/src/main/kotlin/com/fwdekker/randomness/integer/IntegerSchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/integer/IntegerSchemeEditor.kt index 675364320..88647996a 100644 --- a/src/main/kotlin/com/fwdekker/randomness/integer/IntegerSchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/integer/IntegerSchemeEditor.kt @@ -24,7 +24,6 @@ import com.fwdekker.randomness.ui.loadMnemonic import com.fwdekker.randomness.ui.withFilter import com.fwdekker.randomness.ui.withFixedWidth import com.fwdekker.randomness.ui.withName -import com.intellij.openapi.ui.ComboBox import com.intellij.ui.dsl.builder.AlignX import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.panel @@ -89,7 +88,7 @@ class IntegerSchemeEditor(scheme: IntegerScheme = IntegerScheme()) : SchemeEdito .bindSelected(scheme::groupingSeparatorEnabled) .also { groupingSeparatorEnabled = it.component } - cell(ComboBox(PRESET_GROUPING_SEPARATORS)) + comboBox(PRESET_GROUPING_SEPARATORS) .enabledIf(base.hasValue { it == DECIMAL_BASE }.and(groupingSeparatorEnabled.selected)) .withName("groupingSeparator") .isEditable(true) diff --git a/src/main/kotlin/com/fwdekker/randomness/string/StringScheme.kt b/src/main/kotlin/com/fwdekker/randomness/string/StringScheme.kt index 50c8c81b2..ab6011dfa 100644 --- a/src/main/kotlin/com/fwdekker/randomness/string/StringScheme.kt +++ b/src/main/kotlin/com/fwdekker/randomness/string/StringScheme.kt @@ -131,7 +131,7 @@ data class StringScheme( /** * The preset values for the [capitalization] field. */ - val PRESET_CAPITALIZATION = arrayOf( + val PRESET_CAPITALIZATION = listOf( CapitalizationMode.RETAIN, CapitalizationMode.LOWER, CapitalizationMode.UPPER, diff --git a/src/main/kotlin/com/fwdekker/randomness/string/StringSchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/string/StringSchemeEditor.kt index a9116982b..e8ddad54b 100644 --- a/src/main/kotlin/com/fwdekker/randomness/string/StringSchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/string/StringSchemeEditor.kt @@ -1,7 +1,6 @@ package com.fwdekker.randomness.string import com.fwdekker.randomness.Bundle -import com.fwdekker.randomness.CapitalizationMode import com.fwdekker.randomness.SchemeEditor import com.fwdekker.randomness.array.ArrayDecoratorEditor import com.fwdekker.randomness.string.StringScheme.Companion.PRESET_CAPITALIZATION @@ -9,13 +8,12 @@ import com.fwdekker.randomness.ui.UIConstants import com.fwdekker.randomness.ui.loadMnemonic import com.fwdekker.randomness.ui.withFixedWidth import com.fwdekker.randomness.ui.withName -import com.fwdekker.randomness.ui.withSimpleRenderer -import com.intellij.openapi.ui.ComboBox import com.intellij.ui.dsl.builder.AlignX import com.intellij.ui.dsl.builder.BottomGap import com.intellij.ui.dsl.builder.bindItem import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.bindText +import com.intellij.ui.dsl.builder.listCellRenderer import com.intellij.ui.dsl.builder.panel import com.intellij.ui.dsl.builder.toNullableProperty import com.intellij.ui.layout.selected @@ -56,8 +54,7 @@ class StringSchemeEditor(scheme: StringScheme = StringScheme()) : SchemeEditor Cell>.withFilter(filter: DocumentFilter): Cell> return this } -/** - * Sets an item renderer on the [ComboBox] in this [Cell] that renders a label displaying the mapping of an item using - * [toString], and returns `this`. - */ -fun Cell>.withSimpleRenderer(toString: (E) -> String = { it.toString() }): Cell> { - component.setRenderer { _, value, _, _, _ -> JBLabel(toString(value)) } - return this -} - /** * A predicate that always returns [output]. @@ -163,12 +152,6 @@ fun Cell>.bindCurrentText(property: KMutableProperty0) property.toMutableProperty() ) -/** - * Binds the value of the [ComboBox] in this [Cell] to [property], asserting that the value is not `null`. - */ -fun Cell>.bindItemNotNull(property: KMutableProperty0) = - bindItem({ property.get() }, { property.set(it!!) }) - /** * Binds the value of the [JIntSpinner] in this [Cell] to [property]. */ diff --git a/src/main/kotlin/com/fwdekker/randomness/uuid/UuidSchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/uuid/UuidSchemeEditor.kt index a35ce9374..62b9f46b5 100644 --- a/src/main/kotlin/com/fwdekker/randomness/uuid/UuidSchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/uuid/UuidSchemeEditor.kt @@ -4,16 +4,18 @@ import com.fwdekker.randomness.Bundle import com.fwdekker.randomness.SchemeEditor import com.fwdekker.randomness.affix.AffixDecoratorEditor import com.fwdekker.randomness.array.ArrayDecoratorEditor -import com.fwdekker.randomness.ui.bindItemNotNull import com.fwdekker.randomness.ui.isEditable import com.fwdekker.randomness.ui.loadMnemonic import com.fwdekker.randomness.ui.withName -import com.fwdekker.randomness.ui.withSimpleRenderer import com.fwdekker.randomness.uuid.UuidScheme.Companion.PRESET_AFFIX_DECORATOR_DESCRIPTORS -import com.intellij.openapi.ui.ComboBox +import com.intellij.ui.ColoredListCellRenderer +import com.intellij.ui.SimpleTextAttributes import com.intellij.ui.dsl.builder.AlignX +import com.intellij.ui.dsl.builder.bindItem import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.panel +import com.intellij.ui.dsl.builder.toNullableProperty +import javax.swing.JList /** @@ -26,11 +28,10 @@ class UuidSchemeEditor(scheme: UuidScheme = UuidScheme()) : SchemeEditor() { + override fun customizeCellRenderer( + list: JList, + value: Int?, + index: Int, + selected: Boolean, + hasFocus: Boolean, + ) { + if (value == null) return + + append("$value") + append(" ") + append(Bundle("uuid.ui.value.version.$value"), SimpleTextAttributes.GRAYED_ATTRIBUTES) + } + } } diff --git a/src/main/kotlin/com/fwdekker/randomness/word/WordScheme.kt b/src/main/kotlin/com/fwdekker/randomness/word/WordScheme.kt index f7df44445..eaed795ce 100644 --- a/src/main/kotlin/com/fwdekker/randomness/word/WordScheme.kt +++ b/src/main/kotlin/com/fwdekker/randomness/word/WordScheme.kt @@ -70,7 +70,7 @@ data class WordScheme( /** * The preset values for the [capitalization] field. */ - val PRESET_CAPITALIZATION = arrayOf( + val PRESET_CAPITALIZATION = listOf( CapitalizationMode.RETAIN, CapitalizationMode.LOWER, CapitalizationMode.UPPER, diff --git a/src/main/kotlin/com/fwdekker/randomness/word/WordSchemeEditor.kt b/src/main/kotlin/com/fwdekker/randomness/word/WordSchemeEditor.kt index 8503ebce4..9edc27b83 100644 --- a/src/main/kotlin/com/fwdekker/randomness/word/WordSchemeEditor.kt +++ b/src/main/kotlin/com/fwdekker/randomness/word/WordSchemeEditor.kt @@ -1,7 +1,6 @@ package com.fwdekker.randomness.word import com.fwdekker.randomness.Bundle -import com.fwdekker.randomness.CapitalizationMode import com.fwdekker.randomness.SchemeEditor import com.fwdekker.randomness.affix.AffixDecoratorEditor import com.fwdekker.randomness.array.ArrayDecoratorEditor @@ -10,7 +9,6 @@ import com.fwdekker.randomness.ui.addChangeListenerTo import com.fwdekker.randomness.ui.onResetThis import com.fwdekker.randomness.ui.withFixedHeight import com.fwdekker.randomness.ui.withName -import com.fwdekker.randomness.ui.withSimpleRenderer import com.fwdekker.randomness.word.WordScheme.Companion.PRESET_AFFIX_DECORATOR_DESCRIPTORS import com.fwdekker.randomness.word.WordScheme.Companion.PRESET_CAPITALIZATION import com.intellij.openapi.Disposable @@ -25,6 +23,7 @@ import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.util.Disposer import com.intellij.ui.dsl.builder.AlignX import com.intellij.ui.dsl.builder.bindItem +import com.intellij.ui.dsl.builder.listCellRenderer import com.intellij.ui.dsl.builder.panel import com.intellij.ui.dsl.builder.toMutableProperty import com.intellij.ui.dsl.builder.toNullableProperty @@ -43,9 +42,8 @@ class WordSchemeEditor(scheme: WordScheme = WordScheme()) : SchemeEditor if (event.stateChange == ItemEvent.SELECTED) { @@ -87,8 +85,7 @@ class WordSchemeEditor(scheme: WordScheme = WordScheme()) : SchemeEditor