resultReceive=communicationManager.receiveAndDecryptString();
+ if(resultReceive.success) {
+ if(resultReceive.payload.trim().startsWith("java")) {
+ communicationPanel.addLog(resultReceive.payload.trim(), true);
+ } else {
+ communicationPanel.addLog(resultReceive.payload.trim(), false);
+ }
+ } else {
+ communicationPanel.addLog(resultReceive.error.toString(), true);
+ }
+ }
+}
diff --git a/client/src/gui/panel/CommunicationPanel.java b/client/src/gui/panel/CommunicationPanel.java
new file mode 100644
index 0000000..dd32e56
--- /dev/null
+++ b/client/src/gui/panel/CommunicationPanel.java
@@ -0,0 +1,85 @@
+package gui.panel;
+
+import java.awt.GridBagConstraints;
+import java.awt.event.KeyEvent;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+import gui.GUI;
+
+/**
+ * Handle the communication with the server
+ * Allow the user to input and send commands and display their results.
+ */
+public class CommunicationPanel extends LogPanel {
+ private static final long serialVersionUID = 1L;
+ private JLabel commandLabel;
+ private JTextField commandText;
+ private JButton executeButton;
+
+ private GUI gui;
+
+ public CommunicationPanel(GUI gui) {
+ super();
+ this.gui=gui;
+ initialize();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ //GridBagLayout gbl_main=new GridBagLayout();
+ //this.setLayout(gbl_main);
+
+ commandLabel=new JLabel("labelCommand");
+ GridBagConstraints gbc_commandLabel=new GridBagConstraints();
+ gbc_commandLabel.gridx=0;
+ gbc_commandLabel.gridy=0;
+ gbc_commandLabel.anchor=GridBagConstraints.WEST;
+ this.add(commandLabel,gbc_commandLabel);
+
+ commandText=new JTextField();
+ commandText.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyPressed(java.awt.event.KeyEvent e) {
+ if(e.getKeyCode() == KeyEvent.VK_ENTER){
+ executeButton.doClick();
+ }
+ }
+ });
+ GridBagConstraints gbc_commandText=new GridBagConstraints();
+ gbc_commandText.gridx=0;
+ gbc_commandText.gridy=1;
+ gbc_commandText.weightx=1.0d;
+ gbc_commandText.fill=GridBagConstraints.BOTH;
+ this.add(commandText,gbc_commandText);
+
+ executeButton=new JButton("executeButton");
+ executeButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ if(commandText.getText().isBlank()==false) {
+ gui.sendCommand(commandText.getText());
+ }
+ }
+ });
+ GridBagConstraints gbc_executeButton=new GridBagConstraints();
+ gbc_executeButton.gridx=3;
+ gbc_executeButton.gridy=1;
+ this.add(executeButton,gbc_executeButton);
+
+ setText();
+ }
+
+ @Override
+ public void setText() {
+ super.setText();
+ ResourceBundle resourceBundle=ResourceBundle.getBundle("bundle/Bundle",Locale.getDefault());
+ commandLabel.setText(resourceBundle.getString("commandToExecute"));
+ executeButton.setText(resourceBundle.getString("execute"));
+ }
+}
\ No newline at end of file
diff --git a/client/src/gui/panel/ConnectionPanel.java b/client/src/gui/panel/ConnectionPanel.java
new file mode 100644
index 0000000..107d79b
--- /dev/null
+++ b/client/src/gui/panel/ConnectionPanel.java
@@ -0,0 +1,145 @@
+package gui.panel;
+
+import java.awt.GridBagConstraints;
+import java.awt.event.KeyEvent;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.JToggleButton;
+import javax.swing.SwingConstants;
+
+import gui.GUI;
+
+/**
+ * Handle connection state, allowing to set up and establish a connection as well as displaying it status.
+ */
+public class ConnectionPanel extends LogPanel {
+ private static final long serialVersionUID = 1L;
+ private JLabel addressLabel;
+ private JTextField addressText;
+ private JLabel portLabel;
+ private JTextField portText;
+ private JLabel addressPortSepartatorLabel;
+ private JToggleButton connectionToggleButton;
+
+ private GUI gui;
+
+ public void setAddress(String address) {
+ if(addressText!=null) addressText.setText(address);
+ }
+ public void setPort(String port) {
+ if(portText!=null) portText.setText(port);
+ }
+
+ public ConnectionPanel(GUI gui) {
+ super();
+ this.gui=gui;
+ initialize();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ /*GridBagLayout gbl_main=new GridBagLayout();
+ this.setLayout(gbl_main);*/
+
+ addressLabel=new JLabel("addressLabel");
+ GridBagConstraints gbc_addressLabel=new GridBagConstraints();
+ gbc_addressLabel.gridx=0;
+ gbc_addressLabel.gridy=0;
+ this.add(addressLabel,gbc_addressLabel);
+
+ addressText=new JTextField();
+ addressText.setHorizontalAlignment(SwingConstants.CENTER);
+ addressText.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyPressed(java.awt.event.KeyEvent e) {
+ if(e.getKeyCode() == KeyEvent.VK_ENTER){
+ if(connectionToggleButton.isSelected()==false) {
+ connectionToggleButton.doClick();
+ }
+ }
+ }
+ });
+ GridBagConstraints gbc_addressText=new GridBagConstraints();
+ gbc_addressText.gridx=0;
+ gbc_addressText.gridy=1;
+ gbc_addressText.weightx=0.5d;
+ gbc_addressText.fill=GridBagConstraints.BOTH;
+ this.add(addressText,gbc_addressText);
+
+ addressPortSepartatorLabel=new JLabel(" : ");
+ addressPortSepartatorLabel.setHorizontalAlignment(SwingConstants.CENTER);
+ GridBagConstraints gbc_addressPortSepartatorLabel=new GridBagConstraints();
+ gbc_addressPortSepartatorLabel.gridx=1;
+ gbc_addressPortSepartatorLabel.gridy=1;
+ this.add(addressPortSepartatorLabel,gbc_addressPortSepartatorLabel);
+
+ portLabel=new JLabel("portLabel");
+ GridBagConstraints gbc_portLabel=new GridBagConstraints();
+ gbc_portLabel.gridx=2;
+ gbc_portLabel.gridy=0;
+ this.add(portLabel,gbc_portLabel);
+
+ portText=new JTextField();
+ portText.setHorizontalAlignment(SwingConstants.CENTER);
+ portText.addKeyListener(new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyPressed(java.awt.event.KeyEvent e) {
+ if(e.getKeyCode() == KeyEvent.VK_ENTER){
+ if(connectionToggleButton.isSelected()==false) {
+ connectionToggleButton.doClick();
+ }
+ }
+ }
+ });
+ GridBagConstraints gbc_portText=new GridBagConstraints();
+ gbc_portText.gridx=2;
+ gbc_portText.gridy=1;
+ gbc_portText.weightx=0.5d;
+ gbc_portText.fill=GridBagConstraints.BOTH;
+ this.add(portText,gbc_portText);
+
+ connectionToggleButton=new JToggleButton("connectionToggleButton");
+ connectionToggleButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ boolean success=gui.changeConnectionStatus(connectionToggleButton.isSelected(),addressText.getText(),portText.getText());
+ if(success==false) {
+ connectionToggleButton.setSelected(false);
+ }
+ setTextConnectionToggleButton();
+ }
+ });
+ GridBagConstraints gbc_connectionToggleButton=new GridBagConstraints();
+ gbc_connectionToggleButton.gridx=3;
+ gbc_connectionToggleButton.gridy=1;
+ gbc_connectionToggleButton.fill=GridBagConstraints.HORIZONTAL;
+ this.add(connectionToggleButton,gbc_connectionToggleButton);
+
+ setText();
+ }
+
+ /**
+ * Set the correct text for toggleButtonConnection regarding the selected language and it's status.
+ */
+ private void setTextConnectionToggleButton() {
+ ResourceBundle resourceBundle=ResourceBundle.getBundle("bundle/Bundle",Locale.getDefault());
+ if(connectionToggleButton.isSelected()) {
+ connectionToggleButton.setText(resourceBundle.getString("connected"));
+ }else {
+ connectionToggleButton.setText(resourceBundle.getString("connection"));
+ }
+ }
+
+ @Override
+ public void setText() {
+ super.setText();
+ ResourceBundle resourceBundle=ResourceBundle.getBundle("bundle/Bundle",Locale.getDefault());
+ addressLabel.setText(resourceBundle.getString("address"));
+ portLabel.setText(resourceBundle.getString("port"));
+ setTextConnectionToggleButton();
+ }
+}
diff --git a/client/src/gui/panel/LogPanel.java b/client/src/gui/panel/LogPanel.java
new file mode 100644
index 0000000..851ca62
--- /dev/null
+++ b/client/src/gui/panel/LogPanel.java
@@ -0,0 +1,97 @@
+package gui.panel;
+
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextPane;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+
+public class LogPanel extends JPanel {
+ private static final long serialVersionUID = 1L;
+ private JTextPane logTextPane;
+ private StyledDocument logStyleDocument;
+ private SimpleAttributeSet normalAttributeSet;
+ private SimpleAttributeSet errorAttributeSet;
+ private JScrollPane logScrollPane;
+ private JButton clearLogButton;
+
+ public LogPanel( ) {
+ super();
+ normalAttributeSet=new SimpleAttributeSet();
+ normalAttributeSet.addAttribute(StyleConstants.Foreground,Color.black);
+ errorAttributeSet=new SimpleAttributeSet();
+ errorAttributeSet.addAttribute(StyleConstants.Foreground,Color.red);
+ // initialize();
+ }
+
+ /**
+ * Initialize the default state of the different GUI elements.
+ */
+ protected void initialize() {
+ GridBagLayout gbl_main=new GridBagLayout();
+ this.setLayout(gbl_main);
+
+ logTextPane=new JTextPane();
+ logStyleDocument=logTextPane.getStyledDocument();
+ logScrollPane=new JScrollPane(logTextPane);
+ GridBagConstraints gbc_logScrollPane=new GridBagConstraints();
+ gbc_logScrollPane.gridx=0;
+ gbc_logScrollPane.gridy=2;
+ gbc_logScrollPane.weightx=1.0d;
+ gbc_logScrollPane.weighty=1.0d;
+ gbc_logScrollPane.gridwidth=4;
+ gbc_logScrollPane.fill=GridBagConstraints.BOTH;
+ gbc_logScrollPane.insets=new Insets(5,0,0,0);
+ this.add(logScrollPane,gbc_logScrollPane);
+
+ clearLogButton=new JButton("clearLogButton");
+ clearLogButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ logTextPane.setText("");
+ }
+ });
+ GridBagConstraints gbc_clearLogButton=new GridBagConstraints();
+ gbc_clearLogButton.gridx=3;
+ gbc_clearLogButton.gridy=3;
+ gbc_clearLogButton.fill=GridBagConstraints.HORIZONTAL;
+ this.add(clearLogButton,gbc_clearLogButton);
+ }
+
+ /**
+ * Set the correct text for all graphical elements according to the default {@link Locale}.
+ * @see java.util.Locale#getDefault()
+ */
+ public void setText() {
+ ResourceBundle resourceBundle=ResourceBundle.getBundle("bundle/Bundle",Locale.getDefault());
+ clearLogButton.setText(resourceBundle.getString("clear"));
+ }
+
+ /**
+ * Append data to the log.
+ * @param data message to append.
+ * @param error indicate if data correspond to an error or not.
+ */
+ public void addLog(String data,Boolean error) {
+ try {
+ if(logStyleDocument.getLength()>0) data="\n"+data;
+ if(error) {
+ logStyleDocument.insertString(logStyleDocument.getLength(), data, errorAttributeSet);
+ }else {
+ logStyleDocument.insertString(logStyleDocument.getLength(), data, normalAttributeSet);
+ }
+ }catch(BadLocationException e) {
+ logTextPane.setText(logTextPane.getText()+"\n"+data.trim().trim());
+ }
+ }
+}
diff --git a/client/src/main/Primary.java b/client/src/main/Primary.java
new file mode 100644
index 0000000..d83ef5c
--- /dev/null
+++ b/client/src/main/Primary.java
@@ -0,0 +1,76 @@
+package main;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import generic.Status;
+import gui.GUI;
+import network.Client;
+import network.CommunicationManager;
+
+public class Primary {
+
+ public static void main(String[] args) {
+ String serverAddress="127.0.0.1";
+ int serverPort=6200;
+ String command="";
+
+ //Handle user arguments
+ if(args.length>0){
+ for(int i=0;i connectStatus=communicationManager.connect();
+ if(connectStatus.success==false) {
+ connectStatus.error.toString();
+ return;
+ }
+ System.out.println(resourceBundle.getString("connectedTo")+": "+serverAddress+":"+serverPort);
+
+ Status