You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

  1. // package org.gerweck.scalafx.util
  2. // package prefs
  3. // import java.util.prefs._
  4. // import scalafx.application.Platform.runLater
  5. // import scalafx.beans.property.ObjectProperty
  6. // import org.gerweck.scala.util.prefs._
  7. // /* TODO: take an implicit that will deteremine whether this is an `ObjectProperty` or what */
  8. // class ObservablePref[A] protected (path: String)(implicit handler: Pref.AccessHandler[A], prefs: Preferences)
  9. // extends Pref[A](path) { thisPref =>
  10. // lazy val observe: ObjectProperty[A] = {
  11. // val initialValue: A = this()
  12. // val property = ObjectProperty[A](initialValue)
  13. // /* We build two bridges, one that listens for changes in the preferences system and pushes
  14. // * them into the observable property, and another that listens for updates to the property and
  15. // * pushes them to the preference system. Each bridge is gated so that it only activates if the
  16. // * value has actually changed, which prevents the infinite looping that would otherwise occur
  17. // * in a bidirectional bridge. */
  18. // /* Preferences => Property bridge */
  19. // /* In Scala 2.12, the callback could just be bare inside `addPreferenceChangeListener`.
  20. // * However, it must be created explicitly since we cross-compile against Scala 2.11. */
  21. // val changeListener = new PreferenceChangeListener {
  22. // def preferenceChange(pce: PreferenceChangeEvent): Unit = {
  23. // if (pce.getKey == path) {
  24. // runLater {
  25. // val currentValue = thisPref()
  26. // if (property.value != currentValue) {
  27. // property.value = currentValue
  28. // }
  29. // }
  30. // }
  31. // }
  32. // }
  33. // prefs.addPreferenceChangeListener(changeListener)
  34. // /* Property => Preferences bridge */
  35. // property.onChange { (_, _, newV) =>
  36. // if (newV != this()) {
  37. // this() = newV
  38. // }
  39. // }
  40. // /* Return the bridged property */
  41. // property
  42. // }
  43. // }
  44. // object ObservablePref {
  45. // def apply[A](path: String)(implicit handler: PrefHandler[A], prefs: Preferences) = {
  46. // new ObservablePref(path)(new Pref.AccessHandler.Optional, prefs)
  47. // }
  48. // def apply[A](path: String, default: A)(implicit handler: PrefHandler[A], prefs: Preferences) = {
  49. // new ObservablePref(path)(new Pref.AccessHandler.Defaulted(default), prefs)
  50. // }
  51. // }