search results JList now stores KaZaClient.SearchResult items
git-svn-id: svn://anubis/gvsu@52 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
15f81fc270
commit
45c7f9a6bc
@ -13,7 +13,7 @@ public class KaZaClient
|
||||
private Socket m_socket;
|
||||
private DataOutputStream m_os;
|
||||
private FileServer m_fileServer;
|
||||
private Vector<ClientDownloader> m_clientDownloaders;
|
||||
private HashMap<Integer, ClientDownloader> 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<ClientDownloader>();
|
||||
m_clientDownloaders = new HashMap<Integer, ClientDownloader>();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,36 +157,29 @@ public class KaZaGUI extends JFrame
|
||||
m_searchResultsPanel.validate();
|
||||
}
|
||||
|
||||
Vector<String> stringResults = new Vector<String>();
|
||||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user