From 883ddcc81621a187e4a13930729adf8343782907 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Fri, 23 Oct 2020 03:01:50 +0300 Subject: [PATCH] init commit --- .classpath | 7 ++ .gitignore | 1 + .idea/.gitignore | 3 + .idea/artifacts/JavaFXApp.xml | 15 ++++ .idea/compiler.xml | 23 ++++++ .idea/description.html | 2 + .idea/encodings.xml | 6 ++ .idea/gradle.xml | 4 + .idea/libraries/javafx_base.xml | 11 +++ .idea/misc.xml | 9 +++ .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 125 ++++++++++++++++++++++++++++++++ .idea/vcs.xml | 6 ++ .project | 15 ++++ fx1.eml | 9 +++ fx1.iml | 12 +++ src/sample/Main.java | 28 +++++++ src/sample/StreetsPane.java | 65 +++++++++++++++++ 18 files changed, 349 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/JavaFXApp.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/description.html create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/libraries/javafx_base.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 .project create mode 100644 fx1.eml create mode 100644 fx1.iml create mode 100644 src/sample/Main.java create mode 100644 src/sample/StreetsPane.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3fa64fa --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89f9ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/artifacts/JavaFXApp.xml b/.idea/artifacts/JavaFXApp.xml new file mode 100644 index 0000000..7106138 --- /dev/null +++ b/.idea/artifacts/JavaFXApp.xml @@ -0,0 +1,15 @@ + + + $PROJECT_DIR$/out/artifacts/JavaFXApp + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..cc10d56 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1,2 @@ +Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided. + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..3e3960b --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/javafx_base.xml b/.idea/libraries/javafx_base.xml new file mode 100644 index 0000000..3b0fab9 --- /dev/null +++ b/.idea/libraries/javafx_base.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b8ef383 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..297ecab --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..3ff802d --- /dev/null +++ b/.project @@ -0,0 +1,15 @@ + + + fx1 + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.jdt.core.javanature + + diff --git a/fx1.eml b/fx1.eml new file mode 100644 index 0000000..033ad7c --- /dev/null +++ b/fx1.eml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/fx1.iml b/fx1.iml new file mode 100644 index 0000000..88c172a --- /dev/null +++ b/fx1.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/sample/Main.java b/src/sample/Main.java new file mode 100644 index 0000000..9e56583 --- /dev/null +++ b/src/sample/Main.java @@ -0,0 +1,28 @@ +package sample; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.input.MouseButton; +import javafx.stage.Stage; + +public class Main extends Application { + + @Override + public void start(Stage primaryStage) throws Exception{ + //Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); + StreetsPane root = new StreetsPane(); + root.setFocusTraversable(true); + primaryStage.setTitle("Street View"); + primaryStage.setScene(new Scene(root, 300, 275)); + primaryStage.show(); + System.out.println("Started application"); + root.drawStreet();//Made this because root/Pane width/height is -1 before show() + root.placeBallOnStreet(); + + } + + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/sample/StreetsPane.java b/src/sample/StreetsPane.java new file mode 100644 index 0000000..829cb42 --- /dev/null +++ b/src/sample/StreetsPane.java @@ -0,0 +1,65 @@ +package sample; + +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Line; +import javafx.util.Duration; + +public class StreetsPane extends Pane { + + private Circle dummyBus; + private Line dummyStreetLine; + private double streetDistance;//not needed + private Timeline animation; + private boolean moveable = true; + + public StreetsPane() { + super(); + dummyBus = new Circle(); + dummyBus.setFill(Color.BLUE); + dummyBus.setRadius(10); + dummyStreetLine = new Line(); + dummyStreetLine.setFill(Color.BLACK); + getChildren().addAll(dummyStreetLine, dummyBus); + animation = new Timeline(new KeyFrame(Duration.millis(100), e -> { + if (isMoveable()) moveBus(); + else System.out.println("not movable"); + })); + animation.setCycleCount(-1); + animation.play(); + } + + void placeBallOnStreet(){ + dummyBus.setCenterX(dummyStreetLine.getStartX()); + dummyBus.setCenterY(dummyStreetLine.getStartY()); + } + + void moveBus(){ + System.out.println("moving bus"); + if (dummyBus.getCenterX() < dummyStreetLine.getEndX()){ + double oldX = dummyBus.getCenterX(); + double newX = dummyBus.getCenterX() + 1; + dummyBus.setCenterX(newX); + System.out.printf("Bus moved from %f to %f\n", oldX, newX); + } + else { + moveable = false; + animation.stop(); + System.out.println("Bus reached Dist"); + } + } + + void drawStreet(){ + dummyStreetLine.setStartY(this.getHeight()/2); + dummyStreetLine.setEndY(this.getHeight()/2); + dummyStreetLine.setStartX(this.getWidth()*0.2); + dummyStreetLine.setEndX(this.getWidth()*0.8); + streetDistance = dummyStreetLine.getEndX() - dummyStreetLine.getStartX(); + + } + + public boolean isMoveable() { return moveable; } +}