search results now include connection speed

git-svn-id: svn://anubis/gvsu@49 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-03-09 00:58:39 +00:00
parent 7d32bc5dca
commit a4bc6d4ebf
3 changed files with 19 additions and 7 deletions

View File

@ -82,7 +82,7 @@ public class KaZaClient
break;
StringTokenizer tokens = new StringTokenizer(resultStr, "|");
SearchResult result = new SearchResult();
for (int i = 0; i < 4; i++)
for (int i = 0; i < 5; i++)
{
if (tokens.hasMoreTokens())
{
@ -96,9 +96,12 @@ public class KaZaClient
result.userName = t;
break;
case 2:
result.fileName = t;
result.speed = Integer.parseInt(t);
break;
case 3:
result.fileName = t;
break;
case 4:
result.fileDescription = t;
break;
}
@ -115,6 +118,7 @@ public class KaZaClient
{
String peerAddress = "";
String userName = "";
int speed = 0;
String fileName = "";
String fileDescription = "";
}

View File

@ -158,7 +158,8 @@ public class KaZaGUI extends JFrame
for (KaZaClient.SearchResult r : results)
{
String res = "User: \"" + r.userName + "\" [" +
r.peerAddress + "], File: \"" +
r.peerAddress + ", " + getSpeedString(r.speed) +
"], File: \"" +
r.fileName + "\" (" + r.fileDescription + ")";
stringResults.add(res);
}
@ -173,6 +174,16 @@ public class KaZaGUI extends JFrame
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;
@ -257,10 +268,6 @@ public class KaZaGUI extends JFrame
p.add(m_searchButton);
clientPanel.add(p);
clientPanel.add(m_searchResultsPanel);
// clientPanel.add(new Box.Filler(new Dimension(0, 0),
// new Dimension(0, Short.MAX_VALUE),
// new Dimension(Short.MAX_VALUE,
// Short.MAX_VALUE)));
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(m_statusLabel);

View File

@ -224,6 +224,7 @@ public class KaZaServer implements Runnable
{
results += clientIP + "|" +
m_clientData.get(clientIP).userName + "|" +
m_clientData.get(clientIP).speed + "|" +
fileName + "|" +
files.get(fileName) + "\n";
}