Skip to main content

How to rewrite this code for JavaFX 2.2

No replies
rcbandit
Offline
Joined: 2011-07-19
Points: 0

Can you help me to rewrite this source code for JavaFX 2.2

Source http://d.hatena.ne.jp/bluepapa32/20091020/1256058875

import java.lang.Thread;

import javafx.async.Task;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.HBox;
import javafx.scene.layout.LayoutInfo;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import com.bluepapa32.async.ActionTask;
import com.bluepapa32.async.ProgressTask;

import net.sf.libgrowl.Application;
import net.sf.libgrowl.GrowlConnector;
import net.sf.libgrowl.Notification;
import net.sf.libgrowl.NotificationType;

       
var task: Task;

Stage {
  title: "Use Growl in Javafx"
  width: 260
  height: 100
  scene: Scene {
    content: VBox {
      translateX: 10, translateY: 10
      spacing: 10
      content: [
        HBox {
          spacing: 5
          content:[
            ProgressBar {
                progress: bind task.percentDone / 100
                layoutInfo: LayoutInfo { width: 200 }
            }
            Label { text: bind "{task.percentDone as Integer} %"; }
          ]
        }
        HBox {
          spacing: 10
          content: [
            Button { text: "Start",  action: start,  disable: bind started() }
            Button { text: "Cancel", action: cancel, disable: bind not started() }
          ]
        }
      ]
    }
  }
}

function start(): Void {
    task = ProgressTask { task: GrowlTask {} }
    task.start();
}

function cancel(): Void {
    task.stop();
}

bound function started(): Boolean {
    task.started and not task.stopped and not task.done
}

class GrowlTask extends ActionTask {

    def COMPLETE = new NotificationType("COMPLETE", "Sample Complete");

    init {

        var application = new Application("Growl on JavaFX");
        application.setIcon("http://duke.kenai.com/iconSized/duke.gif");

        var growl = new GrowlConnector();
        growl.register(application, [ COMPLETE ]);

        action = function() {
            this.progress = 0;
            this.maxProgress = 100;
            for (progress in [1..100]) {
                Thread.sleep(50);
                this.progress = progress;
            }
        }
        onDone = function() {
            growl.notify(new Notification(
                                application, COMPLETE,
                                "Hello, World!!", "My name is Duke!"));
        }
    }
}