May 28
Here’s a little something I didn’t know before taking a loop at Chris Oliver’s Heroes example: You can hook up to the dur keyword’s iteration of an array of values, by using the (undocument) primitive unitinterval and a “normal” for loop. Example from his code:
for (unitinterval r in dur 500 fps 100) {
bookY = 420 + (r * -200);
bookOpacity = r;
bookScale = (0.8 * r);
bookRotation = -10 + (10 * r);
}
The value for r is going to be between 0 and 1 – So you will almost always have to use it with multiplication of a real value.
I suppose that in that case, you can say that the code x = [1..100] dur 500 is actually:
var x;
var arr = [1..100];
for (unitinterval s in dur 500) {
x = arr[s * sizeof arr];
}
May 26
Playing around with JavaFX I created something I was always interested in, which is a label a la Web 2.0 which, when clicked, turns into a text field for editing abilities and binds its contents with something exterior (such as the name of a person, for example).
Here’s the JFX code:
class EditableLabel extends CompositeNode {
attribute x: Number;
attribute y: Number;
attribute text: String;
attribute editing: Boolean;
operation toggle();
}
attribute EditableLabel.editing = false;
function EditableLabel.composeNode() = Group {
content: bind if editing then View {
transform: bind translate(x, y)
content: TextField {
value: bind text
action: operation() { toggle(); }
}
} else Text {
x: bind x y: bind y
content: bind text
onMousePressed: operation(e:CanvasMouseEvent) { toggle(); }
}
};
operation EditableLabel.toggle() {
editing = not editing;
}
And to use it, just create it:
EditableLabel { x: 100 y: 100 text: "Chaotic Java" }
May 25
As the discussion over JavaFX grows both in the forums and wiki I start to get a better sense of what binding requires from the Java objects. The problem with the simple case (of getters and setters) is not much different than the Java/Swing binding problem. That problem was solved by creating the JavaBeans standard, which in turn was so complex to implement that people started forgetting what it was and regarded it as a standard for properties alone, which is obviously not true.
With today’s tools things can get much simpler. Recently, Ben Galbraith posted about his use of @AspectJ to easily create JavaBeans property events. At the end of his post he even shows how, using load-time weaving, there was no need to change the code of the original class to get it JavaBeans’ events compliant. And this is the direction the Java/JFX binding should go to: Easy, no brainer binding with older code.
Continue reading »