From fc951d9db4947fb4d05aef1e55bd17664a0c5d6f Mon Sep 17 00:00:00 2001 From: Hanis03 Date: Thu, 16 Feb 2023 15:35:29 +0100 Subject: [PATCH 1/2] updated BrView --- .../a_birthdate_reminder/BrView.java | 36 +++++++++++++++---- .../resources/data/data.sql | 4 ++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java index f61d37f..49d9e99 100644 --- a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java +++ b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java @@ -3,16 +3,14 @@ import cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder.model.HumanRepository; import cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder.model.Human; import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.scene.Scene; -import javafx.scene.control.DateCell; import javafx.scene.control.DatePicker; -import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; -import javafx.stage.Screen; import javafx.stage.Stage; -import javafx.util.Callback; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.time.LocalDate; @@ -34,16 +32,40 @@ public void start(Stage stage) throws Exception { this.dp.setValue(this.date); this.mainBp.setTop(this.dp); this.mainBp.setCenter(this.tf); + //this.customizeDp(); - for (Human h:model.getAll()) { - this.tf.getChildren().add(new Text(h.getFirstName()+" "+h.getSecondName()+String.format("(%s)", h.getBirthdate()))); + /*for (Human h : model.getAll()) { + for (int i = 0; i <= 7; i++){ + this.tf.getChildren().add(new Text(h.getFirstName() + " " + h.getSecondName() + String.format("(%s)", h.getBirthdate()))); this.tf.getChildren().add(new Text("\n")); - } + } + }*/ + setHandlers(); stage.setScene(this.scene); stage.show(); } + public void setHandlers(){ + this.dp.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent actionEvent) { + BrView.this.tf.getChildren().clear(); + BrView.this.date = BrView.this.dp.getValue(); + for (int i = 0; i <= 7; i++){ + LocalDate tmp = BrView.this.date.plusDays(i); + BrView.this.tf.getChildren().add(new Text("\n" + tmp.getDayOfWeek() + " " + tmp + " ")); + for (Human h : model.getAll()){ + if (h.getBirthdate().getMonth() == tmp.getMonth() && h.getBirthdate().getDayOfMonth() == tmp.getDayOfMonth()){ + int vek = tmp.getYear() - h.getBirthdate().getYear(); + BrView.this.tf.getChildren().add(new Text(h.getFirstName() + " " + h.getSecondName() + " - slaví " + vek + "té narozeniny")); + + } + } + } + } + }); + } public static void main(String[] args) { Application.launch(args); diff --git a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql index 56ea4bd..682b771 100644 --- a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql +++ b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql @@ -1,4 +1,6 @@ INSERT INTO human (id, email, firstName, secondName, birthdate) VALUES (1, 'as@ff.com', 'Dan', 'Kolář', '2001-01-01'), (2, 'aadss@fsdf.com', 'Pavel', 'Fíkovníků', '1900-01-01'), -(3, 'aadssdfs@fsdf.com', 'Petr', 'Pavel', '1212-07-07'); +(3, 'aadssdfs@fsdf.com', 'Petr', 'Pavel', '1212-07-07'), +(4, 'test@test.ts','Test','Test','2013-02-17'), +(5, 'test@test.ts','Test','Test','2003-02-18'); From 41dacfe2ee8a66b2b115649cb4148ab9ee77e87d Mon Sep 17 00:00:00 2001 From: Hanis03 Date: Mon, 13 Mar 2023 11:51:15 +0100 Subject: [PATCH 2/2] Full update birthdate reminder --- .../a_birthdate_reminder/BrView.java | 94 +++++++++++++------ .../model/MonthlyCal.java | 72 ++++++++++++++ .../resources/data/data.sql | 25 +++-- 3 files changed, 156 insertions(+), 35 deletions(-) create mode 100644 src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/model/MonthlyCal.java diff --git a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java index 1c0bfea..a5aeec6 100644 --- a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java +++ b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/BrView.java @@ -1,22 +1,26 @@ package cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder; import cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder.model.HumanRepository; -import cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder.model.Human; +import cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder.model.MonthlyCal; import javafx.application.Application; +import javafx.geometry.Pos; import javafx.scene.Scene; -import javafx.scene.control.DateCell; +import javafx.scene.control.Button; import javafx.scene.control.DatePicker; import javafx.scene.control.Label; +import javafx.scene.image.Image; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import javafx.scene.text.Text; import javafx.scene.text.TextFlow; -import javafx.stage.Screen; import javafx.stage.Stage; -import javafx.util.Callback; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.time.LocalDate; +import java.time.Month; +import java.time.format.TextStyle; +import java.util.Locale; public class BrView extends Application { @@ -27,37 +31,68 @@ public class BrView extends Application { private DatePicker dp = new DatePicker(); private Scene scene = new Scene(mainBp); private TextFlow tf = new TextFlow(); + private void updateYearLabel(Label yearLabel) { + yearLabel.setText(Integer.toString(date.getYear())); + GridPane gridPane = new GridPane(); + gridPane.setHgap(25); + for (int i = 1; i <= 12; i++) { + VBox vb = new VBox(); + Label lbl = new Label(Month.values()[i-1].getDisplayName(TextStyle.FULL_STANDALONE,new Locale("cs", "CZ"))); + lbl.setStyle("-fx-font-size: 18px;"); + vb.setAlignment(Pos.CENTER); + vb.getChildren().add(lbl); + vb.getChildren().add(new MonthlyCal(this.date.getYear(), i, model)); + gridPane.add(vb, (i - 1) % 3, (i - 1) / 3); + } + this.mainBp.setCenter(gridPane); + + } @Override public void start(Stage stage) throws Exception { this.mainBp.setMinSize(500, 700); this.date = LocalDate.now(); this.dp.setValue(this.date); - this.mainBp.setTop(new VBox( - new MonthlyCal(2023, 1), - new MonthlyCal(2023, 2), - new MonthlyCal(2023, 3) - )); - this.mainBp.setCenter(this.tf); - //this.customizeDp(); - //for (Human h:model.getAll()) { - for (int i = 0; i < 7; i++) { - LocalDate tmp = this.date.plusDays(i); - this.tf.getChildren().add(new Text("\n" + tmp)); - for (Human h: model.getAll()) { - if(h.getBirthdate().getDayOfYear()== tmp.getDayOfYear()) { - int age = this.date.getYear() - h.getBirthdate().getYear(); - this.tf.getChildren().add(new Text(" "+ h.getFirstName()+" "+h.getSecondName() + "(" + age + ")")); - } - } - - /*this.tf.getChildren().add(new Text(String.format("(%s)", h.getBirthdate()) + h.getFirstName()+" "+h.getSecondName()));*/ - - } - - - //} + HBox bar = new HBox(); + bar.setAlignment(Pos.TOP_CENTER); + + Button back = new Button(); + Button next = new Button(); + Label yearLabel = new Label(Integer.toString(date.getYear())); + + back.setText("<"); + back.setOnAction(event -> { + this.date = this.date.minusYears(1); + this.dp.setValue(this.date); + updateYearLabel(yearLabel); + }); + + + next.setText(">"); + next.setOnAction(event -> { + this.date = this.date.plusYears(1); + this.dp.setValue(this.date); + updateYearLabel(yearLabel); + }); + updateYearLabel(yearLabel); + yearLabel.setStyle("-fx-font-size: 18px;"); + + Label space = new Label(); + space.setStyle("-fx-padding: 10px"); + Label space2 = new Label(); + space2.setStyle("-fx-padding: 10px"); + + bar.getChildren().add(back); + bar.getChildren().add(space); + bar.getChildren().add(yearLabel); + bar.getChildren().add(space2); + bar.getChildren().add(next); + + this.mainBp.setTop(bar); + + stage.setTitle("Birthday reminder"); + stage.getIcons().add(new Image("https://itvitek.eu/img/me.png")); stage.setScene(this.scene); stage.show(); @@ -65,6 +100,7 @@ public void start(Stage stage) throws Exception { public static void main(String[] args) { Application.launch(args); + } } diff --git a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/model/MonthlyCal.java b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/model/MonthlyCal.java new file mode 100644 index 0000000..3d41e1e --- /dev/null +++ b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/model/MonthlyCal.java @@ -0,0 +1,72 @@ +package cz.spsmb.ctvrtak.f_pop.a_mvp_based.a_birthdate_reminder.model; + +import javafx.scene.control.Label; +import javafx.scene.control.Tooltip; +import javafx.scene.layout.GridPane; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.format.TextStyle; +import java.util.Locale; + +public class MonthlyCal extends GridPane { + private HumanRepository humanRepository; + + public MonthlyCal(int year, int month, HumanRepository humanRepository) { + super(); + this.humanRepository = humanRepository; + + for (DayOfWeek dow:DayOfWeek.values() + ) { + this.add(new Label(dow.getDisplayName(TextStyle.SHORT, new Locale("cs", "CZ"))+" "), dow.getValue(), 0); + } + + LocalDate ld = LocalDate.of(year, month, 1); + int rowCount = 1; + int weekCount = isFirstWeekZero(year) ? 0 : 1; + if (month > 1) weekCount += (LocalDate.of(year, 1, 1).getDayOfWeek().getValue() - 1 + ld.getDayOfYear()) / 7; + while (ld.getMonth().getValue() == month) { + Label l = new Label(Integer.toString(ld.getDayOfMonth())+" "); + l.setStyle("-fx-font-size: 20;"); + LocalDate finalLd = ld; + l.setOnMouseEntered(e -> { + StringBuilder sb = new StringBuilder(); + for (Human h : humanRepository.getAll()) { + if (h.getBirthdate().getMonth().getValue() == month && h.getBirthdate().getDayOfMonth() == finalLd.getDayOfMonth()) { + int bir_date = year - h.getBirthdate().getYear(); + sb.append(h.getFirstName() + " "+ h.getSecondName() + " " + bir_date).append("\n"); + } + } + if (sb.length() > 0) { + Tooltip tooltip = new Tooltip(sb.toString()); + l.setTooltip(tooltip); + } + }); + + + for (Human h : humanRepository.getAll()) { + if (h.getBirthdate().getMonth().getValue() == month && h.getBirthdate().getDayOfMonth() == ld.getDayOfMonth()) { + l.setStyle("-fx-background-color: yellow; -fx-font-size: 26;"); + break; + } + } + this.add(l, ld.getDayOfWeek().getValue(), rowCount); + if (ld.getDayOfWeek() == DayOfWeek.SUNDAY) { + this.add(new Label(Integer.toString(weekCount)), 0, rowCount); + rowCount++; + weekCount++; + } + ld = ld.plusDays(1); + } + } + + private boolean isFirstWeekZero(int year){ + LocalDate ld = LocalDate.of(year, 1, 1); + for (int i = 1; i <= 4; i++) { + if(ld.getDayOfWeek() == DayOfWeek.THURSDAY){ + return false; + } + ld=ld.plusDays(1); + } + return true; + } +} diff --git a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql index e186c4e..77c45d4 100644 --- a/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql +++ b/src/cz/spsmb/ctvrtak/f_pop/a_mvp_based/a_birthdate_reminder/resources/data/data.sql @@ -1,7 +1,20 @@ INSERT INTO human (id, email, firstName, secondName, birthdate) VALUES -(1, 'as@ff.com', 'Dan', 'Kolář', '2001-01-01'), -(2, 'aadss@fsdf.com', 'Pavel', 'Fíkovníků', '1900-01-01'), -(3, 'aadssdfs@fsdf.com', 'Petr', 'Pavel', '1212-07-07'), -(4,'jirka.potucek@seznam.cz','Jirka','Potůček','2003-2-16'), -(5, 'ahdslk@seznam.cz','Martin','Louka','2000-06-29') -; +(1, 'dan.kolar@gmail.com', 'Dan', 'Kolář', '2001-01-01'), +(2, 'pavel.fikovniku@seznam.cz', 'Pavel', 'Fíkovníků', '1900-01-01'), +(3, 'petr.pavel@email.cz', 'Petr', 'Pavel', '1212-07-07'), +(4, 'jirka.potucek@seznam.cz', 'Jirka', 'Potůček', '2003-02-16'), +(5, 'martin.louka@spotify.com', 'Martin', 'Louka', '2000-06-29'), +(6, 'marian.abdul@yahoo.com', 'Marian', 'Abdul', '1975-08-15'), +(7, 'jan.novak@hotmail.com', 'Jan', 'Novák', '1995-04-12'), +(8, 'anna.kralova@seznam.cz', 'Anna', 'Králová', '1988-12-31'), +(9, 'michal.vesely@gmail.com', 'Michal', 'Veselý', '1970-09-15'), +(10, 'petr.novak@email.cz', 'Petr', 'Novák', '1985-03-20'), +(11, 'anna.janackova@seznam.cz', 'Anna', 'Janáčková', '1990-07-15'), +(12, 'jiri.honzik@gmail.com', 'Jiří', 'Honzík', '1978-10-01'), +(13, 'martina.svobodova@outlook.cz', 'Martina', 'Svobodová', '2001-02-05'), +(14, 'radek.kral@centrum.cz', 'Radek', 'Král', '1965-11-23'), +(15, 'tomas.prochazka@yahoo.com', 'Tomáš', 'Procházka', '1989-06-14'), +(16, 'petra.novotna@seznam.cz', 'Petra', 'Novotná', '1992-09-30'), +(17, 'jakub.pavelka@email.cz', 'Jakub', 'Pavelka', '1980-12-10'), +(18, 'klara.vyskocilova@gmail.com', 'Klára', 'Vyskočilová', '1973-05-28'), +(19, 'jan.bubenik@volny.cz', 'Jan', 'Bubeník', '2002-01-29'); \ No newline at end of file