447 lines
15 KiB
Java
447 lines
15 KiB
Java
package net.altimate.app;
|
|
|
|
import java.io.File;
|
|
import java.lang.Object;
|
|
import java.lang.Class;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Arrays;
|
|
|
|
import javafx.application.Application;
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.ListChangeListener;
|
|
import javafx.collections.ObservableList;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.event.Event;
|
|
import javafx.event.EventHandler;
|
|
import javafx.geometry.HPos;
|
|
import javafx.geometry.Insets;
|
|
import javafx.geometry.Pos;
|
|
import javafx.scene.Group;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.layout.GridPane;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.stage.Stage;
|
|
import java.io.*;
|
|
import java.util.Optional;
|
|
|
|
|
|
import static java.util.stream.Collectors.toList;
|
|
|
|
|
|
public class App extends Application {
|
|
|
|
Scene sceneHome;
|
|
Scene sceneCreate;
|
|
Scene sceneList;
|
|
|
|
public static String filesDirectory = "/home/mic/files";
|
|
|
|
|
|
|
|
|
|
public static void main(String args[]){
|
|
launch(args);
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public void start(Stage primaryStage) throws Exception {
|
|
//GridPane grid = new GridPane();
|
|
//grid.setPadding(new Insets(10, 10, 10, 10));
|
|
//grid.setVgap(5);
|
|
//grid.setHgap(5);
|
|
|
|
//Start = new Scene(grid, 600, 300);
|
|
|
|
setupSceneList(primaryStage);
|
|
setupSceneHome(primaryStage);
|
|
setupSceneCreate(primaryStage);
|
|
|
|
|
|
primaryStage.setTitle("Work out a S.M.A.R.T. Target ");
|
|
primaryStage.setScene(sceneHome);
|
|
primaryStage.show();
|
|
}
|
|
|
|
|
|
|
|
|
|
private void navigationButtons(Stage primaryStage, GridPane grid, Label label) {
|
|
|
|
StartUpCheck.checkFilesDirectory(filesDirectory);
|
|
|
|
|
|
boolean reloadValue = false;
|
|
|
|
Button home = new Button("Home");
|
|
GridPane.setConstraints(home, 0, 0);
|
|
home.setOnAction(e -> primaryStage.setScene(sceneHome));
|
|
grid.getChildren().add(home);
|
|
|
|
Button create = new Button("Create");
|
|
GridPane.setConstraints(create, 1, 0);
|
|
create.setOnAction(e -> primaryStage.setScene(sceneCreate));
|
|
grid.getChildren().add(create);
|
|
|
|
Button list = new Button("List");
|
|
GridPane.setConstraints(list, 2, 0);
|
|
//list.setOnAction(e -> primaryStage.setScene(sceneList));
|
|
grid.getChildren().add(list);
|
|
|
|
list.setOnAction(new EventHandler<ActionEvent>() {
|
|
@Override
|
|
public void handle(ActionEvent e) {
|
|
primaryStage.setScene(sceneList);
|
|
//ListFilesInDir.listFilesInDir("/home/mic/files");
|
|
}
|
|
});
|
|
|
|
}
|
|
// grid, textfieldname , textfield, TextPrefColumnCount, rowColumn, rowIndex
|
|
private void addTextfield(GridPane grid, String textFieldName, String textFieldText, int prefColumnCount, int rowColumn, int rowIndex) {
|
|
|
|
|
|
final TextField nameSmartZiel = new TextField();
|
|
nameSmartZiel.setPromptText(textFieldText);
|
|
nameSmartZiel.setPrefColumnCount(1);
|
|
GridPane.setConstraints(nameSmartZiel,rowColumn,rowIndex);
|
|
grid.getChildren().add(nameSmartZiel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setupSceneHome(Stage primaryStage) throws Exception {
|
|
GridPane grid = new GridPane();
|
|
grid.setPadding(new Insets(10, 10, 10, 10));
|
|
grid.setVgap(5);
|
|
grid.setHgap(5);
|
|
|
|
sceneHome = new Scene(grid, 600, 300);
|
|
|
|
Label label = new Label("This is the Home Scene");
|
|
|
|
navigationButtons(primaryStage, grid, label);
|
|
|
|
//Button button = new Button("Forward");
|
|
//button.setOnAction(e -> primaryStage.setScene(sceneList));
|
|
|
|
//TextField text = new TextField();
|
|
//text.setMaxWidth(100);
|
|
|
|
//layout.getChildren().addAll(label1, button);
|
|
|
|
}
|
|
|
|
public void setupSceneCreate(Stage primaryStage) throws Exception {
|
|
GridPane grid = new GridPane();
|
|
grid.setPadding(new Insets(10, 10, 10, 10));
|
|
grid.setVgap(5);
|
|
grid.setHgap(5);
|
|
|
|
sceneCreate = new Scene(grid, 600, 300);
|
|
|
|
|
|
Label label = new Label();
|
|
|
|
navigationButtons(primaryStage, grid, label);
|
|
|
|
DatePicker checkInDatePicker;
|
|
checkInDatePicker = new DatePicker();
|
|
|
|
|
|
final TextField nameSmartZiel = new TextField();
|
|
nameSmartZiel.setPromptText("Gib dm Smart Ziel einen Namen");
|
|
nameSmartZiel.setPrefColumnCount(1);
|
|
GridPane.setConstraints(nameSmartZiel,0,1);
|
|
grid.getChildren().add(nameSmartZiel);
|
|
|
|
final TextField sinnesSpezifisch = new TextField();
|
|
sinnesSpezifisch.setPromptText("wie ist es sinnespezifisch wahrnehmbar");
|
|
sinnesSpezifisch.setPrefColumnCount(1);
|
|
//sinnesSpezifisch.getText();
|
|
GridPane.setConstraints(sinnesSpezifisch, 0, 2);
|
|
grid.getChildren().add(sinnesSpezifisch);
|
|
|
|
final TextField messBar = new TextField();
|
|
messBar.setPrefColumnCount(20);
|
|
messBar.setPromptText("Wie ist es messabr, wenn Du es erreicht hat");
|
|
GridPane.setConstraints(messBar, 0, 3);
|
|
grid.getChildren().add(messBar);
|
|
|
|
final TextField attraktiv = new TextField();
|
|
attraktiv.setPrefColumnCount(20);
|
|
attraktiv.setPromptText("Ist es attraktiv?");
|
|
GridPane.setConstraints(attraktiv, 0, 4);
|
|
grid.getChildren().add(attraktiv);
|
|
|
|
final TextField realistisch = new TextField();
|
|
realistisch.setPrefColumnCount(20);
|
|
realistisch.setPromptText("Ist es realistisch selbst erreichbar ?");
|
|
GridPane.setConstraints(realistisch, 0, 5);
|
|
grid.getChildren().add(realistisch);
|
|
|
|
|
|
final Label checkInlabel = new Label("Terminiert bis");
|
|
grid.add(checkInlabel, 0, 6);
|
|
grid.add(checkInDatePicker, 0, 7);
|
|
|
|
Button submit = new Button("Submit");
|
|
GridPane.setConstraints(submit, 0, 8);
|
|
grid.getChildren().add(submit);
|
|
|
|
Button clear = new Button("Clear");
|
|
GridPane.setConstraints(clear, 1, 8);
|
|
grid.getChildren().add(clear);
|
|
|
|
submit.setOnAction(new EventHandler<ActionEvent>() {
|
|
@Override
|
|
public void handle(ActionEvent e) {
|
|
if (
|
|
(nameSmartZiel.getText() != null && !nameSmartZiel.getText().isEmpty())
|
|
&& (sinnesSpezifisch.getText() != null && !sinnesSpezifisch.getText().isEmpty())
|
|
&& (messBar.getText() != null && !messBar.getText().isEmpty())
|
|
&& (attraktiv.getText() != null && !attraktiv.getText().isEmpty())
|
|
&& (realistisch.getText() != null && !realistisch.getText().isEmpty())
|
|
) {
|
|
label.setText( nameSmartZiel.getText() + " " + sinnesSpezifisch.getText() + " " +
|
|
messBar.getText() + " " + attraktiv.getText() + " " + realistisch.getText() + ", "
|
|
+ "thanks" + checkInDatePicker.getValue());
|
|
String date = checkInDatePicker.getValue().format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
|
|
long seconds = System.currentTimeMillis() / 1000l;
|
|
String state = "open";
|
|
|
|
String[] createSmart = {
|
|
nameSmartZiel.getText() + "|" +
|
|
sinnesSpezifisch.getText() + "|" +
|
|
messBar.getText() + "|" +
|
|
attraktiv.getText() + "|" +
|
|
realistisch.getText() + "|" +
|
|
state + "|" +
|
|
seconds + "|" +
|
|
date
|
|
};
|
|
|
|
|
|
CreateFile.writeFile(filesDirectory + "/" + seconds + ".smart", createSmart);
|
|
|
|
} else {
|
|
label.setText("You have not filed out the complete form");
|
|
}
|
|
}
|
|
});
|
|
|
|
clear.setOnAction(new EventHandler<ActionEvent>() {
|
|
@Override
|
|
public void handle(ActionEvent e) {
|
|
nameSmartZiel.clear();
|
|
sinnesSpezifisch.clear();
|
|
messBar.clear();
|
|
attraktiv.clear();
|
|
realistisch.clear();
|
|
checkInlabel.setText(null);
|
|
label.setText(null);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//addTextfield(grid, "sinnesSpezifisch", "blash", 1, 1, 1);
|
|
//Button button = new Button("Home");
|
|
//button.setOnAction(e -> primaryStage.setScene(sceneHome));
|
|
//TextField text = new TextField();
|
|
//text.setMaxWidth(100);
|
|
//layout.getChildren().addAll(label1, button);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setupSceneList(Stage primaryStage) throws Exception {
|
|
|
|
|
|
GridPane grid = new GridPane();
|
|
grid.setPadding(new Insets(10, 10, 10, 10));
|
|
grid.setVgap(5);
|
|
grid.setHgap(5);
|
|
|
|
//layout.setAlignment(Pos.CENTER);
|
|
|
|
sceneList = new Scene(grid, 600, 300);
|
|
|
|
Label label = new Label();
|
|
|
|
navigationButtons(primaryStage, grid, label);
|
|
|
|
Button reload = new Button("Reload");
|
|
GridPane.setConstraints(reload, 1, 8);
|
|
grid.getChildren().add(reload);
|
|
|
|
reload.setOnAction(new EventHandler<ActionEvent>() {
|
|
@Override
|
|
public void handle(ActionEvent e) {
|
|
System.out.println("theoretischer reload des Inhaltes");
|
|
}
|
|
});
|
|
Filter filter = new Filter();
|
|
|
|
//filter.getSmartTargetName(filesDirectory);
|
|
|
|
|
|
/*
|
|
int filesDirTmpLength = ListFilesInDir.listFilesInDir(filesDirectory).length;
|
|
String filesDirTmp[] = new String[filesDirTmpLength];
|
|
filesDirTmp = ListFilesInDir.listFilesInDir(filesDirectory);
|
|
//String filesDir[][] = new String[filesDirTmpLength][filesDirTmpLength];
|
|
String filesContent[] = new String[filesDirTmpLength];
|
|
String filesShow[] = new String[filesDirTmpLength];
|
|
|
|
|
|
for (int i = 0; i < filesDirTmpLength; ++i) {
|
|
filesContent[i] = ReadFile.readFile(filesDirectory + "/" + filesDirTmp[i]);
|
|
String regex = "\\|";
|
|
String[] nameOfTarget = filesContent[i].replaceAll("^\\[", "").replaceAll("^\\]", "").split(regex);
|
|
filesShow[i] = nameOfTarget[0];
|
|
}
|
|
*/
|
|
|
|
ListView<String> list1 = new ListView<String>();
|
|
ObservableList<String> items = FXCollections.observableArrayList( filter.filterRemoveWithRegex(".smart", filesDirectory ));
|
|
//ObservableList<String> items = FXCollections.observableArrayList(Filter.getSmartTargetName(filesDirectory));
|
|
//list1.getItems().addAll(items);
|
|
//list1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
|
//list1.getSelectionModel().getSelectedItems().addListener((ListChangeListener<? super String>) c -> selectionChanged());
|
|
list1.setItems(items);
|
|
GridPane.setConstraints(list1, 0, 1);
|
|
grid.getChildren().add(list1);
|
|
|
|
//ObservableList selectedIndices = list1.getSelectionModel().getSelectedIndices();
|
|
|
|
String[] filesContent = new String[30];
|
|
filesContent[0] ="000000";
|
|
filesContent[1] ="1111111";
|
|
|
|
|
|
|
|
Button button = new Button("Read Selected Value");
|
|
GridPane.setConstraints(button, 2, 8);
|
|
grid.getChildren().add(button);
|
|
button.setOnAction(event -> {
|
|
ObservableList selectedIndices = list1.getSelectionModel().getSelectedIndices();
|
|
|
|
for(Object o : selectedIndices){
|
|
System.out.println("o = " + o + " (" + o.getClass() + ")");
|
|
System.out.println(filesContent[(int) o]);
|
|
|
|
String[] ar = filter.filterSplitValues((int) o, filesDirectory );
|
|
|
|
final TextField max = new TextField(ar[0]);
|
|
max.setPrefColumnCount(20);
|
|
max.setPromptText("max");
|
|
GridPane.setConstraints(max, 1, 1);
|
|
grid.getChildren().add(max);
|
|
|
|
|
|
//final TextField max2 = new TextField(filesContent[(int) o]);
|
|
final TextField max2 = new TextField(ar[1]);
|
|
max.setPrefColumnCount(20);
|
|
max.setPromptText("max2");
|
|
GridPane.setConstraints(max2, 1, 2);
|
|
grid.getChildren().add(max2);
|
|
|
|
final TextField max3 = new TextField(ar[2]);
|
|
max.setPrefColumnCount(20);
|
|
max.setPromptText("max3");
|
|
GridPane.setConstraints(max3, 1, 3);
|
|
grid.getChildren().add(max3);
|
|
|
|
|
|
//final TextField max2 = new TextField(filesContent[(int) o]);
|
|
final TextField max4 = new TextField(ar[3]);
|
|
max.setPrefColumnCount(20);
|
|
max.setPromptText("max4");
|
|
GridPane.setConstraints(max4, 1, 4);
|
|
grid.getChildren().add(max4);
|
|
|
|
final TextField max5 = new TextField(ar[4]);
|
|
max.setPrefColumnCount(20);
|
|
max.setPromptText("max5");
|
|
GridPane.setConstraints(max5, 1, 5);
|
|
grid.getChildren().add(max5);
|
|
|
|
|
|
//final TextField max2 = new TextField(filesContent[(int) o]);
|
|
final TextField max6 = new TextField(ar[5]);
|
|
max.setPrefColumnCount(20);
|
|
max.setPromptText("max6");
|
|
GridPane.setConstraints(max6, 1, 6);
|
|
grid.getChildren().add(max6);
|
|
|
|
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
ListView listView = new ListView();
|
|
|
|
listView.getItems().add("Item 1");
|
|
listView.getItems().add("Item 2");
|
|
listView.getItems().add("Item 3");
|
|
|
|
GridPane.setConstraints(listView, 0, 2);
|
|
grid.getChildren().add(listView);
|
|
|
|
Button button = new Button("Read Selected Value");
|
|
GridPane.setConstraints(button, 2, 8);
|
|
grid.getChildren().add(button);
|
|
|
|
button.setOnAction(event -> {
|
|
ObservableList selectedIndices = listView.getSelectionModel().getSelectedIndices();
|
|
|
|
for(Object o : selectedIndices){
|
|
System.out.println("o = " + o + " (" + o.getClass() + ")");
|
|
}
|
|
});
|
|
*/
|
|
|
|
|
|
//ListFilesInDir.listFilesInDir(filesDirectory);
|
|
//ListView<String> list1 = new ListView<String>();
|
|
//ObservableList<String> items = FXCollections.observableArrayList (ListFilesInDir.listFilesInDir(filesDirectory));
|
|
//list1.setItems(items);
|
|
//GridPane.setConstraints(list1, 0, 1);
|
|
//grid.getChildren().add(list1);
|
|
|
|
|
|
//Button button = new Button("Backward");
|
|
//button.setOnAction(e -> primaryStage.setScene(sceneHome));
|
|
|
|
//TextField text = new TextField();
|
|
//text.setMaxWidth(100);
|
|
|
|
//grid.getChildren().addAll(label, button);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|