This page is no longer maintained — Please continue to the home page at www.scala-lang.org

RE: "Scala FX" and properties

2 replies
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Isn't that what Sun's scenegraph/scenario project is?
As far as binding to dependencies, if I understood the source code Ingo has an ingenious solution in his ScalaFX project, using a stack.
There are two problems. How to recalculate the expression later is solved by using by name parameters.
The big problem is knowing when to recalculate. The answer is whenever a bindable dependency changes, but how do you know when that occurs? What objects do you listen to?
If the binding assignment operator prepares a thread-local stack, and every bindable property read puts itself on the stack, then the binder can know which properties were read from in this thread between the beginning and end of evaluating the expression. Simple, and ingenious!



From: Scot McSweeney-Roberts <maethorechannen [at] googlemail [dot] com>
Sent: Monday, June 22, 2009 9:30 AM
To: scala-debate [at] listes [dot] epfl [dot] ch
Subject: [scala-debate] "Scala FX" and properties

> did I understand it correctly, that Scala couldn't be used as a direct alternative to Java FX Script?
I think there are a couple of problems with using Scala as direct alternative to JavaFXScript. The biggest problem I can think of (and which affects both desktop and mobile JavaFX profiles) is that there doesn't appear to be any documentation for how Java code can access the JavaFX runtime. I haven't been able to find any such docs, but if they existed then it might be possible to just use Scala in place of Java, at least on the desktop. The mobile profile presents even more of a challenge as it's meant to run on top of JavaME. I don't think Scala has ever worked on JavaME (I could be wrong, but that was the last thing I heard) and if 2.8 is dropping JDK 1.4 support then it certainly won't be possible.
>  I think that Scala is powerful enough so it should be possible to wrap properties into a class that allows you to bind them; i.e. when one property of one object changes (e.g. a check box is toggled) then another property of a different object changes as well (e.g. a boolean property of a business model object). In Java FX Script, this feature is a very fundamental part of the language, automatically enabled for all properties, but not so in Scala. 
I haven't been able to replicate JavaFXScript's binding style in Scala - no matter what I try the variable/value on the LHS of the bind takes the value of the variable on the RHS at the time of binding and never changes. Maybe somebody else can come up with a way to do it - if so I'd love to see how to do it, as I'm stumped. And that was just variable binding - bound functions and replace triggers are probably even more of challenge. To be honest though, I haven't yet found any real use for JavaFXScript's data binding - but that could be because the docs don't really show it being used in any meaningful way.
As an aside, I really wish the JavaFXScript developers would have used Scala style syntax for things like vals (which in JavaFXScript are "def"s) and traits (which are defined by preceding class with "mixin"), had made semicolons optional and had used any other syntax than the one chosen for appending values to sequences ("insert x into xs;" - yuck). Had they done so, then JavaFXScript might have been a good stepping stone to Scala. 
Scot McSweeney-...
Joined: 2009-06-22,
User offline. Last seen 42 years 45 weeks ago.
Re: "Scala FX" and properties


On Mon, Jun 22, 2009 at 17:55, Naftoli Gugenheim <naftoligug [at] gmail [dot] com> wrote:
Isn't that what Sun's scenegraph/scenario project is?


From what I can gather from the project site, scenegraph is/was a way for Java code to access the same scenegraph code JavaFX was using as opposed to a full Java <-> JavaFX bridge. The project looks dead - there's no mention of JavaFX 1.2, there haven't been any code commits since September 2008 and there's no mention of it on the JavaFX site (where the Learn JavaFX page has an almost empty section on "JavaFX, Java, Javascript"). To top things off - it's GPL without the classpath exception, which could be quite restricting.

However, I've found this post on using JavaFX 1.2's scenario.jar in Java
http://lqd.hybird.org/journal/?p=147

And there's an interesting article on using JavaFX's binding mechanism in java here -
http://today.java.net/pub/a/today/2009/06/02/hacking-javafx-binding.html


So it probably is possible to use Scala as a JavaFXScript replacement (at least on the Desktop), if you're willing to spend quality time with Google.

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: "Scala FX" and properties
This scenario 1.2 is in the JavaFX SDK? Where?The binding doesn't sound like it's anything you can't write in scala in less lines than it takes to use the other binding frameworks, thanks to update and apply syntactic sugar. Correct me if I'm wrong. I actually started working on such a framework, including support for states and animation. It's amazing what you can do in scala in only a few lines, but I don't know how much time I have to take it further, and besides which whatever time I would have I might as well invest in ScalaFX. But I'll attach what I did so far.


On Mon, Jun 22, 2009 at 4:13 PM, Scot McSweeney-Roberts <maethorechannen [at] googlemail [dot] com> wrote:


On Mon, Jun 22, 2009 at 17:55, Naftoli Gugenheim <naftoligug [at] gmail [dot] com> wrote:
Isn't that what Sun's scenegraph/scenario project is?


From what I can gather from the project site, scenegraph is/was a way for Java code to access the same scenegraph code JavaFX was using as opposed to a full Java <-> JavaFX bridge. The project looks dead - there's no mention of JavaFX 1.2, there haven't been any code commits since September 2008 and there's no mention of it on the JavaFX site (where the Learn JavaFX page has an almost empty section on "JavaFX, Java, Javascript"). To top things off - it's GPL without the classpath exception, which could be quite restricting.

However, I've found this post on using JavaFX 1.2's scenario.jar in Java
http://lqd.hybird.org/journal/?p=147

And there's an interesting article on using JavaFX's binding mechanism in java here -
http://today.java.net/pub/a/today/2009/06/02/hacking-javafx-binding.html


So it probably is possible to use Scala as a JavaFXScript replacement (at least on the Desktop), if you're willing to spend quality time with Google.


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland