summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java')
-rw-r--r--dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java194
1 files changed, 122 insertions, 72 deletions
diff --git a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
index 7bc00fd8..dc5de7b0 100644
--- a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
+++ b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java
@@ -39,6 +39,7 @@ import models.Image;
import models.Links;
import models.SessionData;
+import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.ini4j.InvalidFileFormatException;
import org.ini4j.Wini;
@@ -57,11 +58,14 @@ import config.Config;
public class FTPSearchDownloader_GUI extends JFrame implements
PropertyChangeListener {
+ private final static Logger LOGGER = Logger
+ .getLogger(FTPEditDownloader_GUI.class);
+
@SuppressWarnings("unused")
private JPanel contentPane;
private final JPanel contentPanel = new JPanel();
JLabel lblPath;
- JLabel downspeed;
+ JLabel lblDownSpeed;
User user;
JProgressBar progressBar;
String host = SessionData.session.getServerAdress();
@@ -69,24 +73,26 @@ public class FTPSearchDownloader_GUI extends JFrame implements
String downloadFile = "";
static String arg = "";
DownloadTask task;
- JLabel lblBytesread;
- JLabel lblNewLabel_3;
- JLabel labelVerbleibend;
+ JLabel lblFertig;
+ JLabel lblFilesize;
+ JLabel lblVerbleibend;
JFileChooser fc;
long filesize;
double speed;
int progress = 0; // progress of download
long bytesread;
- JLabel labelZeit;
+ JLabel lblZeit;
boolean taskrun = false;
ThriftConnection con = new ThriftConnection();
Client client = models.Client.clientcon.getClient();
JButton btnZurck = new JButton("Zurück");
JButton btnDownloadStarten = new JButton("Download starten");
JButton btnMainMenu = new JButton("Hauptmenü");
+ JButton btnDownloadStoppen = new JButton("Download abbrechen");
private JLabel lblAnleitung;
private boolean isCurrentlyLoading = false; // currently up or downloading
// file
+ private boolean isAborted = false; // down- or upload was manually aborted
/**
* Create the frame.
@@ -164,7 +170,8 @@ public class FTPSearchDownloader_GUI extends JFrame implements
if (dir != null) {
// is selected
// create dir if it does not exists.
- if (!dir.exists()) dir.mkdirs();
+ if (!dir.exists())
+ dir.mkdirs();
lblPath.setText(dir.getAbsolutePath());
} else {
// no directory selected
@@ -219,42 +226,42 @@ public class FTPSearchDownloader_GUI extends JFrame implements
lblDownloadgeschwindigkeit.setBounds(102, 275, 141, 14);
contentPanel.add(lblDownloadgeschwindigkeit);
- downspeed = new JLabel("0");
- downspeed.setBounds(374, 275, 117, 14);
- contentPanel.add(downspeed);
+ lblDownSpeed = new JLabel("0");
+ lblDownSpeed.setBounds(374, 275, 117, 14);
+ contentPanel.add(lblDownSpeed);
- JLabel lblFertig = new JLabel("Fertig:");
- lblFertig.setBounds(102, 325, 46, 14);
- contentPanel.add(lblFertig);
+ JLabel lblFertig_1 = new JLabel("Fertig:");
+ lblFertig_1.setBounds(102, 325, 46, 14);
+ contentPanel.add(lblFertig_1);
- lblBytesread = new JLabel("0");
- lblBytesread.setBounds(183, 325, 108, 14);
- contentPanel.add(lblBytesread);
+ lblFertig = new JLabel("0");
+ lblFertig.setBounds(183, 325, 108, 14);
+ contentPanel.add(lblFertig);
JLabel lblVon = new JLabel("von:");
lblVon.setBounds(318, 325, 46, 14);
contentPanel.add(lblVon);
- lblNewLabel_3 = new JLabel("0");
- lblNewLabel_3.setBounds(374, 325, 117, 14);
- contentPanel.add(lblNewLabel_3);
+ lblFilesize = new JLabel("0");
+ lblFilesize.setBounds(374, 325, 117, 14);
+ contentPanel.add(lblFilesize);
JLabel lblMbVerbleibend = new JLabel("Verbleibend:");
lblMbVerbleibend.setBounds(102, 350, 71, 14);
contentPanel.add(lblMbVerbleibend);
- labelVerbleibend = new JLabel("0");
- labelVerbleibend.setBounds(183, 350, 108, 14);
- contentPanel.add(labelVerbleibend);
+ lblVerbleibend = new JLabel("0");
+ lblVerbleibend.setBounds(183, 350, 108, 14);
+ contentPanel.add(lblVerbleibend);
JLabel lblGeschtzteVerbleibendeZeit = new JLabel(
"Geschätzte Verbleibende Zeit:");
lblGeschtzteVerbleibendeZeit.setBounds(102, 300, 150, 14);
contentPanel.add(lblGeschtzteVerbleibendeZeit);
- labelZeit = new JLabel("0");
- labelZeit.setBounds(374, 300, 117, 14);
- contentPanel.add(labelZeit);
+ lblZeit = new JLabel("0");
+ lblZeit.setBounds(374, 300, 117, 14);
+ contentPanel.add(lblZeit);
JPanel panel = new JPanel();
panel.setLayout(null);
@@ -404,6 +411,28 @@ public class FTPSearchDownloader_GUI extends JFrame implements
});
lblAnleitung.setBounds(102, 448, 311, 14);
contentPanel.add(lblAnleitung);
+ btnDownloadStoppen.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+
+ isAborted = true; // set flag
+ try {
+ client.DeleteFtpUser(user.userName);
+ LOGGER.info("Deleted FTP user.");
+ } catch (TException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ task.cancel(true);
+ resetValues();
+
+ // reset buttons
+ resetButtons();
+ }
+ });
+
+ btnDownloadStoppen.setEnabled(false);
+ btnDownloadStoppen.setBounds(306, 200, 173, 23);
+ contentPanel.add(btnDownloadStoppen);
{
JPanel buttonPane = new JPanel();
@@ -444,10 +473,10 @@ public class FTPSearchDownloader_GUI extends JFrame implements
si.setVisible(true);
dispose();
}// end else
- // save config in any case
+ // save config in any case
Config.setLastDownloadPath(lblPath.getText());
Config.store();
- }//end action
+ }// end action
});
btnZurck.setActionCommand("Cancel");
buttonPane.add(btnZurck);
@@ -457,7 +486,7 @@ public class FTPSearchDownloader_GUI extends JFrame implements
public void actionPerformed(ActionEvent arg0) {
Config.setLastDownloadPath(lblPath.getText());
Config.store();
-
+
MainMenue_GUI mm = new MainMenue_GUI();
mm.setVisible(true);
dispose();
@@ -472,6 +501,7 @@ public class FTPSearchDownloader_GUI extends JFrame implements
private void buttonDownloadActionPerformed(ActionEvent event) {
+ isAborted = false;
progressBar.setValue(0);
btnDownloadStarten.setEnabled(false); // verhindert schnellen zweiten
// Klick
@@ -502,61 +532,64 @@ public class FTPSearchDownloader_GUI extends JFrame implements
public void propertyChange(PropertyChangeEvent arg0) {
- progress = 0;
- if ("progress" == arg0.getPropertyName()) {
- progress = (Integer) arg0.getNewValue();
- progressBar.setValue(progress);
- }
-
- // Button zum Fertigstellen freischalten, wenn 100% erreicht sind
- if (isCurrentlyLoading() == true) {
- // not uploading currently
- btnMainMenu.setEnabled(false);
- } else {
- // currently uploading, don't let user interact
- btnMainMenu.setEnabled(true);
- }
+ if (isAborted == false) {
+ progress = 0;
+ if ("progress" == arg0.getPropertyName()) {
+ progress = (Integer) arg0.getNewValue();
+ progressBar.setValue(progress);
+ }
- if ("speed" == arg0.getPropertyName()) {
- speed = (double) arg0.getNewValue();
- // if(speed<=1){
+ // Button zum Fertigstellen freischalten, wenn 100% erreicht sind
+ if (isCurrentlyLoading() == false) {
+ // not uploading currently
+ btnDownloadStoppen.setEnabled(false);
+ btnMainMenu.setEnabled(true);
+ } else {
+ // currently uploading, don't let user interact
+ btnDownloadStoppen.setEnabled(true);
+ btnMainMenu.setEnabled(false);
+ }
- downspeed.setText(String.valueOf(speed).substring(0,
- String.valueOf(speed).lastIndexOf(".") + 3)
- + " MB/s");
+ if ("speed" == arg0.getPropertyName()) {
+ speed = (double) arg0.getNewValue();
+ // if(speed<=1){
- }
- if ("bytesread" == arg0.getPropertyName()) {
- bytesread = (long) arg0.getNewValue();
- lblBytesread.setText((bytesread / 1024 / 1024) + " MB");
- labelVerbleibend
- .setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024))
- + " MB");
-
- labelZeit
- .setText(String
- .valueOf(
- ((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
- .substring(
- 0,
- String.valueOf(
- (((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60)
- .lastIndexOf("."))
- + " Minuten");
+ lblDownSpeed.setText(String.valueOf(speed).substring(0,
+ String.valueOf(speed).lastIndexOf(".") + 3)
+ + " MB/s");
- }
- if ("filesize" == arg0.getPropertyName()) {
- filesize = (long) arg0.getNewValue();
- lblNewLabel_3.setText((filesize / 1024 / 1024) + " MB");
+ }
+ if ("bytesread" == arg0.getPropertyName()) {
+ bytesread = (long) arg0.getNewValue();
+ lblFertig.setText((bytesread / 1024 / 1024) + " MB");
+ lblVerbleibend
+ .setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024))
+ + " MB");
+
+ lblZeit.setText(String
+ .valueOf(
+ ((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1)
+ .substring(
+ 0,
+ String.valueOf(
+ (((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60)
+ .lastIndexOf("."))
+ + " Minuten");
- }
+ }
+ if ("filesize" == arg0.getPropertyName()) {
+ filesize = (long) arg0.getNewValue();
+ lblFilesize.setText((filesize / 1024 / 1024) + " MB");
- }
+ }
+ }// end if
+ }// end propertyChange
public boolean isCurrentlyLoading() {
isCurrentlyLoading = false;
- if (labelVerbleibend.getText().equals("0 MB") || labelVerbleibend.getText().equals("0")) {
+ if (lblVerbleibend.getText().equals("0 MB")
+ || lblVerbleibend.getText().equals("0")) {
isCurrentlyLoading = false;
} else {
isCurrentlyLoading = true;
@@ -564,4 +597,21 @@ public class FTPSearchDownloader_GUI extends JFrame implements
return isCurrentlyLoading;
}// end isCurrentlyLoading()
+ public void resetValues() {
+ lblDownSpeed.setText("0");
+ lblZeit.setText("0");
+ lblFertig.setText("0");
+ lblFilesize.setText("0");
+ lblVerbleibend.setText("0");
+ progressBar.setValue(0);
+ }// end resetValues
+
+ public void resetButtons() {
+ // btnFinish.setEnabled(false);
+ btnDownloadStarten.setEnabled(true);
+ btnDownloadStarten.setText("Download starten");
+ btnDownloadStoppen.setEnabled(false);
+
+ }// end resetButtons
+
}// end class \ No newline at end of file