From a0d62c65d73a69abd8518e8e4415a8a287f5c882 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 22 Jul 2021 20:11:14 +0300 Subject: [PATCH] Fix FX ValueChooser crash --- ui/ring/build.gradle.kts | 1 - .../visionforge/editor/TextValueChooser.kt | 2 +- .../visionforge/editor/ValueChooser.kt | 7 +++---- .../visionforge/editor/ValueChooserBase.kt | 12 ++++++----- .../editor/VisualObjectEditorFragment.kt | 20 +++++++++---------- .../editor/VisualObjectTreeFragment.kt | 15 ++++++++------ .../kscience/visionforge/solid/FX3DPlugin.kt | 6 +++--- .../visionforge/solid/FXReferenceFactory.kt | 2 +- .../solid/VisualObjectFXBinding.kt | 12 +++++------ 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/ui/ring/build.gradle.kts b/ui/ring/build.gradle.kts index 84d33b43..4469b8cf 100644 --- a/ui/ring/build.gradle.kts +++ b/ui/ring/build.gradle.kts @@ -22,7 +22,6 @@ dependencies{ implementation(npm("@jetbrains/icons", "3.14.1")) implementation(npm("@jetbrains/ring-ui", "4.0.7")) - implementation(npm("core-js","3.12.1")) implementation(npm("file-saver", "2.0.2")) compileOnly(npm("url-loader","4.1.1")) compileOnly(npm("postcss-loader","5.2.0")) diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/TextValueChooser.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/TextValueChooser.kt index ea55fc83..e7beac2b 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/TextValueChooser.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/TextValueChooser.kt @@ -15,7 +15,7 @@ import space.kscience.dataforge.names.asName import space.kscience.dataforge.values.* import tornadofx.* -class TextValueChooser : ValueChooserBase() { +public class TextValueChooser : ValueChooserBase() { private val displayText: String get() = currentValue().let { diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt index c3796fa0..8816a250 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooser.kt @@ -14,7 +14,6 @@ import space.kscience.dataforge.meta.descriptors.ValueDescriptor import space.kscience.dataforge.misc.Named import space.kscience.dataforge.misc.Type import space.kscience.dataforge.names.toName -import space.kscience.dataforge.provider.provideByType import space.kscience.dataforge.values.Null import space.kscience.dataforge.values.Value import space.kscience.visionforge.widget @@ -63,7 +62,7 @@ public interface ValueChooser { public fun setCallback(callback: ValueCallback) - @Type("space.kscience.dataforge.vis.fx.valueChooserFactory") + @Type("space.kscience..fx.valueChooserFactory") public interface Factory : Named { public operator fun invoke(meta: Meta = Meta.EMPTY): ValueChooser } @@ -75,7 +74,7 @@ public interface ValueChooser { TextValueChooser.name -> TextValueChooser ColorValueChooser.name -> ColorValueChooser ComboBoxValueChooser.name -> ComboBoxValueChooser - else -> context.provideByType(type)//Search for additional factories in the plugin + else -> null//context.provideByType(type)//Search for additional factories in the plugin } } @@ -101,7 +100,7 @@ public interface ValueChooser { } } - fun build( + public fun build( context: Context, value: ObservableValue, descriptor: ValueDescriptor? = null, diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooserBase.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooserBase.kt index 81dc42ac..98790f96 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooserBase.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/ValueChooserBase.kt @@ -18,16 +18,18 @@ import tornadofx.* * * @author Alexander Nozik */ -abstract class ValueChooserBase : ValueChooser { +public abstract class ValueChooserBase : ValueChooser { - override val node by lazy { buildNode() } - final override val valueProperty = SimpleObjectProperty(Null) - final override val descriptorProperty = SimpleObjectProperty() + override val node: T by lazy { buildNode() } + final override val valueProperty: SimpleObjectProperty = + SimpleObjectProperty(Null) + final override val descriptorProperty: SimpleObjectProperty = + SimpleObjectProperty() override var descriptor: ValueDescriptor? by descriptorProperty override var value: Value? by valueProperty - fun resetValue() { + public fun resetValue() { setDisplayValue(currentValue()) } diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectEditorFragment.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectEditorFragment.kt index 929c7e85..a918a3a5 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectEditorFragment.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectEditorFragment.kt @@ -13,13 +13,13 @@ import space.kscience.dataforge.meta.update import space.kscience.visionforge.* import tornadofx.* -class VisualObjectEditorFragment(val selector: (Vision) -> Meta) : Fragment() { +public class VisualObjectEditorFragment(public val selector: (Vision) -> Meta) : Fragment() { - val itemProperty = SimpleObjectProperty() - var item: Vision? by itemProperty - val descriptorProperty = SimpleObjectProperty() + public val itemProperty: SimpleObjectProperty = SimpleObjectProperty() + public var item: Vision? by itemProperty + public val descriptorProperty: SimpleObjectProperty = SimpleObjectProperty() - constructor( + public constructor( item: Vision?, descriptor: NodeDescriptor?, selector: (Vision) -> MutableItemProvider = { it.allProperties() }, @@ -30,13 +30,13 @@ class VisualObjectEditorFragment(val selector: (Vision) -> Meta) : Fragment() { private var currentConfig: Config? = null - private val configProperty: Binding = itemProperty.objectBinding { visualObject -> - if (visualObject == null) return@objectBinding null - val meta = selector(visualObject) + private val configProperty: Binding = itemProperty.objectBinding { vision -> + if (vision == null) return@objectBinding null + val meta = selector(vision) val config = Config().apply { update(meta) onChange(this@VisualObjectEditorFragment) { key, _, after -> - visualObject.setProperty(key, after) + vision.setProperty(key, after) } } //remember old config reference to cleanup listeners @@ -51,7 +51,7 @@ class VisualObjectEditorFragment(val selector: (Vision) -> Meta) : Fragment() { } } - private val styleBoxProperty: Binding = configProperty.objectBinding() { + private val styleBoxProperty: Binding = configProperty.objectBinding { VBox().apply { item?.styles?.forEach { styleName -> val styleMeta = item?.getStyle(styleName) diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectTreeFragment.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectTreeFragment.kt index f1faaf1a..2fa6cee1 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectTreeFragment.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/editor/VisualObjectTreeFragment.kt @@ -3,6 +3,7 @@ package space.kscience.visionforge.editor import javafx.beans.property.SimpleObjectProperty import javafx.scene.control.SelectionMode import javafx.scene.control.TreeItem +import javafx.scene.layout.VBox import space.kscience.visionforge.Vision import space.kscience.visionforge.VisionGroup import tornadofx.* @@ -29,13 +30,13 @@ private fun toTreeItem(vision: Vision, title: String): TreeItem() - var item: Vision? by itemProperty +public class VisualObjectTreeFragment : Fragment() { + public val itemProperty: SimpleObjectProperty = SimpleObjectProperty() + public var item: Vision? by itemProperty - val selectedProperty = SimpleObjectProperty() + public val selectedProperty: SimpleObjectProperty = SimpleObjectProperty() - override val root = vbox { + override val root: VBox = vbox { titledpane("Object tree", collapsible = false) { treeview> { cellFormat { @@ -47,7 +48,9 @@ class VisualObjectTreeFragment : Fragment() { } } selectionModel.selectionMode = SelectionMode.SINGLE - val selectedValue = selectionModel.selectedItemProperty().objectBinding { it?.value?.second } + val selectedValue = selectionModel.selectedItemProperty().objectBinding { + it?.value?.second + } selectedProperty.bind(selectedValue) } } diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt index f843e02c..d46bab32 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt @@ -23,7 +23,7 @@ import kotlin.collections.set import kotlin.math.PI import kotlin.reflect.KClass -class FX3DPlugin : AbstractPlugin() { +public class FX3DPlugin : AbstractPlugin() { override val tag: PluginTag get() = Companion.tag private val objectFactories = HashMap, FX3DFactory<*>>() @@ -42,7 +42,7 @@ class FX3DPlugin : AbstractPlugin() { as FX3DFactory? } - fun buildNode(obj: Solid): Node { + public fun buildNode(obj: Solid): Node { val binding = VisualObjectFXBinding(this, obj) return when (obj) { is SolidReferenceGroup -> referenceFactory(obj, binding) @@ -149,7 +149,7 @@ public interface FX3DFactory { public operator fun invoke(obj: T, binding: VisualObjectFXBinding): Node public companion object { - public const val TYPE = "fx3DFactory" + public const val TYPE: String = "fx3DFactory" } } diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXReferenceFactory.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXReferenceFactory.kt index dc72f7f1..022900df 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXReferenceFactory.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXReferenceFactory.kt @@ -7,7 +7,7 @@ import space.kscience.visionforge.Vision import space.kscience.visionforge.onPropertyChange import kotlin.reflect.KClass -class FXReferenceFactory(val plugin: FX3DPlugin) : FX3DFactory { +public class FXReferenceFactory(public val plugin: FX3DPlugin) : FX3DFactory { override val type: KClass get() = SolidReferenceGroup::class override fun invoke(obj: SolidReferenceGroup, binding: VisualObjectFXBinding): Node { diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/VisualObjectFXBinding.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/VisualObjectFXBinding.kt index 5045a375..a2f41fbe 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/VisualObjectFXBinding.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/VisualObjectFXBinding.kt @@ -14,7 +14,7 @@ import tornadofx.* /** * A caching binding collection for [Vision] properties */ -public class VisualObjectFXBinding(public val fx: FX3DPlugin, public val obj: Vision) { +public class VisualObjectFXBinding(private val fx: FX3DPlugin, public val obj: Vision) { private val bindings = HashMap>() init { @@ -33,15 +33,13 @@ public class VisualObjectFXBinding(public val fx: FX3DPlugin, public val obj: Vi } } - public operator fun get(key: Name): ObjectBinding { - return bindings.getOrPut(key) { - object : ObjectBinding() { - override fun computeValue(): MetaItem? = obj.getProperty(key) - } + public operator fun get(key: Name): ObjectBinding = bindings.getOrPut(key) { + object : ObjectBinding() { + override fun computeValue(): MetaItem? = obj.getProperty(key) } } - public operator fun get(key: String) = get(key.toName()) + public operator fun get(key: String): ObjectBinding?> = get(key.toName()) } public fun ObjectBinding.value(): Binding = objectBinding { it.value }