Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -27,44 +31,76 @@ 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();

}

public static void main(String[] args) {
Application.launch(args);

}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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');