From 4c3be08ec81a639a8549e1f28bc81fba2593c89b Mon Sep 17 00:00:00 2001 From: Ivan Olexyn Date: Sat, 7 Mar 2020 18:19:59 +0100 Subject: [PATCH] - Add and Remove Buttons manipulate logic as intended. - UI moved to separate package. --- src/com/olexyn/ensync/Flow.java | 8 ++- src/com/olexyn/ensync/Main.java | 21 +++----- src/com/olexyn/ensync/artifacts/Sync.java | 11 ++++ .../ensync/artifacts/SyncDirectory.java | 31 ++--------- src/com/olexyn/ensync/artifacts/SyncMap.java | 3 ++ src/com/olexyn/ensync/saved_directories.xml | 11 ++++ .../olexyn/ensync/{ => ui}/Controller.java | 54 ++++++++++++++++--- src/com/olexyn/ensync/ui/UI.java | 39 ++++++++++++++ src/com/olexyn/ensync/{ => ui}/layout.fxml | 2 +- 9 files changed, 125 insertions(+), 55 deletions(-) create mode 100644 src/com/olexyn/ensync/artifacts/Sync.java create mode 100644 src/com/olexyn/ensync/saved_directories.xml rename src/com/olexyn/ensync/{ => ui}/Controller.java (72%) create mode 100644 src/com/olexyn/ensync/ui/UI.java rename src/com/olexyn/ensync/{ => ui}/layout.fxml (96%) diff --git a/src/com/olexyn/ensync/Flow.java b/src/com/olexyn/ensync/Flow.java index 5e04fd2..800a102 100644 --- a/src/com/olexyn/ensync/Flow.java +++ b/src/com/olexyn/ensync/Flow.java @@ -9,16 +9,12 @@ import java.util.Map; public class Flow { - public Flow(){ - - } public void start() { - File asdf = new File("/home/user/"); - System.out.println(asdf.lastModified()); + Tools tools = new Tools(); Execute x = new Execute(); @@ -76,4 +72,6 @@ public class Flow { } } } + + } diff --git a/src/com/olexyn/ensync/Main.java b/src/com/olexyn/ensync/Main.java index 8acbc28..54570cf 100644 --- a/src/com/olexyn/ensync/Main.java +++ b/src/com/olexyn/ensync/Main.java @@ -1,5 +1,8 @@ package com.olexyn.ensync; +import com.olexyn.ensync.artifacts.Sync; +import com.olexyn.ensync.artifacts.SyncMap; +import com.olexyn.ensync.ui.UI; import javafx.application.Application; import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; @@ -13,33 +16,25 @@ import javafx.stage.Stage; import javafx.stage.Window; -public class Main extends Application { +public class Main extends UI { + public static Sync sync = new Sync(); - @Override - public void start(Stage primaryStage) throws Exception { - Parent root = FXMLLoader.load(getClass().getResource("layout.fxml")); - Scene scene = new Scene(root, 500, 500); + public static void main(String[] args) { - primaryStage.setTitle("EnSync"); - primaryStage.setScene(scene); - primaryStage.show(); - } - - + sync.syncMaps.put("test", new SyncMap("test")); - public static void main(String[] args) { - launch(args); + UI.main(args); } } diff --git a/src/com/olexyn/ensync/artifacts/Sync.java b/src/com/olexyn/ensync/artifacts/Sync.java new file mode 100644 index 0000000..08caaee --- /dev/null +++ b/src/com/olexyn/ensync/artifacts/Sync.java @@ -0,0 +1,11 @@ +package com.olexyn.ensync.artifacts; + +import java.util.HashMap; +import java.util.Map; + +public class Sync { + + + + public Map syncMaps = new HashMap<>(); +} diff --git a/src/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/com/olexyn/ensync/artifacts/SyncDirectory.java index 62bbf41..6f9bec9 100644 --- a/src/com/olexyn/ensync/artifacts/SyncDirectory.java +++ b/src/com/olexyn/ensync/artifacts/SyncDirectory.java @@ -8,11 +8,7 @@ import java.util.*; public class SyncDirectory { - private String firstName; - private String surname; - private Date date; - private String occupation; - private double salary; + private String flowState; private SyncMap syncMap; @@ -39,14 +35,7 @@ public class SyncDirectory { } - public SyncDirectory(String firstName, String surname, Date date, String occupation, double salary){ - this.firstName = firstName; - this.surname = surname; - this.date = date; - this.occupation = occupation; - this.salary = salary; - } /** @@ -342,25 +331,11 @@ public class SyncDirectory { } - public double getSalary(){ - return 0.0; - } - - public Date getDateOfBirth(){ - return null; + public String flowState(){ + return flowState == null ? "NONE" : flowState; } - public String getFirstName(){ - return "firstName"; - } - public String getSurname(){ - return "surname"; - } - - public String getOccupation(){ - return "occupation"; - } } diff --git a/src/com/olexyn/ensync/artifacts/SyncMap.java b/src/com/olexyn/ensync/artifacts/SyncMap.java index 5f2d7f3..c201aee 100644 --- a/src/com/olexyn/ensync/artifacts/SyncMap.java +++ b/src/com/olexyn/ensync/artifacts/SyncMap.java @@ -40,6 +40,9 @@ public class SyncMap { } } + public void removeDirectory(String realPath) { + syncDirectories.remove(realPath); + } diff --git a/src/com/olexyn/ensync/saved_directories.xml b/src/com/olexyn/ensync/saved_directories.xml new file mode 100644 index 0000000..a2f56b5 --- /dev/null +++ b/src/com/olexyn/ensync/saved_directories.xml @@ -0,0 +1,11 @@ + + SyncMap1 + + SyncDirectory1 + /foo/dir + + + SyncDirectory2 + /bar/dir + + diff --git a/src/com/olexyn/ensync/Controller.java b/src/com/olexyn/ensync/ui/Controller.java similarity index 72% rename from src/com/olexyn/ensync/Controller.java rename to src/com/olexyn/ensync/ui/Controller.java index ac9d56b..f51ceac 100644 --- a/src/com/olexyn/ensync/Controller.java +++ b/src/com/olexyn/ensync/ui/Controller.java @@ -1,12 +1,12 @@ -package com.olexyn.ensync; +package com.olexyn.ensync.ui; +import com.olexyn.ensync.Main; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.TextField; -import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.scene.text.Text; import javafx.stage.DirectoryChooser; @@ -33,7 +33,6 @@ public class Controller implements Initializable { Button addDirButton = new Button("Add"); addDirButton.setId("addDirButton"); - addDirButton.setOnAction(event -> { this.addDir();}); gridPane.add(directoryField, 0, 0); @@ -46,8 +45,6 @@ public class Controller implements Initializable { } - - @FXML protected GridPane gridPane; @@ -59,7 +56,6 @@ public class Controller implements Initializable { directoryChooser.setTitle("Select Directory."); directoryChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - File dir = directoryChooser.showDialog(stage); if (dir != null) { @@ -67,15 +63,17 @@ public class Controller implements Initializable { pathTextField.setText(dir.getAbsolutePath()); pathTextField.setDisable(true); + // TODO for now there is only one SyncMap "test". + Main.sync.syncMaps.get("test").addDirectory(dir.getAbsolutePath()); + TextField stateTextField = new TextField(); stateTextField.setText("STATE"); - stateTextField.setStyle("-fx-text-fill: green"); stateTextField.setDisable(true); - Button removeButton = new Button("Remove"); removeButton.setId("removeButton" + dir.getAbsolutePath()); + removeButton.setOnAction(event -> { this.rmDir(removeButton.getId());}); List nodeList = new ArrayList<>(); @@ -120,4 +118,44 @@ public class Controller implements Initializable { } + private void rmDir(String id) { + String path = id.replace("removeButton", ""); + + Main.sync.syncMaps.get("test").removeDirectory(path); + + List nodeList = new ArrayList<>(); + + nodeList.addAll(gridPane.getChildren()); + + + for (Node node : nodeList) { + + if (node.getId() != null && node.getId().equals(id)) { + int i = nodeList.indexOf(node) - 5; + for (int j = 0; j < 5; j++) { + nodeList.remove(i); + } + break; + } + } + + gridPane.getChildren().clear(); + + int col = 0; + int row = 0; + + for (Node node : nodeList) { + + gridPane.add(node, col, row); + col++; + if (nodeList.indexOf(node) % 5 == 4) { + row++; + col = 0; + } + + } + + } + + } diff --git a/src/com/olexyn/ensync/ui/UI.java b/src/com/olexyn/ensync/ui/UI.java new file mode 100644 index 0000000..81940d5 --- /dev/null +++ b/src/com/olexyn/ensync/ui/UI.java @@ -0,0 +1,39 @@ +package com.olexyn.ensync.ui; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + + +public class UI extends Application { + + + + + + + + @Override + public void start(Stage primaryStage) throws Exception { + Parent root = FXMLLoader.load(getClass().getResource("layout.fxml")); + Scene scene = new Scene(root, 500, 500); + + + + + + primaryStage.setTitle("EnSync"); + primaryStage.setScene(scene); + primaryStage.show(); + } + + public static void main(String[] args) { + UI.launch(args); + + } + + + +} diff --git a/src/com/olexyn/ensync/layout.fxml b/src/com/olexyn/ensync/ui/layout.fxml similarity index 96% rename from src/com/olexyn/ensync/layout.fxml rename to src/com/olexyn/ensync/ui/layout.fxml index 7e3dd15..614e320 100644 --- a/src/com/olexyn/ensync/layout.fxml +++ b/src/com/olexyn/ensync/ui/layout.fxml @@ -6,7 +6,7 @@ - +