Swing application framework

Here are examples of Swing codes based on Swing Application Framework.

Actions

File org.chorem.jtimer.test.SafTest1.java:

public void SafTest1 extends SingleFrameApplication {

    public JButton helloWorldButton;

    public static void main(String[] args) {
        launch(SafTest1.class, args);
    }

    @Action
    public void helloWorld() {
        System.out.prinln("Hello world");
    }

    @Override
    public void initialize() {
        helloWorldButton = new JButton();
        helloWorldButton.setAction(getAction("helloWorld");
    }

    @Override
    public void ready() {
        show(helloWorldButton);
    }
}

File org/chorem/jtimer/test/resources/SafTest1.properties:

Application.title = Test 1
Application.id = saftest1

helloWorld.Action.text=Say hello
helloWorld.Action.shortDescription=Click me to say hello

I18N

To translate previous example, in french for example, just create a properties file suffixed by the locale containing translated strings.

File org/chorem/jtimer/test/resources/SafTest1_fr.properties:

helloWorld.Action.text=Dit bonjour
helloWorld.Action.shortDescription=Cliquer pour dire bonjour !

Bindings

We can how bind some properties to swing elements. This bindings have to be set in action annotation, this properties concern all element bind on this action.

File org.chorem.jtimer.test.SafTest2.java:

public void SafTest2 extends SingleFrameApplication {

    public JButton helloWorldButton;

    public static void main(String[] args) {
        launch(SafTest1.class, args);
    }

    public boolean isActive() {
        return false;
    }

    @Action(enabledProperty="active")
    public void helloWorld() {
        System.out.prinln("Hello world");
    }

    @Override
    public void initialize() {
        helloWorldButton = new JButton();
        helloWorldButton.setAction(getAction("helloWorld");
    }

    @Override
    public void ready() {
        show(helloWorldButton);
    }
}