Merge pull request 'Fix 103 (GUI)' (#108) from fix103 into master
All checks were successful
flavien's git/Projet_JAVA_P2P_STRI2A/pipeline/head This commit looks good

This commit is contained in:
Louis Royer 2020-04-12 19:13:37 +02:00
commit 46ea62e684
10 changed files with 833 additions and 1 deletions

4
Jenkinsfile vendored
View File

@ -14,6 +14,9 @@
sh 'echo "BUILDING TRACKER"'
sh 'echo Main-Class: tracker/Tracker > MANIFEST.MF'
sh 'jar -cvmf MANIFEST.MF tracker.jar $(find bin/ -maxdepth 1 -mindepth 1 -printf "-C bin %f\n")'
sh 'echo "BUILDING CLIENT GUI"'
sh 'echo Main-Class: gui/Gui > MANIFEST.MF'
sh 'jar -cvmf MANIFEST.MF clientGUI.jar $(find bin/ -maxdepth 1 -mindepth 1 -printf "-C bin %f\n")'
sh 'echo "CREATING sources.tar.gz"'
sh 'tar -zcvf sources.tar.gz src/'
}
@ -29,6 +32,7 @@
archiveArtifacts artifacts: 'client.jar', fingerprint: true
archiveArtifacts artifacts: 'server.jar', fingerprint: true
archiveArtifacts artifacts: 'tracker.jar', fingerprint: true
archiveArtifacts artifacts: 'clientGUI.jar', fingerprint:true
archiveArtifacts artifacts: 'sources.tar.gz', fingerprint: true
}
}

View File

@ -1,5 +1,5 @@
package exception;
public abstract class LocalException extends Exception {
private static final long serialVersionUID = 12L;
private static final long serialVersionUID = 13L;
}

179
src/gui/ArgumentsGen.java Normal file
View File

@ -0,0 +1,179 @@
package gui;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
*@version 1.0
*/
public class ArgumentsGen extends javax.swing.JPanel {
private javax.swing.JButton jButton1;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private static final long serialVersionUID = 13L;
/**
* Creates new form ArgumentsGen
*/
public ArgumentsGen() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox<>();
jTextField1 = new javax.swing.JTextField("7070");
jTextField2 = new javax.swing.JTextField("localhost");
jTextField3 = new javax.swing.JTextField("localhost");
jTextField4 = new javax.swing.JTextField("6969");
jButton1 = new javax.swing.JButton();
jLabel1.setText("Enter connection informations:");
jLabel2.setText("Server hostname:");
jLabel3.setText("Server port:");
jLabel4.setText("Tracker hostname:");
jLabel5.setText("Tracker port:");
jLabel6.setText("Client's protocol:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "TCP", "UDP" }));
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
jButton1.setText("Connect");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addGap(71, 71, 71)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField1)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
.addComponent(jTextField3)
.addComponent(jTextField4)))))
.addContainerGap(138, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap(16, Short.MAX_VALUE))
);
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/** Actions when click on connect: creat a clientP2Pgui with the infos from textfields*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String hostnameServer = jTextField2.getText();
String portServerStr = jTextField1.getText();
String hostnameTracker = jTextField3.getText();
String portTrackerStr = jTextField4.getText();
String protocolClient = jComboBox1.getSelectedItem().toString();
System.out.println("hostnameServer: " + hostnameServer);
System.out.println("portServer: " + portServerStr);
System.out.println("hostnameTracker: " + hostnameTracker);
System.out.println("portTracker: " + portTrackerStr);
System.out.println("protocol: " + protocolClient);
int portServer = Integer.parseInt(portServerStr);
int portTracker = Integer.parseInt(portTrackerStr);
ClientP2PGUI c = new ClientP2PGUI(hostnameServer, portServer, hostnameTracker, portTracker, protocolClient);
c.connect();
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
topFrame.dispose();
}
}

View File

@ -0,0 +1,145 @@
package gui;
import clientP2P.*;
import clientP2P.ClientInterface;
import clientP2P.ClientManagement;
import tools.SearchFile;
import tools.LogLevel;
import tools.Logger;
import localException.ProtocolError;
import localException.InternalError;
import localException.ProtocolError;
import localException.SizeError;
import localException.TransmissionError;
import localException.VersionError;
import localException.SocketClosed;
import remoteException.EmptyFile;
import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError;
import remoteException.NotFound;
import remoteException.ProtocolRemoteError;
import remoteException.VersionRemoteError;
import remoteException.NotATracker;
import remoteException.UnknownHost;
import java.io.IOException;
import java.net.UnknownHostException;
import java.net.SocketException;
import javax.swing.JFrame;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
/** Implementation of P2P-JAVA-PROJECT CLIENT interface for CLI
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class ClientInterfaceGUI extends ClientInterface {
/** Constructor with clientManagement, logger and scanner.
* @param clientManagement ClientManagement used
* @param logger Logger used
*/
Logger loggerC;
private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
public ClientInterfaceGUI(ClientManagement clientManagement, Logger logger, ServerManagementTCP smtcp, ServerManagementUDP smudp) {
super(clientManagement, logger);
this.loggerC = logger;
this.smtcp = smtcp;
this.smudp = smudp;
}
/** Implementation of Runnable
*/
public void run(){
boolean isRunning = initHostList();
if (isRunning) {
try{
int i = 1;
SearchFile searchEngine = new SearchFile();
int optionSearch = 0;
String searchInput = "";
String[] list = clientManagement.listDirectory();
//System.out.println("running ClientInterfaceGUI and creating window");
//for(String listItem: list){
//System.out.println(listItem);
//}
JFrame win = new JFrame();
win.setTitle("Client");
win.setSize(550, 250);
win.setLocationRelativeTo(null);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.add(new DownloadSelectionGen(list, clientManagement, loggerC, smtcp, smudp));
win.setVisible(true);
} catch (EmptyDirectory e) {
writeLog("Server has no file in directory", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Server has no file in directory");
}
catch (InternalError e) {
writeLog("Client internal error", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Client internal error");
} catch (UnknownHostException e) {
writeLog("Server host is unknown", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Server host is unknown");
} catch (IOException e) {
writeLog("Request cannot be send or response cannot be received", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Request cannot be send or response cannot be received");
} catch (TransmissionError e) {
writeLog("Message received is too big", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Message received is too big");
} catch (ProtocolError e) {
writeLog("Cannot decode servers response", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Cannot decode servers response");
} catch (VersionError e) {
writeLog("Servers response use bad version of the protocol", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Servers response use bad version of the protocol");
} catch (SizeError e) {
writeLog("Cannot handle this packets because of internal representation limitations of numbers on the client", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Cannot handle this packets because of internal representation limitations of numbers on the client");
} catch (InternalRemoteError e) {
writeLog("Server internal error", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Server internal error");
} catch (ProtocolRemoteError e) {
writeLog("Server cannot decode clients request", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Server cannot decode clients request");
} catch (VersionRemoteError e) {
writeLog("Server cannot decode this version of the protocol", LogLevel.Error);
ErrorFrame err = new ErrorFrame("Server cannot decode this version of the protocol");
}
}
}
/** Initialization of hostList with retry in failure
* @return true if successfully initialized
*/
private boolean initHostList() {
boolean contacted = false;
boolean firstLoop = true;
boolean stop = false;
while (!contacted && !stop) {
try {
if (!firstLoop) {
writeLog("Cannot contact tracker... ", LogLevel.Error);
}
firstLoop = false;
clientManagement.initHostList();
contacted = true;
} catch (SocketException e) {
} catch (UnknownHostException e) {
} catch (IOException e) {
} catch (Exception e) {
return false;
}
}
return !stop;
}
}

133
src/gui/ClientP2PGUI.java Normal file
View File

@ -0,0 +1,133 @@
package gui;
import clientP2P.*;
import java.util.List;
import clientP2P.ClientManagementUDP;
import clientP2P.ClientManagementTCP;
import serverP2P.ServerManagementUDP;
import clientP2P.ClientInterfaceCLI;
import serverP2P.ServerManagementTCP;
import tools.Logger;
import tools.LogLevel;
import tools.Directories;
import tools.HostItem;
import tools.ServerPortRange;
import tools.TrackerPortRange;
/** Client + Server implementation in GUI
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class ClientP2PGUI {
private String logDir = "logs/";
private String partsDir = ".parts/";
private Logger loggerServer;
private Logger loggerClient;
private Directories directories;
private HostItem tracker;
private HostItem server;
final static boolean DEBUG = false;
private String hostnameServer;
private String hostnameTracker;
private int portServer;
private int portTracker;
private String protocolP2P;
/** Initialize loggers if directories and logger are null,
* else fail silently.
*/
public void initDirectoriesAndLoggers() {
if (directories == null && loggerServer == null && loggerClient == null) {
directories = new Directories("P2P_JAVA_PROJECT_" + server.getPort());
directories.createSubdir(logDir);
loggerServer = new Logger(directories.getDataHomeDirectory() + logDir + "server.log", DEBUG);
loggerClient = new Logger(directories.getDataHomeDirectory() + logDir + "client.log", DEBUG);
directories.createSubdir(partsDir);
}
}
/** Constructor.
* @param hostnameServer hostname to bind
* @param portServer port to bind
* @param hostnameTracker hostname of tracker
* @param portTracker port of tracker
* @param protocolP2P protocol used
*/
public ClientP2PGUI(String hostnameServer, int portServer, String hostnameTracker, int portTracker, String protocolP2P) {
this.hostnameServer = hostnameServer;
this.hostnameTracker = hostnameTracker;
this.portServer = portServer;
this.portTracker = portTracker;
this.protocolP2P = protocolP2P;
final ServerPortRange serverPortRange = new ServerPortRange();
final TrackerPortRange trackerPortRange = new TrackerPortRange();
if (!serverPortRange.isPortInRange(portServer)){
ErrorFrame erreur = new ErrorFrame("SERVER: Port not in range. ");
}
if (!trackerPortRange.isPortInRange(portTracker)){
ErrorFrame erreur = new ErrorFrame("TRACKER: Port not in range");
}
server = new HostItem(hostnameServer, portServer);
tracker = new HostItem(hostnameTracker, portTracker);
initDirectoriesAndLoggers();
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory());
}
/**Initiate a connection using fields from ArgumentsGen*/
public void connect(){
System.out.println("using hostname : " + hostnameServer);
System.out.println("using port : " + portServer);
System.out.println("tracker hostname : " + hostnameTracker);
System.out.println("tracker port : " + portTracker);
ServerManagementUDP smudp = new ServerManagementUDP(directories.getDataHomeDirectory(), server, tracker, loggerServer);
ServerManagementTCP smtcp = new ServerManagementTCP(directories.getDataHomeDirectory(), server, tracker, loggerServer);
Thread tudp = new Thread(smudp);
tudp.setName("server UDP P2P-JAVA-PROJECT");
tudp.start();
Thread ttcp = new Thread(smtcp);
ttcp.setName("server TCP P2P-JAVA-PROJECT");
ttcp.start();
// Wait a bit before printing client interface
// This is not required, but allow to have a cleaner interface
try {
Thread.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Thread tclient;
switch (protocolP2P) {
case "UDP":
case "udp":
case "upd": // to avoid users typos
case "2" :
System.out.println("Starting with UDP");
ClientManagementUDP cmudp = new ClientManagementUDP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
tclient = new Thread(new ClientInterfaceGUI(cmudp, loggerClient, smtcp, smudp));
break;
case "TCP":
case "tcp":
case "1":
default:
System.out.println("Starting with TCP");
ClientManagementTCP cmtcp = new ClientManagementTCP(directories.getDataHomeDirectory(), tracker, directories.getDataHomeDirectory() + partsDir, loggerClient, server);
tclient = new Thread(new ClientInterfaceGUI(cmtcp, loggerClient, smtcp, smudp));
break;
}
tclient.setName("client P2P-JAVA-PROJECT GUI");
tclient.start();
try {
tclient.join();
} catch (InterruptedException e) {}
//smudp.setStop();
//smtcp.setStop();
}
}

View File

@ -0,0 +1,88 @@
package gui;
import clientP2P.*;
import clientP2P.ClientInterface;
import clientP2P.ClientManagement;
import tools.SearchFile;
import tools.LogLevel;
import tools.Logger;
import localException.ProtocolError;
import localException.InternalError;
import localException.ProtocolError;
import localException.SizeError;
import localException.TransmissionError;
import localException.VersionError;
import localException.SocketClosed;
import remoteException.EmptyFile;
import remoteException.EmptyDirectory;
import remoteException.InternalRemoteError;
import remoteException.NotFound;
import remoteException.ProtocolRemoteError;
import remoteException.VersionRemoteError;
import remoteException.NotATracker;
import remoteException.UnknownHost;
import java.io.IOException;
import java.net.UnknownHostException;
import java.net.SocketException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
public class DownloadFileGUI extends JPanel{
private static final long serialVersionUID = 13L;
private String fileToDownload;
private ClientManagement clientManagement;
private Logger logger;
private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
public DownloadFileGUI(String fileToDownload, ClientManagement clientManagement, Logger logger, ServerManagementTCP smtcp, ServerManagementUDP smudp){
this.fileToDownload = fileToDownload;
this.clientManagement = clientManagement;
this.logger = logger;
this.smtcp = smtcp;
this.smudp = smudp;
}
public void download() {
try {
System.out.println("Downloading " + fileToDownload + " ... ");
clientManagement.download(fileToDownload);
smudp.setStop();
smtcp.setStop();
ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " sucessfully downloaded");
} catch (NumberFormatException e) {
ErrorFrame erreur = new ErrorFrame("File " + fileToDownload + " unsucessfully downloaded, wrong number");
} catch (InternalError e) {
ErrorFrame err = new ErrorFrame("Client internal error");
} catch (UnknownHostException e) {
ErrorFrame err = new ErrorFrame("Server host is unknown");
} catch (IOException e) {
ErrorFrame err = new ErrorFrame("Request cannot be send or response cannot be received");
} catch (TransmissionError e) {
ErrorFrame err = new ErrorFrame("Message received is too big");
} catch (ProtocolError e) {
ErrorFrame err = new ErrorFrame("Cannot decode servers response");
} catch (VersionError e) {
ErrorFrame err = new ErrorFrame("Servers response use bad version of the protocol");
} catch (SizeError e) {
ErrorFrame err = new ErrorFrame("Cannot handle this packets because of internal representation limitations of numbers on the client");
} catch (InternalRemoteError e) {
ErrorFrame err = new ErrorFrame("Server internal error");
} catch (ProtocolRemoteError e) {
ErrorFrame err = new ErrorFrame("Server cannot decode clients request");
} catch (VersionRemoteError e) {
ErrorFrame err = new ErrorFrame("Server cannot decode this version of the protocol");
} catch (NotFound e) {
ErrorFrame err = new ErrorFrame("Server has not this file in directory");
} catch (EmptyFile e) {
ErrorFrame err = new ErrorFrame("File is empty");
}
}
}

View File

@ -0,0 +1,143 @@
package gui;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import clientP2P.*;
import tools.LogLevel;
import tools.Logger;
import serverP2P.ServerManagementUDP;
import serverP2P.ServerManagementTCP;
/**
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class DownloadSelectionGen extends javax.swing.JPanel {
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JList<String> jList1;
private javax.swing.JScrollPane jScrollPane1;
private static final long serialVersionUID = 13L;
private String[] listFilesToDownload;
private ClientManagement clientManagement;
private Logger logger;
private ServerManagementTCP smtcp;
private ServerManagementUDP smudp;
/**
* @param listFilesToDownload list of files to display
* @param clientManagement clientManagement
* @param logger logger
* Creates new form ArgumentsGen
*/
public DownloadSelectionGen(String[] listFilesToDownload, ClientManagement clientManagement, Logger logger, ServerManagementTCP smtcp, ServerManagementUDP smudp) {
this.listFilesToDownload = listFilesToDownload;
this.clientManagement = clientManagement;
this.logger = logger;
this.smtcp = smtcp;
this.smudp = smudp;
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList<>();
jButton2 = new javax.swing.JButton();
jLabel1.setText("Select a file to download:");
jButton1.setText("Download");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jList1.setModel(new javax.swing.AbstractListModel<String>() {
String[] strings = listFilesToDownload;
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
jList1.setSelectedIndex(0);
jButton2.setText("Back");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(97, 97, 97)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(104, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(23, 23, 23))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(24, Short.MAX_VALUE))
);
}// </editor-fold>
/** Actions to initiate when button "Download" is pressed */
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String fileSelected = jList1.getSelectedValue();
System.out.println("File to download: " + fileSelected);
DownloadFileGUI dl = new DownloadFileGUI(fileSelected, clientManagement, logger, smtcp, smudp);
dl.download();
}
/** Actions to initiate when button "Back" is initiate */
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
ArgumentsGen a = new ArgumentsGen();
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
topFrame.add(a);
this.setVisible(false);
}
}

92
src/gui/ErrorFrame.java Normal file
View File

@ -0,0 +1,92 @@
package gui;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
*/
public class ErrorFrame extends javax.swing.JFrame {
private javax.swing.JLabel jLabel1;
private javax.swing.JToggleButton jToggleButton1;
private String message;
private static final long serialVersionUID = 13L;
/**
* @param message error message that will be displayed
* Create new Errorframe, used to display an error and stop the program when needed
*/
public ErrorFrame(String message) {
this.message = message;
initComponents();
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jToggleButton1 = new javax.swing.JToggleButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jToggleButton1.setText("Close");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
jLabel1.setText(message);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(253, 253, 253)
.addComponent(jToggleButton1)))
.addContainerGap(205, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(30, 30, 30)
.addComponent(jToggleButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
this.setLocationRelativeTo(null);
this.setAlwaysOnTop(true);
pack();
}// </editor-fold>
/**force exit the program when the button "Close" is pressed*/
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(1);
}
}

20
src/gui/Gui.java Normal file
View File

@ -0,0 +1,20 @@
package gui;
import javax.swing.JFrame;
/** Class to download file
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
* Class used to create the Graphical interface
*/
public class Gui{
public static void main(String[] args) {
MainWindow win = new MainWindow();
}
}

28
src/gui/MainWindow.java Normal file
View File

@ -0,0 +1,28 @@
package gui;
import javax.swing.JFrame;
/** Class to download file
* @author Louis Royer
* @author Flavien Haas
* @author JS Auge
* @version 1.0
* Class used to create the main window of the GUI
*/
public class MainWindow extends JFrame{
private static final long serialVersionUID = 13L;
public MainWindow(){
JFrame fenetre = new JFrame();
fenetre.setTitle("Client");
fenetre.setSize(550, 250);
fenetre.setLocationRelativeTo(null);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.add(new ArgumentsGen());
fenetre.setVisible(true);
}
}