Reformat whole project

This commit is contained in:
Arnaud Vergnet 2021-01-31 20:28:54 +01:00
parent 547c94110e
commit b281b4b530
37 changed files with 159 additions and 161 deletions

View file

@ -7,10 +7,10 @@ import org.json.JSONObject;
@SuppressWarnings("FieldCanBeLocal") @SuppressWarnings("FieldCanBeLocal")
public class Config { public class Config {
private ServerConfig serverConfig;
private LocalConfig localConfig;
private final String SERVER_KEY = "serveur"; private final String SERVER_KEY = "serveur";
private final String LOCAL_KEY = "local"; private final String LOCAL_KEY = "local";
private ServerConfig serverConfig;
private LocalConfig localConfig;
public Config() { public Config() {
serverConfig = new ServerConfig(); serverConfig = new ServerConfig();
@ -30,6 +30,7 @@ public class Config {
public ServerConfig getServerConfig() { public ServerConfig getServerConfig() {
return serverConfig; return serverConfig;
} }
public LocalConfig getLocalConfig() { public LocalConfig getLocalConfig() {
return localConfig; return localConfig;
} }
@ -38,21 +39,18 @@ public class Config {
public static class ServerConfig { public static class ServerConfig {
public static final int DEFAULT_PRESENCE_PORT = 35650; public static final int DEFAULT_PRESENCE_PORT = 35650;
public static final int DEFAULT_PROXY_PORT = 35750; public static final int DEFAULT_PROXY_PORT = 35750;
private JSONObject obj;
private boolean enabled;
private String uri;
private ServerType type;
private int presencePort;
private int proxyPort;
private final String ENABLED_KEY = "actif"; private final String ENABLED_KEY = "actif";
private final String URI_KEY = "uri"; private final String URI_KEY = "uri";
private final String TYPE_KEY = "type"; private final String TYPE_KEY = "type";
private final String PORTS_KEY = "ports"; private final String PORTS_KEY = "ports";
private final String PORT_PRESENCE_KEY = "presence"; private final String PORT_PRESENCE_KEY = "presence";
private final String PORT_PROXY_KEY = "proxy"; private final String PORT_PROXY_KEY = "proxy";
private JSONObject obj;
private boolean enabled;
private String uri;
private ServerType type;
private int presencePort;
private int proxyPort;
/** /**
* Basic constructor setting the default server configuration * Basic constructor setting the default server configuration
@ -160,14 +158,11 @@ public class Config {
@SuppressWarnings("FieldCanBeLocal") @SuppressWarnings("FieldCanBeLocal")
public static class LocalConfig { public static class LocalConfig {
public static final int DEFAULT_TCP_PORT = 31598; public static final int DEFAULT_TCP_PORT = 31598;
private JSONObject obj;
private boolean enabled;
private int port;
private final String ENABLED_KEY = "actif"; private final String ENABLED_KEY = "actif";
private final String PORT_KEY = "port"; private final String PORT_KEY = "port";
private JSONObject obj;
private boolean enabled;
private int port;
/** /**
* Basic constructor setting the default local configuration * Basic constructor setting the default local configuration

View file

@ -89,6 +89,14 @@ public class NetDiscoverer {
} }
private interface BroadcastReceivedCallback {
void onBroadcastReceived(InetAddress ipAddr, String data);
}
public interface ResponseReceivedCallback {
void onResponseReceived(InetAddress ipAddr, String data);
}
private static class BroadcastSender extends Thread { private static class BroadcastSender extends Thread {
private final String broadcastMessage; private final String broadcastMessage;
private final ErrorCallback errorCallback; private final ErrorCallback errorCallback;
@ -246,13 +254,4 @@ public class NetDiscoverer {
} }
} }
private interface BroadcastReceivedCallback {
void onBroadcastReceived(InetAddress ipAddr, String data);
}
public interface ResponseReceivedCallback {
void onResponseReceived(InetAddress ipAddr, String data);
}
} }

View file

@ -35,8 +35,8 @@ public class InsaPresence implements Presence {
private final String path; private final String path;
private final int presencePort; private final int presencePort;
private TcpConnection presenceConnection;
private final Proxy proxy; private final Proxy proxy;
private TcpConnection presenceConnection;
public InsaPresence(String path, int presencePort, int proxyPort) { public InsaPresence(String path, int presencePort, int proxyPort) {
this.path = path; this.path = path;

View file

@ -35,6 +35,7 @@ public class LoadingScreenController implements Initializable {
/** /**
* Instantly shows the loading screen * Instantly shows the loading screen
*
* @param label The text to display bellow the loading indicator * @param label The text to display bellow the loading indicator
*/ */
public void show(String label) { public void show(String label) {
@ -51,6 +52,7 @@ public class LoadingScreenController implements Initializable {
/** /**
* Sets the text to display bellow the loading indicator * Sets the text to display bellow the loading indicator
*
* @param label The text to use * @param label The text to use
*/ */
public void setLabel(@Nullable String label) { public void setLabel(@Nullable String label) {
@ -62,6 +64,7 @@ public class LoadingScreenController implements Initializable {
/** /**
* Gets the main container styles to apply custom styling * Gets the main container styles to apply custom styling
*
* @return The style list * @return The style list
*/ */
public ObservableList<String> getRootStyle() { public ObservableList<String> getRootStyle() {

View file

@ -4,9 +4,9 @@ import com.jfoenix.controls.JFXSnackbar;
import fr.insa.clavardator.client.config.Config; import fr.insa.clavardator.client.config.Config;
import fr.insa.clavardator.client.config.ConfigLoader; import fr.insa.clavardator.client.config.ConfigLoader;
import fr.insa.clavardator.client.db.DatabaseController; import fr.insa.clavardator.client.db.DatabaseController;
import fr.insa.clavardator.client.server.ServerType;
import fr.insa.clavardator.client.server.presence.Presence; import fr.insa.clavardator.client.server.presence.Presence;
import fr.insa.clavardator.client.server.presence.PresenceFactory; import fr.insa.clavardator.client.server.presence.PresenceFactory;
import fr.insa.clavardator.client.server.ServerType;
import fr.insa.clavardator.client.server.presence.UnknownPresenceException; import fr.insa.clavardator.client.server.presence.UnknownPresenceException;
import fr.insa.clavardator.client.ui.chat.ChatController; import fr.insa.clavardator.client.ui.chat.ChatController;
import fr.insa.clavardator.client.ui.dialogs.AboutDialogController; import fr.insa.clavardator.client.ui.dialogs.AboutDialogController;
@ -32,6 +32,7 @@ import java.util.TimerTask;
public class MainController implements Initializable { public class MainController implements Initializable {
private final CurrentUser currentUser; private final CurrentUser currentUser;
private final int DEFAULT_PORT = 31598;
@FXML @FXML
private StackPane root; private StackPane root;
@FXML @FXML
@ -50,14 +51,10 @@ public class MainController implements Initializable {
private LoadingScreenController loadingController; private LoadingScreenController loadingController;
@FXML @FXML
private ErrorScreenController errorController; private ErrorScreenController errorController;
private JFXSnackbar snackbar; private JFXSnackbar snackbar;
private UserList userList; private UserList userList;
private Presence presenceServer; private Presence presenceServer;
private boolean online; private boolean online;
private final int DEFAULT_PORT = 31598;
private int port = DEFAULT_PORT; private int port = DEFAULT_PORT;
private boolean localEnabled = true; private boolean localEnabled = true;

View file

@ -23,6 +23,7 @@ public class ToolbarController implements Initializable {
public void setEditListener(ButtonPressEvent listener) { public void setEditListener(ButtonPressEvent listener) {
editListeners = listener; editListeners = listener;
} }
public void setAboutListener(ButtonPressEvent listener) { public void setAboutListener(ButtonPressEvent listener) {
aboutListeners = listener; aboutListeners = listener;
} }
@ -32,6 +33,7 @@ public class ToolbarController implements Initializable {
editListeners.onPress(); editListeners.onPress();
} }
} }
public void onAboutPress() { public void onAboutPress() {
if (aboutListeners != null) { if (aboutListeners != null) {
aboutListeners.onPress(); aboutListeners.onPress();

View file

@ -1,10 +1,10 @@
package fr.insa.clavardator.client.ui.chat; package fr.insa.clavardator.client.ui.chat;
import fr.insa.clavardator.client.chat.ChatHistory; import fr.insa.clavardator.client.chat.ChatHistory;
import fr.insa.clavardator.lib.message.Message;
import fr.insa.clavardator.client.ui.LoadingScreenController; import fr.insa.clavardator.client.ui.LoadingScreenController;
import fr.insa.clavardator.client.ui.NoSelectionModel; import fr.insa.clavardator.client.ui.NoSelectionModel;
import fr.insa.clavardator.client.users.PeerUser; import fr.insa.clavardator.client.users.PeerUser;
import fr.insa.clavardator.lib.message.Message;
import fr.insa.clavardator.lib.util.ErrorCallback; import fr.insa.clavardator.lib.util.ErrorCallback;
import fr.insa.clavardator.lib.util.Log; import fr.insa.clavardator.lib.util.Log;
import javafx.application.Platform; import javafx.application.Platform;
@ -36,18 +36,19 @@ public class ChatController implements Initializable {
private VBox emptyContainer; private VBox emptyContainer;
private PeerUser remoteUser; private PeerUser remoteUser;
// public void setAttachmentListener(ButtonPressEvent listener) { // public void setAttachmentListener(ButtonPressEvent listener) {
// chatFooterController.setAttachmentListener(listener); // chatFooterController.setAttachmentListener(listener);
// } // }
public void setSendErrorListener(ErrorCallback listener) { public void setSendErrorListener(ErrorCallback listener) {
chatFooterController.setSendErrorListener(listener); chatFooterController.setSendErrorListener(listener);
} }
/** /**
* Check the user that finished loading is the right one then set the chat state to done * Check the user that finished loading is the right one then set the chat state to done
*
* @param user The user that finished loading * @param user The user that finished loading
*/ */
private void onHistoryLoaded (PeerUser user) { private void onHistoryLoaded(PeerUser user) {
if (user.equals(remoteUser)) { if (user.equals(remoteUser)) {
setState(State.DONE); setState(State.DONE);
scrollToEnd(); scrollToEnd();

View file

@ -24,6 +24,8 @@ import java.util.ResourceBundle;
* Controller for the chat input field and associated buttons * Controller for the chat input field and associated buttons
*/ */
public class ChatFooterController implements Initializable { public class ChatFooterController implements Initializable {
FileChooser fileChooser = new FileChooser();
File attachedFile;
@FXML @FXML
private HBox container; private HBox container;
@FXML @FXML
@ -32,15 +34,10 @@ public class ChatFooterController implements Initializable {
private JFXButton sendButton; private JFXButton sendButton;
@FXML @FXML
private JFXButton attachButton; private JFXButton attachButton;
private ErrorCallback sendErrorListeners; private ErrorCallback sendErrorListeners;
private PeerUser remoteUser; private PeerUser remoteUser;
private HashMap<PeerUser, String> savedText; private HashMap<PeerUser, String> savedText;
FileChooser fileChooser = new FileChooser();
File attachedFile;
public void setSendErrorListener(ErrorCallback listener) { public void setSendErrorListener(ErrorCallback listener) {
sendErrorListeners = listener; sendErrorListeners = listener;
} }

View file

@ -52,5 +52,6 @@ public class ChatHeaderController implements Initializable {
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) {} public void initialize(URL location, ResourceBundle resources) {
}
} }

View file

@ -1,9 +1,9 @@
package fr.insa.clavardator.client.ui.chat; package fr.insa.clavardator.client.ui.chat;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import fr.insa.clavardator.client.users.CurrentUser;
import fr.insa.clavardator.lib.message.FileMessage; import fr.insa.clavardator.lib.message.FileMessage;
import fr.insa.clavardator.lib.message.Message; import fr.insa.clavardator.lib.message.Message;
import fr.insa.clavardator.client.users.CurrentUser;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@ -30,6 +30,7 @@ public class MessageListItemController implements Initializable {
private Label timestamp; private Label timestamp;
@FXML @FXML
private FontIcon attachmentIcon; private FontIcon attachmentIcon;
/** /**
* Sets the message to display * Sets the message to display
* *
@ -108,5 +109,6 @@ public class MessageListItemController implements Initializable {
} }
@Override @Override
public void initialize(URL url, ResourceBundle rb) {} public void initialize(URL url, ResourceBundle rb) {
}
} }

View file

@ -7,8 +7,6 @@ import com.jfoenix.validation.base.ValidatorBase;
import fr.insa.clavardator.client.ui.ButtonPressEvent; import fr.insa.clavardator.client.ui.ButtonPressEvent;
import fr.insa.clavardator.client.users.CurrentUser; import fr.insa.clavardator.client.users.CurrentUser;
import fr.insa.clavardator.client.users.UserList; import fr.insa.clavardator.client.users.UserList;
import fr.insa.clavardator.lib.util.ParametrizedCallback;
import fr.insa.clavardator.lib.util.SimpleCallback;
import javafx.beans.property.ReadOnlyBooleanWrapper; import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@ -69,6 +67,7 @@ public class EditUsernameDialogController implements Initializable {
public void setOnSuccessListener(ButtonPressEvent listener) { public void setOnSuccessListener(ButtonPressEvent listener) {
this.successListener = listener; this.successListener = listener;
} }
public void setOnCancelListener(ButtonPressEvent listener) { public void setOnCancelListener(ButtonPressEvent listener) {
this.cancelListener = listener; this.cancelListener = listener;
} }
@ -76,12 +75,11 @@ public class EditUsernameDialogController implements Initializable {
/** /**
* Plays the dialog show animation * Plays the dialog show animation
* *
* @param root The dialog's root component
* @param mode The dialog display mode
* @implNote WARNING: Do not try to open the dialog instantly after closing it. * @implNote WARNING: Do not try to open the dialog instantly after closing it.
* Due to JFoenix animations, the dialog will not reopen. * Due to JFoenix animations, the dialog will not reopen.
* If you must, wait at least 500ms before reopening. * If you must, wait at least 500ms before reopening.
*
* @param root The dialog's root component
* @param mode The dialog display mode
*/ */
public void show(StackPane root, Mode mode) { public void show(StackPane root, Mode mode) {
setLocked(false); setLocked(false);
@ -202,7 +200,7 @@ public class EditUsernameDialogController implements Initializable {
textField.setOnKeyPressed(event -> { textField.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) { if (event.getCode() == KeyCode.ENTER) {
event.consume(); event.consume();
if(!textField.getText().isEmpty()){ if (!textField.getText().isEmpty()) {
onConfirm(); onConfirm();
} }
} }

View file

@ -72,6 +72,7 @@ public class UserActiveIndicatorController implements Initializable {
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) {} public void initialize(URL location, ResourceBundle resources) {
}
} }

View file

@ -4,8 +4,8 @@ import com.jfoenix.controls.JFXButton;
import fr.insa.clavardator.client.ui.ButtonPressEvent; import fr.insa.clavardator.client.ui.ButtonPressEvent;
import fr.insa.clavardator.client.ui.UserSelectedEvent; import fr.insa.clavardator.client.ui.UserSelectedEvent;
import fr.insa.clavardator.client.users.PeerUser; import fr.insa.clavardator.client.users.PeerUser;
import fr.insa.clavardator.lib.users.User;
import fr.insa.clavardator.client.users.UserList; import fr.insa.clavardator.client.users.UserList;
import fr.insa.clavardator.lib.users.User;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
@ -22,14 +22,17 @@ public class UserListController implements Initializable {
private ButtonPressEvent refreshUserListener; private ButtonPressEvent refreshUserListener;
private UserSelectedEvent userSelectedListener; private UserSelectedEvent userSelectedListener;
public UserListController() {} public UserListController() {
}
public void setRefreshUserListener(ButtonPressEvent listener) { public void setRefreshUserListener(ButtonPressEvent listener) {
refreshUserListener = listener; refreshUserListener = listener;
} }
public void setUserSelectedListener(UserSelectedEvent listener) { public void setUserSelectedListener(UserSelectedEvent listener) {
userSelectedListener = listener; userSelectedListener = listener;
} }
public void onRefreshUserListPress() { public void onRefreshUserListPress() {
if (refreshUserListener != null) { if (refreshUserListener != null) {
refreshUserListener.onPress(); refreshUserListener.onPress();
@ -38,6 +41,7 @@ public class UserListController implements Initializable {
/** /**
* Enables or disables the refresh button * Enables or disables the refresh button
*
* @param enabled True to enable, false otherwise * @param enabled True to enable, false otherwise
*/ */
public void setRefreshButtonEnabled(boolean enabled) { public void setRefreshButtonEnabled(boolean enabled) {
@ -63,6 +67,7 @@ public class UserListController implements Initializable {
/** /**
* Sets the user list to subscribe to * Sets the user list to subscribe to
*
* @param userList The user list to use * @param userList The user list to use
*/ */
public void setUserList(UserList userList) { public void setUserList(UserList userList) {

View file

@ -111,5 +111,6 @@ public class UserListItemController implements Initializable {
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) {} public void initialize(URL location, ResourceBundle resources) {
}
} }

View file

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!--suppress JavaFxUnresolvedFxIdReference -->
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<!--suppress JavaFxUnresolvedFxIdReference --> <AnchorPane xmlns:fx="http://javafx.com/fxml/1"
<?import javafx.scene.control.Label?> xmlns="http://javafx.com/javafx/11.0.1" fx:controller="fr.insa.clavardator.client.ui.chat.ChatController"
<?import com.jfoenix.controls.JFXSpinner?>
<?import javafx.geometry.Insets?>
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.insa.clavardator.client.ui.chat.ChatController"
stylesheets="@../styles.css" styleClass="container"> stylesheets="@../styles.css" styleClass="container">
<StackPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" <StackPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

View file

@ -5,8 +5,8 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import org.kordamp.ikonli.javafx.FontIcon?> <?import org.kordamp.ikonli.javafx.FontIcon?>
<HBox xmlns="http://javafx.com/javafx" <HBox xmlns:fx="http://javafx.com/fxml"
xmlns:fx="http://javafx.com/fxml" xmlns="http://javafx.com/javafx"
fx:controller="fr.insa.clavardator.client.ui.chat.ChatFooterController" fx:controller="fr.insa.clavardator.client.ui.chat.ChatFooterController"
stylesheets="@../styles.css" styleClass="container" alignment="CENTER" spacing="10.0" fx:id="container"> stylesheets="@../styles.css" styleClass="container" alignment="CENTER" spacing="10.0" fx:id="container">
<padding> <padding>

View file

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?> <?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import org.kordamp.ikonli.javafx.FontIcon?> <?import org.kordamp.ikonli.javafx.FontIcon?>
<VBox xmlns="http://javafx.com/javafx/11.0.1" <VBox xmlns:fx="http://javafx.com/fxml/1"
xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/11.0.1"
fx:controller="fr.insa.clavardator.client.ui.chat.MessageListItemController" fx:controller="fr.insa.clavardator.client.ui.chat.MessageListItemController"
stylesheets="@../styles.css" stylesheets="@../styles.css"
styleClass="inner" styleClass="inner"

View file

@ -2,7 +2,6 @@
<?import com.jfoenix.controls.JFXButton?> <?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXDialog?> <?import com.jfoenix.controls.JFXDialog?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
@ -22,7 +21,7 @@
<padding> <padding>
<Insets bottom="10"/> <Insets bottom="10"/>
</padding> </padding>
<Label styleClass="dialog-title" >À Propos</Label> <Label styleClass="dialog-title">À Propos</Label>
<VBox VBox.vgrow="ALWAYS" alignment="CENTER" spacing="30"> <VBox VBox.vgrow="ALWAYS" alignment="CENTER" spacing="30">
<Label VBox.vgrow="ALWAYS">Application réalisée par Yohan SIMARD et Arnaud VERGNET</Label> <Label VBox.vgrow="ALWAYS">Application réalisée par Yohan SIMARD et Arnaud VERGNET</Label>
<Label VBox.vgrow="ALWAYS">INSA Toulouse 2020-2021</Label> <Label VBox.vgrow="ALWAYS">INSA Toulouse 2020-2021</Label>

View file

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import org.kordamp.ikonli.javafx.FontIcon?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<?import org.kordamp.ikonli.javafx.FontIcon?>
<AnchorPane xmlns:fx="http://javafx.com/fxml" <AnchorPane xmlns:fx="http://javafx.com/fxml"
xmlns="http://javafx.com/javafx" xmlns="http://javafx.com/javafx"
fx:controller="fr.insa.clavardator.client.ui.dialogs.SnackbarController" fx:controller="fr.insa.clavardator.client.ui.dialogs.SnackbarController"

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import com.jfoenix.controls.JFXButton?>
<?import org.kordamp.ikonli.javafx.FontIcon?> <?import org.kordamp.ikonli.javafx.FontIcon?>
<VBox xmlns:fx="http://javafx.com/fxml" <VBox xmlns:fx="http://javafx.com/fxml"
xmlns="http://javafx.com/javafx" xmlns="http://javafx.com/javafx"

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!--suppress JavaFxUnresolvedFxIdReference --> <!--suppress JavaFxUnresolvedFxIdReference -->
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<StackPane xmlns:fx="http://javafx.com/fxml/1" <StackPane xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/11.0.1" xmlns="http://javafx.com/javafx/11.0.1"

View file

@ -1,4 +1,3 @@
/******************************************************** /********************************************************
THEME THEME
*********************************************************/ *********************************************************/
@ -17,7 +16,6 @@
} }
/******************************************************** /********************************************************
STYLE STYLE
*********************************************************/ *********************************************************/

View file

@ -3,10 +3,12 @@
<?import com.jfoenix.controls.JFXButton?> <?import com.jfoenix.controls.JFXButton?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import org.kordamp.ikonli.javafx.FontIcon?> <?import org.kordamp.ikonli.javafx.FontIcon?>
<VBox xmlns="http://javafx.com/javafx" <VBox xmlns:fx="http://javafx.com/fxml"
xmlns:fx="http://javafx.com/fxml" xmlns="http://javafx.com/javafx"
fx:controller="fr.insa.clavardator.client.ui.ToolbarController" fx:controller="fr.insa.clavardator.client.ui.ToolbarController"
stylesheets="@styles.css" styleClass="container"> stylesheets="@styles.css" styleClass="container">
<HBox alignment="CENTER_LEFT" prefHeight="64.0" spacing="10"> <HBox alignment="CENTER_LEFT" prefHeight="64.0" spacing="10">

View file

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.shape.Circle?> <?import javafx.scene.shape.Circle?>
<HBox xmlns="http://javafx.com/javafx" <HBox xmlns:fx="http://javafx.com/fxml"
xmlns:fx="http://javafx.com/fxml" xmlns="http://javafx.com/javafx"
fx:controller="fr.insa.clavardator.client.ui.users.UserActiveIndicatorController" fx:controller="fr.insa.clavardator.client.ui.users.UserActiveIndicatorController"
stylesheets="@../styles.css" alignment="CENTER"> stylesheets="@../styles.css" alignment="CENTER">
<Circle fx:id="circle" radius="5.0" styleClass="active-user-dot"/> <Circle fx:id="circle" radius="5.0" styleClass="active-user-dot"/>

View file

@ -4,13 +4,14 @@
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import org.kordamp.ikonli.javafx.FontIcon?> <?import org.kordamp.ikonli.javafx.FontIcon?>
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1" <AnchorPane xmlns:fx="http://javafx.com/fxml/1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.insa.clavardator.client.ui.users.UserListController" xmlns="http://javafx.com/javafx/11.0.1" fx:controller="fr.insa.clavardator.client.ui.users.UserListController"
stylesheets="@../styles.css" styleClass="container"> stylesheets="@../styles.css" styleClass="container">
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" <VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox alignment="CENTER" prefHeight="64.0" spacing="10.0"> <HBox alignment="CENTER" prefHeight="64.0" spacing="10.0">
<JFXButton mnemonicParsing="false" text="Utilisateurs" onMouseClicked="#onRefreshUserListPress" fx:id="refreshButton"> <JFXButton mnemonicParsing="false" text="Utilisateurs" onMouseClicked="#onRefreshUserListPress"
fx:id="refreshButton">
<graphic> <graphic>
<FontIcon iconLiteral="fas-sync-alt" iconSize="24"/> <FontIcon iconLiteral="fas-sync-alt" iconSize="24"/>
</graphic> </graphic>

View file

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!--suppress JavaFxUnresolvedFxIdReference -->
<?import com.jfoenix.controls.JFXButton?> <?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<!--suppress JavaFxUnresolvedFxIdReference --> <AnchorPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="40.0" xmlns="http://javafx.com/javafx/11.0.1"
<AnchorPane prefHeight="40.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="fr.insa.clavardator.client.ui.users.UserListItemController" stylesheets="@../styles.css" fx:controller="fr.insa.clavardator.client.ui.users.UserListItemController" stylesheets="@../styles.css"
styleClass="inner"> styleClass="inner">
<!--suppress JavaFxRedundantPropertyValue -->
<JFXButton fx:id="button" alignment="CENTER_LEFT" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" <JFXButton fx:id="button" alignment="CENTER_LEFT" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0"
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0" onAction="#onPress"> AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0" onAction="#onPress">
<graphic> <graphic>

View file

@ -1,7 +1,7 @@
package fr.insa.clavardator; package fr.insa.clavardator;
import fr.insa.clavardator.lib.message.Message;
import fr.insa.clavardator.client.db.DatabaseController; import fr.insa.clavardator.client.db.DatabaseController;
import fr.insa.clavardator.lib.message.Message;
import fr.insa.clavardator.lib.users.UserInformation; import fr.insa.clavardator.lib.users.UserInformation;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View file

@ -14,8 +14,8 @@ public class FileMessage extends Message {
public static final String STORED_FILES_FOLDER = "clavardator_stored_files"; public static final String STORED_FILES_FOLDER = "clavardator_stored_files";
private final String fileName; private final String fileName;
private String path;
byte[] rawFile = null; byte[] rawFile = null;
private String path;
/** /**
* Constructs a FileMessage * Constructs a FileMessage

View file

@ -17,7 +17,7 @@ public class Message implements Serializable, SenderInfo, RecipientInfo {
} }
public Message(User sender, User recipient, Date date) { public Message(User sender, User recipient, Date date) {
this(sender, recipient, date,""); this(sender, recipient, date, "");
} }
public Message(UserInformation sender, UserInformation recipient, Date date, String text) { public Message(UserInformation sender, UserInformation recipient, Date date, String text) {

View file

@ -14,12 +14,12 @@ import java.net.Socket;
public class TcpConnection { public class TcpConnection {
private final int port;
private final Object outputStreamGuard = new Object();
private Socket socket; private Socket socket;
private ObjectOutputStream outputStream; private ObjectOutputStream outputStream;
private ObjectInputStream inputStream; private ObjectInputStream inputStream;
private boolean shouldStop = false; private boolean shouldStop = false;
private final int port;
private final Object outputStreamGuard = new Object();
/** /**
* Creates a new connection, and connects to the peer * Creates a new connection, and connects to the peer
@ -103,6 +103,15 @@ public class TcpConnection {
return socket != null && socket.isConnected() && !socket.isClosed(); return socket != null && socket.isConnected() && !socket.isClosed();
} }
public interface SocketConnectedCallback {
void onSocketConnected(TcpConnection connection);
}
public interface MessageReceivedCallback {
void onMessageReceived(Object msg) throws IOException;
}
private class Connector extends Thread { private class Connector extends Thread {
private final InetAddress ipAddr; private final InetAddress ipAddr;
private final SocketConnectedCallback callback; private final SocketConnectedCallback callback;
@ -129,7 +138,6 @@ public class TcpConnection {
} }
} }
private class Sender extends Thread { private class Sender extends Thread {
private final Serializable message; private final Serializable message;
private final SimpleCallback callback; private final SimpleCallback callback;
@ -198,13 +206,4 @@ public class TcpConnection {
} }
} }
} }
public interface SocketConnectedCallback {
void onSocketConnected(TcpConnection connection);
}
public interface MessageReceivedCallback {
void onMessageReceived(Object msg) throws IOException;
}
} }

View file

@ -30,12 +30,16 @@ public class TcpListener {
} }
public interface NewConnectionCallback {
void onNewConnection(Socket clientSocket);
}
private static class Acceptor extends Thread { private static class Acceptor extends Thread {
private boolean shouldStop = false;
private final NewConnectionCallback callback; private final NewConnectionCallback callback;
private final ErrorCallback errorCallback; private final ErrorCallback errorCallback;
private ServerSocket server;
private final int port; private final int port;
private boolean shouldStop = false;
private ServerSocket server;
public Acceptor(int port, NewConnectionCallback callback, ErrorCallback errorCallback) { public Acceptor(int port, NewConnectionCallback callback, ErrorCallback errorCallback) {
this.port = port; this.port = port;
@ -66,9 +70,4 @@ public class TcpListener {
} }
} }
} }
public interface NewConnectionCallback {
void onNewConnection(Socket clientSocket);
}
} }

View file

@ -5,17 +5,10 @@ import java.beans.PropertyChangeSupport;
import java.io.Serializable; import java.io.Serializable;
public class User implements Serializable { public class User implements Serializable {
private String username;
private String id;
// Make this class observable // Make this class observable
private final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); private final transient PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public void addObserver(PropertyChangeListener listener) { private String username;
pcs.addPropertyChangeListener(listener); private String id;
}
public void removeObserver(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}
public User() { public User() {
} }
@ -29,6 +22,14 @@ public class User implements Serializable {
this.username = username; this.username = username;
} }
public void addObserver(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
}
public void removeObserver(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}
public PropertyChangeSupport getPcs() { public PropertyChangeSupport getPcs() {
return pcs; return pcs;
} }

View file

@ -21,6 +21,6 @@ shadowJar {
mergeServiceFiles() mergeServiceFiles()
} }
run{ run {
standardInput = System.in standardInput = System.in
} }

View file

@ -51,7 +51,7 @@ public class Main {
printVersion(); printVersion();
System.exit(0); System.exit(0);
} }
for (int i = 0; i < args.length -1; i++) { for (int i = 0; i < args.length - 1; i++) {
if (PROXY_ARGS.contains(args[i])) { if (PROXY_ARGS.contains(args[i])) {
proxyPort = getPort(args[i + 1], PROXY_PORT); proxyPort = getPort(args[i + 1], PROXY_PORT);
} }

View file

@ -30,7 +30,7 @@ public class Presence {
public void publish(UserInformation info) { public void publish(UserInformation info) {
ArrayList<UserInformation> msg = new ArrayList<>(1); ArrayList<UserInformation> msg = new ArrayList<>(1);
msg.add(info); msg.add(info);
for (Map.Entry<String,TcpConnection> entry : subscribers.entrySet()) { for (Map.Entry<String, TcpConnection> entry : subscribers.entrySet()) {
// Do not send update to self // Do not send update to self
if (!entry.getKey().equals(info.id)) { if (!entry.getKey().equals(info.id)) {
entry.getValue().send(msg, null, entry.getValue().send(msg, null,