diff --git a/cs654/proj1/KaZaClient.java b/cs654/proj1/KaZaClient.java index e1f9ebc..22bc184 100644 --- a/cs654/proj1/KaZaClient.java +++ b/cs654/proj1/KaZaClient.java @@ -13,7 +13,7 @@ public class KaZaClient private Socket m_socket; private DataOutputStream m_os; private FileServer m_fileServer; - private Vector m_clientDownloaders; + private HashMap m_clientDownloaders; public KaZaClient(String userName, int kbps, String sharedFolder, String server) @@ -53,7 +53,7 @@ public class KaZaClient m_fileServer = new FileServer(LISTEN_PORT, m_sharedFolder); Thread fsThread = new Thread(m_fileServer); m_connected = true; - m_clientDownloaders = new Vector(); + m_clientDownloaders = new HashMap(); } public boolean connected() { return m_connected; } @@ -126,6 +126,24 @@ public class KaZaClient int speed = 0; String fileName = ""; String fileDescription = ""; + + public String toString() + { + return "User: \"" + userName + "\" [" + + peerAddress + ", " + getSpeedString(speed) + + "], File: \"" + + fileName + "\" (" + fileDescription + ")"; + } + + /* val is measured in Kbps */ + private String getSpeedString(int val) + { + if (val > 999999) + return (val/1000000) + " Gbps"; + if (val > 999) + return (val / 1000) + " Mbps"; + return val + " Kbps"; + } } public void downloadFile(String host, String fileName) @@ -133,7 +151,7 @@ public class KaZaClient ClientDownloader cd = new ClientDownloader(host, fileName); synchronized (m_clientDownloaders) { - m_clientDownloaders.add(cd); + m_clientDownloaders.put(cd.getIndex(), cd); } Thread t = new Thread(cd); t.start(); @@ -157,6 +175,8 @@ public class KaZaClient m_index = getTransferIndex(); } + public int getIndex() { return m_index; } + public void run() { FileOutputStream fos; @@ -193,7 +213,7 @@ public class KaZaClient synchronized (m_clientDownloaders) { - m_clientDownloaders.remove(this); + m_clientDownloaders.remove(getIndex()); } } } diff --git a/cs654/proj1/KaZaGUI.java b/cs654/proj1/KaZaGUI.java index bcab399..f9b4771 100644 --- a/cs654/proj1/KaZaGUI.java +++ b/cs654/proj1/KaZaGUI.java @@ -157,36 +157,29 @@ public class KaZaGUI extends JFrame m_searchResultsPanel.validate(); } - Vector stringResults = new Vector(); - for (KaZaClient.SearchResult r : results) - { - String res = "User: \"" + r.userName + "\" [" + - r.peerAddress + ", " + getSpeedString(r.speed) + - "], File: \"" + - r.fileName + "\" (" + r.fileDescription + ")"; - stringResults.add(res); - } - m_searchResultsList = new JList(stringResults.toArray()); + m_searchResultsList = new JList(results.toArray()); m_searchResultsList.setVisibleRowCount(-1); m_searchResultsScrollPane = new JScrollPane(m_searchResultsList); m_searchResultsScrollPane.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); m_searchResultsPanel.add(m_searchResultsScrollPane); + + MouseListener mouseListener = new MouseAdapter() { + public void mouseClicked(MouseEvent e) + { + if (e.getClickCount() == 2) + { + int index = m_searchResultsList.locationToIndex(e.getPoint()); + } + } + }; + m_searchResultsList.addMouseListener(mouseListener); + m_searchResultsPanel.validate(); m_searchResultsPanel.repaint(); repaint(); } - /* val is measured in Kbps */ - private String getSpeedString(int val) - { - if (val > 999999) - return (val/1000000) + " Gbps"; - if (val > 999) - return (val / 1000) + " Mbps"; - return val + " Kbps"; - } - private class ConnectionSpeed { private String m_caption; diff --git a/cs654/proj1/KaZaServer.java b/cs654/proj1/KaZaServer.java index 11db7a9..34933e0 100644 --- a/cs654/proj1/KaZaServer.java +++ b/cs654/proj1/KaZaServer.java @@ -126,7 +126,7 @@ public class KaZaServer implements Runnable { m_clientInfo.userName = inLine.substring(5); } - System.out.println("Got HELO from " + m_clientInfo.userName); +// System.out.println("Got HELO from " + m_clientInfo.userName); } else if (opCode.equals("SPED")) { @@ -138,7 +138,7 @@ public class KaZaServer implements Runnable { m_clientInfo.speed = speed; } - System.out.println("Got SPED of " + m_clientInfo.speed); +// System.out.println("Got SPED of " + m_clientInfo.speed); } } else if (opCode.equals("DESC")) @@ -150,8 +150,8 @@ public class KaZaServer implements Runnable { m_clientInfo.files.put(fileName, fileDesc); } - System.out.println("Got DESC of '" + fileName + - "': '" + fileDesc + "'"); +// System.out.println("Got DESC of '" + fileName + +// "': '" + fileDesc + "'"); } else if (opCode.equals("SRCH")) { @@ -165,8 +165,8 @@ public class KaZaServer implements Runnable String searchResults = performSearch(depth, query); os.writeBytes(searchResults); os.writeBytes(".\n"); - System.out.println("Got SRCH for " + query + - ", results:\n" + searchResults); +// System.out.println("Got SRCH for " + query + +// ", results:\n" + searchResults); } } }