Skip to content

Commit

Permalink
MainClass and Controller no longer linked
Browse files Browse the repository at this point in the history
  • Loading branch information
Merjey committed Oct 19, 2016
1 parent 23ea74b commit 0c15901
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 75 deletions.
104 changes: 52 additions & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
11 changes: 1 addition & 10 deletions src/com/github/merjey/scrambler/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
18 changes: 7 additions & 11 deletions src/com/github/merjey/scrambler/gui/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
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 {
@FXML
private Button encrypt;
@FXML
private Button decrypt;
private MainClass mainClass;
@FXML
private AnchorPane rootLayout;
private Double startTime, ellapsedTime;

public Controller() {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -95,16 +95,12 @@ 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);
alert.showAndWait();
}
}

public void setMainClass(MainClass mC) {
mainClass=mC;
}

}
8 changes: 6 additions & 2 deletions src/com/github/merjey/scrambler/gui/Scrambler.fxml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="50.0" maxWidth="150.0" minHeight="50.0" minWidth="150.0" prefHeight="50.0" prefWidth="150.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.merjey.scrambler.gui.Controller">
<AnchorPane fx:id="rootLayout" maxHeight="50.0" maxWidth="150.0" minHeight="50.0" minWidth="150.0" prefHeight="50.0" prefWidth="150.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.merjey.scrambler.gui.Controller">
<children>
<Button fx:id="encrypt" layoutX="-1.0" layoutY="2.0" maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" onAction="#encryptPressed" prefHeight="23.0" prefWidth="148.0" text="Encrypt" textFill="RED" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="1.0" />
<Button fx:id="decrypt" layoutX="-1.0" layoutY="2.0" maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" onAction="#decryptPressed" prefHeight="23.0" prefWidth="148.0" text="Decrypt" textFill="GREEN" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" />
<Button fx:id="decrypt" layoutX="-1.0" layoutY="2.0" maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" onAction="#decryptPressed" prefHeight="23.0" prefWidth="148.0" text="Decrypt" textFill="GREEN" textOverrun="WORD_ELLIPSIS" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0">
<opaqueInsets>
<Insets />
</opaqueInsets></Button>
</children>
</AnchorPane>

0 comments on commit 0c15901

Please sign in to comment.