fxml files changes + first style
This commit is contained in:
@@ -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<String> 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ActionEvent>() {
|
||||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<HardinessZone> 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<String> 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());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user