Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
/ xtendfx Public archive
forked from svenefftinge/xtendfx

JavaFX on steroids with Eclipse Xtend

Notifications You must be signed in to change notification settings

boliangt/xtendfx

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 @FXBean annotation and get the boilerplate eliminated automatically:

/**
 * A login bean written in Xtend.
 */
@FXBean 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)

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!

About

JavaFX on steroids with Eclipse Xtend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published