file transfers working! transfers tab GUI updated

git-svn-id: svn://anubis/gvsu@54 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-03-09 03:50:56 +00:00
parent 3f0d05cf79
commit 272671701e
2 changed files with 20 additions and 16 deletions

View File

@ -52,6 +52,7 @@ public class KaZaClient
m_fileServer = new FileServer(LISTEN_PORT, m_sharedFolder);
Thread fsThread = new Thread(m_fileServer);
fsThread.start();
m_connected = true;
m_clientDownloaders = new HashMap<Integer, ClientDownloader>();
}
@ -205,9 +206,10 @@ public class KaZaClient
byte[] buff = new byte[1500];
while (!socket.isClosed())
for (;;)
{
int bytesRead = is.read(buff, 0, buff.length);
System.out.println("bytesRead: " + bytesRead);
if (bytesRead < 0)
break;
fos.write(buff, 0, bytesRead);

View File

@ -29,8 +29,7 @@ public class KaZaGUI extends JFrame
private JList m_searchResultsList;
/* transfer tab components */
private JPanel m_transfersPanel;
private JLabel m_transfersLabel;
private JTextArea m_transfersTextArea;
/* server tab components */
private JLabel m_serverClientsLabel;
@ -145,15 +144,19 @@ public class KaZaGUI extends JFrame
m_serverClientsLabel.setText(caption);
}
Set<Integer> indices = m_activeDownloads.keySet();
for (Integer i : indices)
synchronized (m_activeDownloads)
{
if (!m_client.isDownloadActive(i))
Set<Integer> indices = m_activeDownloads.keySet();
for (Integer i : indices)
{
KaZaClient.SearchResult sr = m_activeDownloads.get(i);
m_transfersLabel.setText(m_transfersLabel.getText() + "\n" +
"Completed downloading \"" + sr.fileName + "\"");
m_activeDownloads.remove(i);
if (!m_client.isDownloadActive(i))
{
KaZaClient.SearchResult sr = m_activeDownloads.get(i);
m_transfersTextArea.setText(m_transfersTextArea.getText() +
"\n" + "Completed downloading \"" +
sr.fileName + "\"");
m_activeDownloads.remove(i);
}
}
}
}
@ -190,8 +193,8 @@ public class KaZaGUI extends JFrame
m_activeDownloads.put(m_client.downloadFile(sr.peerAddress,
sr.fileName),
sr);
String curText = m_transfersLabel.getText();
m_transfersLabel.setText(curText +
String curText = m_transfersTextArea.getText();
m_transfersTextArea.setText(curText +
(curText.equals("") ? "" : "\n") +
"Started download of \"" + sr.fileName + "\" from " +
sr.userName + " [" + sr.peerAddress + "]");
@ -307,8 +310,8 @@ public class KaZaGUI extends JFrame
private JPanel getTransferPanel()
{
m_transfersPanel = new JPanel();
m_transfersLabel = new JLabel();
m_transfersTextArea = new JTextArea();
m_transfersTextArea.setEditable(false);
JPanel transferPanel = new JPanel();
transferPanel.setLayout(new BoxLayout(transferPanel, BoxLayout.Y_AXIS));
@ -319,8 +322,7 @@ public class KaZaGUI extends JFrame
new Dimension(Short.MAX_VALUE, 0),
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)));
transferPanel.add(p);
m_transfersPanel.add(m_transfersLabel);
JScrollPane jsp = new JScrollPane(m_transfersPanel);
JScrollPane jsp = new JScrollPane(m_transfersTextArea);
jsp.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
transferPanel.add(jsp);
return transferPanel;