GUI-induced downloading and notifications implemented!
git-svn-id: svn://anubis/gvsu@53 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
45c7f9a6bc
commit
3f0d05cf79
@ -56,6 +56,14 @@ public class KaZaClient
|
|||||||
m_clientDownloaders = new HashMap<Integer, ClientDownloader>();
|
m_clientDownloaders = new HashMap<Integer, ClientDownloader>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDownloadActive(int index)
|
||||||
|
{
|
||||||
|
synchronized (m_clientDownloaders)
|
||||||
|
{
|
||||||
|
return m_clientDownloaders.containsKey(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean connected() { return m_connected; }
|
public boolean connected() { return m_connected; }
|
||||||
|
|
||||||
public void close()
|
public void close()
|
||||||
@ -146,7 +154,7 @@ public class KaZaClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadFile(String host, String fileName)
|
public int downloadFile(String host, String fileName)
|
||||||
{
|
{
|
||||||
ClientDownloader cd = new ClientDownloader(host, fileName);
|
ClientDownloader cd = new ClientDownloader(host, fileName);
|
||||||
synchronized (m_clientDownloaders)
|
synchronized (m_clientDownloaders)
|
||||||
@ -155,6 +163,7 @@ public class KaZaClient
|
|||||||
}
|
}
|
||||||
Thread t = new Thread(cd);
|
Thread t = new Thread(cd);
|
||||||
t.start();
|
t.start();
|
||||||
|
return cd.getIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int getTransferIndex()
|
public synchronized int getTransferIndex()
|
||||||
|
@ -11,6 +11,7 @@ public class KaZaGUI extends JFrame
|
|||||||
private KaZaServer m_server;
|
private KaZaServer m_server;
|
||||||
private Thread m_serverThread;
|
private Thread m_serverThread;
|
||||||
private javax.swing.Timer m_timer;
|
private javax.swing.Timer m_timer;
|
||||||
|
private HashMap<Integer, KaZaClient.SearchResult> m_activeDownloads;
|
||||||
|
|
||||||
/* client tab components */
|
/* client tab components */
|
||||||
private JButton m_browseButton;
|
private JButton m_browseButton;
|
||||||
@ -29,6 +30,7 @@ public class KaZaGUI extends JFrame
|
|||||||
|
|
||||||
/* transfer tab components */
|
/* transfer tab components */
|
||||||
private JPanel m_transfersPanel;
|
private JPanel m_transfersPanel;
|
||||||
|
private JLabel m_transfersLabel;
|
||||||
|
|
||||||
/* server tab components */
|
/* server tab components */
|
||||||
private JLabel m_serverClientsLabel;
|
private JLabel m_serverClientsLabel;
|
||||||
@ -58,6 +60,8 @@ public class KaZaGUI extends JFrame
|
|||||||
JPanel serverPanel = getServerPanel();
|
JPanel serverPanel = getServerPanel();
|
||||||
pane.add("Server", serverPanel);
|
pane.add("Server", serverPanel);
|
||||||
|
|
||||||
|
m_activeDownloads = new HashMap<Integer, KaZaClient.SearchResult>();
|
||||||
|
|
||||||
m_timer = new javax.swing.Timer(1000, m_handler);
|
m_timer = new javax.swing.Timer(1000, m_handler);
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
@ -140,6 +144,18 @@ public class KaZaGUI extends JFrame
|
|||||||
}
|
}
|
||||||
m_serverClientsLabel.setText(caption);
|
m_serverClientsLabel.setText(caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<Integer> indices = m_activeDownloads.keySet();
|
||||||
|
for (Integer i : indices)
|
||||||
|
{
|
||||||
|
if (!m_client.isDownloadActive(i))
|
||||||
|
{
|
||||||
|
KaZaClient.SearchResult sr = m_activeDownloads.get(i);
|
||||||
|
m_transfersLabel.setText(m_transfersLabel.getText() + "\n" +
|
||||||
|
"Completed downloading \"" + sr.fileName + "\"");
|
||||||
|
m_activeDownloads.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +185,16 @@ public class KaZaGUI extends JFrame
|
|||||||
{
|
{
|
||||||
if (e.getClickCount() == 2)
|
if (e.getClickCount() == 2)
|
||||||
{
|
{
|
||||||
int index = m_searchResultsList.locationToIndex(e.getPoint());
|
KaZaClient.SearchResult sr = (KaZaClient.SearchResult)
|
||||||
|
m_searchResultsList.getSelectedValue();
|
||||||
|
m_activeDownloads.put(m_client.downloadFile(sr.peerAddress,
|
||||||
|
sr.fileName),
|
||||||
|
sr);
|
||||||
|
String curText = m_transfersLabel.getText();
|
||||||
|
m_transfersLabel.setText(curText +
|
||||||
|
(curText.equals("") ? "" : "\n") +
|
||||||
|
"Started download of \"" + sr.fileName + "\" from " +
|
||||||
|
sr.userName + " [" + sr.peerAddress + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -283,6 +308,7 @@ public class KaZaGUI extends JFrame
|
|||||||
private JPanel getTransferPanel()
|
private JPanel getTransferPanel()
|
||||||
{
|
{
|
||||||
m_transfersPanel = new JPanel();
|
m_transfersPanel = new JPanel();
|
||||||
|
m_transfersLabel = new JLabel();
|
||||||
|
|
||||||
JPanel transferPanel = new JPanel();
|
JPanel transferPanel = new JPanel();
|
||||||
transferPanel.setLayout(new BoxLayout(transferPanel, BoxLayout.Y_AXIS));
|
transferPanel.setLayout(new BoxLayout(transferPanel, BoxLayout.Y_AXIS));
|
||||||
@ -293,6 +319,7 @@ public class KaZaGUI extends JFrame
|
|||||||
new Dimension(Short.MAX_VALUE, 0),
|
new Dimension(Short.MAX_VALUE, 0),
|
||||||
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)));
|
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)));
|
||||||
transferPanel.add(p);
|
transferPanel.add(p);
|
||||||
|
m_transfersPanel.add(m_transfersLabel);
|
||||||
JScrollPane jsp = new JScrollPane(m_transfersPanel);
|
JScrollPane jsp = new JScrollPane(m_transfersPanel);
|
||||||
jsp.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
|
jsp.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
|
||||||
transferPanel.add(jsp);
|
transferPanel.add(jsp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user