overhaul gui icons + settings

This commit is contained in:
giavaphi 2022-11-20 17:39:18 +01:00
parent bfe3fcfb79
commit e96280cd0c
18 changed files with 198 additions and 17 deletions

View File

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

View File

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

View File

@ -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<ActionEvent> getGoToCropDetailEvent(Crop crop) {
return (event) -> {
try {

View File

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

View File

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

View File

@ -80,7 +80,7 @@
<ImageView fx:id="imageView" fitHeight="300.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true" HBox.hgrow="NEVER" />
</children>
</HBox>
<Label text="Growth Phases:">
<Label text="Tasks:">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
@ -90,7 +90,7 @@
<Insets bottom="10.0" />
</VBox.margin>
</VBox>
<Button mnemonicParsing="false" onAction="#editTaskList" prefHeight="25.0" prefWidth="92.0" text="Edit Tasklist">
<Button fx:id="editTaskList_button" mnemonicParsing="false" onAction="#editTaskList" prefHeight="25.0" prefWidth="45.0">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
@ -113,7 +113,7 @@
<Insets right="10.0" />
</HBox.margin>
</Label>
<Button fx:id="area_button" mnemonicParsing="false" onAction="#setArea" prefHeight="25.0" prefWidth="116.0" text="Add Area" />
<Button fx:id="area_button" mnemonicParsing="false" onAction="#setArea" prefHeight="25.0" prefWidth="116.0" text="Set Area" />
</children>
<VBox.margin>
<Insets bottom="10.0" />
@ -131,7 +131,7 @@
<Insets right="10.0" />
</HBox.margin>
</Label>
<Button fx:id="location_button" mnemonicParsing="false" onAction="#setLocation" prefHeight="25.0" prefWidth="115.0" text="Add Location" />
<Button fx:id="location_button" mnemonicParsing="false" onAction="#setLocation" prefHeight="25.0" prefWidth="115.0" text="Set Location" />
</children>
</HBox>
</children>

View File

@ -13,7 +13,7 @@
<children>
<VBox layoutX="75.0" layoutY="73.0" prefHeight="729.0" prefWidth="1060.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label text="Gartenverwaltung">
<Label text="Garden Management">
<font>
<Font size="34.0" />
</font>

View File

@ -9,11 +9,12 @@
<children>
<HBox maxWidth="35.0" minHeight="35.0" prefHeight="38.0" prefWidth="1110.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Button fx:id="home_button" mnemonicParsing="false" onAction="#goToHome" prefHeight="38.0" prefWidth="121.0" text="Home" HBox.hgrow="NEVER" />
<Button fx:id="plants_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToPlants" prefHeight="38.0" prefWidth="121.0" text="Plants" />
<Button fx:id="home_button" mnemonicParsing="false" onAction="#goToHome" prefHeight="38.0" prefWidth="40.0" HBox.hgrow="NEVER" />
<Button fx:id="myGarden_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToMyPlants" prefHeight="38.0" prefWidth="121.0" text="My Garden" />
<Button fx:id="mySchedule_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToMySchedule" prefHeight="38.0" prefWidth="121.0" text="My Schedule" />
<Button fx:id="tutorial_button" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#goToTutorial" prefHeight="38.0" prefWidth="121.0" text="Tutorial" />
<Pane maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<Button fx:id="settings_button" maxHeight="1.7976931348623157E308" mnemonicParsing="false" onAction="#openSettings" prefHeight="38.0" prefWidth="40.0" HBox.hgrow="NEVER" />
</children>
</HBox>
<AnchorPane fx:id="mainPane" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="35.0" />

View File

@ -63,7 +63,7 @@
<Font name="System Bold" size="17.0" />
</font>
</Label>
<TitledPane animated="false" text="Saison">
<TitledPane animated="false" text="Seasons">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="80.0" prefWidth="374.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.SettingsController">
<children>
<VBox layoutX="14.0" layoutY="14.0" prefHeight="73.0" prefWidth="374.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox prefHeight="23.0" prefWidth="334.0">
<children>
<Label maxWidth="1.7976931348623157E308" text="Show Tutorial Menu" HBox.hgrow="ALWAYS" />
<CheckBox fx:id="showTutorial_checkBox" mnemonicParsing="false" />
</children>
<VBox.margin>
<Insets left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="20.0" layoutY="20.0" prefHeight="23.0" prefWidth="334.0">
<children>
<Label maxWidth="1.7976931348623157E308" text="Select Default Hardiness Zone" HBox.hgrow="ALWAYS" />
<ComboBox fx:id="selectHardinessZone_comboBox" prefWidth="150.0" promptText="Hardniness Zone" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
</children>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB