diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..da3172b --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..10e4539 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + JavaFXConcurrentSample + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.eclipse.xtext.ui.shared.xtextNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7341ab1 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/build.fxbuild b/build.fxbuild new file mode 100644 index 0000000..993a3fb --- /dev/null +++ b/build.fxbuild @@ -0,0 +1,6 @@ +jfx.build.stagingdir = ${workspace}/JavaFXConcurrentSample/build +jfx.build.apptitle = JavaFXConcurrentSample +jfx.build.vendorname = mas0061.net +jfx.build.appversion = 1.0 +jfx.build.applicationClass = net.mas0061.javafx.sample.concurrent.ConcurrentSampleMain +jfx.deploy.nativePackage = true \ No newline at end of file diff --git a/src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleControl.java b/src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleControl.java new file mode 100644 index 0000000..39006dc --- /dev/null +++ b/src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleControl.java @@ -0,0 +1,89 @@ +package net.mas0061.javafx.sample.concurrent; + +import java.net.URL; +import java.util.ResourceBundle; + +import javafx.concurrent.Task; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ProgressBar; +import javafx.scene.control.ProgressIndicator; +import javafx.scene.paint.Color; + +public class ConcurrentSampleControl implements Initializable { + + @FXML + private Label msgLabel; + @FXML + private Button pushButton; + @FXML + private Button startButton; + @FXML + private Button stopButton; + @FXML + private ProgressBar sampleBar; + @FXML + private ProgressIndicator sampleIndicator; + + Task task; + + @Override + public void initialize(URL arg0, ResourceBundle arg1) { + msgLabel.setTextFill(Color.RED); + msgLabel.setText("initialize."); + } + + @FXML + protected void start(ActionEvent event) { + msgLabel.setTextFill(Color.BLACK); + msgLabel.setText("start"); + + if (task == null || task.isCancelled()) { + task = new Task() { + @Override + protected Void call() { + try { + for (double c = 1; c <= 100; c++) { + if (isCancelled()) { break; } + + sampleBar.setProgress(c / 100); + sampleIndicator.setProgress(c / 100); + + Thread.sleep(100); + } + } catch (InterruptedException e) { + } + + return null; + } + @Override protected void cancelled() { + super.cancelled(); + updateMessage("Cancelled!"); + } + }; + + Thread thread = new Thread(task); + thread.setDaemon(true); + thread.start(); + } + } + + @FXML + protected void stop(ActionEvent event) { + if (task != null) { + msgLabel.setTextFill(Color.BLACK); + msgLabel.setText("stop"); + task.cancel(); + } + } + + @FXML + protected void push(ActionEvent event) { + msgLabel.setTextFill(Color.BLACK); + msgLabel.setText("push"); + } + +} diff --git a/src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleMain.java b/src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleMain.java new file mode 100644 index 0000000..c6ac539 --- /dev/null +++ b/src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleMain.java @@ -0,0 +1,26 @@ +package net.mas0061.javafx.sample.concurrent; + +import java.io.IOException; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class ConcurrentSampleMain extends Application { + + @Override + public void start(Stage primaryStage) throws IOException { + primaryStage.setTitle("Concurrent sample"); + Parent root = FXMLLoader.load(getClass().getResource("concurrent.fxml")); + + Scene scene = new Scene(root); + primaryStage.setScene(scene); + primaryStage.show(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/net/mas0061/javafx/sample/concurrent/concurrent.fxml b/src/net/mas0061/javafx/sample/concurrent/concurrent.fxml new file mode 100644 index 0000000..5b257b8 --- /dev/null +++ b/src/net/mas0061/javafx/sample/concurrent/concurrent.fxml @@ -0,0 +1,18 @@ + + + + + + + + + + +