An example of JavaFX
This is a really simple thing I wrapped up in a couple of minutes. It doesn't show much, and certainly isn't very flashy, but it does show some main points I wanted to share about my 5-minutes experience with JFX.
By the way, this code can be just taken as is and put directly into the JavaFX Pad.
import javafx.ui.*;
import javafx.ui.canvas.*;
class Person {
attribute name:String ;
attribute parent:Person inverse Person.children;
attribute children:Person* inverse Person.parent;
attribute gender:String;
}
Canvas {
var father = Person { name:"George", gender:"Male" }
var jen = Person {name:"Jennifer", parent:father, gender: "Female" }
var matt = Person { name:"Matt", parent:father, gender:"Male" }
var lara = Person {name:"Lara", parent:father, gender: "Female" }
content: select Text {content: p.name y:indexof p * 15}
from p in father.children
where p.gender == "Female"
}
The points I want to show off:
- No need to update the "children" attribute: Notice that I do not update the
childrenattribute ofdad. Sincechildrenandparentare defined to beinverseto one another, just specifying who the parent is is enough. - Creating graphical elements is easy: I can create graphical elements using a
selectstatement on the array of items I have in my data model, and use their attributes as values to the elements. It's that simple - I create three elements here with one line of code, and I could create complex queries using joins andwhereclauses.
Text elements. I changed the creation to be like this:
Text {
var x1:Number = 0
var y1:Number = indexof p * 15 + 20
content: p.name
x:bind x1
y:bind y1
cursor:HAND
onMouseDragged:operation(e:CanvasMouseEvent) {
x1 += e.localDragTranslation.x;
y1 += e.localDragTranslation.y;
}
But, it didn't work! It did change the cursor to "Hand" when the mouse was over an element, but it didn't make the drag work. I can't imagine why - In an example on the openjfx.org site something similar was made, but there they used subclassing and adding attributes instead of adding variables dynamically like I chose to do here. Maybe that's the case; but it really isn't clear. If anyone has an idea, please let me know!
Comments (11)
CompositeNodeand it wasn't at all clear that this was the requirement.