Skip to content

Commit

Permalink
Added window refresh stategy on language change
Browse files Browse the repository at this point in the history
  • Loading branch information
Botxan committed Mar 26, 2022
1 parent a70294d commit 6ce2f1c
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 128 deletions.
16 changes: 16 additions & 0 deletions .idea/resourceBundles.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

232 changes: 111 additions & 121 deletions src/main/java/uicontrollers/BrowseQuestionsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,144 +20,134 @@
import utils.Dates;

public class BrowseQuestionsController implements Controller {
@FXML private Button btnClose;
@FXML private DatePicker datepicker;
@FXML private TableColumn<Event, Integer> ec1;
@FXML private TableColumn<Event, String> ec2;
@FXML private TableColumn<Event, Integer> qc1;
@FXML private TableColumn<Event, Integer> qc2;
@FXML private TableView<Event> tblEvents;
@FXML private TableView<Question> tblQuestions;
@FXML private Label eventDateLbl;
@FXML private Label eventsLbl;
@FXML private Label selectedEventLbl;


private List<LocalDate> holidays = new ArrayList<>();

private BlFacade businessLogic;
private MainGUI mainGUI;

public BrowseQuestionsController(BlFacade bl) {
businessLogic = bl;
}

@FXML
private ResourceBundle resources;

@FXML
private URL location;

@FXML
private Button btnClose;

@FXML
private DatePicker datepicker;

@FXML
private TableColumn<Event, Integer> ec1;

@FXML
private TableColumn<Event, String> ec2;
@FXML
void closeClick(ActionEvent event) {
mainGUI.goForward("MainTitle");
}

@FXML
private TableColumn<Event, Integer> qc1;
private void setEvents(int year, int month) {
Date date = Dates.toDate(year, month);

@FXML
private TableColumn<Event, Integer> qc2;
for (Date day : businessLogic.getEventsMonth(date)) {
holidays.add(Dates.convertToLocalDateViaInstant(day));
}
}

@FXML
private TableView<Event> tblEvents;
private void setEventsPrePost(int year, int month) {
LocalDate date = LocalDate.of(year, month, 1);
setEvents(date.getYear(), date.getMonth().getValue());
setEvents(date.plusMonths(1).getYear(), date.plusMonths(1).getMonth().getValue());
setEvents(date.plusMonths(-1).getYear(), date.plusMonths(-1).getMonth().getValue());
}

@FXML
private TableView<Question> tblQuestions;
@FXML
void initialize() {

setupEventSelection();

private MainGUI mainGUI;
setEventsPrePost(LocalDate.now().getYear(), LocalDate.now().getMonth().getValue());

private List<LocalDate> holidays = new ArrayList<>();
datepicker.setOnMouseClicked(e -> {
// get a reference to datepicker inner content
// attach a listener to the << and >> buttons
// mark events for the (prev, current, next) month and year shown
DatePickerSkin skin = (DatePickerSkin) datepicker.getSkin();
skin.getPopupContent().lookupAll(".button").forEach(node -> {
node.setOnMouseClicked(event -> {
List<Node> labels = skin.getPopupContent().lookupAll(".label").stream().toList();
String month = ((Label) (labels.get(0))).getText();
String year = ((Label) (labels.get(1))).getText();
YearMonth ym = Dates.getYearMonth(month + " " + year);
setEventsPrePost(ym.getYear(), ym.getMonthValue());
});
});

private BlFacade businessLogic;

public BrowseQuestionsController(BlFacade bl) {
businessLogic = bl;
}
});

datepicker.setDayCellFactory(new Callback<DatePicker, DateCell>() {
@Override
public DateCell call(DatePicker param) {
return new DateCell() {
@Override
public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);

if (!empty && item != null) {
if (holidays.contains(item)) {
this.setStyle("-fx-background-color: pink");
}
}
}
};
}
});

@FXML
void closeClick(ActionEvent event) {
mainGUI.goForward("MainTitle");
}
// a date has been chosen, update the combobox of Events
datepicker.setOnAction(actionEvent -> {
tblEvents.getItems().clear();
Vector<domain.Event> events = businessLogic.getEvents(Dates.convertToDate(datepicker.getValue()));
for (domain.Event ev : events) {
tblEvents.getItems().add(ev);
}
});

private void setEvents(int year, int month) {
Date date = Dates.toDate(year,month);
// Bind columns to Event attributes
ec1.setCellValueFactory(new PropertyValueFactory<>("eventID"));
ec2.setCellValueFactory(new PropertyValueFactory<>("description"));
// Bind columns to Question attributes
qc1.setCellValueFactory(new PropertyValueFactory<>("questionID"));
qc2.setCellValueFactory(new PropertyValueFactory<>("question"));

for (Date day : businessLogic.getEventsMonth(date)) {
holidays.add(Dates.convertToLocalDateViaInstant(day));
}
}

private void setEventsPrePost(int year, int month) {
LocalDate date = LocalDate.of(year, month, 1);
setEvents(date.getYear(), date.getMonth().getValue());
setEvents(date.plusMonths(1).getYear(), date.plusMonths(1).getMonth().getValue());
setEvents(date.plusMonths(-1).getYear(), date.plusMonths(-1).getMonth().getValue());
}

@FXML
void initialize() {

setupEventSelection();

setEventsPrePost(LocalDate.now().getYear(), LocalDate.now().getMonth().getValue());

datepicker.setOnMouseClicked(e -> {
// get a reference to datepicker inner content
// attach a listener to the << and >> buttons
// mark events for the (prev, current, next) month and year shown
DatePickerSkin skin = (DatePickerSkin) datepicker.getSkin();
skin.getPopupContent().lookupAll(".button").forEach(node -> {
node.setOnMouseClicked(event -> {
List<Node> labels = skin.getPopupContent().lookupAll(".label").stream().toList();
String month = ((Label) (labels.get(0))).getText();
String year = ((Label) (labels.get(1))).getText();
YearMonth ym = Dates.getYearMonth(month + " " + year);
setEventsPrePost(ym.getYear(), ym.getMonthValue());
});
});

private void setupEventSelection() {
tblEvents.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
if (newSelection != null) {

});
tblQuestions.getItems().clear();
for (Question q : tblEvents.getSelectionModel().getSelectedItem().getQuestions()) {
tblQuestions.getItems().add(q);
}
}
});
}

datepicker.setDayCellFactory(new Callback<DatePicker, DateCell>() {
@Override
public DateCell call(DatePicker param) {
return new DateCell() {
@Override
public void updateItem(LocalDate item, boolean empty) {
super.updateItem(item, empty);
@Override
public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}

if (!empty && item != null) {
if (holidays.contains(item)) {
this.setStyle("-fx-background-color: pink");
}
}
}
};
}
});

// a date has been chosen, update the combobox of Events
datepicker.setOnAction(actionEvent -> {
tblEvents.getItems().clear();
Vector<domain.Event> events = businessLogic.getEvents(Dates.convertToDate(datepicker.getValue()));
for (domain.Event ev : events) {
tblEvents.getItems().add(ev);
}
});

// Bind columns to Event attributes
ec1.setCellValueFactory(new PropertyValueFactory<>("eventID"));
ec2.setCellValueFactory(new PropertyValueFactory<>("description"));
// Bind columns to Question attributes
qc1.setCellValueFactory(new PropertyValueFactory<>("questionID"));
qc2.setCellValueFactory(new PropertyValueFactory<>("question"));

}

private void setupEventSelection() {
tblEvents.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
if (newSelection != null) {

tblQuestions.getItems().clear();
for (Question q : tblEvents.getSelectionModel().getSelectedItem().getQuestions()) {
tblQuestions.getItems().add(q);
}
}
});
}

@Override
public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}
@Override
public void redraw() {
btnClose.setText(ResourceBundle.getBundle("Etiquetas").getString("Close"));
eventDateLbl.setText(ResourceBundle.getBundle("Etiquetas").getString("EventDate"));
eventsLbl.setText(ResourceBundle.getBundle("Etiquetas").getString("Events"));
selectedEventLbl.setText(ResourceBundle.getBundle("Etiquetas").getString("SelectedEvent"));
ec2.setText(ResourceBundle.getBundle("Etiquetas").getString("Events"));
qc1.setText("#" + ResourceBundle.getBundle("Etiquetas").getString("Question"));
qc2.setText(ResourceBundle.getBundle("Etiquetas").getString("Question"));
}
}
9 changes: 9 additions & 0 deletions src/main/java/uicontrollers/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
import ui.MainGUI;

public interface Controller {
/**
* Setter for the main GUI
* @param mainGUI the main GUI
*/
void setMainApp(MainGUI mainGUI);

/**
* Refreshes all the texts inside the window
*/
public void redraw();
}
5 changes: 5 additions & 0 deletions src/main/java/uicontrollers/CreateQuestionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,9 @@ public void updateItem(LocalDate item, boolean empty) {
public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}

@Override
public void redraw() {

}
}
5 changes: 5 additions & 0 deletions src/main/java/uicontrollers/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public LoginController(BlFacade bl) {
public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}

@Override
public void redraw() {

}
}
5 changes: 5 additions & 0 deletions src/main/java/uicontrollers/MainGUIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ void initialize() {}
public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}

@Override
public void redraw() {

}
}
6 changes: 6 additions & 0 deletions src/main/java/uicontrollers/NavBarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}

@Override
public void redraw() {

}

/* -------------------------------- LEFT SIDE BUTTONS -------------------------------- */

/**
Expand Down Expand Up @@ -140,6 +145,7 @@ void setLocale(ActionEvent e) {
}

((Button) e.getSource()).getStyleClass().add("selectedLang");
mainGUI.getHistory().getCurrentWindow().getController().redraw();
}


Expand Down
5 changes: 5 additions & 0 deletions src/main/java/uicontrollers/RegisterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public RegisterController(BlFacade bl) {
public void setMainApp(MainGUI mainGUI) {
this.mainGUI = mainGUI;
}

@Override
public void redraw() {

}
}
6 changes: 3 additions & 3 deletions src/main/resources/BrowseQuestions.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AnchorPane prefHeight="405.0" prefWidth="992.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="uicontrollers.BrowseQuestionsController">
<children>
<DatePicker fx:id="datepicker" layoutX="24.0" layoutY="78.0" />
<Label layoutX="24.0" layoutY="49.0" text="%EventDate" />
<Label fx:id="eventDateLbl" layoutX="24.0" layoutY="49.0" text="%EventDate" />
<TableView fx:id="tblEvents" layoutX="232.0" layoutY="78.0" prefHeight="200.0" prefWidth="330.0">
<columns>
<TableColumn fx:id="ec1" maxWidth="200.0" minWidth="30.0" prefWidth="200.0" text="Id" />
Expand All @@ -29,9 +29,9 @@
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<Label layoutX="232.0" layoutY="49.0" text="%Events" />
<Label fx:id="eventsLbl" layoutX="232.0" layoutY="49.0" text="%Events" />
<Label layoutX="358.0" layoutY="49.0" text=" " />
<Label layoutX="576.0" layoutY="49.0" text="%SelectedEvent" />
<Label fx:id="selectedEventLbl" layoutX="576.0" layoutY="49.0" text="%SelectedEvent" />
<Button fx:id="btnClose" layoutX="535.0" layoutY="332.0" mnemonicParsing="false" onAction="#closeClick" text="%Back" />
</children>
</AnchorPane>
4 changes: 0 additions & 4 deletions src/main/resources/Etiquetas.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ TermsException=You must accept Conditions and Privacy Policy before registering.
ErrorQuestion=Error\: Introduce a question
January=January
UserMenu=User Menu
UserMenuGUI.mnNewMenu.text=New menu
UserMenuGUI.rdbtnmntmNewRadioItem.text=New radio item
MainGUI.btnNewButton.text=New button
MainTitle=Bet & Ruin project
Psw6=The password must have 6 characters at least.
Login=Login
Expand All @@ -26,7 +23,6 @@ May=May
ForecastAddedSuccessfully=Forecast added successfully
March=March
CreateEvent=Create Event
UserMenuGUI.rdbtnmntmNewRadioItem_1.text=New radio item
ErrorEventHasFinished=Error\: Event Has Finished
October=October
Events=Events
Expand Down

0 comments on commit 6ce2f1c

Please sign in to comment.