All Projects → svenefftinge → xtendfx

svenefftinge / xtendfx

Licence: other
JavaFX on steroids with Eclipse Xtend

Programming Languages

Xtend
68 projects
java
68154 projects - #9 most used programming language

XtendFX

XtendFX is a little library making JavaFX programming in Java and Xtend a joy. Here's the typical JavaFX hello world written in Xtend :

@FXApp class HelloWorldXtend {
  override void start(Stage it) {
    title = "Hello World!"
    scene = new Scene(new StackPane => [
      children += new Button => [
        text = "Say 'Hello World'"
        onAction = [
          println("Hello World!")
        ]
      ]
    ], 300, 250)
    show
  }
}

The annotation @FXApp will make the class extend javafx.application.Application and adds a main method. The operator => lets you pass lambda expressions (the blocks in square brackets) to an expression. With a constructor this makes for a nice builder pattern. Lambdas are also handy listener for events (see onAction).

Note that besides @FXApp this is just raw JavaFX + Xtend. Let's see how XtendFX can improve on that.

FX Beans

Writing JavaFX conformant java beans is super tedious: You need to declare two fields and three methods per property! With XtendFX you can use the @FXBindable annotation and get the boilerplate eliminated automatically:

/**
 * A login bean written in Xtend.
 */
@FXBindable class LoginBeanXtend {
  String userName = ""
	String password
}

XtendFX already supports readonly and lazy properties, but it's also very easy to build your own active annotation and make it tailored to your specific needs. See active annotations.

Data Binding

The JavaFX databinding framework is awesome but programming it with Java a real pain. XtendFX let's you replace the following Java:

// JAVA CODE!
startButton.disableProperty().bind(anim.statusProperty().isNotEqualTo(Animation.Status.STOPPED));
pauseButton.disableProperty().bind(anim.statusProperty().isNotEqualTo(Animation.Status.RUNNING));
resumeButton.disableProperty().bind(anim.statusProperty().isNotEqualTo(Animation.Status.PAUSED));
stopButton.disableProperty().bind(anim.statusProperty().isEqualTo(Animation.Status.STOPPED));

with this :

startButton.disableProperty  -> (anim.statusProperty != STOPPED)
pauseButton.disableProperty  -> (anim.statusProperty != RUNNING)
resumeButton.disableProperty -> (anim.statusProperty != PAUSED)
stopButton.disableProperty   -> (anim.statusProperty == STOPPED)

this only needs the correct static extension:

import static extension xtendfx.beans.binding.BindingExtensions.*

More Examples

Here's the full code the three small examples:

Btw. we are looking for creative and smart people who want to join the party!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].