diff --git a/cs654/proj1/KaZaClient.java b/cs654/proj1/KaZaClient.java index 0e0c2f7..1004896 100644 --- a/cs654/proj1/KaZaClient.java +++ b/cs654/proj1/KaZaClient.java @@ -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(); } @@ -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); diff --git a/cs654/proj1/KaZaGUI.java b/cs654/proj1/KaZaGUI.java index 33f3b91..5146f83 100644 --- a/cs654/proj1/KaZaGUI.java +++ b/cs654/proj1/KaZaGUI.java @@ -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 indices = m_activeDownloads.keySet(); - for (Integer i : indices) + synchronized (m_activeDownloads) { - if (!m_client.isDownloadActive(i)) + Set 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;