From 780ecbee0fdbb603f4c5091248334a8cccc3d8e3 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Sat, 29 Jan 2022 10:06:28 +0100 Subject: [PATCH] Changed encoding to utf-8 --- client/app/build.gradle.kts | 6 +- client/app/src/main/java/customUI/Button.java | 8 --- .../app/src/main/java/customUI/Converter.java | 21 ------- client/app/src/main/java/customUI/Label.java | 15 ----- .../app/src/main/java/customUI/Tooltip.java | 9 --- .../src/main/java/helper/SvgBtnCreator.java | 4 +- .../main/java/main/EditEventController.java | 3 +- .../src/main/java/main/MainController.java | 10 ++-- .../src/main/java/main/OptionController.java | 51 ++++++++++++----- .../main/java/users/EditUserController.java | 19 +++++++ .../src/main/resources/users/create-user.fxml | 5 +- .../src/main/resources/users/edit-user.fxml | 57 +++++++++++++++++++ client/data/build.gradle.kts | 4 ++ client/data/src/main/java/res/Event.java | 18 ++---- 14 files changed, 135 insertions(+), 95 deletions(-) delete mode 100644 client/app/src/main/java/customUI/Button.java delete mode 100644 client/app/src/main/java/customUI/Converter.java delete mode 100644 client/app/src/main/java/customUI/Label.java delete mode 100644 client/app/src/main/java/customUI/Tooltip.java create mode 100644 client/app/src/main/java/users/EditUserController.java create mode 100644 client/app/src/main/resources/users/edit-user.fxml diff --git a/client/app/build.gradle.kts b/client/app/build.gradle.kts index d75d3b4..3a8a5d6 100644 --- a/client/app/build.gradle.kts +++ b/client/app/build.gradle.kts @@ -5,13 +5,17 @@ plugins { } javafx { - version = "11" + version = "11.0.2" modules( "javafx.controls", "javafx.fxml" ) } +tasks.withType { + options.encoding = "UTF-8" +} + application { mainClassName = "main.MainApplication" } diff --git a/client/app/src/main/java/customUI/Button.java b/client/app/src/main/java/customUI/Button.java deleted file mode 100644 index 61df976..0000000 --- a/client/app/src/main/java/customUI/Button.java +++ /dev/null @@ -1,8 +0,0 @@ -package customUI; - -public class Button extends javafx.scene.control.Button { - - public void setTextValue(String text){ - super.setText(Converter.convertString(text)); - } -} diff --git a/client/app/src/main/java/customUI/Converter.java b/client/app/src/main/java/customUI/Converter.java deleted file mode 100644 index dc737af..0000000 --- a/client/app/src/main/java/customUI/Converter.java +++ /dev/null @@ -1,21 +0,0 @@ -package customUI; - -public class Converter { - /* - Ä, ä \u00c4, \u00e4 - Ö, ö \u00d6, \u00f6 - Ü, ü \u00dc, \u00fc - ß \u00df - */ - @SuppressWarnings("all") - public static String convertString(String str){ - return str - .replace("ä", "\u00e4") - .replace("Ä", "\u00c4") - .replace("ö", "\u00f6") - .replace("Ö", "\u00d6") - .replace("ü", "\u00fc") - .replace("Ü", "\u00dc") - .replace("ß", "\u00df"); - } -} diff --git a/client/app/src/main/java/customUI/Label.java b/client/app/src/main/java/customUI/Label.java deleted file mode 100644 index ad5321e..0000000 --- a/client/app/src/main/java/customUI/Label.java +++ /dev/null @@ -1,15 +0,0 @@ -package customUI; - -public class Label extends javafx.scene.control.Label { - public Label(String content){ - super(Converter.convertString(content)); - } - - public Label(){ - super(); - } - - public void setTextValue(String text){ - super.setText(Converter.convertString(text)); - } -} diff --git a/client/app/src/main/java/customUI/Tooltip.java b/client/app/src/main/java/customUI/Tooltip.java deleted file mode 100644 index 2a5324a..0000000 --- a/client/app/src/main/java/customUI/Tooltip.java +++ /dev/null @@ -1,9 +0,0 @@ -package customUI; - -public class Tooltip extends javafx.scene.control.Tooltip { - - public Tooltip(String tollTipText){ - super(Converter.convertString(tollTipText)); - } - -} diff --git a/client/app/src/main/java/helper/SvgBtnCreator.java b/client/app/src/main/java/helper/SvgBtnCreator.java index c9546fe..2dbf4cd 100644 --- a/client/app/src/main/java/helper/SvgBtnCreator.java +++ b/client/app/src/main/java/helper/SvgBtnCreator.java @@ -2,9 +2,7 @@ package helper; import javafx.geometry.Bounds; import javafx.scene.Group; -import customUI.Button; -import javafx.scene.control.ContentDisplay; -import customUI.Tooltip; +import javafx.scene.control.*; import javafx.scene.shape.SVGPath; public class SvgBtnCreator { diff --git a/client/app/src/main/java/main/EditEventController.java b/client/app/src/main/java/main/EditEventController.java index b562fb5..a6f811f 100644 --- a/client/app/src/main/java/main/EditEventController.java +++ b/client/app/src/main/java/main/EditEventController.java @@ -1,6 +1,5 @@ package main; -import customUI.Converter; import helper.HttpRequestException; import res.DataController; import res.Event; @@ -16,7 +15,7 @@ public class EditEventController extends CreateEventController{ public void setCurrentEvent(Event currentEvent) { this.currentEvent = currentEvent; - textName.setText(Converter.convertString(currentEvent.getName())); + textName.setText(currentEvent.getName()); datePickerDate.setValue(currentEvent.getDate().toLocalDate()); ComboBoxPriotity.getSelectionModel().select(currentEvent.getPriority()); diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index 0a5ae54..02b80e3 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -2,8 +2,6 @@ package main; import config.Config; import config.ConfigLoader; -import customUI.Button; -import customUI.Label; import helper.SvgBtnCreator; import helper.HttpRequestException; import javafx.fxml.FXML; @@ -12,7 +10,7 @@ import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; -import javafx.scene.control.ScrollPane; +import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -154,7 +152,7 @@ public class MainController { private void createWeek() { for (int i = 0; i < 7; i++) { Label label = new Label(); - label.setTextValue(dayNames[i]); + label.setText(dayNames[i]); label.setMaxHeight(Double.MAX_VALUE); label.setMaxWidth(Double.MAX_VALUE); label.getStyleClass().add("labelDays"); @@ -248,7 +246,7 @@ public class MainController { Label typeLabel = new Label("Wer: " + event.getOwnerName()); vBox.getChildren().add(typeLabel); - Label prioLabel = new Label("Priorit\u00e4t: " + event.getPriority()); + Label prioLabel = new Label("Priorität: " + event.getPriority()); vBox.getChildren().add(prioLabel); if (event.isFullDay()) { @@ -286,7 +284,7 @@ public class MainController { weekStartDateTime = now.plusDays(weekOffset * 7L - dayOfWeek + 1); for (int i = 0; i < 7; i++) { - dayLabel[i].setTextValue(dayFormatter.format(weekStartDateTime.plusDays(i))); + dayLabel[i].setText(dayFormatter.format(weekStartDateTime.plusDays(i))); } LabelMonth.setText(dateFormatter.format(weekStartDateTime)); diff --git a/client/app/src/main/java/main/OptionController.java b/client/app/src/main/java/main/OptionController.java index 11fae92..aefd27a 100644 --- a/client/app/src/main/java/main/OptionController.java +++ b/client/app/src/main/java/main/OptionController.java @@ -9,6 +9,8 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Modality; @@ -20,6 +22,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; public class OptionController { @@ -36,10 +39,13 @@ public class OptionController { @FXML public GridPane mainGrid; + private JFXComboBox comboBox; + private DataController dataController; + private List users; + @FXML public void initialize(){ - DataController dataController = new DataController(); - List users; + dataController = new DataController(); try{ users = dataController.getAllUser(); } catch (HttpRequestException e){ @@ -50,7 +56,7 @@ public class OptionController { for (User user: users) { observableUserList.add(user.getLogin()); } - JFXComboBox comboBox = new JFXComboBox<>(observableUserList); + comboBox = new JFXComboBox<>(observableUserList); comboBox.getStyleClass().add("comboBox"); mainGrid.add(comboBox, 2,2); @@ -62,14 +68,36 @@ public class OptionController { } public void onCreateBtnClick(ActionEvent actionEvent) { - try{ - FXMLLoader fxmlLoader = new FXMLLoader( - MainApplication.class.getResource("../users/create-user.fxml")); - Scene scene = new Scene(fxmlLoader.load(), 800, 650); + loadUserScene(actionEvent, "User erstellen", "../users/create-user.fxml"); + } + + public void onUpdateBtnClick(ActionEvent actionEvent) { + loadUserScene(actionEvent, "User bearbeiten", "../users/edit-user.fxml"); + } + + public void onDeleteBtnClick(ActionEvent actionEvent) { + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Wirklich löschen?"); + Optional result = alert.showAndWait(); + if(result.isPresent() && result.get() == ButtonType.OK){ + try { + dataController.deleteUser(users.get(comboBox.getSelectionModel().getSelectedIndex())); + } catch (HttpRequestException e) { + Alert alert1 = new Alert(Alert.AlertType.ERROR, e.getMessage()); + alert1.showAndWait(); + } + } + } + + private Scene loadUserScene(ActionEvent actionEvent, String title, String fxml) { + FXMLLoader fxmlLoader = new FXMLLoader( + MainApplication.class.getResource(fxml)); + Scene scene = null; + try { + scene = new Scene(fxmlLoader.load(), 800, 650); scene.getStylesheets().add(Objects.requireNonNull( MainApplication.class.getResource("../users/create-user.css")).toExternalForm()); Stage stage = new Stage(); - stage.setTitle("User erstellen"); + stage.setTitle(title); stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); @@ -79,11 +107,6 @@ public class OptionController { } catch (IOException e) { e.printStackTrace(); } - } - - public void onUpdateBtnClick(ActionEvent actionEvent) { - } - - public void onDeleteBtnClick(ActionEvent actionEvent) { + return scene; } } diff --git a/client/app/src/main/java/users/EditUserController.java b/client/app/src/main/java/users/EditUserController.java new file mode 100644 index 0000000..e51ffbc --- /dev/null +++ b/client/app/src/main/java/users/EditUserController.java @@ -0,0 +1,19 @@ +package users; + +import res.User; + +public class EditUserController extends CreateUserController{ + private User currentUser; + + public User getCurrentUser() { + return currentUser; + } + + public void setCurrentUser(User currentUser) { + this.currentUser = currentUser; + + textForename.setText(currentUser.getForename()); + textName.setText(currentUser.getName()); + textLogin.setText(currentUser.getLogin()); + } +} diff --git a/client/app/src/main/resources/users/create-user.fxml b/client/app/src/main/resources/users/create-user.fxml index e542f73..c4741a9 100644 --- a/client/app/src/main/resources/users/create-user.fxml +++ b/client/app/src/main/resources/users/create-user.fxml @@ -3,6 +3,7 @@ + @@ -40,7 +41,7 @@ - + diff --git a/client/app/src/main/resources/users/edit-user.fxml b/client/app/src/main/resources/users/edit-user.fxml new file mode 100644 index 0000000..3f89f8b --- /dev/null +++ b/client/app/src/main/resources/users/edit-user.fxml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/data/build.gradle.kts b/client/data/build.gradle.kts index 147ec02..790eeb5 100644 --- a/client/data/build.gradle.kts +++ b/client/data/build.gradle.kts @@ -2,6 +2,10 @@ plugins { java } +tasks.withType { + options.encoding = "UTF-8" +} + dependencies { val jacksonVersion = "2.13.0" implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") diff --git a/client/data/src/main/java/res/Event.java b/client/data/src/main/java/res/Event.java index 179f622..0520e06 100644 --- a/client/data/src/main/java/res/Event.java +++ b/client/data/src/main/java/res/Event.java @@ -1,19 +1,11 @@ package res; -import com.sun.jdi.event.StepEvent; - -import java.io.Serializable; -import java.nio.charset.StandardCharsets; -import java.sql.SQLOutput; import java.time.Duration; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; public class Event { @@ -44,15 +36,15 @@ public class Event { System.out.println("Create Event"); if (name.length() < 3) { - throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben."); + throw new IllegalArgumentException("Der Name muss eine Länge von 3 haben."); } - Pattern pattern = Pattern.compile("[A-Za-z\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-9 =!?+*/$.:,;_<>()-]*"); + Pattern pattern = Pattern.compile("[A-Za-zäöüÄÖÜß0-9 =!?+*/$.:,;_<>()-]*"); Matcher matcher = pattern.matcher(name); if (!matcher.matches()) { - throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$.:,;_ <>()-"); + throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: äöü ÄÖÜ ß =!?+*/$.:,;_ <>()-"); } if (priority < 0) { - throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen."); + throw new IllegalArgumentException("Bitte eine Priorität wählen."); } LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay(); if (Duration.between(today, date).isNegative()) { @@ -82,9 +74,7 @@ public class Event { } public void setName(String name) { - System.out.println(name); this.name = name; - System.out.println(this.name); } public int getPriority() {