use of com.biglybt.ui.swt.views.ViewUtils.SpeedAdapter in project BiglyBT by BiglySoftware.
the class CategoryUIUtils method createMenuItems.
public static void createMenuItems(final Menu menu, final Category category) {
if (category.getType() == Category.TYPE_USER) {
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemDelete, "MyTorrentsView.menu.category.delete");
itemDelete.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> managers = category.getDownloadManagers(gm.getDownloadManagers());
// move to array,since setCategory removed it from the category,
// which would mess up our loop
DownloadManager[] dms = managers.toArray(new DownloadManager[managers.size()]);
for (DownloadManager dm : dms) {
DownloadManagerState state = dm.getDownloadState();
if (state != null) {
state.setCategory(null);
}
}
CategoryManager.removeCategory(category);
}
});
}
if (category.getType() != Category.TYPE_ALL) {
long kInB = DisplayFormatters.getKinB();
long maxDownload = COConfigurationManager.getIntParameter("Max Download Speed KBs", 0) * kInB;
long maxUpload = COConfigurationManager.getIntParameter("Max Upload Speed KBs", 0) * kInB;
int down_speed = category.getDownloadSpeed();
int up_speed = category.getUploadSpeed();
ViewUtils.addSpeedMenu(menu.getShell(), menu, true, true, true, true, false, down_speed == 0, down_speed, down_speed, maxDownload, false, up_speed == 0, up_speed, up_speed, maxUpload, 1, null, new SpeedAdapter() {
@Override
public void setDownSpeed(int val) {
category.setDownloadSpeed(val);
}
@Override
public void setUpSpeed(int val) {
category.setUploadSpeed(val);
}
});
}
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> managers = category.getDownloadManagers(gm.getDownloadManagers());
final DownloadManager[] dms = managers.toArray(new DownloadManager[managers.size()]);
boolean start = false;
boolean stop = false;
for (DownloadManager dm : dms) {
stop = stop || ManagerUtils.isStopable(dm);
start = start || ManagerUtils.isStartable(dm);
}
// Queue
final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue");
Utils.setMenuItemImage(itemQueue, "start");
itemQueue.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.queueDataSources(dms, true);
}
});
itemQueue.setEnabled(start);
// Stop
final MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemStop, "MyTorrentsView.menu.stop");
Utils.setMenuItemImage(itemStop, "stop");
itemStop.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.stopDataSources(dms);
}
});
itemStop.setEnabled(stop);
if (category.canBePublic()) {
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemPublic = new MenuItem(menu, SWT.CHECK);
itemPublic.setSelection(category.isPublic());
Messages.setLanguageText(itemPublic, "cat.share");
itemPublic.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
category.setPublic(itemPublic.getSelection());
}
});
}
// share with friends
PluginInterface bpi = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaceByClass(BuddyPlugin.class);
int cat_type = category.getType();
if (bpi != null && cat_type != Category.TYPE_UNCATEGORIZED) {
final BuddyPlugin buddy_plugin = (BuddyPlugin) bpi.getPlugin();
if (buddy_plugin.isClassicEnabled()) {
final Menu share_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem share_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(share_item, "azbuddy.ui.menu.cat.share");
share_item.setMenu(share_menu);
List<BuddyPluginBuddy> buddies = buddy_plugin.getBuddies();
if (buddies.size() == 0) {
final MenuItem item = new MenuItem(share_menu, SWT.CHECK);
item.setText(MessageText.getString("general.add.friends"));
item.setEnabled(false);
} else {
final String cname;
if (cat_type == Category.TYPE_ALL) {
cname = "All";
} else {
cname = category.getName();
}
final boolean is_public = buddy_plugin.isPublicTagOrCategory(cname);
final MenuItem itemPubCat = new MenuItem(share_menu, SWT.CHECK);
Messages.setLanguageText(itemPubCat, "general.all.friends");
itemPubCat.setSelection(is_public);
itemPubCat.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (is_public) {
buddy_plugin.removePublicTagOrCategory(cname);
} else {
buddy_plugin.addPublicTagOrCategory(cname);
}
}
});
new MenuItem(share_menu, SWT.SEPARATOR);
for (final BuddyPluginBuddy buddy : buddies) {
if (buddy.getNickName() == null) {
continue;
}
final boolean auth = buddy.isLocalRSSTagOrCategoryAuthorised(cname);
final MenuItem itemShare = new MenuItem(share_menu, SWT.CHECK);
itemShare.setText(buddy.getName());
itemShare.setSelection(auth || is_public);
if (is_public) {
itemShare.setEnabled(false);
}
itemShare.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (auth) {
buddy.removeLocalAuthorisedRSSTagOrCategory(cname);
} else {
buddy.addLocalAuthorisedRSSTagOrCategory(cname);
}
}
});
}
}
}
}
if (category.getType() != Category.TYPE_ALL) {
TrancodeUIUtils.TranscodeTarget[] tts = TrancodeUIUtils.getTranscodeTargets();
if (tts.length > 0) {
final Menu t_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem t_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(t_item, "cat.autoxcode");
t_item.setMenu(t_menu);
String existing = category.getStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET);
for (TrancodeUIUtils.TranscodeTarget tt : tts) {
TrancodeUIUtils.TranscodeProfile[] profiles = tt.getProfiles();
if (profiles.length > 0) {
final Menu tt_menu = new Menu(t_menu.getShell(), SWT.DROP_DOWN);
final MenuItem tt_item = new MenuItem(t_menu, SWT.CASCADE);
tt_item.setText(tt.getName());
tt_item.setMenu(tt_menu);
for (final TrancodeUIUtils.TranscodeProfile tp : profiles) {
final MenuItem p_item = new MenuItem(tt_menu, SWT.CHECK);
p_item.setText(tp.getName());
boolean selected = existing != null && existing.equals(tp.getUID());
if (selected) {
Utils.setMenuItemImage(tt_item, "blacktick");
}
p_item.setSelection(selected);
p_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
category.setStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET, p_item.getSelection() ? tp.getUID() : null);
}
});
}
}
}
}
}
// rss feed
final MenuItem rssOption = new MenuItem(menu, SWT.CHECK);
rssOption.setSelection(category.getBooleanAttribute(Category.AT_RSS_GEN));
Messages.setLanguageText(rssOption, "cat.rss.gen");
rssOption.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = rssOption.getSelection();
category.setBooleanAttribute(Category.AT_RSS_GEN, set);
}
});
if (cat_type != Category.TYPE_UNCATEGORIZED && cat_type != Category.TYPE_ALL) {
final MenuItem upPriority = new MenuItem(menu, SWT.CHECK);
upPriority.setSelection(category.getIntAttribute(Category.AT_UPLOAD_PRIORITY) > 0);
Messages.setLanguageText(upPriority, "cat.upload.priority");
upPriority.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = upPriority.getSelection();
category.setIntAttribute(Category.AT_UPLOAD_PRIORITY, set ? 1 : 0);
}
});
}
// options
MenuItem itemOptions = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemOptions, "cat.options");
itemOptions.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
MultipleDocumentInterface mdi = uiFunctions.getMDI();
if (mdi != null) {
mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
}
}
}
});
if (dms.length == 0) {
itemOptions.setEnabled(false);
}
}
use of com.biglybt.ui.swt.views.ViewUtils.SpeedAdapter in project BiglyBT by BiglySoftware.
the class TagUIUtils method createTF_RateLimitMenuItems.
private static void createTF_RateLimitMenuItems(Menu menu, Tag tag, TagType tag_type, int userMode) {
final TagFeatureRateLimit tf_rate_limit = (TagFeatureRateLimit) tag;
boolean has_up = tf_rate_limit.supportsTagUploadLimit();
boolean has_down = tf_rate_limit.supportsTagDownloadLimit();
if (has_up || has_down) {
long kInB = DisplayFormatters.getKinB();
long maxDownload = COConfigurationManager.getIntParameter("Max Download Speed KBs", 0) * kInB;
long maxUpload = COConfigurationManager.getIntParameter("Max Upload Speed KBs", 0) * kInB;
int down_speed = tf_rate_limit.getTagDownloadLimit();
int up_speed = tf_rate_limit.getTagUploadLimit();
Map<String, Object> menu_properties = new HashMap<>();
if (tag_type.getTagType() == TagType.TT_PEER_IPSET || tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
if (has_up) {
menu_properties.put(ViewUtils.SM_PROP_PERMIT_UPLOAD_DISABLE, true);
}
if (has_down) {
menu_properties.put(ViewUtils.SM_PROP_PERMIT_DOWNLOAD_DISABLE, true);
}
}
ViewUtils.addSpeedMenu(menu.getShell(), menu, has_up, has_down, true, true, down_speed == -1, down_speed == 0, down_speed, down_speed, maxDownload, up_speed == -1, up_speed == 0, up_speed, up_speed, maxUpload, 1, menu_properties, new SpeedAdapter() {
@Override
public void setDownSpeed(int val) {
tf_rate_limit.setTagDownloadLimit(val);
}
@Override
public void setUpSpeed(int val) {
tf_rate_limit.setTagUploadLimit(val);
}
});
}
if (userMode > 0) {
if (tf_rate_limit.getTagUploadPriority() >= 0) {
final MenuItem upPriority = new MenuItem(menu, SWT.CHECK);
upPriority.setSelection(tf_rate_limit.getTagUploadPriority() > 0);
Messages.setLanguageText(upPriority, "cat.upload.priority");
upPriority.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = upPriority.getSelection();
tf_rate_limit.setTagUploadPriority(set ? 1 : 0);
}
});
}
/* Usually set once: Can be set in Tags Overview*/
if (tf_rate_limit.getTagMinShareRatio() >= 0) {
MenuItem itemSR = new MenuItem(menu, SWT.PUSH);
final String existing = String.valueOf(tf_rate_limit.getTagMinShareRatio() / 1000.0f);
Messages.setLanguageText(itemSR, "menu.min.share.ratio", new String[] { existing });
itemSR.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("min.sr.window.title", "min.sr.window.message");
entryWindow.setPreenteredText(existing, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
try {
String text = receiver.getSubmittedInput().trim();
int sr = 0;
if (text.length() > 0) {
try {
float f = Float.parseFloat(text);
sr = (int) (f * 1000);
if (sr < 0) {
sr = 0;
} else if (sr == 0 && f > 0) {
sr = 1;
}
} catch (Throwable e) {
Debug.out(e);
}
tf_rate_limit.setTagMinShareRatio(sr);
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
}
if (tf_rate_limit.getTagMaxShareRatio() >= 0) {
MenuItem itemSR = new MenuItem(menu, SWT.PUSH);
final String existing = String.valueOf(tf_rate_limit.getTagMaxShareRatio() / 1000.0f);
Messages.setLanguageText(itemSR, "menu.max.share.ratio", new String[] { existing });
itemSR.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("max.sr.window.title", "max.sr.window.message");
entryWindow.setPreenteredText(existing, false);
entryWindow.selectPreenteredText(true);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
if (!receiver.hasSubmittedInput()) {
return;
}
try {
String text = receiver.getSubmittedInput().trim();
int sr = 0;
if (text.length() > 0) {
try {
float f = Float.parseFloat(text);
sr = (int) (f * 1000);
if (sr < 0) {
sr = 0;
} else if (sr == 0 && f > 0) {
sr = 1;
}
} catch (Throwable e) {
Debug.out(e);
}
tf_rate_limit.setTagMaxShareRatio(sr);
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
}
/**/
}
}
Aggregations