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

org.marid.fx.extensions.ConcurrentPropertiesExtensions.kt Maven / Gradle / Ivy

There is a newer version: 0.9.8.10
Show newest version
package org.marid.fx.extensions

import javafx.application.Platform
import javafx.beans.binding.IntegerBinding
import javafx.beans.value.*
import java.util.concurrent.CompletableFuture

typealias ObservableIntValue = ObservableIntegerValue
typealias IntBinding = IntegerBinding

val ObservableIntegerValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(get())
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(get()) }
    future
  }

val ObservableLongValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(get())
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(get()) }
    future
  }

val ObservableFloatValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(get())
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(get()) }
    future
  }

val ObservableDoubleValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(get())
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(get()) }
    future
  }

val ObservableStringValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(get())
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(get()) }
    future
  }

val ObservableBooleanValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(get())
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(get()) }
    future
  }

val  ObservableValue.safe: CompletableFuture
  get() = if (Platform.isFxApplicationThread()) {
    CompletableFuture.completedFuture(value)
  } else {
    val future = CompletableFuture()
    Platform.runLater { future.complete(value) }
    future
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy