protected Menu getPopUpMenu() {
if (getSelectionCount()<1)
return no_items_menu;
SharedFile shared_file = shared_files_table.getSelectedObject();
if (shared_file.isCompleted()) {
rating_menu.setEnabled(true);
rating_menu.setVisible(true);
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
switch (shared_file.getFileQuality()) {
case FAKE : file_fake.setSelection(true); break;
case POOR : file_poor.setSelection(true); break;
case FAIR : file_fair.setSelection(true); break;
case GOOD : file_good.setSelection(true); break;
case EXCELLENT : file_excellent.setSelection(true); break;
default : file_not_rated.setSelection(true); break;
}
} else { rating_menu.setEnabled(false); }
properties_menu_item.setEnabled(true);
copy_ed2k_link_menu_item.setEnabled(true);
remove_from_disk_menu_item.setEnabled(true);
if (getSelectedObject().getHashSet() == null) {
properties_menu_item.setEnabled(false);
copy_ed2k_link_menu_item.setEnabled(false);
remove_from_disk_menu_item.setEnabled(false);
}
if (getSelectionCount()>1)
properties_menu_item.setEnabled(false);
open_selected_menu_item.setEnabled(false);
if (selectedRunnableFiles())
open_selected_menu_item.setEnabled(true);
return select_completed_file_menu;
}
int HASHED = 0x01;
int UNHASHED = 0x02;
int HASHING = 0x03;
public void updateRow(SharedFile object) {
int status = HASHED;
java.util.List<CompletedFile> file_list = sharing_manager.getUnhashedFiles();
if (file_list != null) {
for(CompletedFile unhashed_file : file_list) {
if (unhashed_file.getFile().equals(object.getFile())) {
status = UNHASHED;
break;
}
}
}
SharedFile hashing_file = sharing_manager.getCurrentHashingFile();
if (hashing_file != null)
if (object.getFile().equals(hashing_file.getFile()))
status = HASHING;
Image icon = SWTImageRepository.getIconByExtension(object.getSharingName());
setRowImage(object, SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID, icon);
String text = object.getSharingName();
setRowText(object, SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID, text);
long file_size = object.getFile().length();
setRowText(object, SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID, FileFormatter.formatFileSize(file_size));
String mime_type = FileFormatter.formatMimeType(object.getMimeType());
setRowText(object,SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID,mime_type);
double percent_completed = 100d;
if (object instanceof PartialFile) {
PartialFile partial_file = (PartialFile)object;
percent_completed = partial_file.getPercentCompleted();
}
if (status == HASHED) {
setRowText(object,SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID,FileFormatter.formatProgress(percent_completed));
setRowText(object,SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, object.getFileHash().getAsString());
} else
if (status == HASHING)
setRowText(object,SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, _._("mainwindow.sharedtab.label.hashing"));
else
setRowText(object,SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, _._("mainwindow.sharedtab.label.waiting_to_hash"));
}
};
int width;
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID);
shared_files_table.addColumn(SWT.LEFT, SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID, _._("mainwindow.sharedtab.column.filename"), "", width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID);
shared_files_table.addColumn(SWT.RIGHT, SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID, _._("mainwindow.sharedtab.column.filesize"), "", width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID);
shared_files_table.addColumn(SWT.LEFT, SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID, _._("mainwindow.sharedtab.column.filetype"), "",width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID);
shared_files_table.addColumn(SWT.LEFT, SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, _._("mainwindow.sharedtab.column.fileid"), "", width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID);
shared_files_table.addColumn(SWT.RIGHT, SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID, _._("mainwindow.sharedtab.column.completed"), "", width);
shared_files_table.updateColumnSettings();
no_items_menu = new Menu(shared_files_table);
MenuItem column_setup_menu_item = new MenuItem(no_items_menu,SWT.PUSH);
column_setup_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.column_setup"));
column_setup_menu_item.setImage(SWTImageRepository.getImage("columns_setup.png"));
column_setup_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shared_files_table.showColumnEditorWindow();
}});
select_completed_file_menu = new Menu(shared_files_table);
open_selected_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
open_selected_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.open"));
open_selected_menu_item.setImage(SWTImageRepository.getImage("open_file.png"));
open_selected_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
openSelected();
}});
copy_ed2k_link_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
copy_ed2k_link_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.copy_ed2k_link"));
copy_ed2k_link_menu_item.setImage(SWTImageRepository.getImage("ed2k_link.png"));
copy_ed2k_link_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
copyED2KLink();
}});
remove_from_disk_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
remove_from_disk_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.remove_from_disk"));
remove_from_disk_menu_item.setImage(SWTImageRepository.getImage("cancel.png"));
remove_from_disk_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
removeFromDisk();
}});
MenuItem selected_column_setup_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
selected_column_setup_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.column_setup"));
selected_column_setup_menu_item.setImage(SWTImageRepository.getImage("columns_setup.png"));
selected_column_setup_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shared_files_table.showColumnEditorWindow();
}});
rating_menu_item = new MenuItem(select_completed_file_menu, SWT.CASCADE);
rating_menu_item.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu"));
rating_menu = new Menu(select_completed_file_menu);
rating_menu_item.setMenu(rating_menu);
file_not_rated = new MenuItem(rating_menu, SWT.RADIO);
file_not_rated.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.not_rated"));
file_not_rated.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.NOTRATED);
}
});
}});
file_fake = new MenuItem(rating_menu, SWT.RADIO);
file_fake.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.fake"));
file_fake.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.FAKE);
}});
}});
file_poor = new MenuItem(rating_menu, SWT.RADIO);
file_poor.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.poor"));
file_poor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.POOR);
}});
}});
file_fair = new MenuItem(rating_menu, SWT.RADIO);
file_fair.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.fair"));
file_fair.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.FAIR);
}});
}});
file_good = new MenuItem(rating_menu, SWT.RADIO);
file_good.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.good"));
file_good.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.GOOD);
}});
}});
file_excellent = new MenuItem(rating_menu, SWT.RADIO);
file_excellent.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.excellent"));
file_excellent.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.EXCELLENT);
}});
}});
new MenuItem(select_completed_file_menu,SWT.SEPARATOR);
properties_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
properties_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.properties"));
properties_menu_item.setImage(SWTImageRepository.getImage("info.png"));
properties_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SharedFile shared_file = shared_files_table.getSelectedObject();
SharedFilePropertiesWindow window = new SharedFilePropertiesWindow(shared_file);
window.getCoreComponents();
window.initUIComponents();
}});
config_manager.addConfigurationListener(new ConfigurationAdapter() {
public void sharedDirectoriesChanged(java.util.List<File> sharedDirs) {
updateDirList(sharedDirs);
}
});
try {
updateDirList(config_manager.getSharedFolders());
} catch (ConfigurationManagerException e) {
e.printStackTrace();
}
refreshable = new Refreshable() {
public void refresh() {
if (isDisposed()) return;
String text = _._("mainwindow.sharedtab.group.shared_files");
SharedFile hashing_file = sharing_manager.getCurrentHashingFile();
if (hashing_file != null) {
text +=" Hashing [";
DecimalFormat formatter = new DecimalFormat("0.00");
String file_name = hashing_file.getSharingName();
if (file_name.length()>20)
file_name = file_name.substring(0, 20) + "...";
text +=file_name+" : " + formatter.format(sharing_manager.getCurrentHashingFilePercent())+"%";
text +="]";
}