- Add and Remove Buttons manipulate logic as intended.

- UI moved to separate package.
pull/1/head
Ivan Olexyn 5 years ago
parent e004e6fdb7
commit 4c3be08ec8

@ -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 {
}
}
}
}

@ -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);
}
}

@ -0,0 +1,11 @@
package com.olexyn.ensync.artifacts;
import java.util.HashMap;
import java.util.Map;
public class Sync {
public Map<String, SyncMap> syncMaps = new HashMap<>();
}

@ -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";
}
}

@ -40,6 +40,9 @@ public class SyncMap {
}
}
public void removeDirectory(String realPath) {
syncDirectories.remove(realPath);
}

@ -0,0 +1,11 @@
<syncmap>
<name>SyncMap1</name>
<syncdirectory>
<name>SyncDirectory1</name>
<path>/foo/dir</path>
</syncdirectory>
<syncdirectory>
<name>SyncDirectory2</name>
<path>/bar/dir</path>
</syncdirectory>
</syncmap>

@ -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<Node> 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<Node> 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;
}
}
}
}

@ -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);
}
}

@ -6,7 +6,7 @@
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.*?>
<ScrollPane fitToHeight="true" fitToWidth="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="394.0" prefWidth="672.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.olexyn.ensync.Controller">
<ScrollPane fitToHeight="true" fitToWidth="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="394.0" prefWidth="672.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.olexyn.ensync.ui.Controller">
<content>
<GridPane fx:id="gridPane">
<columnConstraints>
Loading…
Cancel
Save