From 605857a1ef614964d73ea83e0561d1bfb06e611b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 29 May 2015 17:56:36 +0200 Subject: [client] Compiles again, but is broken.... --- .../main/java/gui/image/FTPEditDownloader_GUI.java | 193 ++++++++------------- 1 file changed, 75 insertions(+), 118 deletions(-) (limited to 'dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java') diff --git a/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java index b7b0a9f4..11aed0f9 100644 --- a/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/FTPEditDownloader_GUI.java @@ -36,7 +36,7 @@ import models.person; import org.apache.log4j.Logger; import org.apache.thrift.TException; -import org.openslx.sat.thrift.iface.User; +import org.openslx.sat.thrift.iface.TransferInformation; import org.openslx.thrifthelper.ThriftManager; import util.GuiManager; @@ -46,23 +46,18 @@ import ftp.DownloadTask; import gui.intro.MainMenue_GUI; @SuppressWarnings("serial") -public class FTPEditDownloader_GUI extends JInternalFrame implements - PropertyChangeListener { +public class FTPEditDownloader_GUI extends JInternalFrame implements PropertyChangeListener { /** * Logger instance for this class. */ - private final static Logger LOGGER = Logger - .getLogger(FTPEditDownloader_GUI.class); - + private final static Logger LOGGER = Logger.getLogger(FTPEditDownloader_GUI.class); + private final JPanel contentPanel = new JPanel(); private JLabel lblPath; private JLabel lblDownSpeed; - private User user; private JProgressBar progressBar; private String host = SessionData.serverAdress; - private int port = 21; - private String downloadFile = ""; private DownloadTask task; private JLabel lblFertig; private JLabel lblFilesize; @@ -78,9 +73,9 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements private JButton btnDownloadStarten = new JButton("Download starten"); private JButton btnDownloadStoppen = new JButton("Download abbrechen"); private JLabel lblAnleitung; - private boolean isCurrentlyLoading = false; // currently up or downloading - // file + private boolean isCurrentlyLoading = false; // currently up or downloading file private boolean isAborted = false; // down- or upload was manually aborted + private TransferInformation transferInfo = null; public static final String HELP_MESSAGE = "
" + "Hier können Sie Images herunterladen.
" + "Klicken Sie anschließend auf \"Zurück\", um zu Ihrer vorherigen Auswahl zurückzugelangen.
" @@ -91,34 +86,25 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements */ public FTPEditDownloader_GUI() { + final String[] options = { "Beenden", "Abbrechen" }; - final Object[] options = { "Beenden", "Abbrechen" }; addInternalFrameListener(new InternalFrameAdapter() { @Override public void internalFrameClosing(InternalFrameEvent arg0) { if (taskrun == true) { // check if user wants to quit. - int choice = JOptionPane - .showOptionDialog( - null, - "Aktuell ist ein Download aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?", - "Upload aktiv", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, null, - options, options[1]); + int choice = JOptionPane.showOptionDialog( + null, + "Aktuell ist ein Download aktiv. Wollen Sie diesen Abbrechen und das Programm beenden?", + "Upload aktiv", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, + null, options, options[1]); // 0=beenden, 1=abbrechen if (choice == 0) { try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName,SessionData.authToken); - try { - ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); - } catch (TException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + ThriftManager.getSatClient().cancelDownload(transferInfo.token); + ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); } catch (TException e1) { - - e1.printStackTrace(); + LOGGER.error("Error cancelling download..", e1); } task.cancel(true); System.exit(0); @@ -129,7 +115,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements setResizable(false); setBackground(Color.WHITE); - setTitle("Dozentenmodul - Image herunterladen - "+person.verantwortlicher.getUserID()); + setTitle("Dozentenmodul - Image herunterladen - " + person.verantwortlicher.getUserID()); // Aktion die beim Schliessen durchgefuehrt werden soll setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); @@ -141,9 +127,9 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); { - JButton btnSpeicherortAuswhlen = new JButton( - "Speicherort auswählen"); + JButton btnSpeicherortAuswhlen = new JButton("Speicherort auswählen"); btnSpeicherortAuswhlen.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent arg0) { fc = new JFileChooser(Config.getLastDownloadPath()); @@ -174,6 +160,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements lblPath.setText(Config.getLastDownloadPath()); lblPath.addPropertyChangeListener(new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent arg0) { if (lblPath.getText().trim().isEmpty()) { // wenn leer, dann upload button nicht freigeben @@ -191,6 +178,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements btnDownloadStarten.setEnabled(false); btnDownloadStarten.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent arg0) { buttonDownloadActionPerformed(arg0); } @@ -205,8 +193,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements progressBar.setBounds(102, 234, 485, 30); contentPanel.add(progressBar); - JLabel lblDownloadgeschwindigkeit = new JLabel( - "Downloadgeschwindigkeit:"); + JLabel lblDownloadgeschwindigkeit = new JLabel("Downloadgeschwindigkeit:"); lblDownloadgeschwindigkeit.setBounds(102, 275, 141, 14); contentPanel.add(lblDownloadgeschwindigkeit); @@ -238,8 +225,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements lblVerbleibend.setBounds(183, 350, 108, 14); contentPanel.add(lblVerbleibend); - JLabel lblGeschtzteVerbleibendeZeit = new JLabel( - "Geschätzte Verbleibende Zeit:"); + JLabel lblGeschtzteVerbleibendeZeit = new JLabel("Geschätzte Verbleibende Zeit:"); lblGeschtzteVerbleibendeZeit.setBounds(102, 300, 150, 14); contentPanel.add(lblGeschtzteVerbleibendeZeit); @@ -259,8 +245,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements panel.add(lblImageDownloader); JTextPane txtpnWhlenSieEinen = new JTextPane(); - txtpnWhlenSieEinen - .setText("Wählen Sie einen Ort aus, um das von Ihnen gewählte Image herunterzuladen."); + txtpnWhlenSieEinen.setText("Wählen Sie einen Ort aus, um das von Ihnen gewählte Image herunterzuladen."); txtpnWhlenSieEinen.setEditable(false); txtpnWhlenSieEinen.setBackground(SystemColor.menu); txtpnWhlenSieEinen.setBounds(10, 36, 509, 32); @@ -323,7 +308,6 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements menuBar.setBounds(0, 0, 597, 21); contentPanel.add(menuBar); - lblAnleitung = new JLabel( "Anleitung zum Erstellen einer virtuellen Maschine herunterladen"); lblAnleitung.setForeground(Color.BLUE); @@ -336,15 +320,13 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements lblAnleitung.setBounds(102, 448, 311, 14); contentPanel.add(lblAnleitung); btnDownloadStoppen.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { isAborted = true; // set flag try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName,SessionData.authToken); - LOGGER.info("FTP user deleted."); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - - e1.printStackTrace(); } task.cancel(true); resetValues(); @@ -364,25 +346,20 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements getContentPane().add(buttonPane, BorderLayout.SOUTH); { btnZurck.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // check if loading file or not if (isCurrentlyLoading() == true) { - int choice = JOptionPane - .showOptionDialog( - null, - "Nicht abgeschlossene Uploads werden beendet. Trotzdem zurück gehen?", - "Warnung", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, null, - options, options[1]); + int choice = JOptionPane.showOptionDialog(null, + "Nicht abgeschlossene Uploads werden beendet. Trotzdem zurück gehen?", + "Warnung", JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, null, options, options[1]); // 0=beenden, 1=abbrechen if (choice == 0) { task.cancel(true); try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName,SessionData.authToken); + ThriftManager.getSatClient().cancelDownload(transferInfo.token); } catch (TException e1) { - - e1.printStackTrace(); } // go back one page @@ -400,8 +377,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements if (f.isDirectory()) { Config.setLastDownloadPath(f.toString()); } else if (f.getParentFile().isDirectory()) { - Config.setLastDownloadPath(f.getParentFile() - .toString()); + Config.setLastDownloadPath(f.getParentFile().toString()); } Config.store(); @@ -413,7 +389,6 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements } setVisible(true); - } private void buttonDownloadActionPerformed(ActionEvent event) { @@ -424,88 +399,70 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements // Klick btnDownloadStarten.setText("Bitte warten"); try { - user = ThriftManager.getSatClient().getFtpUser(SessionData.authToken); - - downloadFile = user.path - + "/" - + ThriftManager.getSatClient().getPathOfImage(Image.ImageId, - Image.Version,SessionData.authToken); - + transferInfo = ThriftManager.getSatClient().requestDownload(SessionData.authToken, Image.ImageId); } catch (TException e) { - - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", + transferInfo = null; + JOptionPane.showMessageDialog(null, e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", JOptionPane.ERROR_MESSAGE); } - task = new DownloadTask(host, port, user.userName, user.password, - downloadFile, lblPath.getText().trim().trim()); + task = new DownloadTask(host, transferInfo.plainPort, transferInfo.token, lblPath.getText().trim(), Image.Filesize); task.addPropertyChangeListener(this); task.execute(); taskrun = true; } + @Override public void propertyChange(PropertyChangeEvent arg0) { - if (isAborted == false) { - progress = 0; - if ("progress" == arg0.getPropertyName()) { - progress = (Integer) arg0.getNewValue(); - progressBar.setValue(progress); - } + if (isAborted) + return; + progress = 0; + if ("progress".equals(arg0.getPropertyName())) { + progress = (Integer) arg0.getNewValue(); + progressBar.setValue(progress); + } - if ("speed" == arg0.getPropertyName()) { - speed = (double) arg0.getNewValue(); + if ("speed".equals(arg0.getPropertyName())) { + speed = (double) arg0.getNewValue(); + lblDownSpeed.setText(String.format("%.2f", speed) + " MB/s"); + } - lblDownSpeed.setText(String.valueOf(speed).substring(0, - String.valueOf(speed).lastIndexOf(".") + 3) - + " MB/s"); - } + // Button zum Fertigstellen freischalten, wenn 100% erreicht sind + if (isCurrentlyLoading() == false || progressBar.getPercentComplete() == 1.0) { + // no download + btnDownloadStoppen.setEnabled(false); + } else { + // currently uploading, don't let user interact + btnDownloadStoppen.setEnabled(true); + } - // Button zum Fertigstellen freischalten, wenn 100% erreicht sind - if (isCurrentlyLoading() == false - || progressBar.getPercentComplete() == 1.0) { - // no download - btnDownloadStoppen.setEnabled(false); - } else { - // currently uploading, don't let user interact - btnDownloadStoppen.setEnabled(true); - } + if (arg0.getPropertyName().equals("bytesread")) { + bytesread = (long) arg0.getNewValue(); + lblFertig.setText((bytesread / 1024 / 1024) + " MB"); + lblVerbleibend.setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) + " MB"); - if (arg0.getPropertyName().equals("bytesread")) { - 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"); + 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 (arg0.getPropertyName().equals("filesize")) { - filesize = (long) arg0.getNewValue(); - lblFilesize.setText((filesize / 1024 / 1024) + " MB"); + } + if (arg0.getPropertyName().equals("filesize")) { + filesize = (long) arg0.getNewValue(); + lblFilesize.setText((filesize / 1024 / 1024) + " MB"); - } - }// end if + } }// end PropertyChange() - public boolean isCurrentlyLoading() { + private boolean isCurrentlyLoading() { isCurrentlyLoading = false; - if (lblVerbleibend.getText().trim().equals("0 MB") - || lblVerbleibend.getText().trim().equals("0")) { + if (lblVerbleibend.getText().trim().equals("0 MB") || lblVerbleibend.getText().trim().equals("0")) { isCurrentlyLoading = false; } else { isCurrentlyLoading = true; @@ -513,7 +470,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements return isCurrentlyLoading; }// end isCurrentlyLoading() - public void resetValues() { + private void resetValues() { lblDownSpeed.setText("0"); lblZeit.setText("0"); lblFertig.setText("0"); @@ -522,7 +479,7 @@ public class FTPEditDownloader_GUI extends JInternalFrame implements progressBar.setValue(0); }// end resetValues - public void resetButtons() { + private void resetButtons() { btnDownloadStarten.setEnabled(true); btnDownloadStarten.setText("Download starten"); btnDownloadStoppen.setEnabled(false); -- cgit v1.2.3-55-g7522