Skip to content
Snippets Groups Projects
Commit f1bdab06 authored by alexandre.ducarne's avatar alexandre.ducarne
Browse files

Add maven support and base client app

parent 5058cafc
No related branches found
No related tags found
2 merge requests!87V3 (somehow),!58Release v2
Showing
with 623 additions and 0 deletions
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ai12</groupId>
<artifactId>othello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>othello</name>
<description>ai12 othello game</description>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package baleine.client;
import baleine.client.game.controller.TransApplicationController;
import baleine.client.game.view.TransApplicationView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* Main application
*
* @author thomas
*/
public class ClientApp extends Application {
private TransApplicationView view;
private TransApplicationController controller;
@Override
public void start(Stage stage) throws Exception {
view = new TransApplicationView();
controller = new TransApplicationController(view);
// Application content display
stage.setTitle("Translator");
stage.setScene(new Scene(view, 600, 400));
stage.setResizable(false);
stage.show();
}
/**
* Run
*
* @param args
*/
public static void main(String[] args) {
launch(args);
}
}
package baleine.client.game.controller;
import java.io.File;
import baleine.client.game.model.TransApplicationModel;
import baleine.client.game.model.TransItem;
import baleine.client.game.view.CardShape;
import baleine.client.game.view.TransApplicationView;
import javafx.collections.SetChangeListener;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
public class TransApplicationController {
/**
* Main application view
*/
private TransApplicationView mainView;
/**
* Application model
*/
private TransApplicationModel model;
/**
* Class constructor
*
* @param view : application view
*/
public TransApplicationController(TransApplicationView view) {
mainView = view;
model = new TransApplicationModel();
initViewActions();
initModelBiding();
}
/**
* Actions mapping of all components in the view
*/
private void initViewActions() {
mainView.openButton.setOnAction(evt -> actionOpenFile());
}
/**
* Model change listener
*/
private void initModelBiding() {
// Définition de la fonction de réponse
SetChangeListener<TransItem> f;
f = change -> {
if (change.wasRemoved()) {
mainView.cardsTilePane.getChildren().clear();
}
if (change.wasAdded()) {
mainView.cardsTilePane.getChildren().add(new CardShape(change.getElementAdded()));
}
};
// Installation de la fonction
model.transItemsSet.addListener(f);
}
/**
* Method called on openButton click
*/
private void actionOpenFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new ExtensionFilter("Text file", "*.txt"));
fileChooser.setInitialDirectory(new File(System.getProperty("user.dir") + "/src/td2/transFiles"));
File f = fileChooser.showOpenDialog(new Stage());
if (f != null) {
model.parse(f);
}
}
}
package baleine.client.game.model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class TransApplicationModel {
public ObservableSet<TransItem> transItemsSet;
public TransApplicationModel() {
transItemsSet = FXCollections.observableSet();
}
/**
* Parsing of the specified file
*
* @param f
*/
public void parse(File f) {
transItemsSet.clear();
try {
List<String> lines = Files.readAllLines(Paths.get(f.getAbsolutePath()));
for (String l : lines) {
String[] content = l.replace(" ", "").split("=");
transItemsSet.add(new TransItem(content[0], content[1]));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package baleine.client.game.model;
public class TransItem {
private String word;
private String translation;
/**
* Constructor using a word and its translation
*
* @param w : word
* @param t : word's translation
*/
public TransItem(String w, String t) {
word = w;
translation = t;
}
// Getters
public final String getWord() {
return word;
}
public final String getTranslation() {
return translation;
}
}
package baleine.client.game.view;
import baleine.client.game.model.TransItem;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
public class CardShape extends StackPane {
private TransItem relatedItem;
private boolean isTranslated;
private Text currentText;
private Rectangle rect;
private static final Color REGULAR_COLOR = Color.BURLYWOOD;
private static final Color SECONDARY_COLOR = Color.CORNFLOWERBLUE;
/**
* Constructor
*
* @param item : related TransItem
*/
public CardShape(TransItem item) {
relatedItem = item;
isTranslated = false; // default value
initHmi();
new CardController().bind();
}
/**
* HMI initialization
*/
private void initHmi() {
rect = new Rectangle(147, 60);
rect.setFill(Color.BURLYWOOD);
rect.setStroke(Color.WHITESMOKE);
rect.setStrokeWidth(3);
currentText = new Text(relatedItem.getWord());
getChildren().addAll(rect, currentText);
}
/**
* Changes the displayed text
*/
private void switchToTranslation() {
isTranslated = !isTranslated;
currentText.setText(isTranslated ? relatedItem.getTranslation() : relatedItem.getWord());
// Change color
if (rect.getFill().equals(REGULAR_COLOR)) {
rect.setFill(SECONDARY_COLOR);
} else {
rect.setFill(REGULAR_COLOR);
}
}
/**
* CardShape controller
*
* @author thomas
*/
private class CardController {
/**
* Binds the clic on the card to the language switch
*/
private void bind() {
currentText.setOnMouseClicked(evt -> switchToTranslation());
rect.setOnMouseClicked(evt -> switchToTranslation());
}
}
}
package baleine.client.game.view;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.TilePane;
/**
* Main application view
*/
public class TransApplicationView extends BorderPane {
public Button openButton;
public TilePane cardsTilePane;
/**
* Main application view constructor
*/
public TransApplicationView() {
super();
initToolBar();
initTilePane();
}
/**
* Application toolbar initialization, places the toolbar at the top
*/
private void initToolBar() {
openButton = new Button("Ouvrir");
ToolBar bar = new ToolBar(openButton);
setTop(bar);
}
/**
* Application cards panel
*/
private void initTilePane() {
cardsTilePane = new TilePane();
setCenter(cardsTilePane);
}
}
package baleine.client.main.controller;
import baleine.client.game.model.TransApplicationModel;
import baleine.client.game.model.TransItem;
import baleine.client.game.view.CardShape;
import baleine.client.game.view.TransApplicationView;
import javafx.collections.SetChangeListener;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import java.io.File;
public class TransApplicationController {
/**
* Main application view
*/
private TransApplicationView mainView;
/**
* Application model
*/
private TransApplicationModel model;
/**
* Class constructor
*
* @param view : application view
*/
public TransApplicationController(TransApplicationView view) {
mainView = view;
model = new TransApplicationModel();
initViewActions();
initModelBiding();
}
/**
* Actions mapping of all components in the view
*/
private void initViewActions() {
mainView.openButton.setOnAction(evt -> actionOpenFile());
}
/**
* Model change listener
*/
private void initModelBiding() {
// Définition de la fonction de réponse
SetChangeListener<TransItem> f;
f = change -> {
if (change.wasRemoved()) {
mainView.cardsTilePane.getChildren().clear();
}
if (change.wasAdded()) {
mainView.cardsTilePane.getChildren().add(new CardShape(change.getElementAdded()));
}
};
// Installation de la fonction
model.transItemsSet.addListener(f);
}
/**
* Method called on openButton click
*/
private void actionOpenFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new ExtensionFilter("Text file", "*.txt"));
fileChooser.setInitialDirectory(new File(System.getProperty("user.dir") + "/src/td2/transFiles"));
File f = fileChooser.showOpenDialog(new Stage());
if (f != null) {
model.parse(f);
}
}
}
package baleine.client.main.model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class TransApplicationModel {
public ObservableSet<TransItem> transItemsSet;
public TransApplicationModel() {
transItemsSet = FXCollections.observableSet();
}
/**
* Parsing of the specified file
*
* @param f
*/
public void parse(File f) {
transItemsSet.clear();
try {
List<String> lines = Files.readAllLines(Paths.get(f.getAbsolutePath()));
for (String l : lines) {
String[] content = l.replace(" ", "").split("=");
transItemsSet.add(new TransItem(content[0], content[1]));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package baleine.client.main.model;
public class TransItem {
private String word;
private String translation;
/**
* Constructor using a word and its translation
*
* @param w : word
* @param t : word's translation
*/
public TransItem(String w, String t) {
word = w;
translation = t;
}
// Getters
public final String getWord() {
return word;
}
public final String getTranslation() {
return translation;
}
}
package baleine.client.main.view;
import baleine.client.main.model.TransItem;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
public class CardShape extends StackPane {
private TransItem relatedItem;
private boolean isTranslated;
private Text currentText;
private Rectangle rect;
private static final Color REGULAR_COLOR = Color.BURLYWOOD;
private static final Color SECONDARY_COLOR = Color.CORNFLOWERBLUE;
/**
* Constructor
*
* @param item : related TransItem
*/
public CardShape(TransItem item) {
relatedItem = item;
isTranslated = false; // default value
initHmi();
new CardController().bind();
}
/**
* HMI initialization
*/
private void initHmi() {
rect = new Rectangle(147, 60);
rect.setFill(Color.BURLYWOOD);
rect.setStroke(Color.WHITESMOKE);
rect.setStrokeWidth(3);
currentText = new Text(relatedItem.getWord());
getChildren().addAll(rect, currentText);
}
/**
* Changes the displayed text
*/
private void switchToTranslation() {
isTranslated = !isTranslated;
currentText.setText(isTranslated ? relatedItem.getTranslation() : relatedItem.getWord());
// Change color
if (rect.getFill().equals(REGULAR_COLOR)) {
rect.setFill(SECONDARY_COLOR);
} else {
rect.setFill(REGULAR_COLOR);
}
}
/**
* CardShape controller
*
* @author thomas
*/
private class CardController {
/**
* Binds the clic on the card to the language switch
*/
private void bind() {
currentText.setOnMouseClicked(evt -> switchToTranslation());
rect.setOnMouseClicked(evt -> switchToTranslation());
}
}
}
package baleine.client.main.view;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.TilePane;
/**
* Main application view
*/
public class TransApplicationView extends BorderPane {
public Button openButton;
public TilePane cardsTilePane;
/**
* Main application view constructor
*/
public TransApplicationView() {
super();
initToolBar();
initTilePane();
}
/**
* Application toolbar initialization, places the toolbar at the top
*/
private void initToolBar() {
openButton = new Button("Ouvrir");
ToolBar bar = new ToolBar(openButton);
setTop(bar);
}
/**
* Application cards panel
*/
private void initTilePane() {
cardsTilePane = new TilePane();
setCenter(cardsTilePane);
}
}
package baleine.common.dataModel;
import java.util.List;
public class UserHeavy extends UserMeta {
String password;
String serverAddress;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment