Skip to content

Commit

Permalink
initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mas0061 committed Sep 21, 2012
0 parents commit 3352e38
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="at.bestsolution.efxclipse.tooling.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JavaFXConcurrentSample</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions build.fxbuild
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<Void> 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<Void>() {
@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");
}

}
26 changes: 26 additions & 0 deletions src/net/mas0061/javafx/sample/concurrent/ConcurrentSampleMain.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions src/net/mas0061/javafx/sample/concurrent/concurrent.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="206.0" prefWidth="427.0" xmlns:fx="http://javafx.com/fxml" fx:controller="net.mas0061.javafx.sample.concurrent.ConcurrentSampleControl">
<!-- TODO Add Nodes -->
<children>
<Button fx:id="pushButton" layoutX="277.0" layoutY="131.0" mnemonicParsing="false" onAction="#push" text="Push!" />
<ProgressBar fx:id="sampleBar" layoutX="52.0" layoutY="47.0" prefWidth="282.0" progress="0.0" />
<Label fx:id="msgLabel" layoutX="52.0" layoutY="92.0" prefWidth="282.0" />
<Button fx:id="startButton" layoutX="52.0" layoutY="131.0" mnemonicParsing="false" onAction="#start" text="Start" />
<ProgressIndicator fx:id="sampleIndicator" layoutX="352.0" layoutY="38.0" progress="0.0" />
<Button fx:id="stopButton" layoutX="121.0" layoutY="131.0" mnemonicParsing="false" onAction="#stop" text="Stop" />
</children>
</AnchorPane>

0 comments on commit 3352e38

Please sign in to comment.