|
@@ -23,16 +23,25 @@
|
23
|
23
|
package com.dmdirc.addons.dcc;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.ui.swing.components.TextFrame;
|
26
|
|
-
|
27
|
26
|
import com.dmdirc.ui.swing.components.TextLabel;
|
28
|
27
|
|
|
28
|
+import javax.swing.JPanel;
|
|
29
|
+import javax.swing.JLabel;
|
|
30
|
+import javax.swing.JProgressBar;
|
|
31
|
+import javax.swing.JButton;
|
|
32
|
+
|
|
33
|
+import java.awt.event.ActionEvent;
|
|
34
|
+import java.awt.event.ActionListener;
|
|
35
|
+
|
|
36
|
+import net.miginfocom.swing.MigLayout;
|
|
37
|
+
|
29
|
38
|
/**
|
30
|
39
|
* This class links DCC Send objects to a window.
|
31
|
40
|
*
|
32
|
41
|
* @author Shane 'Dataforce' McCormack
|
33
|
42
|
* @version $Id: DCC.java 969 2007-04-30 18:38:20Z ShaneMcC $
|
34
|
43
|
*/
|
35
|
|
-public class DCCSendWindow extends DCCFrame implements DCCSendInterface {
|
|
44
|
+public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionListener {
|
36
|
45
|
/** The DCCSend object we are a window for */
|
37
|
46
|
private final DCCSend dcc;
|
38
|
47
|
|
|
@@ -42,6 +51,15 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface {
|
42
|
51
|
/** Other Nickname */
|
43
|
52
|
private final String otherNickname;
|
44
|
53
|
|
|
54
|
+ /** Total data transfered */
|
|
55
|
+ private long transferCount = 0;
|
|
56
|
+
|
|
57
|
+ /** Progress Bar */
|
|
58
|
+ private final JProgressBar progress = new JProgressBar();
|
|
59
|
+
|
|
60
|
+ /** Status Label */
|
|
61
|
+ private final JLabel status = new JLabel("Status: Waiting");
|
|
62
|
+
|
45
|
63
|
/**
|
46
|
64
|
* Creates a new instance of DCCSendWindow with a given DCCSend object.
|
47
|
65
|
*
|
|
@@ -58,12 +76,62 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface {
|
58
|
76
|
nickname = nick;
|
59
|
77
|
otherNickname = targetNick;
|
60
|
78
|
|
61
|
|
- final TextLabel label = new TextLabel("This is a placeholder dcc send window.");
|
|
79
|
+ getContentPane().setLayout(new MigLayout());
|
|
80
|
+
|
|
81
|
+ transferCount = dcc.getFileStart();
|
|
82
|
+
|
|
83
|
+ progress.setMinimum(0);
|
|
84
|
+ progress.setMaximum(100);
|
|
85
|
+ progress.setStringPainted(true);
|
|
86
|
+ progress.setValue(0);
|
|
87
|
+
|
|
88
|
+ if (dcc.getType() == DCCSend.TransferType.SEND) {
|
|
89
|
+ getContentPane().add(new JLabel("Sending: "+dcc.getFileName()), "wrap");
|
|
90
|
+ getContentPane().add(new JLabel("To: "+targetNick), "wrap");
|
|
91
|
+ } else {
|
|
92
|
+ getContentPane().add(new JLabel("Recieving: "+dcc.getFileName()), "wrap");
|
|
93
|
+ getContentPane().add(new JLabel("From: "+targetNick), "wrap");
|
|
94
|
+ }
|
|
95
|
+ getContentPane().add(status, "wrap");
|
|
96
|
+ getContentPane().add(progress, "growx, wrap");
|
|
97
|
+
|
|
98
|
+ final JButton button = new JButton("Cancel");
|
|
99
|
+ button.addActionListener(this);
|
|
100
|
+
|
|
101
|
+ getContentPane().add(button, "wrap, align right");
|
62
|
102
|
|
63
|
|
- ((TextFrame)getFrame()).getContentPane().add(label);
|
64
|
103
|
plugin.addWindow(this);
|
65
|
104
|
}
|
66
|
105
|
|
|
106
|
+ /** {@inheritDoc} */
|
|
107
|
+ public void actionPerformed(final ActionEvent e) {
|
|
108
|
+ if (e.getActionCommand().equals("Cancel")) {
|
|
109
|
+ ((JButton)e.getSource()).setEnabled(false);
|
|
110
|
+ dcc.close();
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ /**
|
|
115
|
+ * Called when data is sent/recieved
|
|
116
|
+ *
|
|
117
|
+ * @param dcc The DCCSend that this message is from
|
|
118
|
+ * @param bytes The number of new bytes that were transfered
|
|
119
|
+ */
|
|
120
|
+ public void dataTransfered(final DCCSend dcc, final int bytes) {
|
|
121
|
+ transferCount += bytes;
|
|
122
|
+ final double percent = (100.00 / dcc.getFileSize()) * transferCount;
|
|
123
|
+
|
|
124
|
+ if (dcc.getType() == DCCSend.TransferType.SEND) {
|
|
125
|
+ status.setText("Status: Sending");
|
|
126
|
+ } else {
|
|
127
|
+ status.setText("Status: Recieving");
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ System.out.printf("Data Transfered. [ %d / %f ]\n", bytes, percent);
|
|
131
|
+
|
|
132
|
+ progress.setValue((int)Math.floor(percent));
|
|
133
|
+ }
|
|
134
|
+
|
67
|
135
|
/**
|
68
|
136
|
* Called when the socket is closed
|
69
|
137
|
*
|
|
@@ -71,7 +139,11 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface {
|
71
|
139
|
*/
|
72
|
140
|
@Override
|
73
|
141
|
public void socketClosed(final DCCSend dcc) {
|
74
|
|
-
|
|
142
|
+ if (transferCount == dcc.getFileSize()) {
|
|
143
|
+ status.setText("Status: Transfer Compelete.");
|
|
144
|
+ } else {
|
|
145
|
+ status.setText("Status: Transfer Failed.");
|
|
146
|
+ }
|
75
|
147
|
}
|
76
|
148
|
|
77
|
149
|
/**
|
|
@@ -81,7 +153,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface {
|
81
|
153
|
*/
|
82
|
154
|
@Override
|
83
|
155
|
public void socketOpened(final DCCSend dcc) {
|
84
|
|
-
|
|
156
|
+ status.setText("Status: Socket Opened");
|
85
|
157
|
}
|
86
|
158
|
|
87
|
159
|
/**
|