From e96280cd0c3b0d722abaa52ca9a08e8fc5019a78 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 20 Nov 2022 17:39:18 +0100 Subject: [PATCH 1/9] overhaul gui icons + settings --- .../CropDetailController.java | 20 ++++++ .../gartenverwaltung/MainFXMLController.java | 63 ++++++++++++++++-- .../gartenverwaltung/MyGardenController.java | 23 ++++++- .../ch/zhaw/gartenverwaltung/Settings.java | 15 +++++ .../gartenverwaltung/SettingsController.java | 40 +++++++++++ .../ch/zhaw/gartenverwaltung/CropDetail.fxml | 8 +-- .../ch/zhaw/gartenverwaltung/Home.fxml | 2 +- .../ch/zhaw/gartenverwaltung/MainFXML.fxml | 5 +- .../ch/zhaw/gartenverwaltung/Plants.fxml | 2 +- .../ch/zhaw/gartenverwaltung/Settings.fxml | 37 ++++++++++ .../zhaw/gartenverwaltung/icons/addIcon.png | Bin 0 -> 9058 bytes .../zhaw/gartenverwaltung/icons/areaIcon.png | Bin 0 -> 67278 bytes .../gartenverwaltung/icons/deleteIcon.png | Bin 0 -> 16015 bytes .../gartenverwaltung/icons/detailsIcon.png | Bin 0 -> 4470 bytes .../zhaw/gartenverwaltung/icons/editIcon.png | Bin 0 -> 6425 bytes .../zhaw/gartenverwaltung/icons/homeIcon.png | Bin 0 -> 21630 bytes .../gartenverwaltung/icons/locationIcon.png | Bin 0 -> 28966 bytes .../gartenverwaltung/icons/settingsIcon.png | Bin 0 -> 31441 bytes 18 files changed, 198 insertions(+), 17 deletions(-) create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/Settings.fxml create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/addIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/areaIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/deleteIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/detailsIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/editIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/homeIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/locationIcon.png create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/icons/settingsIcon.png diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index 7051bfa..85fb66d 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -14,6 +14,7 @@ import javafx.fxml.FXML; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -72,6 +73,9 @@ public class CropDetailController { @FXML private Label spacing_label; + @FXML + private Button editTaskList_button; + @FXML void editTaskList() { @@ -114,6 +118,9 @@ public class CropDetailController { } catch (HardinessZoneNotSetException | IOException e) { throw new PlantNotFoundException(); } + setIconToButton(editTaskList_button, "editIcon.png"); + setIconToButton(area_button, "areaIcon.png"); + setIconToButton(location_button, "locationIcon.png"); } private void createTaskLists(Crop crop) { @@ -149,4 +156,17 @@ public class CropDetailController { pests_vbox.getChildren().addAll(label, hBox); } } + + /** + * 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); + } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java b/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java index fca8b69..6970451 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java @@ -4,9 +4,12 @@ import ch.zhaw.gartenverwaltung.bootstrap.AfterInject; import ch.zhaw.gartenverwaltung.bootstrap.AppLoader; import ch.zhaw.gartenverwaltung.bootstrap.ChangeViewEvent; import ch.zhaw.gartenverwaltung.bootstrap.Inject; +import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; -import javafx.scene.control.Button; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; @@ -33,7 +36,10 @@ public class MainFXMLController { private Button mySchedule_button; @FXML - private Button plants_button; + private Button settings_button; + + @FXML + private Button tutorial_button; @FXML void goToHome() { @@ -54,9 +60,31 @@ public class MainFXMLController { } @FXML - void goToPlants() { - showPaneAsMainView("Plants.fxml"); - styleChangeButton(plants_button); + public void openSettings(ActionEvent actionEvent) throws IOException { + Dialog dialog = new Dialog<>(); + dialog.setTitle("Settings"); + dialog.setHeaderText("Settings"); + dialog.setResizable(false); + + DialogPane dialogPane = dialog.getDialogPane(); + + ButtonType saveSettings = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE); + dialogPane.getButtonTypes().addAll(saveSettings, ButtonType.CANCEL); + + if (appLoader.loadPaneToDialog("Settings.fxml", dialogPane) instanceof SettingsController controller) { + + dialog.showAndWait() + .ifPresent(button -> { + if (button.equals(saveSettings)) { + controller.saveSettings(); + } + }); + } + } + + public void goToTutorial(ActionEvent actionEvent) { + //showPaneAsMainView("Tutorial.fxml"); + styleChangeButton(tutorial_button); } /** @@ -100,11 +128,32 @@ public class MainFXMLController { public void init() { try { preloadPanes(); - showPaneAsMainView("Home.fxml"); - styleChangeButton(home_button); + showPaneAsMainView("MyGarden.fxml"); + styleChangeButton(myGarden_button); } catch (IOException e) { LOG.log(Level.SEVERE, "Failed to load FXML-Pane!", e); } + setIconToButton(home_button, "homeIcon.png"); + setIconToButton(settings_button, "settingsIcon.png"); + Settings.getInstance().getShowTutorialProperty().addListener((observable, oldValue, newValue) -> { + tutorial_button.setVisible(newValue); + }); + tutorial_button.setVisible(Settings.getInstance().getShowTutorial()); } + + /** + * 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); + } + + } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java index e54e608..3de534f 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyGardenController.java @@ -17,6 +17,7 @@ import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.ButtonType; import javafx.scene.control.Label; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; @@ -43,6 +44,8 @@ public class MyGardenController { public AnchorPane myGardenRoot; @FXML private VBox myPlants_vbox; + @FXML + private Button addPlant_button; @AfterInject @SuppressWarnings("unused") @@ -59,6 +62,7 @@ public class MyGardenController { } catch (HardinessZoneNotSetException | IOException e) { LOG.log(Level.SEVERE, "Could not update view of croplist!", e); } + setIconToButton(addPlant_button, "addIcon.png"); } @FXML @@ -91,8 +95,10 @@ public class MyGardenController { label.setMaxWidth(2000); HBox.setHgrow(label, Priority.ALWAYS); - Button details = new Button("Details"); - Button delete = new Button("delete"); + Button details = new Button(""); + Button delete = new Button(""); + setIconToButton(details, "detailsIcon.png"); + setIconToButton(delete, "deleteIcon.png"); details.setOnAction(getGoToCropDetailEvent(crop)); delete.setOnAction(getDeleteCropEvent(crop)); @@ -100,6 +106,19 @@ public class MyGardenController { return hBox; } + /** + * 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 EventHandler getGoToCropDetailEvent(Crop crop) { return (event) -> { try { diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Settings.java b/src/main/java/ch/zhaw/gartenverwaltung/Settings.java index 792f5c0..c15454c 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Settings.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Settings.java @@ -1,10 +1,13 @@ package ch.zhaw.gartenverwaltung; import ch.zhaw.gartenverwaltung.types.HardinessZone; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; public class Settings { private HardinessZone currentHardinessZone = HardinessZone.ZONE_8A; private static Settings instance; + private final BooleanProperty showTutorial = new SimpleBooleanProperty(false); static { instance = new Settings(); @@ -23,4 +26,16 @@ public class Settings { public void setCurrentHardinessZone(HardinessZone currentHardinessZone) { this.currentHardinessZone = currentHardinessZone; } + + public void setShowTutorial (boolean showTutorial) { + this.showTutorial.setValue(showTutorial); + } + + public BooleanProperty getShowTutorialProperty() { + return this.showTutorial; + } + + public boolean getShowTutorial() { + return this.showTutorial.get(); + } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java b/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java new file mode 100644 index 0000000..9a8158f --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/SettingsController.java @@ -0,0 +1,40 @@ +package ch.zhaw.gartenverwaltung; + +import ch.zhaw.gartenverwaltung.types.HardinessZone; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; + +import java.net.URL; +import java.util.ResourceBundle; + +public class SettingsController implements Initializable { + Settings settings = Settings.getInstance(); + + @FXML + private ComboBox selectHardinessZone_comboBox; + + @FXML + private CheckBox showTutorial_checkBox; + + /** + * save selected values to {@link Settings} + */ + public void saveSettings() { + settings.setShowTutorial(showTutorial_checkBox.isSelected()); + settings.setCurrentHardinessZone(selectHardinessZone_comboBox.getValue()); + } + + /** + * save default values form {@link Settings} + * @param location location + * @param resources resources + */ + @Override + public void initialize(URL location, ResourceBundle resources) { + showTutorial_checkBox.setSelected(settings.getShowTutorial()); + selectHardinessZone_comboBox.getItems().addAll(HardinessZone.values()); + selectHardinessZone_comboBox.setValue(settings.getCurrentHardinessZone()); + } +} diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml index ed3a476..160c0a7 100644 --- a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml +++ b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml @@ -80,7 +80,7 @@ -