Commit 275c3e94 authored by Peining Li's avatar Peining Li
Browse files

Merge branch 'ihm-main/develop' into 'develop'

Ihm main/develop

See merge request !131
parents f937701e 0006b9e1
......@@ -5,6 +5,7 @@
*/
package com.utclo23.ihmmain;
import com.utclo23.data.module.DataException;
import com.utclo23.ihmmain.constants.SceneName;
import com.utclo23.ihmmain.controller.AbstractController;
import com.utclo23.ihmmain.controller.PlayerProfileController;
......@@ -65,11 +66,11 @@ public class IHMMain {
} catch (FileNotFoundException ex) {
Logger.getLogger(PlayerListController.class.getName()).log(Level.SEVERE, null, ex);
}
//add onClose event handler which handle the event when user clicks X
//add onClose event handler which handle the event when user clics X
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent we) {
System.exit(0);
exit();
}
});
}
......@@ -176,4 +177,14 @@ public class IHMMain {
return scene;
}
public void exit(){
try{
facade.iDataIHMMain.signOut();
System.out.println("Logged out");
}catch (Exception e) {
//not displaying anything, the app is closing
}
System.exit(0);
}
}
......@@ -64,7 +64,7 @@ public class LoginController extends AbstractController{
*/
@FXML
private void exitAction(ActionEvent event){
System.exit(0);
getIhmmain().exit();
}
/**
......
......@@ -61,7 +61,7 @@ public class MenuController extends AbstractController{
@FXML
private void exit(ActionEvent event){
System.exit(0);
getIhmmain().exit();
}
@FXML
......
......@@ -5,9 +5,13 @@
*/
package com.utclo23.ihmmain.controller;
import com.utclo23.data.module.DataException;
import com.utclo23.data.structure.PublicUser;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.time.ZoneId;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.concurrent.Task;
......@@ -17,19 +21,25 @@ import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
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.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
/**
* Object: display all info of player profile.
* Display user's own profile (writable)
* Display others profiles (read-only)
* Displays all info of player profile.
* Displays user's own profile (writable).
* Displays others profiles (read-only).
*
* @author Lipeining
*/
......@@ -53,7 +63,8 @@ public class PlayerProfileController extends AbstractController{
private boolean isLoading = false;
private boolean isOther = false;
private String attribut;
private String imagePath;
private Image avatarImage;
private PopupController control;
@FXML
@Override
......@@ -65,6 +76,7 @@ public class PlayerProfileController extends AbstractController{
private void back(ActionEvent event) throws IOException{
getIhmmain().toMenu();
}
@FXML
private void toPlayerList(ActionEvent event) throws IOException{
getIhmmain().toPlayerList();
......@@ -77,6 +89,7 @@ public class PlayerProfileController extends AbstractController{
text = description.getText();
description.setText(text);
}
@FXML
private void closeEdit(KeyEvent event) throws IOException{
KeyCode code = event.getCode();
......@@ -84,54 +97,117 @@ public class PlayerProfileController extends AbstractController{
description.setEditable(false);
}
}
@FXML
private void editPlayerName(ActionEvent event) throws IOException{
attribut="PlayerName";
popup(attribut);
}
@FXML
private void editFirstName(ActionEvent event) throws IOException{
attribut="FirstName";
popup(attribut);
}
@FXML
private void editLastName(ActionEvent event) throws IOException{
attribut="LastName";
popup(attribut);
}
@FXML
private void editBirthday(ActionEvent event) throws IOException{
attribut="Birthday";
popup(attribut);
}
@FXML
private void editPassword(ActionEvent event) throws IOException{
attribut="Password";
popup(attribut);
}
@FXML
private void editAvatar(ActionEvent event) throws IOException, DataException{
String avatarPath;
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open avatar file");
File selectedFile = fileChooser.showOpenDialog(getIhmmain().primaryStage);
if (selectedFile != null){
avatarPath = selectedFile.getPath();
Logger.getLogger(CreateUserController.class.getName()).log(
Level.INFO, "The chosen file is : {0}", avatarPath);
getFacade().iDataIHMMain.updateFileImage(avatarPath);
refresh();
}
}
/**
* Generate a pop-up
* The content of pop-up is generated dynamically.
* For updating the birthday, the date picker replace the text field in pop-up.
* @param attribut:name of info that user would like to modify
* @throws IOException
*/
private void popup(String attribut) throws IOException{
final Stage primaryStage = getIhmmain().primaryStage;
String path = "/fxml/ihmmain/popup.fxml";
FXMLLoader loader = new FXMLLoader(getClass().getResource(path));
Parent sceneLoader = loader.load();
PopupController controller=loader.getController();
controller.setFacade(getFacade());
controller.setIhmmain(getIhmmain());
controller.setAttribut(attribut);
Scene newScene;
newScene = new Scene(sceneLoader);
Stage popup = new Stage();
popup.initOwner(primaryStage);
popup.setScene(newScene);
if(attribut == "Birthday"){
final DatePicker date = new DatePicker();
Button back = new Button();
Button submit = new Button();
back.setText("Back");
back.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
((Node) (event.getSource())).getScene().getWindow().hide();
}
});
submit.setText("Submit");
submit.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
try {
Date birthDate = Date.from(date.getValue().atStartOfDay(ZoneId.systemDefault()).toInstant());
getFacade().iDataIHMMain.updateBirthdate(birthDate);
refresh();
((Node) (event.getSource())).getScene().getWindow().hide();
} catch (DataException ex) {
Logger.getLogger(PlayerProfileController.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
Pane root = new Pane();
root.setId("root");
Scene display = new Scene(root,400,150);
display.getStylesheets().add(getClass().getResource("/styles/ihmmain.css").toExternalForm());
popup.setScene(display);
root.getChildren().add(back);
root.getChildren().add(submit);
back.setLayoutX(60);
back.setLayoutY(91);
submit.setLayoutX(231);
submit.setLayoutY(91);
root.getChildren().add(date);
date.setLayoutX(90);
date.setLayoutY(35);
}
else{
String path = "/fxml/ihmmain/popup.fxml";
FXMLLoader loader = new FXMLLoader(getClass().getResource(path));
Parent sceneLoader = loader.load();
PopupController controller=loader.getController();
controller.setFacade(getFacade());
controller.setIhmmain(getIhmmain());
controller.setAttribut(attribut);
Scene newScene;
newScene = new Scene(sceneLoader);
popup.setScene(newScene);
}
popup.show();
}
/**
* This function is for receiving the profile of other player asked by user
* This method is for receiving the profile of other player asked by user.
* @param player: profile sent by Data for us to display
* @throws IOException
*/
......@@ -141,8 +217,9 @@ public class PlayerProfileController extends AbstractController{
other = player;
}
}
/**
* This function is for waiting the profile
* This method is for waiting the profile.
* As soon as receive the profile sent by Data, skip the loading and refresh the page.
* @throws IOException
*/
......@@ -200,16 +277,32 @@ public class PlayerProfileController extends AbstractController{
new Thread(wait).start();
}
}
/**
* Get user's avatar
*/
public void getAvatar(PublicUser player){
byte[] thumbnail = player.getLightPublicUser().getAvatarThumbnail();
try{
ByteArrayInputStream inputStream = new ByteArrayInputStream(thumbnail);
avatarImage = new Image(inputStream);
}catch(NullPointerException e){
Logger.getLogger(
PlayerProfileController.class.getName()).log(Level.INFO,
"[PlayerProfile] - error - avatar is null."
);
}
}
@Override
/**
* Initialize all the info of profile
* Initializes all the info of profile.
*/
public void refresh(){
if (!isOther){
try{
//imagePath = me.getLightPublicUser().
//image.setImage(new Image (imagePath));
me = getFacade().iDataIHMMain.getMyPublicUserProfile();
getAvatar(me);
image.setImage(avatarImage);
userID .setText(me.getLightPublicUser().getPlayerName());
firstName.setText(me.getFirstName());
lastName.setText(me.getLastName());
......@@ -225,6 +318,8 @@ public class PlayerProfileController extends AbstractController{
}
else{
try{
getAvatar(other);
image.setImage(avatarImage);
userID.setText(other.getLightPublicUser().getPlayerName());
firstName.setText(other.getFirstName());
lastName.setText(other.getLastName());
......
......@@ -11,15 +11,16 @@ import javafx.scene.Node;
import javafx.scene.control.TextArea;
/**
* Object: Generate a pop-up to enter and to send new info to update player profile
* According to the label transformed by interface player profile, this controller will call
* the update function corresponding created by Data.
* Generates a pop-up to enter and to send new info to update player profile.
* According to the label transformed by interface player profile,
* this controller will call the update function corresponding created by Data.
*
* @author lipeining
*/
public class PopupController extends AbstractController{
public String label;
private boolean textnull = true;
@FXML
private TextArea field;
@FXML
......@@ -27,10 +28,15 @@ public class PopupController extends AbstractController{
((Node) (event.getSource())).getScene().getWindow().hide();
}
@FXML
private void update(ActionEvent event) throws IOException, DataException{
public void update(ActionEvent event) throws IOException, DataException{
String text;
text = field.getText();
switch(label){
if (text.isEmpty()){
field.setText("Can not send empty string");
}
else{
textnull = false;
switch(label){
case "PlayerName":
getFacade().iDataIHMMain.updatePlayername(text);
break;
......@@ -40,22 +46,20 @@ public class PopupController extends AbstractController{
case "LastName":
getFacade().iDataIHMMain.updateLastname(text);
break;
/* To-do: change popup*/
case "Birthday":
getFacade().iDataIHMMain.updateLastname(text);
break;
case "Password":
getFacade().iDataIHMMain.updatePassword(text);
break;
default:
Logger.getLogger(
PopupController.class.getName()).log(
Logger.getLogger( PopupController.class.getName()).log(
Level.INFO,
"[PlayerProfile] - error update profile, attribut not found."
);
}
}
if(textnull == false){
getIhmmain().controllerMap.get(SceneName.PLAYER_PROFILE.toString()).refresh();
((Node) (event.getSource())).getScene().getWindow().hide();
}
getIhmmain().controllerMap.get(SceneName.PLAYER_PROFILE.toString()).refresh();
((Node) (event.getSource())).getScene().getWindow().hide();
}
/**
*
......
......@@ -27,7 +27,7 @@
</HBox>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0">
<children>
<Button mnemonicParsing="false" text="Modify">
<Button mnemonicParsing="false" onAction="#editAvatar" text="Modify">
<opaqueInsets>
<Insets />
</opaqueInsets>
......@@ -116,9 +116,9 @@
<RowConstraints maxHeight="261.6125183105469" minHeight="10.0" prefHeight="67.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Statistics" GridPane.halignment="CENTER">
<Label text="Statistics" GridPane.halignment="LEFT">
<GridPane.margin>
<Insets left="10.0" />
<Insets left="90.0" />
</GridPane.margin>
</Label>
<GridPane prefHeight="125.0" prefWidth="368.0" GridPane.halignment="RIGHT" GridPane.rowIndex="1" GridPane.valignment="CENTER">
......@@ -141,7 +141,7 @@
<Label text="Played" GridPane.columnIndex="1" />
<Label text="Win" GridPane.columnIndex="2" />
<Label text="Loss" GridPane.columnIndex="3" />
<Label text="Abondon" GridPane.columnIndex="4" />
<Label text="Abandoned" GridPane.columnIndex="4" />
<Label prefHeight="17.0" prefWidth="0.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
......@@ -164,9 +164,9 @@
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="30.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="54.0" minHeight="10.0" prefHeight="54.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="74.0" minHeight="10.0" prefHeight="55.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="63.0" minHeight="10.0" prefHeight="61.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="68.0" minHeight="10.0" prefHeight="53.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="74.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
</rowConstraints>
<GridPane.margin>
<Insets left="80.0" />
......@@ -181,7 +181,10 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="backButton" mnemonicParsing="false" onAction="#back" text="Return" GridPane.halignment="CENTER" GridPane.valignment="TOP" />
<Button fx:id="backButton" mnemonicParsing="false" onAction="#back" text="Return" GridPane.halignment="LEFT" GridPane.valignment="TOP">
<GridPane.margin>
<Insets left="80.0" />
</GridPane.margin></Button>
<Button fx:id="playerList" mnemonicParsing="false" onAction="#toPlayerList" text="Other Player" GridPane.columnIndex="1" GridPane.valignment="TOP" />
</children>
</GridPane>
......
......@@ -9,7 +9,7 @@
<AnchorPane id="AnchorPane" prefHeight="150.0" prefWidth="300.0" stylesheets="@../../styles/ihmmain.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.utclo23.ihmmain.controller.PopupController">
<children>
<Pane prefHeight="151.0" prefWidth="400.0">
<Pane prefHeight="151.0" prefWidth="400.0" style="-fx-background-color: #061f30;">
<children>
<GridPane layoutX="51.0" layoutY="50.0" prefHeight="54.0" prefWidth="277.0">
<columnConstraints>
......
......@@ -6,7 +6,9 @@
#generalGrid{
-fx-background-color: #061f30;
}
#root{
-fx-background-color: #061f30;
}
.scroll-pane {
-fx-base: transparent;
-fx-background-color: transparent;
......
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