Commit 769919c8 authored by Louis Bal Dit Sollier's avatar Louis Bal Dit Sollier
Browse files

Merge branch 'revert-7ca04d65' into 'feature/main/displayOwnUser'

Revert "Merge branch 'feature/main/displayOwnUser' into 'int/v2'"

See merge request !36
parents 8b92ffbc 1d22b134
...@@ -19,9 +19,6 @@ import javafx.scene.control.ListCell; ...@@ -19,9 +19,6 @@ import javafx.scene.control.ListCell;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Date; import java.util.Date;
public class FXHome { public class FXHome {
...@@ -99,10 +96,8 @@ public class FXHome { ...@@ -99,10 +96,8 @@ public class FXHome {
String buttonSource = ((Button) e.getSource()).getId(); String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){ switch(buttonSource){
case "homeButtonMyProfile": case "homeButtonMyProfile":
BorderPane layout = FXMLLoader.load( FXProfileConsult fxProfileConsult = new FXProfileConsult();
new URL(FXHome.class.getResource("../fxml/viewProfile.fxml").toExternalForm()) fxProfileConsult.initialize("../fxml/viewProfile.fxml", this.stage);
);
this.stage.setScene(new Scene(layout));
break; break;
case "homeButtonCreateGame": case "homeButtonCreateGame":
BorderPane layout = FXMLLoader.load( BorderPane layout = FXMLLoader.load(
......
package main.java.client.main.controller;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.ResourceBundle;
public class FXModifyProfile implements Initializable {
private MainApplicationModel model;
private Stage stage;
@FXML
private TextField modifyProfileTextFieldName;
@FXML
private TextField modifyProfileTextFieldFirstName;
@FXML
private PasswordField modifyProfilePasswordFieldPassword;
@FXML
private DatePicker modifyProfileTextFieldBirthDate;
@FXML
private TextField modifyProfileTextFieldPseudo;
public FXModifyProfile(){
this.model = ClientApp.mainCore.getFX().getModel();
stage = new Stage();
}
public void setStage(Stage stage){
this.stage = stage;
}
public void initialize(URL fxmlResource, ResourceBundle resource) {
UserLight user = this.model.getUserLight();
Date date = user.getDateOfBirth();
LocalDate localdate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
modifyProfileTextFieldName.setText(user.getLastName());
modifyProfileTextFieldFirstName.setText(user.getFirstName());
modifyProfileTextFieldPseudo.setText(user.getPseudo());
modifyProfileTextFieldBirthDate.setValue(localdate);
}
@FXML
private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){
case "modifyProfileButtonCancel":
setNewScene("../fxml/viewProfile.fxml", e);
break;
case "modifyProfileButtonValidate":
UpdateUserProfile();
setNewScene("../fxml/viewProfile.fxml", e);
break;
default:
System.out.println("["+buttonSource+"] A handler button was triggered, but no action was performed.");
}
}
private void UpdateUserProfile() {
try {
UserLight user = this.model.getUserLight();
LocalDate localDate = this.modifyProfileTextFieldBirthDate.getValue();
Date date = Date.from(localDate.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
user.setFirstName(this.modifyProfileTextFieldFirstName.getText());
user.setLastName(this.modifyProfileTextFieldName.getText());
user.setPseudo(this.modifyProfileTextFieldPseudo.getText());
user.setDateOfBirth(date);
ClientApp.mainCore.getMainToData().updatedProfile(user);
} catch (Exception exception){
System.out.println("Exception caught: " + exception.getMessage());
}
}
private void setNewScene(String path, MouseEvent e) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource(path));
Parent padre = loader.load();
Scene switcher = new Scene(padre);
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
this.stage.setScene(switcher);
}
}
package main.java.client.main.controller; package main.java.client.main.controller;
import javafx.fxml.Initializable;
import main.java.client.ClientApp; import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel; import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight; import main.java.common.dataModel.UserLight;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.Node;
import javafx.scene.Parent;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.time.Period;
import java.time.Year;
import java.time.ZoneId;
import java.util.Date; import java.util.Date;
import java.time.*;
import javafx.scene.control.DatePicker;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import java.io.IOException; import java.io.IOException;
import java.util.ResourceBundle;
public class FXProfileConsult implements Initializable { public class FXProfileConsult {
private MainApplicationModel model; private MainApplicationModel model;
private Stage stage; private Stage stage;
@FXML @FXML
private Text displayProfilePseudo; private TextField modifyProfileTextFieldName;
@FXML
private Text displayProfileLastName;
@FXML @FXML
private Text displayProfileFirstName; private TextField modifyProfileTextFieldFirstName;
@FXML @FXML
private Text displayProfileAge; private PasswordField modifyProfilePasswordFieldPassword;
@FXML @FXML
private Text displayProfileNbVictories; private DatePicker modifyProfileTextFieldBirthDate;
@FXML @FXML
private Text displayProfileNbGames; private TextField modifyProfileTextFieldPseudo;
public FXProfileConsult(){ public FXProfileConsult(){
this.model = ClientApp.mainCore.getFX().getModel(); this.model = ClientApp.mainCore.getFX().getModel();
...@@ -60,54 +50,106 @@ public class FXProfileConsult implements Initializable { ...@@ -60,54 +50,106 @@ public class FXProfileConsult implements Initializable {
this.stage = stage; this.stage = stage;
} }
public void initialize(URL fxmlResource, ResourceBundle resource) { public void initialize(String fxmlResource, Stage stage) throws IOException {
UserLight user = this.model.getUserLight(); FXMLLoader fxmlLoader = new FXMLLoader(getClass()
.getResource(fxmlResource));
BorderPane root = (BorderPane) fxmlLoader.load();
FXProfileConsult controller = fxmlLoader.getController();
controller.setStage(stage);
Date date = user.getDateOfBirth(); Scene scene = new Scene(root, ClientApp.APPLICATION_WIDTH, ClientApp.APPLICATION_HEIGHT);
LocalDate birthdate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); scene.getStylesheets().add(ClientApp.CSS_FILE_PATH);
Date now = new Date();
LocalDate today = now.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int age = Period.between(birthdate, today).getYears();
displayProfileFirstName.setText(user.getFirstName());
displayProfileAge.setText(Integer.toString(age));
displayProfileLastName.setText(user.getLastName());
displayProfilePseudo.setText(user.getPseudo());
displayProfileNbGames.setText(Integer.toString(user.getPlayedGames()));
displayProfileNbVictories.setText(Integer.toString(user.getWonGames()));
stage.setScene(scene);
stage.show();
} }
@FXML @FXML
private void handleButtonClick(MouseEvent e) throws NullPointerException, IOException { private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId(); String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){ switch(buttonSource){
case "viewProfileButtonClose": case "viewProfileButtonClose":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
FXHome fxHome = new FXHome(); FXHome fxHome = new FXHome();
fxHome.initialize("../fxml/home.fxml", this.stage); fxHome.initialize("../fxml/home.fxml", this.stage);
break; break;
case "viewProfileButtonEdit": case "viewProfileButtonEdit":
FXMLLoader loader = new FXMLLoader(getClass().getResource("../fxml/modifyProfile.fxml")); this.stage.setScene(ModifyProfileScene());
Parent padre = loader.load(); break;
Scene switcher = new Scene(padre); case "modifyProfileCancel":
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow(); this.stage.setScene(MyProfileScene());
this.stage.setScene(switcher); break;
case "modifyProfileValidate":
this.stage.setScene(UpdateUserProfile());
break; break;
default: default:
System.out.println("["+buttonSource+"] A handler button was triggered, but no action was performed."); System.out.println("["+buttonSource+"] A handler button was triggered, but no action was performed.");
} }
} }
private void setNewScene(String path, MouseEvent e) throws IOException { private Scene MyProfileScene() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource(path)); FXMLLoader fxmlLoader = new FXMLLoader(getClass()
Parent padre = loader.load(); .getResource("../fxml/viewProfile.fxml"));
Scene switcher = new Scene(padre); BorderPane root = (BorderPane) fxmlLoader.load();
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
this.stage.setScene(switcher); return setNewScene(fxmlLoader, root);
}
private Scene ModifyProfileScene() throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass()
.getResource("../fxml/modifyProfile.fxml"));
BorderPane root = (BorderPane) fxmlLoader.load();
UserLight user = this.model.getUserLight();
Date date = user.getDateOfBirth();
LocalDate localdate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
this.modifyProfileTextFieldName.setText(user.getLastName());
this.modifyProfileTextFieldFirstName.setText(user.getFirstName());
this.modifyProfileTextFieldPseudo.setText(user.getPseudo());
this.modifyProfileTextFieldBirthDate.setValue(localdate);
return setNewScene(fxmlLoader, root);
}
private Scene UpdateUserProfile() throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass()
.getResource("../fxml/viewProfile.fxml"));
BorderPane root = (BorderPane) fxmlLoader.load();
try {
UserLight user = this.model.getUserLight();
LocalDate localDate = this.modifyProfileTextFieldBirthDate.getValue();
Date date = java.util.Date.from(localDate.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
user.setFirstName(this.modifyProfileTextFieldFirstName.getText());
user.setLastName(this.modifyProfileTextFieldName.getText());
user.setPseudo(this.modifyProfileTextFieldPseudo.getText());
user.setDateOfBirth(date);
ClientApp.mainCore.getMainToData().updatedProfile(user);
} catch (Exception exception){
System.out.println("Exception caught: " + exception.getMessage());
}
return setNewScene(fxmlLoader, root);
} }
private Scene setNewScene(FXMLLoader loader, Pane root){
FXProfileConsult controller = loader.getController();
controller.setStage(stage);
Scene scene = new Scene(root, ClientApp.APPLICATION_WIDTH, ClientApp.APPLICATION_HEIGHT);
scene.getStylesheets().add(ClientApp.CSS_FILE_PATH);
return scene;
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment