Преглед изворни кода

Give DCC Sends a UI.

Issue 373


git-svn-id: http://svn.dmdirc.com/trunk@4042 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack пре 16 година
родитељ
комит
5004646689

+ 15
- 3
src/com/dmdirc/addons/dcc/DCCFrame.java Прегледај датотеку

@@ -34,6 +34,9 @@ import com.dmdirc.config.IdentityManager;
34 34
 import com.dmdirc.ui.WindowManager;
35 35
 import com.dmdirc.ui.interfaces.InputWindow;
36 36
 import com.dmdirc.ui.swing.components.InputTextFrame;
37
+import com.dmdirc.ui.swing.components.TextFrame;
38
+
39
+import java.awt.Container;
37 40
 
38 41
 import javax.swing.JPopupMenu;
39 42
 
@@ -57,9 +60,9 @@ public abstract class DCCFrame extends WritableFrameContainer {
57 60
 			 * @param owner The frame container that owns this frame
58 61
 			 */
59 62
 			public EmptyFrame(final WritableFrameContainer owner) {
60
-					super(owner);
61
-					setTextPane(null);
62
-					pack();
63
+				super(owner);
64
+				setTextPane(null);
65
+				pack();
63 66
 			}
64 67
 			
65 68
 			/**
@@ -221,6 +224,15 @@ public abstract class DCCFrame extends WritableFrameContainer {
221 224
 		return myWindow;
222 225
 	}
223 226
 	
227
+	/**
228
+	 * Returns the content pane of the internal frame associated with this object.
229
+	 *
230
+	 * @return The content pane of the internal frame associated with this object
231
+	 */
232
+	public Container getContentPane() {
233
+		return ((TextFrame)getFrame()).getContentPane();
234
+	}
235
+	
224 236
 	/**
225 237
 	 * Returns a string identifier for this object/its frame.
226 238
 	 *

+ 10
- 0
src/com/dmdirc/addons/dcc/DCCSend.java Прегледај датотеку

@@ -244,6 +244,15 @@ public class DCCSend extends DCC {
244 244
 		return -1;
245 245
 	}
246 246
 	
247
+	/**
248
+	 * Get the starting position of the file
249
+	 *
250
+	 * @return starting position of file.
251
+	 */
252
+	public int getFileStart() {
253
+		return this.startpos;
254
+	}
255
+	
247 256
 	/**
248 257
 	 * Change the handler for this DCC Send
249 258
 	 *
@@ -351,6 +360,7 @@ public class DCCSend extends DCC {
351 360
 			readSize = readSize + bytesRead;
352 361
 			
353 362
 			if (bytesRead > 0) {
363
+				if (handler != null) { handler.dataTransfered(this, bytesRead); }
354 364
 				out.write(data, 0, bytesRead);
355 365
 				out.flush();
356 366
 				

+ 8
- 0
src/com/dmdirc/addons/dcc/DCCSendInterface.java Прегледај датотеку

@@ -42,4 +42,12 @@ public interface DCCSendInterface {
42 42
 	 * @param dcc The DCCSend that this message is from
43 43
 	 */
44 44
 	void socketOpened(final DCCSend dcc);
45
+	
46
+	/**
47
+	 * Called when data is sent/recieved
48
+	 *
49
+	 * @param dcc The DCCSend that this message is from
50
+	 * @param bytes The number of new bytes that were transfered
51
+	 */
52
+	void dataTransfered(final DCCSend dcc, final int bytes);
45 53
 }

+ 78
- 6
src/com/dmdirc/addons/dcc/DCCSendWindow.java Прегледај датотеку

@@ -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
 	/**

Loading…
Откажи
Сачувај