Commit 569910af authored by alexandre.ducarne's avatar alexandre.ducarne
Browse files

Rebase

parent 1bc6ae89
package main.java.client.data;
import java.util.List;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.*;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IComToData;
import main.java.common.interfaces.client.IDataToCom;
import main.java.common.interfaces.client.IDataToGame;
import main.java.common.interfaces.client.IDataToMain;
import main.java.common.interfaces.client.IMainToData;
import java.util.List;
public class DataCoreClient {
private UserHeavy localUserHeavy;
......@@ -74,14 +66,14 @@ public class DataCoreClient {
this.dataToCom = dataToCom;
}
public void setListGameLight(List<GameLight> listGameLight) {
this.listGameLight = listGameLight;
}
public List<GameLight> getListGameLight() {
return listGameLight;
}
public void setListGameLight(List<GameLight> listGameLight) {
this.listGameLight = listGameLight;
}
private boolean isMoveValid(Move playerMove, Board boardGame) {
return false;
}
......
package main.java.client.data;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserZero;
import main.java.common.interfaces.client.IGameToData;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
public class GameToDataImpl implements IGameToData {
DataCoreClient dataCoreClient;
......@@ -37,8 +38,11 @@ public class GameToDataImpl implements IGameToData {
}
@Override
public void newMessage(String m, UUID gameId) throws Exception {
dataCoreClient.getDataToCom().sendChatMessage(m, new Timestamp(new Date().getTime()),
dataCoreClient.getLocalUserHeavy().getId(), gameId);
public void newMessage(String m, UUID gameId) {
dataCoreClient.getDataToCom()
.sendChatMessage(
new Message(new Timestamp(new Date().getTime()),
m,
dataCoreClient.getLocalUserLight().convertToUserZero()), gameId);
}
}
package main.java.client.data;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.IMainToData;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
......@@ -11,17 +17,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.GameStatus;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IMainToData;
public class MainToDataImpl implements IMainToData {
DataCoreClient dataCoreClient;
......
package main.java.client.game;
import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
......@@ -12,6 +7,10 @@ import javafx.stage.Stage;
import main.java.client.game.controller.MainGameController;
import main.java.client.game.model.DataToGameImpl;
import main.java.common.interfaces.client.IGameToData;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
public class GameCore {
/**
......
package main.java.client.game.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TabPane;
......@@ -12,10 +9,12 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import main.java.client.game.GameCore;
import main.java.common.dataModel.Message;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* IHM-Game main controller class.
*
* <p>
* Links the FXML elements to the correct methods in the specialized controllers
*/
public class MainGameController {
......@@ -110,7 +109,7 @@ public class MainGameController {
/**
* ActionKeyPressed event managed by the areaSendMessage TextArea.
*
* <p>
* It is used to listen to Enter key, where we want to send a message when Enter
* is pressed
*
......
package main.java.client.game.controller;
import java.util.ArrayList;
import main.java.client.game.GameCore;
import main.java.common.dataModel.UserLight;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import main.java.client.game.GameCore;
import main.java.common.dataModel.UserLight;
import java.util.ArrayList;
/**
* Controller managing the side components
......
package main.java.client.game.model;
import java.io.IOException;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.java.client.game.GameCore;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserLight;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.IDataToGame;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.UUID;
public class DataToGameImpl implements IDataToGame {
/**
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.TilePane?>
<?import javafx.scene.layout.VBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.java.client.game.controller.MainGameController">
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="800.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.172-ea"
fx:controller="main.java.client.game.controller.MainGameController">
<top>
<GridPane id="gridTopPane" fx:id="toolBarGridPane" stylesheets="@game.css" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label fx:id="labelP1Name" alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="150.0" text="j1" GridPane.columnIndex="1">
<Label fx:id="labelP1Name" alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="150.0" text="j1"
GridPane.columnIndex="1">
<padding>
<Insets right="5.0" />
<Insets right="5.0"/>
</padding>
</Label>
<Label fx:id="labelP1Pawn" prefHeight="17.0" prefWidth="150.0" text="pion_j1" GridPane.columnIndex="2" />
<Label alignment="CENTER" prefHeight="17.0" prefWidth="150.0" text="VS" GridPane.columnIndex="3" />
<Label fx:id="labelP2Name" alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="150.0" text="j2" GridPane.columnIndex="4">
<Label fx:id="labelP1Pawn" prefHeight="17.0" prefWidth="150.0" text="pion_j1" GridPane.columnIndex="2"/>
<Label alignment="CENTER" prefHeight="17.0" prefWidth="150.0" text="VS" GridPane.columnIndex="3"/>
<Label fx:id="labelP2Name" alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="150.0" text="j2"
GridPane.columnIndex="4">
<padding>
<Insets right="5.0" />
<Insets right="5.0"/>
</padding>
</Label>
<Label fx:id="labelP2Pawn" prefHeight="17.0" prefWidth="150.0" text="pion_j2" GridPane.columnIndex="5" />
<Button fx:id="btnForfeit" mnemonicParsing="false" onAction="#onForfeit" prefHeight="27.0" prefWidth="78.0" text="Abandon" GridPane.columnIndex="7">
<Label fx:id="labelP2Pawn" prefHeight="17.0" prefWidth="150.0" text="pion_j2" GridPane.columnIndex="5"/>
<Button fx:id="btnForfeit" mnemonicParsing="false" onAction="#onForfeit" prefHeight="27.0"
prefWidth="78.0" text="Abandon" GridPane.columnIndex="7">
<GridPane.margin>
<Insets />
<Insets/>
</GridPane.margin>
</Button>
<Label prefHeight="17.0" prefWidth="150.0" />
<Label prefHeight="17.0" prefWidth="150.0" GridPane.columnIndex="6" />
<Label prefHeight="17.0" prefWidth="150.0"/>
<Label prefHeight="17.0" prefWidth="150.0" GridPane.columnIndex="6"/>
</children>
</GridPane>
</top>
......@@ -61,32 +53,43 @@
<children>
<HBox prefHeight="45.0" prefWidth="780.0">
<children>
<Label fx:id="labelPlaying" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="382.0" text="Tour" />
<Label fx:id="labelTimer" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="382.0" text="Chrono" />
</children></HBox>
<TilePane fx:id="gameBoard" prefHeight="727.0" prefWidth="780.0" />
<Label fx:id="labelPlaying" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefWidth="382.0" text="Tour"/>
<Label fx:id="labelTimer" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefWidth="382.0" text="Chrono"/>
</children>
</HBox>
<TilePane fx:id="gameBoard" prefHeight="727.0" prefWidth="780.0"/>
</children>
</VBox>
</center>
<right>
<TabPane id="ritghtTabPane" fx:id="sideRightTabPane" prefHeight="770.0" prefWidth="420.0" stylesheets="@game.css" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<TabPane id="ritghtTabPane" fx:id="sideRightTabPane" prefHeight="770.0" prefWidth="420.0"
stylesheets="@game.css" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab text="Participants">
<content>
<AnchorPane fx:id="panParticipants" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<AnchorPane fx:id="panParticipants" minHeight="0.0" minWidth="0.0" prefHeight="180.0"
prefWidth="200.0">
<children>
<ListView fx:id="listParticipants" layoutX="11.0" layoutY="98.0" prefHeight="200.0" prefWidth="400.0" />
</children></AnchorPane>
<ListView fx:id="listParticipants" layoutX="11.0" layoutY="98.0" prefHeight="200.0"
prefWidth="400.0"/>
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Chat">
<content>
<AnchorPane fx:id="panChat" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextArea fx:id="areaChatHistory" editable="false" layoutX="10.0" layoutY="42.0" prefHeight="566.0" prefWidth="400.0" />
<TextArea fx:id="areaSendMessage" layoutX="10.0" layoutY="627.0" onKeyPressed="#onActionKeyPressed" prefHeight="95.0" prefWidth="290.0" />
<Button fx:id="btnSendMessage" layoutX="324.0" layoutY="661.0" mnemonicParsing="false" onAction="#onSendMessage" text="Envoi" />
</children></AnchorPane>
<TextArea fx:id="areaChatHistory" editable="false" layoutX="10.0" layoutY="42.0"
prefHeight="566.0" prefWidth="400.0"/>
<TextArea fx:id="areaSendMessage" layoutX="10.0" layoutY="627.0"
onKeyPressed="#onActionKeyPressed" prefHeight="95.0" prefWidth="290.0"/>
<Button fx:id="btnSendMessage" layoutX="324.0" layoutY="661.0" mnemonicParsing="false"
onAction="#onSendMessage" text="Envoi"/>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
......
......@@ -26,7 +26,6 @@ public class DataToMainImpl implements IDataToMain {
}
@Override
public void notifyNonAcceptance() {
......@@ -49,11 +48,11 @@ public class DataToMainImpl implements IDataToMain {
@Override
public void sendLists(List<UserLight> usrList, List<GameLight> gameList) {
for (UserLight user : usrList){
for (UserLight user : usrList) {
this.getController().getFX().getModel().addUserInList(user);
}
for (GameLight game : gameList){
for (GameLight game : gameList) {
this.getController().getFX().getModel().addGameInList(game);
}
}
......@@ -64,7 +63,9 @@ public class DataToMainImpl implements IDataToMain {
}
@Override
public void sendUserInfo(UserLight userLight, UserHeavy userHeavy){
public void sendUserInfo(UserLight userLight, UserHeavy userHeavy) {
this.getController().getFX().getModel().setUserLight(userLight);
};
}
;
}
package main.java.client.main.controller;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
......@@ -14,6 +12,8 @@ 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 org.springframework.util.StringUtils;
import java.io.IOException;
......@@ -60,14 +60,12 @@ public class FXConnection {
private TextField createAccountTextFieldPseudo;
public FXConnection(){
public FXConnection() {
this.model = ClientApp.mainCore.getFX().getModel();
stage = new Stage();
}
public void setStage(Stage stage){
public void setStage(Stage stage) {
this.stage = stage;
}
......@@ -88,7 +86,7 @@ public class FXConnection {
@FXML
private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){
switch (buttonSource) {
case "loginButtonCreateAccount":
this.stage.setScene(CreateAccountScene());
break;
......@@ -108,7 +106,7 @@ public class FXConnection {
this.createAccountTextFieldName.getText(), this.createAccountTextFieldFirstName.getText(),
date, 0, this.createAccountPasswordFieldPassword.getText());
this.stage.setScene(LoginScene());
} catch (Exception exception){
} catch (Exception exception) {
System.out.println("Exception caught: " + exception.getMessage());
}
}
......@@ -134,13 +132,15 @@ public class FXConnection {
long start = System.currentTimeMillis();
this.getModel().setUserLight(null);
// identification attempt
ClientApp.mainCore.getMainToData().identify(this.loginTextFieldIdentifier.getText(),this.loginPasswordFieldPassword.getText(),hostname);
ClientApp.mainCore.getMainToData().identify(this.loginTextFieldIdentifier.getText(), this.loginPasswordFieldPassword.getText(), hostname);
// wait for response
do {Thread.sleep(500);} while (this.getModel().getUserLight() == null && System.currentTimeMillis() - start < 30000);
do {
Thread.sleep(500);
} while (this.getModel().getUserLight() == null && System.currentTimeMillis() - start < 30000);
// if the model has been filled by data layer
if (this.getModel().getUserLight() != null){
if (this.getModel().getUserLight() != null) {
FXHome fxHome = new FXHome();
fxHome.initialize("../fxml/home.fxml", this.stage);
} else {
......@@ -151,7 +151,7 @@ public class FXConnection {
} catch (TimeoutException exception) {
System.out.println("TimeoutException caught: " + exception.getMessage());
} catch (Exception exception){
} catch (Exception exception) {
this.loginTextConnectionError.setVisible(true);
System.out.println("Exception caught: " + exception);
}
......@@ -161,7 +161,7 @@ public class FXConnection {
break;
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.");
}
}
......@@ -181,7 +181,7 @@ public class FXConnection {
return setNewScene(fxmlLoader, root);
}
private Scene setNewScene(FXMLLoader loader, Pane root){
private Scene setNewScene(FXMLLoader loader, Pane root) {
FXConnection controller = loader.getController();
controller.setStage(stage);
......
package main.java.client.main.controller;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
......@@ -22,20 +18,20 @@ import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight;
public class FXCreateGame implements Initializable {
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
private MainApplicationModel model;
private Stage stage;
public class FXCreateGame implements Initializable {
@FXML
protected ComboBox<String> spectatorsCombo = new ComboBox<>();
@FXML
private ComboBox<String> chatCombo;
@FXML
protected ComboBox<String> colorCombo = new ComboBox<>();
private MainApplicationModel model;
private Stage stage;
@FXML
private ComboBox<String> chatCombo;
@FXML
private TextField createGameTextFieldLimitMove;
......
package main.java.client.main.controller;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.Border;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import java.net.URL;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.control.ListView;
import javafx.scene.control.ListCell;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserLight;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
public class FXHome {
......@@ -41,13 +34,13 @@ public class FXHome {
private ObservableList<UserLight> homeListViewUsersOnlineData = FXCollections.observableArrayList();
public FXHome(){
public FXHome() {
this.model = ClientApp.mainCore.getFX().getModel();
this.model.setFxHome(this);
stage = new Stage();
}
public void setStage(Stage stage){
public void setStage(Stage stage) {
this.stage = stage;
}
......@@ -65,7 +58,7 @@ public class FXHome {
stage.show();
}
public void updateData(){
public void updateData() {
// TODO : remove mock when real data update is possible
System.out.println("updateUsersListWithMock");
// Add some sample data.
......@@ -102,7 +95,7 @@ public class FXHome {
@FXML
private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId();
switch(buttonSource){
switch (buttonSource) {
case "homeButtonMyProfile":
BorderPane layout = FXMLLoader.load(
new URL(FXHome.class.getResource("../fxml/viewProfile.fxml").toExternalForm())
......@@ -113,7 +106,7 @@ public class FXHome {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../fxml/createGame.fxml"));
Parent padre = loader.load();
Scene switcher = new Scene(padre);
this.stage = (Stage)((Node)e.getSource()).getScene().getWindow();
this.stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
this.stage.setScene(switcher);
break;
case "homeDeconnection":
......@@ -121,11 +114,11 @@ public class FXHome {
fxConnection.initialize("../fxml/login.fxml", this.stage);
break;