1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
package GUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import downloader.DownloadTask;
import ftp.ftp;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@SuppressWarnings("serial")
public class FTPDownloader extends JFrame implements PropertyChangeListener {
@SuppressWarnings("unused")
private JPanel contentPane;
private final JPanel contentPanel = new JPanel();
JLabel lblNewLabel;
JProgressBar progressBar;
ftp f=new ftp();
String host="openslx-nfs.rz.hs-offenburg.de";
int port=21;
String username="tspitzer";
String password="21071989";
String downloadPath="_vorlagen/";
String filename="";
static String arg="";
/**
* 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.
*/
public FTPDownloader(String name) {
//setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
filename=name;
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//filename=name;
setBackground(Color.WHITE);
setTitle("Downloader");
setBounds(100, 100, 450, 218);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(Color.WHITE);
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JButton btnSpeicherortAuswhlen = new JButton("Speicherort ausw\u00E4hlen");
btnSpeicherortAuswhlen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser fc=new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showOpenDialog(getParent());
File dir=fc.getSelectedFile();
lblNewLabel.setText(dir.getAbsolutePath());
}
});
btnSpeicherortAuswhlen.setBounds(10, 11, 141, 23);
btnSpeicherortAuswhlen.setVerticalAlignment(SwingConstants.TOP);
btnSpeicherortAuswhlen.setHorizontalAlignment(SwingConstants.LEFT);
contentPanel.add(btnSpeicherortAuswhlen);
}
lblNewLabel = new JLabel("C:\\");
lblNewLabel.setBounds(169, 11, 255, 23);
contentPanel.add(lblNewLabel);
JButton btnDownloadStarten = new JButton("Download starten");
btnDownloadStarten.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
buttonDownloadActionPerformed(arg0);
}
});
btnDownloadStarten.setBounds(10, 106, 141, 23);
contentPanel.add(btnDownloadStarten);
progressBar = new JProgressBar(0,100);
progressBar.setStringPainted(true);
progressBar.setBounds(10, 45, 414, 30);
contentPanel.add(progressBar);
{
JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.WHITE);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Zur\u00FCck");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
setVisible(true);
}
private void buttonDownloadActionPerformed(ActionEvent event) {
progressBar.setValue(0);
DownloadTask task = new DownloadTask(host, port, username, password,downloadPath+filename, lblNewLabel.getText(), this);
task.addPropertyChangeListener(this);
task.execute();
}
public void propertyChange(PropertyChangeEvent arg0) {
if ("progress" == arg0.getPropertyName()) {
int progress = (Integer) arg0.getNewValue();
progressBar.setValue(progress);
}
}
}
|