From 0c1590199ffa72513959430c0f227506e7678d8e Mon Sep 17 00:00:00 2001 From: Evgeniy Merjey Date: Wed, 19 Oct 2016 14:42:55 +0300 Subject: [PATCH] MainClass and Controller no longer linked --- .gitignore | 104 +++++++++--------- .../github/merjey/scrambler/MainClass.java | 11 +- .../merjey/scrambler/gui/Controller.java | 18 ++- .../merjey/scrambler/gui/Scrambler.fxml | 8 +- 4 files changed, 66 insertions(+), 75 deletions(-) diff --git a/.gitignore b/.gitignore index 32b80d8..b82a75f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,53 +1,53 @@ -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders -build/ -*.fxbuild -build.fxbuild - -# Eclipse Core -.project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders +build/ +*.fxbuild +build.fxbuild + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders .recommenders/ \ No newline at end of file diff --git a/src/com/github/merjey/scrambler/MainClass.java b/src/com/github/merjey/scrambler/MainClass.java index 0146d5a..ce096d9 100644 --- a/src/com/github/merjey/scrambler/MainClass.java +++ b/src/com/github/merjey/scrambler/MainClass.java @@ -2,8 +2,6 @@ import java.io.IOException; -import com.github.merjey.scrambler.gui.Controller; - import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; @@ -18,8 +16,7 @@ public class MainClass extends Application { private Stage primaryStage; private AnchorPane rootLayout; - private Controller controller; - + @Override public void start(Stage pS) { primaryStage = pS; @@ -31,18 +28,12 @@ public void start(Stage pS) { rootLayout = (AnchorPane) loader.load(); Scene scene = new Scene(rootLayout); primaryStage.setScene(scene); - controller = loader.getController(); - controller.setMainClass(this); primaryStage.show(); } catch (IOException e) { e.printStackTrace(); } } - public Stage getPrimaryStage() { - return primaryStage; - } - public static void main(String[] args) { launch(args); } diff --git a/src/com/github/merjey/scrambler/gui/Controller.java b/src/com/github/merjey/scrambler/gui/Controller.java index ee5f80e..31d61d0 100644 --- a/src/com/github/merjey/scrambler/gui/Controller.java +++ b/src/com/github/merjey/scrambler/gui/Controller.java @@ -5,12 +5,11 @@ import java.io.File; import java.util.Locale; -import com.github.merjey.scrambler.MainClass; - import javafx.fxml.FXML; import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.Alert.AlertType; +import javafx.scene.layout.AnchorPane; import javafx.stage.FileChooser; public class Controller { @@ -18,7 +17,8 @@ public class Controller { private Button encrypt; @FXML private Button decrypt; - private MainClass mainClass; + @FXML + private AnchorPane rootLayout; private Double startTime, ellapsedTime; public Controller() { @@ -45,12 +45,12 @@ public void decryptPressed() { private File openFile() { FileChooser fileChooser = new FileChooser(); - File file = fileChooser.showOpenDialog(mainClass.getPrimaryStage()); + File file = fileChooser.showOpenDialog(rootLayout.getScene().getWindow()); if (file.length()>54000000){ Alert alert; String s = "Are supported only files up to 50 MB"; alert = new Alert(AlertType.WARNING); - alert.initOwner(mainClass.getPrimaryStage()); + alert.initOwner(rootLayout.getScene().getWindow()); alert.setTitle("Scrambler"); alert.setHeaderText("Too big file"); alert.setContentText(s); @@ -86,7 +86,7 @@ private void showSummary(String operation, boolean success) { if (success) { String s = String.format(Locale.ENGLISH, "%s was successfully completed in %.2f seconds.", operation, ellapsedTime); alert = new Alert(AlertType.INFORMATION); - alert.initOwner(mainClass.getPrimaryStage()); + alert.initOwner(rootLayout.getScene().getWindow()); alert.setTitle("Scrambler"); alert.setHeaderText("Success"); alert.setContentText(s); @@ -95,7 +95,7 @@ private void showSummary(String operation, boolean success) { String s = String.format("%s was not completed due to an error. Perhaps you try to "+ "decipher an unencrypted file or do not have access to the file.", operation); alert = new Alert(AlertType.ERROR); - alert.initOwner(mainClass.getPrimaryStage()); + alert.initOwner(rootLayout.getScene().getWindow()); alert.setTitle("Scrambler"); alert.setHeaderText("Error"); alert.setContentText(s); @@ -103,8 +103,4 @@ private void showSummary(String operation, boolean success) { } } - public void setMainClass(MainClass mC) { - mainClass=mC; - } - } diff --git a/src/com/github/merjey/scrambler/gui/Scrambler.fxml b/src/com/github/merjey/scrambler/gui/Scrambler.fxml index 5c8b523..abef605 100644 --- a/src/com/github/merjey/scrambler/gui/Scrambler.fxml +++ b/src/com/github/merjey/scrambler/gui/Scrambler.fxml @@ -1,11 +1,15 @@ + - +