From 0257dd9bf0155cb784f54524ba5a2a7dd21d1252 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Mon, 5 Dec 2022 01:12:18 +0100 Subject: [PATCH] fxml files changes + first style --- .../CropDetailController.java | 52 +-- .../MyScheduleController.java | 19 +- .../ch/zhaw/gartenverwaltung/Settings.java | 10 + .../gartenverwaltung/SettingsController.java | 63 ++- .../ch/zhaw/gartenverwaltung/CropDetail.fxml | 57 +-- .../ch/zhaw/gartenverwaltung/Home.fxml | 415 ++++++++++-------- .../ch/zhaw/gartenverwaltung/MyGarden.fxml | 12 +- .../ch/zhaw/gartenverwaltung/MySchedule.fxml | 68 +-- .../ch/zhaw/gartenverwaltung/Plants.fxml | 156 ++++--- .../ch/zhaw/gartenverwaltung/Settings.fxml | 20 +- .../gartenverwaltung/bootstrap/styles.css | 8 +- .../ch/zhaw/gartenverwaltung/hello-view.fxml | 16 - .../ch/zhaw/gartenverwaltung/io/plantdb.json | 6 +- 13 files changed, 497 insertions(+), 405 deletions(-) delete mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/hello-view.fxml diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index c644865..8682579 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -63,15 +63,9 @@ public class CropDetailController { @FXML private Label description_label; - @FXML - private Label location_label; - @FXML private Label light_label; - @FXML - private Button location_button; - @FXML private Label soil_label; @@ -106,15 +100,7 @@ public class CropDetailController { */ @FXML void setArea() throws IOException { - openTextFieldDialog("set Text Area", "Text Area", area_label.getText(), false); - } - - /** - * open dialog to set location - */ - @FXML - void setLocation() throws IOException { - openTextFieldDialog("set Location", "Location", location_label.getText(), true); + openTextFieldDialog(); } /** @@ -138,7 +124,6 @@ public class CropDetailController { imageView.setImage(plant.image()); } area_label.setText(String.valueOf(crop.getArea())); - location_label.setText(""); setTaskListProperty(crop); taskList_listView.itemsProperty().bind(taskListProperty); @@ -152,7 +137,6 @@ public class CropDetailController { } setIconToButton(addTask_button, "addIcon.png"); setIconToButton(area_button, "areaIcon.png"); - setIconToButton(location_button, "locationIcon.png"); setCellFactoryPests(); setCellFactoryTasks(); } @@ -239,12 +223,8 @@ public class CropDetailController { Label description = new Label(pest.description()); description.setAlignment(Pos.TOP_LEFT); description.setWrapText(true); - description.setMaxWidth(600); - Pane puffer = new Pane(); - HBox.setHgrow(puffer, Priority.ALWAYS); - Button button = new Button("Get Counter Measures"); - HBox.setHgrow(button, Priority.NEVER); - hBox.getChildren().addAll(label, description, puffer, button); + description.setMaxWidth(800); + hBox.getChildren().addAll(label, description); return hBox; } @@ -319,10 +299,10 @@ public class CropDetailController { } - private void openTextFieldDialog(String title, String labelDescription, String value, boolean isLocation) throws IOException { + private void openTextFieldDialog() throws IOException { Dialog dialog = new Dialog<>(); - dialog.setTitle(title); - dialog.setHeaderText(title); + dialog.setTitle("set Text Area"); + dialog.setHeaderText("set Text Area"); dialog.setResizable(false); DialogPane dialogPane = dialog.getDialogPane(); @@ -331,26 +311,20 @@ public class CropDetailController { dialogPane.getButtonTypes().addAll(save, ButtonType.CANCEL); if (appLoader.loadPaneToDialog("TextFieldFormular.fxml", dialogPane) instanceof TextFieldFormularController controller) { - controller.setDescription_label(labelDescription); - controller.setValueTextArea(value); + controller.setDescription_label("Text Area"); + controller.setValueTextArea(area_label.getText()); controller.initSaveButton((Button) dialogPane.lookupButton(save)); dialog.setResultConverter(button -> button.equals(save) ? controller.getValue() : null); dialog.showAndWait() .ifPresent(string -> { - if (isLocation) { - System.out.println(string); - //ToDo method to set location - location_label.setText(string); - } else { - try { - garden.updateCrop(this.crop.withArea(Double.parseDouble(string))); - } catch (IOException e) { - e.printStackTrace(); - } - area_label.setText(string); + try { + garden.updateCrop(this.crop.withArea(Double.parseDouble(string))); + } catch (IOException e) { + e.printStackTrace(); } + area_label.setText(string); }); } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java index f73feb2..781b77c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java @@ -12,6 +12,8 @@ import ch.zhaw.gartenverwaltung.types.Task; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.layout.HBox; @@ -144,14 +146,15 @@ public class MyScheduleController { taskDescription.setMaxSize(600, Double.MAX_VALUE); Pane puffer = new Pane(); HBox.setHgrow(puffer, Priority.ALWAYS); - CheckBox checkBox = new CheckBox("Task completed?"); - checkBox.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (newValue) { - showConfirmation(task, checkBox); + Button button = new Button("Task completed!"); + button.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + showConfirmation(task); } }); - HBox.setHgrow(checkBox, Priority.NEVER); - hBoxDescription.getChildren().addAll(taskDescription, puffer, checkBox); + HBox.setHgrow(button, Priority.NEVER); + hBoxDescription.getChildren().addAll(taskDescription, puffer, button); vBox.getChildren().addAll(hBox, hBoxDescription); } return vBox; @@ -161,7 +164,7 @@ public class MyScheduleController { * Alert to confirm that task has been completed. * @param task {@link Task} which is selected */ - private void showConfirmation(Task task, CheckBox checkBox) { + private void showConfirmation(Task task) { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Task Completed?"); alert.setHeaderText("Are you sure you have completed this task?"); @@ -176,8 +179,6 @@ public class MyScheduleController { } catch (IOException e) { e.printStackTrace(); } - } else { - checkBox.setSelected(false); } }); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Settings.java b/src/main/java/ch/zhaw/gartenverwaltung/Settings.java index c15454c..14a1e42 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Settings.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Settings.java @@ -9,6 +9,8 @@ public class Settings { private static Settings instance; private final BooleanProperty showTutorial = new SimpleBooleanProperty(false); + private String location = ""; + static { instance = new Settings(); } @@ -38,4 +40,12 @@ public class Settings { public boolean getShowTutorial() { return this.showTutorial.get(); } + + public void setLocation(String location) { + this.location = location; + } + + public String getLocation() { + return this.location; + } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java b/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java index 9a8158f..6ad5e88 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java @@ -1,23 +1,41 @@ package ch.zhaw.gartenverwaltung; +import ch.zhaw.gartenverwaltung.bootstrap.AppLoader; +import ch.zhaw.gartenverwaltung.bootstrap.Inject; import ch.zhaw.gartenverwaltung.types.HardinessZone; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; public class SettingsController implements Initializable { Settings settings = Settings.getInstance(); + @Inject + AppLoader appLoader; @FXML private ComboBox selectHardinessZone_comboBox; @FXML private CheckBox showTutorial_checkBox; + @FXML + private Button location_button; + + @FXML + private Label location_label; + + @FXML + void setLocation(ActionEvent event) throws IOException { + openTextFieldDialog(); + } + /** * save selected values to {@link Settings} */ @@ -36,5 +54,46 @@ public class SettingsController implements Initializable { showTutorial_checkBox.setSelected(settings.getShowTutorial()); selectHardinessZone_comboBox.getItems().addAll(HardinessZone.values()); selectHardinessZone_comboBox.setValue(settings.getCurrentHardinessZone()); + setIconToButton(location_button, "locationIcon.png"); + location_label.setText(settings.getLocation()); + } + + /** + * adds icon to button + * @param button the button which get the icon + * @param iconFileName file name of icon + */ + private void setIconToButton(Button button, String iconFileName) { + Image img = new Image(String.valueOf(getClass().getResource("icons/" + iconFileName))); + ImageView imageView = new ImageView(img); + imageView.setFitHeight(20); + imageView.setPreserveRatio(true); + button.setGraphic(imageView); + } + + private void openTextFieldDialog() throws IOException { + Dialog dialog = new Dialog<>(); + dialog.setTitle("Set Location of your Garden"); + dialog.setHeaderText("set Location of your Garden!"); + dialog.setResizable(false); + + DialogPane dialogPane = dialog.getDialogPane(); + + ButtonType save = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE); + dialogPane.getButtonTypes().addAll(save, ButtonType.CANCEL); + + if (appLoader.loadPaneToDialog("TextFieldFormular.fxml", dialogPane) instanceof TextFieldFormularController controller) { + controller.setDescription_label("Set"); + controller.setValueTextArea(settings.getLocation()); + controller.initSaveButton((Button) dialogPane.lookupButton(save)); + + dialog.setResultConverter(button -> button.equals(save) ? controller.getValue() : null); + + dialog.showAndWait() + .ifPresent(string -> { + settings.setLocation(string); + location_label.setText(settings.getLocation()); + }); + } } } diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml index 1ee27fb..86303a7 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml +++ b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml @@ -15,12 +15,9 @@ - + - - - - + - + + + diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml index d09db93..1e31955 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml +++ b/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml @@ -5,46 +5,56 @@ - - - + - - - - - + + - - - - + + + + - + - - - - - - + - + - + + + + diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml index 39303a0..24c5d4b 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml +++ b/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml @@ -4,91 +4,109 @@ - + - + - - - + + + + - + - - - + - - + + + + + + + + + + + + + + + +