JMenuItem start_download, stop_download, cancel_download,
paste_ed2k_links, copy_ed2k_links, column_setup, properties;
public PopupListener() {
start_download = new JMenuItem("Start download");
start_download.setIcon(ImgRep.getIcon("start_download.png"));
start_download.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(DownloadSession session : getSelectedDownloadSessions())
if(session.getStatus() == DownloadStatus.STOPPED)
try {
_download_manager.startDownload(session.getFileHash());
}catch(Throwable cause) {
cause.printStackTrace();
}
}
});
stop_download = new JMenuItem("Stop download");
stop_download.setIcon(ImgRep.getIcon("stop_download.png"));
stop_download.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(DownloadSession session : getSelectedDownloadSessions())
if(session.getStatus() == DownloadStatus.STARTED)
try {
_download_manager.startDownload(session.getFileHash());
}catch( Throwable cause ) {
cause.printStackTrace();
}
}
});
cancel_download = new JMenuItem("Cancel download");
cancel_download.setIcon(ImgRep.getIcon("cancel.png"));
cancel_download.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(DownloadSession session : getSelectedDownloadSessions())
try {
_download_manager.cancelDownload(session.getFileHash());
}catch( Throwable cause ) {
cause.printStackTrace();
}
}
});
paste_ed2k_links = new JMenuItem("Paste ed2k link(s)");
paste_ed2k_links.setIcon(ImgRep.getIcon("ed2k_link_paste.png"));
paste_ed2k_links.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
(new JMThread(new JMRunnable() {
public void JMRun() {
try {
Object clipboard_contents = clipboard.getData(DataFlavor.stringFlavor);
List<ED2KFileLink> clipboard_file_links = ED2KFileLink.extractLinks(clipboard_contents.toString());
if( clipboard_file_links.size() != 0 )
for(ED2KFileLink file_link : clipboard_file_links) {
_download_manager.addDownload(file_link);
}
}catch(Throwable t) {
t.printStackTrace();
}
}
})).start();
}
});
copy_ed2k_links = new JMenuItem("Copy ed2k link(s)");
copy_ed2k_links.setIcon(ImgRep.getIcon("ed2k_link.png"));
copy_ed2k_links.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clipboard.setContents(new Transferable() {
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException,
IOException {
String ed2k_links = "";
DownloadSession[] download_sessions = getSelectedDownloadSessions();
for(DownloadSession session : download_sessions) {
ed2k_links += session.getED2KLink().getAsString() + System.getProperty("line.separator");
}
return ed2k_links;
}
public DataFlavor[] getTransferDataFlavors() {
DataFlavor[] data_flavours = new DataFlavor[1];
data_flavours[0] = DataFlavor.stringFlavor;
return data_flavours;
}
public boolean isDataFlavorSupported(
DataFlavor flavor) {
return flavor.isFlavorTextType();
}
}, new ClipboardOwner() {
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
});
}
});
column_setup = new JMenuItem("Column setup");
column_setup.setIcon(ImgRep.getIcon("columns_setup.png"));
column_setup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Column setup performed");
}
});
properties = new JMenuItem("Properties");
properties.setIcon(ImgRep.getIcon("info.png"));
properties.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DownloadSession sessions[] = getSelectedDownloadSessions();
DownloadDetailsDialog ddd = new DownloadDetailsDialog(parent, sessions[0]);