Skip to content

Commit 9cb3d04

Browse files
committed
Fix change detection and add some quality of life
1 parent 6892637 commit 9cb3d04

File tree

6 files changed

+226
-204
lines changed

6 files changed

+226
-204
lines changed

src/main/kotlin/com/fwdekker/randomness/Scheme.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ abstract class Scheme {
5858
/**
5959
* Copies the given scheme into this scheme.
6060
*
61+
* Works by copying all references in a [deepCopy] of [scheme] into `this`.
62+
*
6163
* @param scheme the scheme to copy into this scheme; should be a subclass of this scheme
6264
*/
63-
// TODO: Is this a deep copy?
64-
fun copyFrom(scheme: Scheme) = XmlSerializerUtil.copyBean(scheme, this)
65+
fun copyFrom(scheme: Scheme) = XmlSerializerUtil.copyBean(scheme.deepCopy(), this)
6566

6667
/**
6768
* Returns a deep copy of this scheme.

src/main/kotlin/com/fwdekker/randomness/array/ArraySchemeDecoratorEditor.form

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="rootComponent" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="490" height="221"/>
6+
<xy x="20" y="20" width="490" height="201"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -13,25 +13,25 @@
1313
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
1414
</constraints>
1515
</component>
16-
<grid id="c14ec" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16+
<component id="30ce4" class="javax.swing.JCheckBox" binding="enabledCheckBox">
17+
<constraints>
18+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
19+
</constraints>
20+
<properties>
21+
<text resource-bundle="randomness" key="settings.enabled"/>
22+
</properties>
23+
</component>
24+
<grid id="c14ec" binding="arrayDetailsPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1725
<margin top="0" left="0" bottom="0" right="0"/>
1826
<constraints>
19-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
27+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
2028
</constraints>
2129
<properties/>
2230
<border type="none"/>
2331
<children>
24-
<component id="30ce4" class="javax.swing.JCheckBox" binding="enabledCheckBox">
25-
<constraints>
26-
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
27-
</constraints>
28-
<properties>
29-
<text resource-bundle="randomness" key="settings.enabled"/>
30-
</properties>
31-
</component>
3232
<component id="1771b" class="javax.swing.JLabel">
3333
<constraints>
34-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
34+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
3535
</constraints>
3636
<properties>
3737
<labelFor value="38ced"/>
@@ -40,7 +40,7 @@
4040
</component>
4141
<component id="38ced" class="com.fwdekker.randomness.ui.JIntSpinner" binding="countSpinner" custom-create="true">
4242
<constraints>
43-
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
43+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="1" indent="0" use-parent-layout="false">
4444
<maximum-size width="65" height="-1"/>
4545
</grid>
4646
</constraints>
@@ -50,7 +50,7 @@
5050
</component>
5151
<component id="37af5" class="javax.swing.JLabel">
5252
<constraints>
53-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
53+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
5454
</constraints>
5555
<properties>
5656
<text resource-bundle="randomness" key="settings.brackets"/>
@@ -59,7 +59,7 @@
5959
<grid id="fb183" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
6060
<margin top="0" left="0" bottom="0" right="0"/>
6161
<constraints>
62-
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
62+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
6363
</constraints>
6464
<properties/>
6565
<border type="none"/>
@@ -110,7 +110,7 @@
110110
</grid>
111111
<component id="99096" class="javax.swing.JLabel">
112112
<constraints>
113-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
113+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
114114
</constraints>
115115
<properties>
116116
<text resource-bundle="randomness" key="settings.separator"/>
@@ -119,7 +119,7 @@
119119
<grid id="4109" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
120120
<margin top="0" left="0" bottom="0" right="0"/>
121121
<constraints>
122-
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
122+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
123123
</constraints>
124124
<properties/>
125125
<border type="none"/>
@@ -162,7 +162,7 @@
162162
</grid>
163163
<component id="e048d" class="javax.swing.JCheckBox" binding="spaceAfterSeparatorCheckBox" default-binding="true">
164164
<constraints>
165-
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
165+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
166166
</constraints>
167167
<properties>
168168
<name value="spaceAfterSeparator" noi18n="true"/>
@@ -173,7 +173,7 @@
173173
</grid>
174174
<vspacer id="dc630">
175175
<constraints>
176-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
176+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
177177
</constraints>
178178
</vspacer>
179179
</children>

src/main/kotlin/com/fwdekker/randomness/array/ArraySchemeDecoratorEditor.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.fwdekker.randomness.array.ArraySchemeDecorator.Companion.MIN_COUNT
77
import com.fwdekker.randomness.ui.JIntSpinner
88
import com.fwdekker.randomness.ui.addChangeListenerTo
99
import com.fwdekker.randomness.ui.getValue
10-
import com.fwdekker.randomness.ui.setEnabled
1110
import com.fwdekker.randomness.ui.setValue
1211
import com.jgoodies.forms.factories.DefaultComponentFactory
1312
import java.util.ResourceBundle
@@ -29,6 +28,7 @@ class ArraySchemeDecoratorEditor(settings: ArraySchemeDecorator) : SchemeEditor<
2928
override lateinit var rootComponent: JPanel private set
3029
private lateinit var separator: JComponent
3130
private lateinit var enabledCheckBox: JCheckBox
31+
private lateinit var arrayDetailsPanel: JPanel
3232
private lateinit var countSpinner: JIntSpinner
3333
private lateinit var bracketsGroup: ButtonGroup
3434
private lateinit var separatorGroup: ButtonGroup
@@ -37,17 +37,11 @@ class ArraySchemeDecoratorEditor(settings: ArraySchemeDecorator) : SchemeEditor<
3737

3838

3939
init {
40-
enabledCheckBox.addChangeListener {
41-
countSpinner.isEnabled = enabledCheckBox.isSelected
42-
bracketsGroup.setEnabled(enabledCheckBox.isSelected)
43-
separatorGroup.setEnabled(enabledCheckBox.isSelected)
44-
newlineSeparatorButton.isEnabled = enabledCheckBox.isSelected
45-
spaceAfterSeparatorCheckBox.isEnabled = enabledCheckBox.isSelected && !newlineSeparatorButton.isSelected
46-
}
40+
enabledCheckBox.addChangeListener { arrayDetailsPanel.isVisible = enabledCheckBox.isSelected }
4741
enabledCheckBox.changeListeners.forEach { it.stateChanged(ChangeEvent(enabledCheckBox)) }
4842

4943
newlineSeparatorButton.addChangeListener {
50-
spaceAfterSeparatorCheckBox.isEnabled = enabledCheckBox.isSelected && !newlineSeparatorButton.isSelected
44+
spaceAfterSeparatorCheckBox.isEnabled = !newlineSeparatorButton.isSelected
5145
}
5246
newlineSeparatorButton.changeListeners.forEach { it.stateChanged(ChangeEvent(newlineSeparatorButton)) }
5347

src/main/kotlin/com/fwdekker/randomness/template/Template.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fwdekker.randomness.template
22

33
import com.fwdekker.randomness.Scheme
4-
import com.fwdekker.randomness.array.ArraySchemeDecorator
54
import com.fwdekker.randomness.decimal.DecimalScheme
65
import com.fwdekker.randomness.integer.IntegerScheme
76
import com.fwdekker.randomness.literal.LiteralScheme
@@ -32,7 +31,7 @@ data class Template(
3231
]
3332
)
3433
var schemes: List<Scheme> = DEFAULT_SCHEMES,
35-
override var decorator: ArraySchemeDecorator = ArraySchemeDecorator(),
34+
override var decorator: Nothing? = null
3635
) : Scheme() {
3736
override fun generateUndecoratedStrings(count: Int) =
3837
schemes.onEach { it.random = random }.map { it.generateStrings(count) }
@@ -88,7 +87,6 @@ data class TemplateList(
8887
templates.firstNotNullOfOrNull { template -> template.doValidate()?.let { "${template.name} > $it" } }
8988

9089
return when {
91-
templates.isEmpty() -> "Configure at least one template."
9290
duplicate != null -> "There are multiple templates with the name '$duplicate'."
9391
invalid != null -> invalid
9492
else -> null
@@ -108,8 +106,11 @@ data class TemplateList(
108106
*/
109107
val DEFAULT_TEMPLATES: List<Template>
110108
get() = listOf(
111-
Template("The Integer", listOf(IntegerScheme())),
112-
Template("My String", listOf(LiteralScheme("start"), StringScheme(), LiteralScheme("end")))
109+
Template("Integer", listOf(IntegerScheme())),
110+
Template("Decimal", listOf(DecimalScheme())),
111+
Template("String", listOf(StringScheme())),
112+
Template("Word", listOf(WordScheme())),
113+
Template("UUID", listOf(UuidScheme()))
113114
)
114115
}
115116
}

0 commit comments

Comments
 (0)