use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class BuddyPluginViewInstance method addPartialBuddyTable.
private Comparator<PartialBuddy> addPartialBuddyTable(Composite child1) {
partial_buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
final String[] headers = { "azbuddy.ui.pbtable.peer", "azbuddy.ui.pbtable.downloads" };
int[] sizes = { 250, 400 };
int[] aligns = { SWT.LEFT, SWT.LEFT };
for (int i = 0; i < headers.length; i++) {
TableColumn tc = new TableColumn(partial_buddy_table, aligns[i]);
tc.setWidth(Utils.adjustPXForDPI(sizes[i]));
Messages.setLanguageText(tc, headers[i]);
}
partial_buddy_table.setHeaderVisible(true);
TableColumn[] columns = partial_buddy_table.getColumns();
columns[0].setData(new Integer(PBFilterComparator.FIELD_PEER));
columns[1].setData(new Integer(PBFilterComparator.FIELD_DOWNLOADS));
final PBFilterComparator comparator = new PBFilterComparator();
Listener sort_listener = new Listener() {
@Override
public void handleEvent(Event e) {
TableColumn tc = (TableColumn) e.widget;
int field = ((Integer) tc.getData()).intValue();
comparator.setField(field);
Collections.sort(partial_buddies, comparator);
updateTable();
}
};
for (int i = 0; i < columns.length; i++) {
columns[i].addListener(SWT.Selection, sort_listener);
}
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.heightHint = partial_buddy_table.getHeaderHeight() * 3;
Utils.setLayoutData(partial_buddy_table, gridData);
partial_buddy_table.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = partial_buddy_table.indexOf(item);
if (index < 0 || index >= partial_buddies.size()) {
return;
}
PartialBuddy buddy = partial_buddies.get(index);
item.setText(0, buddy.ip);
item.setText(1, buddy.getDownloadsSummary());
item.setData(buddy);
}
});
final Menu menu = new Menu(partial_buddy_table);
final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
remove_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.remove"));
remove_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] selection = partial_buddy_table.getSelection();
for (int i = 0; i < selection.length; i++) {
PartialBuddy buddy = (PartialBuddy) selection[i].getData();
buddy.remove();
}
}
});
partial_buddy_table.setMenu(menu);
partial_buddy_table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.stateMask == SWT.MOD1) {
int key = event.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if (key == 'a') {
partial_buddy_table.selectAll();
event.doit = false;
}
} else if (event.stateMask == 0 && event.keyCode == SWT.DEL) {
TableItem[] selection = partial_buddy_table.getSelection();
String str = "";
for (int i = 0; i < selection.length; i++) {
PartialBuddy buddy = (PartialBuddy) selection[i].getData();
str += (str.isEmpty() ? "" : ", ") + buddy.ip;
}
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
for (int i = 0; i < selection.length; i++) {
PartialBuddy buddy = (PartialBuddy) selection[i].getData();
buddy.remove();
}
partial_buddy_table.setSelection(new int[0]);
}
}
});
event.doit = false;
}
}
});
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent arg0) {
TableItem[] selection = partial_buddy_table.getSelection();
remove_item.setEnabled(selection.length > 0);
}
@Override
public void menuHidden(MenuEvent arg0) {
}
});
return (comparator);
}
use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class MessageBoxShell method main.
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.open();
MessageBoxShell messageBoxShell = new MessageBoxShell("Title", "Test\n" + "THis is a very long line that tests whether the box gets really wide which is something we don't want.\n" + "A <A HREF=\"Link\">link</A> for <A HREF=\"http://moo.com\">you</a>", new String[] { "Okay", "Cancyyyyyy", "Maybe" }, 1);
messageBoxShell.setRemember("test2", false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
messageBoxShell.setAutoCloseInMS(15000);
messageBoxShell.setParent(shell);
messageBoxShell.setHtml("<b>Moo</b> goes the cow<p><hr>");
messageBoxShell.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int returnVal) {
System.out.println(returnVal);
}
});
while (!shell.isDisposed()) {
if (!display.isDisposed() && !display.readAndDispatch()) {
display.sleep();
}
}
}
use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class TorrentUtil method removeDownloadsSupport.
private static void removeDownloadsSupport(final DownloadManager[] dms, final AERunnable deleteFailed, final boolean forcePrompt) {
if (dms == null) {
return;
}
// confusing code:
// for loop goes through erasing published and low noise torrents until
// it reaches a normal one. We then prompt the user, and stop the loop.
// When the user finally chooses an option, we act on it. If the user
// chose to act on all, we do immediately all and quit.
// If the user chose an action just for the one torrent, we do that action,
// remove that item from the array (by nulling it), and then call
// removeDownloads again so we can prompt again (or erase more published/low noise torrents)
boolean can_archive = false;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (dm == null) {
continue;
}
if (PluginCoreUtils.wrap(dm).canStubbify()) {
can_archive = true;
}
}
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (dm == null) {
continue;
}
boolean deleteTorrent = COConfigurationManager.getBooleanParameter("def.deletetorrent");
int confirm = COConfigurationManager.getIntParameter("tb.confirm.delete.content");
boolean doPrompt = confirm == 0 | forcePrompt;
if (doPrompt) {
String title = MessageText.getString("deletedata.title");
String text = MessageText.getString("v3.deleteContent.message", new String[] { dm.getDisplayName() });
if (can_archive) {
text += "\n\n" + MessageText.getString("v3.deleteContent.or.archive");
}
String[] buttons;
int defaultButtonPos;
buttons = new String[] { MessageText.getString("Button.cancel"), MessageText.getString("Button.deleteContent.fromComputer"), MessageText.getString("Button.deleteContent.fromLibrary") };
/*
int[] buttonVals = new int[] {
SWT.CANCEL,
1,
2
};
*/
defaultButtonPos = 2;
final MessageBoxShell mb = new MessageBoxShell(title, text, buttons, defaultButtonPos);
int numLeft = (dms.length - i);
if (numLeft > 1) {
mb.setRemember("na", false, MessageText.getString("v3.deleteContent.applyToAll", new String[] { "" + numLeft }));
// never store remember state
mb.setRememberOnlyIfButton(-3);
}
mb.setRelatedObject(dm);
mb.setLeftImage("image.trash");
mb.addCheckBox("deletecontent.also.deletetorrent", 2, deleteTorrent);
final int index = i;
TorrentUtils.startTorrentDelete();
final boolean[] endDone = { false };
try {
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
try {
ImageLoader.getInstance().releaseImage("image.trash");
removeDownloadsPrompterClosed(dms, index, deleteFailed, result, mb.isRemembered(), mb.getCheckBoxEnabled());
} finally {
synchronized (endDone) {
if (!endDone[0]) {
TorrentUtils.endTorrentDelete();
endDone[0] = true;
}
}
}
}
});
} catch (Throwable e) {
Debug.out(e);
synchronized (endDone) {
if (!endDone[0]) {
TorrentUtils.endTorrentDelete();
endDone[0] = true;
}
}
}
return;
} else {
boolean deleteData = confirm == 1;
removeDownloadsPrompterClosed(dms, i, deleteFailed, deleteData ? 1 : 2, true, deleteTorrent);
}
}
}
use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class SBC_SearchResultsView method downloadAction.
public static void downloadAction(final SearchSubsResultBase entry) {
String link = entry.getTorrentLink();
if (link.startsWith("chat:")) {
Utils.launch(link);
return;
}
showDownloadFTUX(entry, new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
String referer_str = null;
String torrentUrl = entry.getTorrentLink();
try {
Map headers = UrlUtils.getBrowserHeaders(referer_str);
if (entry instanceof SBC_SubscriptionResult) {
SBC_SubscriptionResult sub_entry = (SBC_SubscriptionResult) entry;
Subscription subs = sub_entry.getSubscription();
try {
Engine engine = subs.getEngine();
if (engine != null && engine instanceof WebEngine) {
WebEngine webEngine = (WebEngine) engine;
if (webEngine.isNeedsAuth()) {
headers.put("Cookie", webEngine.getCookies());
}
}
} catch (Throwable e) {
Debug.out(e);
}
subs.addPotentialAssociation(sub_entry.getID(), torrentUrl);
} else {
SBC_SearchResult search_entry = (SBC_SearchResult) entry;
Engine engine = search_entry.getEngine();
if (engine != null) {
engine.addPotentialAssociation(torrentUrl);
if (engine instanceof WebEngine) {
WebEngine webEngine = (WebEngine) engine;
if (webEngine.isNeedsAuth()) {
headers.put("Cookie", webEngine.getCookies());
}
}
}
}
byte[] torrent_hash = entry.getHash();
if (torrent_hash != null) {
if (torrent_hash != null && !torrentUrl.toLowerCase().startsWith("magnet")) {
String title = entry.getName();
String magnet = UrlUtils.getMagnetURI(torrent_hash, title, null);
headers.put("X-Alternative-URI-1", magnet);
}
}
PluginInitializer.getDefaultInterface().getDownloadManager().addDownload(new URL(torrentUrl), headers);
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class PlayerInstallWindow method open.
public void open() {
box = new VuzeMessageBox("", "", null, 0);
box.setSubTitle(MessageText.getString("dlg.player.install.subtitle"));
box.addResourceBundle(PlayerInstallWindow.class, SkinPropertiesImpl.PATH_SKIN_DEFS, "skin3_dlg_register");
box.setIconResource("image.player.dlg.header");
this.progressText = MessageText.getString("dlg.player.install.description");
box.setListener(new VuzeMessageBoxListener() {
@Override
public void shellReady(Shell shell, SWTSkinObjectContainer soExtra) {
SWTSkin skin = soExtra.getSkin();
skin.createSkinObject("dlg.register.install", "dlg.register.install", soExtra);
SWTSkinObjectContainer soProgressBar = (SWTSkinObjectContainer) skin.getSkinObject("progress-bar");
if (soProgressBar != null) {
progressBar = new ProgressBar(soProgressBar.getComposite(), SWT.HORIZONTAL);
progressBar.setMinimum(0);
progressBar.setMaximum(100);
progressBar.setLayoutData(Utils.getFilledFormData());
}
soInstallPct = (SWTSkinObjectText) skin.getSkinObject("install-pct");
soProgressText = (SWTSkinObjectText) skin.getSkinObject("progress-text");
if (soProgressText != null && progressText != null) {
soProgressText.setText(progressText);
}
}
});
box.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
installer.setListener(null);
installer.cancel();
}
});
}
Aggregations