diff options
Diffstat (limited to 'Dozentenmodul/src/gui/image/FTPDownloader_GUI.java')
-rw-r--r-- | Dozentenmodul/src/gui/image/FTPDownloader_GUI.java | 188 |
1 files changed, 110 insertions, 78 deletions
diff --git a/Dozentenmodul/src/gui/image/FTPDownloader_GUI.java b/Dozentenmodul/src/gui/image/FTPDownloader_GUI.java index 43f43e99..f6175934 100644 --- a/Dozentenmodul/src/gui/image/FTPDownloader_GUI.java +++ b/Dozentenmodul/src/gui/image/FTPDownloader_GUI.java @@ -6,7 +6,6 @@ import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Toolkit; import java.io.File; - import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; @@ -17,8 +16,8 @@ import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.border.EmptyBorder; - import ftp.DownloadTask; +import gui.intro.MainMenue_GUI; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; @@ -30,11 +29,8 @@ import java.awt.SystemColor; import java.awt.Font; import javax.swing.JTextPane; import javax.swing.JSeparator; - import models.Image; - import org.apache.thrift.TException; - import server.Server.Client; import server.User; import thrift.ThriftConnection; @@ -45,7 +41,7 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener @SuppressWarnings("unused") private JPanel contentPane; private final JPanel contentPanel = new JPanel(); - JLabel lblNewLabel; + JLabel lblPath; JLabel downspeed; User user; JProgressBar progressBar; @@ -56,27 +52,21 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener String downloadFile = ""; static String arg = ""; DownloadTask task; - JLabel bytesreadlbl; + JLabel lblBytesread; JLabel lblNewLabel_3; JLabel labelVerbleibend; long filesize; double speed; + int progress = 0; // progress of download long bytesread; JLabel labelZeit; boolean taskrun = false; ThriftConnection thrift = new ThriftConnection(); Client client = thrift.getThriftConnection(); - JButton buttonback = new JButton("Zur\u00FCck"); + JButton btnZurck = new JButton("Zur\u00FCck"); + JButton btnDownloadStarten = new JButton("Download starten"); + JButton btnMainMenu = new JButton("Hauptmen\u00FC"); - /** - * Launch the application. - */ - /* - * public static void main(String[] args) { EventQueue.invokeLater(new - * Runnable() { public void run() { try { FTPDownloader frame = new - * FTPDownloader(); frame.setVisible(true); } catch (Exception e) { - * e.printStackTrace(); } } }); } - */ /** * Create the frame. @@ -95,14 +85,13 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener } task.cancel(true); } - dispose(); - } + //dispose(); + System.exit(0); + }//end window closing }); setResizable(false); // setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - - try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException @@ -111,7 +100,6 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener e.printStackTrace(); } - setBackground(Color.WHITE); setTitle("Dozentenmodul *Prototyp*"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); @@ -133,76 +121,96 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener fc.showOpenDialog(getParent()); File dir = fc.getSelectedFile(); - lblNewLabel.setText(dir.getAbsolutePath()); + // check if directory is selected + if (dir != null) { + // is selected + System.out.println("Target directory exists."); + lblPath.setText(dir.getAbsolutePath()); + } else { + // no directory selected + lblPath.setText(""); + }// end if } }); - btnSpeicherortAuswhlen.setBounds(57, 124, 141, 23); + btnSpeicherortAuswhlen.setBounds(102, 124, 173, 23); btnSpeicherortAuswhlen.setVerticalAlignment(SwingConstants.TOP); - btnSpeicherortAuswhlen.setHorizontalAlignment(SwingConstants.LEFT); contentPanel.add(btnSpeicherortAuswhlen); } - lblNewLabel = new JLabel("C:\\"); - lblNewLabel.setBounds(208, 124, 238, 23); - contentPanel.add(lblNewLabel); + lblPath = new JLabel(""); + lblPath.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent arg0) { + if (lblPath.getText().isEmpty()) { + // wenn leer, dann upload button nicht freigeben + btnDownloadStarten.setEnabled(false); + btnDownloadStarten.setText("Bitte warten"); + } else { + // wenn leer, dann upload button nicht freigeben + btnDownloadStarten.setEnabled(true); + btnDownloadStarten.setText("Download starten"); + } + } + }); + lblPath.setBounds(102, 158, 485, 23); + contentPanel.add(lblPath); - JButton btnDownloadStarten = new JButton("Download starten"); + btnDownloadStarten.setEnabled(false); btnDownloadStarten.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { buttonDownloadActionPerformed(arg0); } }); - btnDownloadStarten.setBounds(57, 168, 141, 23); + btnDownloadStarten.setBounds(102, 200, 173, 23); contentPanel.add(btnDownloadStarten); progressBar = new JProgressBar(0, 100); progressBar.setStringPainted(true); - progressBar.setBounds(57, 202, 497, 30); + progressBar.setBounds(102, 234, 485, 30); contentPanel.add(progressBar); JLabel lblDownloadgeschwindigkeit = new JLabel( "Downloadgeschwindigkeit:"); - lblDownloadgeschwindigkeit.setBounds(57, 243, 141, 14); + lblDownloadgeschwindigkeit.setBounds(102, 275, 141, 14); contentPanel.add(lblDownloadgeschwindigkeit); downspeed = new JLabel("0"); - downspeed.setBounds(308, 243, 95, 14); + downspeed.setBounds(374, 275, 117, 14); contentPanel.add(downspeed); - JLabel lblNewLabel_1 = new JLabel("Fertig:"); - lblNewLabel_1.setBounds(57, 293, 46, 14); - contentPanel.add(lblNewLabel_1); + JLabel lblFertig = new JLabel("Fertig:"); + lblFertig.setBounds(102, 325, 46, 14); + contentPanel.add(lblFertig); - bytesreadlbl = new JLabel(""); - bytesreadlbl.setBounds(66, 244, 108, 14); - contentPanel.add(bytesreadlbl); + lblBytesread = new JLabel("0"); + lblBytesread.setBounds(183, 325, 108, 14); + contentPanel.add(lblBytesread); - JLabel lblNewLabel_2 = new JLabel("von:"); - lblNewLabel_2.setBounds(226, 293, 46, 14); - contentPanel.add(lblNewLabel_2); + JLabel lblVon = new JLabel("von:"); + lblVon.setBounds(318, 325, 46, 14); + contentPanel.add(lblVon); - lblNewLabel_3 = new JLabel(""); - lblNewLabel_3.setBounds(235, 244, 108, 14); + lblNewLabel_3 = new JLabel("0"); + lblNewLabel_3.setBounds(374, 325, 117, 14); contentPanel.add(lblNewLabel_3); JLabel lblMbVerbleibend = new JLabel("Verbleibend:"); - lblMbVerbleibend.setBounds(57, 318, 71, 14); + lblMbVerbleibend.setBounds(102, 350, 71, 14); contentPanel.add(lblMbVerbleibend); - labelVerbleibend = new JLabel(""); - labelVerbleibend.setBounds(91, 269, 108, 14); + labelVerbleibend = new JLabel("0"); + labelVerbleibend.setBounds(183, 350, 108, 14); contentPanel.add(labelVerbleibend); JLabel lblGeschtzteVerbleibendeZeit = new JLabel( "Gesch\u00E4tzte Verbleibende Zeit:"); - lblGeschtzteVerbleibendeZeit.setBounds(57, 268, 150, 14); + lblGeschtzteVerbleibendeZeit.setBounds(102, 300, 150, 14); contentPanel.add(lblGeschtzteVerbleibendeZeit); - labelZeit = new JLabel(""); - labelZeit.setBounds(261, 219, 117, 14); + labelZeit = new JLabel("0"); + labelZeit.setBounds(374, 300, 117, 14); contentPanel.add(labelZeit); JPanel panel = new JPanel(); @@ -253,21 +261,29 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener separator_1.setBounds(-10, 648, 597, 2); contentPanel.add(separator_1); - JLabel label_6 = new JLabel("1."); - label_6.setBounds(24, 128, 23, 14); - contentPanel.add(label_6); + JLabel lblSchritt = new JLabel("Schritt 1:"); + lblSchritt.setBounds(24, 128, 57, 14); + contentPanel.add(lblSchritt); + + JLabel lblSchritt_1 = new JLabel("Schritt 2:"); + lblSchritt_1.setBounds(24, 204, 57, 14); + contentPanel.add(lblSchritt_1); - JLabel label_7 = new JLabel("2."); - label_7.setBounds(24, 172, 23, 14); - contentPanel.add(label_7); + JLabel lblSchritt_3 = new JLabel("Schritt 3:"); + lblSchritt_3.setBounds(20, 423, 57, 14); + contentPanel.add(lblSchritt_3); + + JLabel lblKlickenSieAuf = new JLabel( + "Klicken Sie auf \"Fertigstellen\"."); + lblKlickenSieAuf.setBounds(98, 423, 241, 14); + contentPanel.add(lblKlickenSieAuf); { JPanel buttonPane = new JPanel(); buttonPane.setBackground(UIManager.getColor("Button.background")); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { - buttonback.setEnabled(false); - buttonback.addActionListener(new ActionListener() { + btnZurck.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (taskrun == true) { task.cancel(true); @@ -279,14 +295,26 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener } } thrift.closeThriftConnection(); - SearchEditImage_GUI se=new SearchEditImage_GUI(); + SearchEditImage_GUI se = new SearchEditImage_GUI(); se.setVisible(true); dispose(); } }); - buttonback.setActionCommand("Cancel"); - buttonPane.add(buttonback); + btnZurck.setActionCommand("Cancel"); + buttonPane.add(btnZurck); } + + + btnMainMenu.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + thrift.closeThriftConnection(); + MainMenue_GUI mm = new MainMenue_GUI(); + mm.setVisible(true); + dispose(); + } + }); + btnMainMenu.setActionCommand("Cancel"); + buttonPane.add(btnMainMenu); } setVisible(true); @@ -295,19 +323,22 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener private void buttonDownloadActionPerformed(ActionEvent event) { progressBar.setValue(0); - + btnDownloadStarten.setEnabled(false); // verhindert schnellen zweiten + // Klick + btnDownloadStarten.setText("Bitte warten"); try { user = client.getFtpUser(); - - downloadFile=client.getPathOfImage(Image.image.getImageId(),Image.image.getVersion()); - + + downloadFile = client.getPathOfImage(Image.image.getImageId(), + Image.image.getVersion()); + } catch (TException e) { // TODO Auto-generated catch block e.printStackTrace(); } - + task = new DownloadTask(host, port, user.userName, user.password, - downloadFile, lblNewLabel.getText(), this); + downloadFile, lblPath.getText(), this); task.addPropertyChangeListener(this); task.execute(); taskrun = true; @@ -316,12 +347,20 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener public void propertyChange(PropertyChangeEvent arg0) { - int progress = 0; + progress = 0; if ("progress" == arg0.getPropertyName()) { progress = (Integer) arg0.getNewValue(); progressBar.setValue(progress); - if (progress == 100) { - buttonback.setEnabled(true); + + // Button zum Fertigstellen freischalten, wenn 100% erreicht sind + if (progress == 0 || progress == 100) { + // not uploading currently + btnZurck.setEnabled(true); + btnMainMenu.setEnabled(true); + } else { + // currently uploading, don't let user interact + btnZurck.setEnabled(false); + btnMainMenu.setEnabled(false); } } @@ -333,17 +372,10 @@ public class FTPDownloader_GUI extends JFrame implements PropertyChangeListener String.valueOf(speed).lastIndexOf(".") + 3) + " MB/s"); - // }else - // { - // double MBSpeed=speed/1024; - // downspeed.setText(String.valueOf((MBSpeed)).substring(0, - // String.valueOf(MBSpeed).indexOf("."))); - // } - } if ("bytesread" == arg0.getPropertyName()) { bytesread = (long) arg0.getNewValue(); - bytesreadlbl.setText((bytesread / 1024 / 1024) + " MB"); + lblBytesread.setText((bytesread / 1024 / 1024) + " MB"); labelVerbleibend .setText(((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) + " MB"); |