From 2fbf3895c5d79ef5753b4c43b8fe360d62ce0ec4 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Mon, 31 Jan 2022 08:51:53 +0100 Subject: [PATCH] Refactor --- .../src/main/java/main/MainController.java | 30 +++---------- client/app/src/main/java/ui/DayPane.java | 44 +++++++++++++++++++ .../java/{helper => ui}/SvgBtnCreator.java | 2 +- 3 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 client/app/src/main/java/ui/DayPane.java rename client/app/src/main/java/{helper => ui}/SvgBtnCreator.java (99%) diff --git a/client/app/src/main/java/main/MainController.java b/client/app/src/main/java/main/MainController.java index c8dc029..e823492 100644 --- a/client/app/src/main/java/main/MainController.java +++ b/client/app/src/main/java/main/MainController.java @@ -2,7 +2,8 @@ package main; import config.Config; import config.ConfigLoader; -import helper.SvgBtnCreator; +import ui.DayPane; +import ui.SvgBtnCreator; import helper.HttpRequestException; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -151,28 +152,11 @@ public class MainController { private void createWeek() { for (int i = 0; i < 7; i++) { - Label label = new 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); + DayPane dayPane = new DayPane(dayNames[i]); + this.dayLabel[i] = dayPane.getDayLabel(); + calendarGrid.add(dayPane.getDayLabel(), i, 0); + dayVBoxes[i] = dayPane.getDayVBox(); + calendarGrid.add(dayPane.getScrollPane(), i, 1); } } diff --git a/client/app/src/main/java/ui/DayPane.java b/client/app/src/main/java/ui/DayPane.java new file mode 100644 index 0000000..d1aa3c8 --- /dev/null +++ b/client/app/src/main/java/ui/DayPane.java @@ -0,0 +1,44 @@ +package ui; + +import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; +import javafx.scene.layout.VBox; + +public class DayPane { + + private Label dayLabel; + private VBox dayVBox; + private ScrollPane scrollPane; + + public DayPane(String name) { + dayLabel = new Label(); + dayLabel.setText(name); + dayLabel.setMaxHeight(Double.MAX_VALUE); + dayLabel.setMaxWidth(Double.MAX_VALUE); + dayLabel.getStyleClass().add("labelDays"); + + scrollPane = new ScrollPane(); + + dayVBox = new VBox(); + dayVBox.getStyleClass().add("vBoxDays"); + dayVBox.setSpacing(10); + scrollPane.setContent(dayVBox); + + scrollPane.setFitToWidth(true); + scrollPane.setFitToHeight(true); + scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + scrollPane.getStyleClass().add("scrollDays"); + } + + public Label getDayLabel() { + return dayLabel; + } + + public VBox getDayVBox() { + return dayVBox; + } + + public ScrollPane getScrollPane() { + return scrollPane; + } +} diff --git a/client/app/src/main/java/helper/SvgBtnCreator.java b/client/app/src/main/java/ui/SvgBtnCreator.java similarity index 99% rename from client/app/src/main/java/helper/SvgBtnCreator.java rename to client/app/src/main/java/ui/SvgBtnCreator.java index 2dbf4cd..fc72cc8 100644 --- a/client/app/src/main/java/helper/SvgBtnCreator.java +++ b/client/app/src/main/java/ui/SvgBtnCreator.java @@ -1,4 +1,4 @@ -package helper; +package ui; import javafx.geometry.Bounds; import javafx.scene.Group;