diff --git a/hellofx/app/src/main/java/client/MainApplication.java b/hellofx/app/src/main/java/client/MainApplication.java index c8a16a4..90fe10a 100644 --- a/hellofx/app/src/main/java/client/MainApplication.java +++ b/hellofx/app/src/main/java/client/MainApplication.java @@ -2,6 +2,7 @@ package client; import javafx.application.Application; import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.stage.Stage; @@ -12,6 +13,7 @@ public class MainApplication extends Application { @Override public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 1200, 700); scene.getStylesheets().add(Objects.requireNonNull(MainApplication.class.getResource("main-view.css")).toExternalForm()); stage.setTitle("Hello!"); diff --git a/hellofx/app/src/main/java/client/MainController.java b/hellofx/app/src/main/java/client/MainController.java index 432efce..13ac105 100644 --- a/hellofx/app/src/main/java/client/MainController.java +++ b/hellofx/app/src/main/java/client/MainController.java @@ -1,42 +1,61 @@ package client; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; -import javafx.scene.Node; +import javafx.geometry.Pos; import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javafx.scene.paint.Color; import javafx.stage.Modality; import javafx.stage.Stage; -import javafx.stage.StageStyle; -import res.Event; import res.DataController; +import res.Event; -import javafx.event.ActionEvent; import java.io.IOException; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.Objects; public class MainController { + @FXML private GridPane calendarGrid; @FXML - private VBox vBoxMon; - @FXML - private VBox vBoxTue; - @FXML - private VBox vBoxWen; - @FXML - private VBox vBoxThu; - @FXML - private VBox vBoxFri; - @FXML - private VBox vBoxSat; - @FXML - private VBox vBoxSun; + private Label LabelMonth; + private final String[] dayNames = {"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"}; + private final Label[] dayLabel = new Label[7]; + private final VBox[] dayVBoxes = new VBox[7]; + + private int weekOffset; + private LocalDateTime weekStartDateTime; + + + public MainController() { + weekOffset = 0; + } + + @FXML + public void initialize(){ + createWeek(); + setDates(); + + DataController dataController = new DataController(); + ArrayList eventList = dataController.getAllVisibleEvents(); + + for(Event event : eventList){ + addEvent(event); + } + } @FXML protected void onAddBtnClick(){ @@ -49,34 +68,109 @@ public class MainController { stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); stage.setResizable(false); - stage.initStyle(StageStyle.UNDECORATED); + //stage.initStyle(StageStyle.UNDECORATED); stage.showAndWait(); } catch (IOException e){ e.printStackTrace(); } + } - - DataController dataController = new DataController(); - Event[] eventList = dataController.getAllEvents(); - - for(Event event : eventList){ + private void createWeek(){ + for (int i = 0; i < 7; i++) { Label label = new Label(); - label.setText(event.toString()); - label.setTextFill(Color.WHITE); - vBoxWen.getChildren().add(label); + label.setText(dayNames[i]); + label.setMaxHeight(Double.MAX_VALUE); + label.setMaxWidth(Double.MAX_VALUE); + label.getStyleClass().add("labelDays"); + dayLabel[i] = label; + calendarGrid.add(label, i, 0); + + ScrollPane scrollPane = new ScrollPane(); + + VBox vBox = new VBox(); + vBox.getStyleClass().add("vBoxDays"); + vBox.setSpacing(10); + dayVBoxes[i] = vBox; + scrollPane.setContent(vBox); + + scrollPane.setFitToWidth(true); + scrollPane.setFitToHeight(true); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + scrollPane.getStyleClass().add("scrollDays"); + + calendarGrid.add(scrollPane, i, 1); } } - @FXML - protected void createBtnClick(ActionEvent event){ - Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); - stage.close(); + private void addEvent(Event event){ + VBox vBox = new VBox(); + vBox.getStyleClass().add("event"); + vBox.setSpacing(5); + + HBox btnHBox = new HBox(); + btnHBox.setAlignment(Pos.BOTTOM_RIGHT); + Button deleteBtn = new Button(); + deleteBtn.setText(" X "); + deleteBtn.setOnAction(e -> { + LocalDateTime eventDate = event.getDate(); + int day = (int)Duration.between(weekStartDateTime.toLocalDate().atStartOfDay(), eventDate.toLocalDate().atStartOfDay()).toDays(); + dayVBoxes[day].getChildren().remove(vBox); + }); + Button editBtn = new Button(); + editBtn.setText("edit"); + btnHBox.getChildren().add(editBtn); + btnHBox.getChildren().add(deleteBtn); + vBox.getChildren().add(btnHBox); + + Label nameLabel = new Label(event.getName()); + vBox.getChildren().add(nameLabel); + + Label timeLabel = new Label(event.getStart() + "-" + event.getEnd()); + vBox.getChildren().add(timeLabel); + + Label typeLabel = new Label("Wer: " + event.getOwnerName()); + vBox.getChildren().add(typeLabel); + + /* + Ä, ä \u00c4, \u00e4 + Ö, ö \u00d6, \u00f6 + Ü, ü \u00dc, \u00fc + ß \u00df + */ + Label prioLabel = new Label("Priorit\u00e4t: " + event.getPriority()); + vBox.getChildren().add(prioLabel); + + if(event.isFullDay()){ + Label fullDayLabel = new Label("Dieser Termin bockiert den ganzen Tag!"); + vBox.getChildren().add(fullDayLabel); + } + + + LocalDateTime eventDate = event.getDate(); + + int day = (int)Duration.between(weekStartDateTime.toLocalDate().atStartOfDay(), eventDate.toLocalDate().atStartOfDay()).toDays(); + + if(day >= 0 && day < 7){ + dayVBoxes[day].getChildren().add(vBox); + } } - @FXML - protected void abortBtnClick(ActionEvent event){ - Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); - stage.close(); + private void setDates(){ + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("LLLL yyyy"); + DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("E dd.MM"); + DateTimeFormatter dayOfWeekFormatter = DateTimeFormatter.ofPattern("e"); + + LocalDateTime now = LocalDateTime.now(); + int dayOfWeek = Integer.parseInt(dayOfWeekFormatter.format(now)); + + weekStartDateTime = now.minusDays(weekOffset * 7L + dayOfWeek - 1); + + for (int i = 0; i < 7; i++) { + dayLabel[i].setText(dayFormatter.format(weekStartDateTime.plusDays(i))); + } + + LabelMonth.setText(dateFormatter.format(weekStartDateTime)); + } } \ No newline at end of file diff --git a/hellofx/app/src/main/resources/client/main-view.css b/hellofx/app/src/main/resources/client/main-view.css index 17c4490..af0f292 100644 --- a/hellofx/app/src/main/resources/client/main-view.css +++ b/hellofx/app/src/main/resources/client/main-view.css @@ -1,5 +1,14 @@ +* { + -fx-base-background-color: #2B2D42; + -fx-base1-background-color: #525E74; + + -fx-main-border-color: #B0B0B0; + -fx-main-text-color: #ffffff; +} + + GridPane{ - -fx-background-color: #2B2D42; + -fx-background-color: -fx-base-background-color; } .main-panel{ @@ -13,11 +22,11 @@ GridPane{ } .gridCalendar Line{ - -fx-stroke: #B0B0B0; + -fx-stroke: -fx-main-border-color; } .gridCalender{ - -fx-background-color: #2B2D42; + -fx-background-color: -fx-base-background-color; -fx-min-height: 80px; -fx-max-height: 80px; } @@ -29,19 +38,33 @@ GridPane{ -fx-font-weight: bold; } +.scrollDays{ + -fx-background-color: -fx-base-background-color; + -fx-border-color: -fx-main-border-color; +} + +.vBoxDays{ + -fx-background-color: -fx-base-background-color; +} + .labelDays{ -fx-alignment: center; - -fx-background-color: #525E74; + -fx-background-color: -fx-base1-background-color; -fx-font-size: 25px; + -fx-border-color: -fx-main-border-color; } Label{ - -fx-text-fill: white; + -fx-text-fill: -fx-main-text-color; +} + +.event{ + -fx-background-color: -fx-base1-background-color; } .main-btn{ -fx-background-color: #ffffff; - -fx-text-fill: white; + -fx-text-fill: -fx-main-text-color; -fx-background-radius: 5em; -fx-min-width: 40px; -fx-min-height: 40px; diff --git a/hellofx/app/src/main/resources/client/main-view.fxml b/hellofx/app/src/main/resources/client/main-view.fxml index 29a2fcd..f42e9b9 100644 --- a/hellofx/app/src/main/resources/client/main-view.fxml +++ b/hellofx/app/src/main/resources/client/main-view.fxml @@ -36,7 +36,7 @@ -