Merge pull request #67 from schrom01/feature_guiOverhaul_M3

Feature gui overhaul m3
This commit is contained in:
gulerdav 2022-11-25 12:11:07 +01:00 committed by GitHub Enterprise
commit 9b08113ff9
7 changed files with 187 additions and 12 deletions

View File

@ -104,16 +104,16 @@ public class CropDetailController {
* open dialog to set area
*/
@FXML
void setArea() {
void setArea() throws IOException {
openTextFieldDialog("set Text Area", "Text Area", area_label.getText(), false);
}
/**
* open dialog to set location
*/
@FXML
void setLocation() {
void setLocation() throws IOException {
openTextFieldDialog("set Location", "Location", location_label.getText(), true);
}
/**
@ -218,6 +218,7 @@ public class CropDetailController {
setIconToButton(edit, "editIcon.png");
setIconToButton(delete, "deleteIcon.png");
edit.setOnAction(getEditTaskEvent(task));
delete.setOnAction(deleteTask(task));
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
return hBox;
@ -260,6 +261,12 @@ public class CropDetailController {
};
}
private EventHandler<ActionEvent> deleteTask(Task task) {
return (event) -> {
showDeleteTask(task);
};
}
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
Dialog<Task> dialog = new Dialog<>();
dialog.setTitle("Set Task");
@ -278,6 +285,7 @@ public class CropDetailController {
if (appLoader.loadPaneToDialog("TaskFormular.fxml", dialogPane) instanceof TaskFormularController controller) {
controller.setCorp(this.crop);
controller.initSaveButton((Button) dialogPane.lookupButton(saveTask));
if (!newTask) {
controller.setTaskValue(givenTask);
}
@ -300,4 +308,56 @@ public class CropDetailController {
}
}
private void openTextFieldDialog(String title, String labelDescription, String value, boolean isLocation) throws IOException {
Dialog<String> dialog = new Dialog<>();
dialog.setTitle(title);
dialog.setHeaderText(title);
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(labelDescription);
controller.setValueTextArea(value);
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 {
System.out.println(string);
//ToDo method to set area of crop in garden
area_label.setText(string);
}
});
}
}
private void showDeleteTask(Task task) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Delete " + task.getName());
alert.setHeaderText("Are you sure want to delete this Task?");
alert.showAndWait()
.ifPresent(buttonType -> {
if (buttonType == ButtonType.OK) {
try {
gardenSchedule.removeTask(task);
setTaskListProperty(this.crop);
} catch (IOException e) {
// TODO: Show error alert
LOG.log(Level.SEVERE, "Could not remove crop.", e);
}
}
});
}
}

View File

@ -2,12 +2,14 @@ package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Task;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.DateCell;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.util.Callback;
import java.net.URL;
@ -56,7 +58,7 @@ public class TaskFormularController implements Initializable {
}
}
private Callback<DatePicker, DateCell> getDayCellFactory() {
private Callback<DatePicker, DateCell> getDayCellFactoryStartDate() {
return (datePicker) -> new DateCell() {
private final LocalDate today = LocalDate.now();
@ -71,16 +73,61 @@ public class TaskFormularController implements Initializable {
setDisable(false);
setStyle("-fx-background-color: #32CD32;");
}
if (end_datePicker.getValue() != null && item.compareTo(end_datePicker.getValue()) > 0) {
setDisable(true);
setStyle("-fx-background-color: #ffc0cb;");
}
}
};
}
private Callback<DatePicker, DateCell> getDayCellFactoryEndDate() {
return (datePicker) -> new DateCell() {
private final LocalDate today = LocalDate.now();
@Override
public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
setDisable(true);
setStyle("-fx-background-color: #ffc0cb;");
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
setDisable(false);
setStyle("-fx-background-color: #32CD32;");
}
if (start_datePicker.getValue() != null && item.compareTo(start_datePicker.getValue()) < 0) {
setDisable(true);
setStyle("-fx-background-color: #ffc0cb;");
}
}
};
}
public void initSaveButton(Button button) {
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
interval_field.setText(newValue.replaceAll("[^\\d]", ""));
}
});
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
.or(end_datePicker.valueProperty().isNull())
.or(taskName_field.textProperty().isEmpty())
.or(description_area.textProperty().isEmpty())
.or(interval_field.textProperty().isEmpty()));
}
@Override
public void initialize(URL location, ResourceBundle resources) {
start_datePicker.setDayCellFactory(getDayCellFactory());
start_datePicker.setDayCellFactory(getDayCellFactoryStartDate());
start_datePicker.setEditable(false);
end_datePicker.setDayCellFactory(getDayCellFactory());
end_datePicker.setDayCellFactory(getDayCellFactoryEndDate());
end_datePicker.setEditable(false);
}
}

View File

@ -0,0 +1,32 @@
package ch.zhaw.gartenverwaltung;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class TextFieldFormularController {
@FXML
private Label description_label;
@FXML
private TextField text_area;
public void setDescription_label(String string) {
description_label.setText(string);
}
public void setValueTextArea(String string) {
text_area.setText(string);
}
public String getValue() {
return text_area.getText();
}
public void initSaveButton(Button button) {
button.disableProperty().bind(text_area.textProperty().isEmpty());
}
}

View File

@ -73,7 +73,10 @@ public class AppLoader {
public Object loadSceneToStage(String fxmlFile, Stage appendee) throws IOException {
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
Pane root = loader.load();
appendee.setScene(new Scene(root));
Scene scene = new Scene(root);
String css = Objects.requireNonNull(this.getClass().getResource("styles.css")).toExternalForm();
appendee.setScene(scene);
scene.getStylesheets().add(css);
Object controller = loader.getController();
annotationInject(controller);
return controller;

View File

@ -48,6 +48,10 @@ public class TaskTemplate {
public Task generateTask(LocalDate realStartDate, long cropId) {
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
if (interval == null) {
this.interval = 0;
}
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
.withInterval(interval)
.withEndDate(endDate);

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="64.0" prefWidth="298.0" xmlns="http://javafx.com/javafx/17"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TextFieldFormularController">
<children>
<HBox alignment="CENTER" layoutX="153.0" layoutY="33.0" prefHeight="100.0" prefWidth="200.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="description_label" maxWidth="1.7976931348623157E308" text="Label" HBox.hgrow="ALWAYS" />
<TextField fx:id="text_area" HBox.hgrow="NEVER" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
</children>
</AnchorPane>

View File

@ -0,0 +1,6 @@
.button{
-fx-text-fill: rgb(49, 89, 23);
-fx-border-color: rgb(49, 89, 23);
-fx-border-radius: 5;
-fx-padding: 3 6 6 6;
}