Another JavaFX example: The editable label
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" }
Comments (2)