Search in sources :

Example 36 with UIInputReceiver

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);
                                }
                            }
                        }
                    });
                }
            });
        }
    /**/
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) MenuListener(org.eclipse.swt.events.MenuListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) DecimalFormat(java.text.DecimalFormat) Point(org.eclipse.swt.graphics.Point) SpeedAdapter(com.biglybt.ui.swt.views.ViewUtils.SpeedAdapter) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 37 with UIInputReceiver

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);
            }
        }
    });
}
Also used : UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver)

Example 38 with UIInputReceiver

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 });
                }
            }
        }
    });
}
Also used : Category(com.biglybt.core.category.Category) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Tag(com.biglybt.core.tag.Tag)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)38 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)36 SimpleTextEntryWindow (com.biglybt.ui.swt.SimpleTextEntryWindow)21 List (java.util.List)11 DownloadManager (com.biglybt.core.download.DownloadManager)9 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)7 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)7 Point (org.eclipse.swt.graphics.Point)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 MenuEvent (org.eclipse.swt.events.MenuEvent)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 MessageText (com.biglybt.core.internat.MessageText)5 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)5 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)5 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)5 DisposeListener (org.eclipse.swt.events.DisposeListener)5