upload_speed.setComparator(new Comparator() {
public int compare(Object o1, Object o2) {
Float u_speed1 = null;
Float u_speed2 = null;
try {
DownloadSession d_session1 = (DownloadSession)o1;
DownloadSession d_session2 = (DownloadSession)o2;
UploadSession u_session1 = null;
UploadSession u_session2 = null;
if(_upload_manager.hasUpload(d_session1.getFileHash()))
u_session1 = _upload_manager.getUpload(d_session1.getFileHash());
if(_upload_manager.hasUpload(d_session2.getFileHash()))
u_session2 = _upload_manager.getUpload(d_session2.getFileHash());
u_speed1 = new Float((u_session1!=null)?u_session1.getSpeed():0.0f);
u_speed2 = new Float((u_session2!=null)?u_session2.getSpeed():0.0f);
}catch(Throwable cause) {
cause.printStackTrace();
}
return Misc.compareAllObjects(u_speed1, u_speed2, "floatValue", true);
}
});
table_columns.add(upload_speed);
TableColumnExt pieces = new TableColumnExt();
pieces.setIdentifier(UIConstants.DOWNLOAD_LIST_PROGRESS_COLUMN_ID);
pieces.setModelIndex(DownloadTableModel.PIECES);
pieces.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_PROGRESS_COLUMN_ID));
pieces.setHeaderValue("Pieces");
pieces.setCellRenderer(new PiecesTableCellRenderer());
pieces.setComparator(new GeneralComparator("getPercentCompleted"));
table_columns.add(pieces);
TableColumnExt done = new TableColumnExt();
done.setIdentifier(UIConstants.DOWNLOAD_LIST_COMPLETED_COLUMN_ID);
done.setModelIndex(DownloadTableModel.DONE);
done.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_COMPLETED_COLUMN_ID));
done.setHeaderValue("Done");
done.setCellRenderer(new DoneTableCellRenderer());
done.setComparator(new GeneralComparator("getPercentCompleted"));
table_columns.add(done);
TableColumnExt progress_bar = new TableColumnExt();
progress_bar.setIdentifier(UIConstants.DOWNLOAD_LIST_PROGRESS_BAR_COLUMN_ID);
progress_bar.setModelIndex(DownloadTableModel.PROGRESS_BAR);
progress_bar.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_PROGRESS_BAR_COLUMN_ID));
progress_bar.setHeaderValue("Progress");
progress_bar.setCellRenderer(new ProgressBarTableCellRenderer());
progress_bar.setComparator(new GeneralComparator("getPercentCompleted"));
table_columns.add(progress_bar);
TableColumnExt complete_sources = new TableColumnExt();
complete_sources.setIdentifier(UIConstants.DOWNLOAD_LIST_COMPLETE_SOURCES_COLUMN_ID);
complete_sources.setModelIndex(DownloadTableModel.COMPLETE_SOURCES);
complete_sources.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_COMPLETE_SOURCES_COLUMN_ID));
complete_sources.setVisible(true);
complete_sources.setHeaderValue("Complete sources");
complete_sources.setCellRenderer(new CompletedSourcesTableCellRenderer());
complete_sources.setComparator(new GeneralComparator("getCompletedSources"));
table_columns.add(complete_sources);
TableColumnExt partial_sources = new TableColumnExt();
partial_sources.setIdentifier(UIConstants.DOWNLOAD_LIST_PARTIAL_SOURCES_COLUMN_ID);
partial_sources.setModelIndex(DownloadTableModel.PARTIAL_SOURCES);
partial_sources.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_PARTIAL_SOURCES_COLUMN_ID));
partial_sources.setVisible(true);
partial_sources.setHeaderValue("Partial sources");
partial_sources.setCellRenderer(new PartialSourcesTableCellRenderer());
partial_sources.setComparator(new GeneralComparator("getPartialSources"));
table_columns.add(partial_sources);
TableColumnExt eta = new TableColumnExt();
eta.setIdentifier(UIConstants.DOWNLOAD_LIST_REMAINING_COLUMN_ID);
eta.setModelIndex(DownloadTableModel.ETA);
eta.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_REMAINING_COLUMN_ID));
eta.setHeaderValue("ETA");
eta.setCellRenderer(new ETATableCellRenderer());
eta.setComparator(new GeneralComparator("getETA"));
table_columns.add(eta);
TableColumnExt status = new TableColumnExt();
status.setIdentifier(UIConstants.DOWNLOAD_LIST_STATUS_COLUMN_ID);
status.setModelIndex(DownloadTableModel.STATUS);
status.setVisible(_pref.isColumnVisible(UIConstants.DOWNLOAD_LIST_STATUS_COLUMN_ID));
status.setHeaderValue("Status");
status.setCellRenderer(new StatusTableCellRenderer());
status.setComparator(new GeneralComparator("getStatus"));
table_columns.add(status);
super.buildColumns(new DownloadTableModel());
class PopupListener extends MouseAdapter {
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]);
SwingUtils.setWindowLocationRelativeTo(ddd, parent);
ddd.setVisible(true);
}
});