use of com.biglybt.pif.ui.UIInputReceiver 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);
DecimalFormat df = new DecimalFormat("0.000");
df.setGroupingUsed(false);
df.setMaximumFractionDigits(3);
final String existing = df.format(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;
}
String text = receiver.getSubmittedInput().trim();
int sr = 0;
if (text.length() > 0) {
try {
float f = DisplayFormatters.parseFloat(df, text);
sr = (int) (f * 1000);
if (sr < 0) {
sr = 0;
} else if (sr == 0 && f > 0) {
sr = 1;
}
tf_rate_limit.setTagMinShareRatio(sr);
} catch (Throwable e) {
MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
mb.open();
Debug.out(e);
}
}
}
});
}
});
}
if (tf_rate_limit.getTagMaxShareRatio() >= 0) {
MenuItem itemSR = new MenuItem(menu, SWT.PUSH);
DecimalFormat df = new DecimalFormat("0.000");
df.setGroupingUsed(false);
df.setMaximumFractionDigits(3);
final String existing = df.format(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;
}
String text = receiver.getSubmittedInput().trim();
int sr = 0;
if (text.length() > 0) {
try {
float f = DisplayFormatters.parseFloat(df, text);
sr = (int) (f * 1000);
if (sr < 0) {
sr = 0;
} else if (sr == 0 && f > 0) {
sr = 1;
}
tf_rate_limit.setTagMaxShareRatio(sr);
} catch (Throwable e) {
MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
mb.open();
Debug.out(e);
}
}
}
});
}
});
}
/**/
}
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class TagUIUtils method openRenameTagDialog.
public static void openRenameTagDialog(Tag tag) {
if (tag == null || tag.getTagType().isTagTypeAuto()) {
return;
}
UIInputReceiver entry = new SimpleTextEntryWindow();
String tagName = tag.getTagName(true);
entry.setPreenteredText(tagName, false);
entry.maintainWhitespace(false);
entry.allowEmptyInput(false);
entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { tagName }));
entry.prompt(result -> {
if (!result.hasSubmittedInput()) {
return;
}
String input = result.getSubmittedInput().trim();
if (input.length() > 0) {
try {
tag.setTagName(input);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
});
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class CategoryUIUtils method showCreateCategoryDialog.
public static void showCreateCategoryDialog(final UIFunctions.TagReturner tagReturner) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("CategoryAddWindow.title", "CategoryAddWindow.message");
entryWindow.setParentShell(Utils.findAnyShell());
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (entryWindow.hasSubmittedInput()) {
TagUIUtils.checkTagSharing(false);
Category newCategory = CategoryManager.createCategory(entryWindow.getSubmittedInput());
if (tagReturner != null) {
tagReturner.returnedTags(new Tag[] { newCategory });
}
}
}
});
}
Aggregations