diff options
Diffstat (limited to 'dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java')
| -rw-r--r-- | dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java | 201 |
1 files changed, 58 insertions, 143 deletions
diff --git a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java index daec08e6..f92d6a5c 100644 --- a/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/FTPSearchDownloader_GUI.java @@ -2,7 +2,6 @@ package gui.image; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.FlowLayout; import java.awt.Font; import java.awt.SystemColor; @@ -19,9 +18,6 @@ import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JProgressBar; @@ -29,7 +25,6 @@ import javax.swing.JSeparator; import javax.swing.JTextPane; import javax.swing.SwingConstants; import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; import javax.swing.border.EmptyBorder; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; @@ -47,59 +42,51 @@ import util.GuiManager; import util.OpenLinks; import config.Config; import ftp.DownloadTask; -import gui.intro.About_GUI; import gui.intro.MainMenue_GUI; @SuppressWarnings("serial") -public class FTPSearchDownloader_GUI extends JInternalFrame implements - PropertyChangeListener { +public class FTPSearchDownloader_GUI extends JInternalFrame implements PropertyChangeListener { - private final static Logger LOGGER = Logger - .getLogger(FTPEditDownloader_GUI.class); + private final static Logger LOGGER = Logger.getLogger(FTPEditDownloader_GUI.class); - @SuppressWarnings("unused") - private JPanel contentPane; private final JPanel contentPanel = new JPanel(); - JLabel lblPath; - JLabel lblDownSpeed; - User user; - JProgressBar progressBar; - String host = SessionData.serverAdress; - int port = 21; - String downloadFile = ""; - static String arg = ""; - DownloadTask task; - JLabel lblFertig; - JLabel lblFilesize; - JLabel lblVerbleibend; - JFileChooser fc; - long filesize; - double speed; - int progress = 0; // progress of download - long bytesread; - JLabel lblZeit; - boolean taskrun = false; - 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 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; + private JLabel lblVerbleibend; + private JFileChooser fc; + private long filesize; + private double speed; + private int progress = 0; // progress of download + private long bytesread; + private JLabel lblZeit; + private boolean taskrun = false; + private JButton btnZurck = new JButton("Zurück"); + private JButton btnDownloadStarten = new JButton("Download starten"); + private JButton btnMainMenu = new JButton("Hauptmenü"); + private JButton btnDownloadStoppen = new JButton("Download abbrechen"); private JLabel lblAnleitung; - Component c = null; private boolean isCurrentlyLoading = false; // currently up or downloading // file private boolean isAborted = false; // down- or upload was manually aborted - public static final String HELP_MESSAGE = "<html><div align=\"center\">" + - "Hier können Sie Images herunterladen.<br />" + - "Klicken Sie anschließend auf \"Zurück\" oder \"Hauptmenü\", um zu Ihrer vorherigen Auswahl oder zum Menü zurückzugelangen.<br />" + - "</div></html>"; + public static final String HELP_MESSAGE = "<html><div align=\"center\">" + + "Hier können Sie Images herunterladen.<br />" + + "Klicken Sie anschließend auf \"Zurück\" oder \"Hauptmenü\", um zu Ihrer vorherigen Auswahl oder zum Menü zurückzugelangen.<br />" + + "</div></html>"; /** * Create the frame. */ public FTPSearchDownloader_GUI() { - - final Object[] options = { "Beenden", "Abbrechen" }; + final String[] options = { "Beenden", "Abbrechen" }; addInternalFrameListener(new InternalFrameAdapter() { @Override public void internalFrameClosing(InternalFrameEvent arg0) { @@ -107,17 +94,15 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements // check if user wants to quit. int choice = JOptionPane .showOptionDialog( - c, + 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]); + "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); + ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken); try { ThriftManager.getSatClient().setSessionInvalid(SessionData.authToken); } catch (TException e1) { @@ -141,68 +126,11 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements } } }); -// addWindowListener(new WindowAdapter() { -// @Override -// public void windowClosing(WindowEvent e) { -// if (taskrun == true) { -// // check if user wants to quit. -// int choice = JOptionPane -// .showOptionDialog( -// c, -// "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(); -// } -// try { -// ThriftManager.getSatClient().setSessionInvalid(SessionData.AuthToken); -// } catch (TException e1) { -// // TODO Auto-generated catch block -// e1.printStackTrace(); -// } -// } catch (TException e1) { -// // TODO Auto-generated catch block -// e1.printStackTrace(); -// } -// task.cancel(true); -// -// System.exit(0); -// }// end if choice -// } else { -// // no download running, close window -// try { -// ThriftManager.getSatClient().setSessionInvalid(SessionData.AuthToken); -// } catch (TException e1) { -// // TODO Auto-generated catch block -// e1.printStackTrace(); -// } -// System.exit(0); -// }// end if taskrun -// }// end window closing -// }); - setResizable(false); - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (ClassNotFoundException | InstantiationException - | IllegalAccessException | UnsupportedLookAndFeelException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + 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); setBounds(0, 0, 603, 722); @@ -213,8 +141,7 @@ public class FTPSearchDownloader_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() { public void actionPerformed(ActionEvent arg0) { fc = new JFileChooser(Config.getLastDownloadPath()); @@ -247,7 +174,7 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements lblPath.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { - if (lblPath.getText().trim() == null) { + if (lblPath.getText().trim().isEmpty()) { // wenn leer, dann upload button nicht freigeben btnDownloadStarten.setEnabled(false); btnDownloadStarten.setText("Bitte warten"); @@ -277,8 +204,7 @@ public class FTPSearchDownloader_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); @@ -310,8 +236,7 @@ public class FTPSearchDownloader_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); @@ -331,8 +256,7 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements panel.add(lblImageDownloader); JTextPane txtpnWhlenSieEinen = new JTextPane(); - txtpnWhlenSieEinen - .setText("Wählen Sie einen Ort aus, um das von Ihnen gwählte Image zu speichern."); + txtpnWhlenSieEinen.setText("Wählen Sie einen Ort aus, um das von Ihnen gwählte Image zu speichern."); txtpnWhlenSieEinen.setEditable(false); txtpnWhlenSieEinen.setBackground(SystemColor.menu); txtpnWhlenSieEinen.setBounds(10, 36, 509, 32); @@ -380,18 +304,17 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements lblSchritt_3.setBounds(20, 423, 57, 14); contentPanel.add(lblSchritt_3); - JLabel lblKlickenSieAuf = new JLabel( - "Klicken Sie auf \"Zurück\" oder \"Hauptmenü\"."); + JLabel lblKlickenSieAuf = new JLabel("Klicken Sie auf \"Zurück\" oder \"Hauptmenü\"."); lblKlickenSieAuf.setBounds(102, 423, 241, 14); contentPanel.add(lblKlickenSieAuf); - + lblAnleitung = new JLabel( "<HTML><U>Anleitung zum erstellen einer virtuellen Maschine herunterladen</U></HTML>"); lblAnleitung.setForeground(Color.BLUE); lblAnleitung.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { - OpenLinks.openWebpage("vmware"); + OpenLinks.openWebpage("vmware"); } }); lblAnleitung.setBounds(102, 448, 311, 14); @@ -401,7 +324,7 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements isAborted = true; // set flag try { - ThriftManager.getSatClient().DeleteFtpUser(user.userName,SessionData.authToken); + ThriftManager.getSatClient().DeleteFtpUser(user.userName, SessionData.authToken); LOGGER.info("Deleted FTP user."); } catch (TException e1) { // TODO Auto-generated catch block @@ -429,19 +352,16 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements public void actionPerformed(ActionEvent e) { // check if loading file or not if (isCurrentlyLoading() == true) { - int choice = JOptionPane - .showOptionDialog( - c, - "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().DeleteFtpUser(user.userName, + SessionData.authToken); } catch (TException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -489,19 +409,18 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements downloadFile = user.path + "/" - + ThriftManager.getSatClient().getPathOfImage(Image.image.getImageId(), - Image.image.getVersion(),SessionData.authToken); + + ThriftManager.getSatClient().getPathOfImage(Image.ImageId, + Image.Version, SessionData.authToken); } catch (TException e) { // TODO Auto-generated catch block e.printStackTrace(); - JOptionPane.showMessageDialog(c, - e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", + 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()); + task = new DownloadTask(host, port, user.userName, user.password, downloadFile, lblPath.getText() + .trim()); task.addPropertyChangeListener(this); task.execute(); taskrun = true; @@ -541,13 +460,10 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements if ("bytesread" == arg0.getPropertyName()) { bytesread = (long) arg0.getNewValue(); lblFertig.setText((bytesread / 1024 / 1024) + " MB"); - lblVerbleibend - .setText(((filesize / 1024 / 1024) - (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) + .valueOf(((((filesize / 1024 / 1024) - (bytesread / 1024 / 1024)) / speed) / 60) + 1) .substring( 0, String.valueOf( @@ -567,8 +483,7 @@ public class FTPSearchDownloader_GUI extends JInternalFrame implements public 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; |
