Search in sources :

Example 11 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class FilesViewMenuUtil method changePriorityManual.

private static void changePriorityManual(final List<DiskManagerFileInfo> file_list) {
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("FilesView.dialog.priority.title", "FilesView.dialog.priority.text");
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String sReturn = entryWindow.getSubmittedInput();
            if (sReturn == null)
                return;
            int priority = 0;
            try {
                priority = Integer.valueOf(sReturn).intValue();
            } catch (NumberFormatException er) {
                Debug.out("Invalid priority: " + sReturn);
                new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("FilePriority.invalid.title"), MessageText.getString("FilePriority.invalid.text", new String[] { sReturn })).open(null);
                return;
            }
            Map<DownloadManager, ArrayList<DiskManagerFileInfo>> mapDMtoDMFI = new IdentityHashMap<>();
            for (DiskManagerFileInfo file : file_list) {
                DownloadManager dm = file.getDownloadManager();
                ArrayList<DiskManagerFileInfo> listFileInfos = mapDMtoDMFI.get(dm);
                if (listFileInfos == null) {
                    listFileInfos = new ArrayList<>(1);
                    mapDMtoDMFI.put(dm, listFileInfos);
                }
                listFileInfos.add(file);
                file.setPriority(priority);
            }
            for (DownloadManager dm : mapDMtoDMFI.keySet()) {
                ArrayList<DiskManagerFileInfo> list = mapDMtoDMFI.get(dm);
                DiskManagerFileInfo[] fileInfos = list.toArray(new DiskManagerFileInfo[0]);
                boolean paused = setSkipped(dm, fileInfos, false, 0, true);
                if (paused) {
                    dm.resume();
                }
            }
        }
    });
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) ArrayList(java.util.ArrayList) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 12 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class SBC_TagsOverview method fillMenu.

@Override
public void fillMenu(String sColumnName, Menu menu) {
    List<Object> ds = tv.getSelectedDataSources();
    List<Tag> tags = new ArrayList<>();
    final List<TagFeatureRateLimit> tags_su = new ArrayList<>();
    final List<TagFeatureRateLimit> tags_sd = new ArrayList<>();
    for (Object obj : ds) {
        if (obj instanceof Tag) {
            Tag tag = (Tag) obj;
            tags.add(tag);
            if (tag instanceof TagFeatureRateLimit) {
                TagFeatureRateLimit rl = (TagFeatureRateLimit) tag;
                if (rl.supportsTagRates()) {
                    long[] up = rl.getTagSessionUploadTotal();
                    if (up != null) {
                        tags_su.add(rl);
                    }
                    long[] down = rl.getTagSessionDownloadTotal();
                    if (down != null) {
                        tags_sd.add(rl);
                    }
                }
            }
        }
    }
    if (sColumnName != null) {
        if ((sColumnName.equals(ColumnTagUpSession.COLUMN_ID) && tags_su.size() > 0) || (sColumnName.equals(ColumnTagDownSession.COLUMN_ID) && tags_sd.size() > 0)) {
            final boolean is_up = sColumnName.equals(ColumnTagUpSession.COLUMN_ID);
            MenuItem mi = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(mi, "menu.reset.session.stats");
            mi.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    for (TagFeatureRateLimit rl : is_up ? tags_su : tags_sd) {
                        if (is_up) {
                            rl.resetTagSessionUploadTotal();
                        } else {
                            rl.resetTagSessionDownloadTotal();
                        }
                    }
                }
            });
            MenuFactory.addSeparatorMenuItem(menu);
        }
        if ((sColumnName.equals(ColumnTagIcon.COLUMN_ID)) || (sColumnName.equals(ColumnTagIconSortOrder.COLUMN_ID))) {
            MenuItem mi = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(mi, "menu.set.icon.sort");
            mi.addListener(SWT.Selection, (e) -> {
                SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("tag.sort.order.title", "tag.sort.order.text");
                entryWindow.allowEmptyInput(true);
                entryWindow.setWidthHint(450);
                entryWindow.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                        if (!entryWindow.hasSubmittedInput()) {
                            return;
                        }
                        String sReturn = entryWindow.getSubmittedInput().trim();
                        if (sReturn.isEmpty()) {
                            for (Tag t : tags) {
                                t.setImageSortOrder(-1);
                            }
                        } else {
                            int start = 0;
                            try {
                                start = Integer.valueOf(sReturn).intValue();
                            } catch (NumberFormatException er) {
                            // Ignore
                            }
                            for (Tag t : tags) {
                                t.setImageSortOrder(start++);
                            }
                        }
                    }
                });
            });
            MenuFactory.addSeparatorMenuItem(menu);
        }
    }
    if (tags.size() == 1) {
        TagUIUtils.createSideBarMenuItems(menu, tags.get(0));
    } else {
        TagUIUtils.createSideBarMenuItems(menu, tags);
    }
}
Also used : UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) KeyListener(org.eclipse.swt.events.KeyListener) ArrayList(java.util.ArrayList) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) KeyEvent(org.eclipse.swt.events.KeyEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 13 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class MenuFactory method addSpeedLimitsToMenu.

public static MenuItem addSpeedLimitsToMenu(final Menu menuParent) {
    MenuItem speedLimitsMenuItem = createTopLevelMenuItem(menuParent, MENU_ID_SPEED_LIMITS);
    MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenuItem.getMenu(), new MenuBuildUtils.MenuBuilder() {

        @Override
        public void buildMenu(Menu menu, MenuEvent menuEvent) {
            if (CoreFactory.isCoreRunning()) {
                Core core = CoreFactory.getSingleton();
                final SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
                MenuItem viewCurrentItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(viewCurrentItem, "MainWindow.menu.speed_limits.view_current");
                viewCurrentItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        Utils.showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.getCurrent());
                    }
                });
                java.util.List<String> profiles = slh.getProfileNames();
                Menu profiles_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
                MenuItem profiles_item = new MenuItem(menu, SWT.CASCADE);
                profiles_item.setMenu(profiles_menu);
                Messages.setLanguageText(profiles_item, "MainWindow.menu.speed_limits.profiles");
                if (profiles.size() == 0) {
                    profiles_item.setEnabled(false);
                } else {
                    for (final String p : profiles) {
                        Menu profile_menu = new Menu(Utils.findAnyShell(), SWT.DROP_DOWN);
                        MenuItem profile_item = new MenuItem(profiles_menu, SWT.CASCADE);
                        profile_item.setMenu(profile_menu);
                        profile_item.setText(p);
                        MenuItem loadItem = new MenuItem(profile_menu, SWT.PUSH);
                        Messages.setLanguageText(loadItem, "MainWindow.menu.speed_limits.load");
                        loadItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                Utils.showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.loadProfile(p));
                            }
                        });
                        MenuItem viewItem = new MenuItem(profile_menu, SWT.PUSH);
                        Messages.setLanguageText(viewItem, "MainWindow.menu.speed_limits.view");
                        viewItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                Utils.showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { p }), slh.getProfile(p));
                            }
                        });
                        addSeparatorMenuItem(profile_menu);
                        MenuItem deleteItem = new MenuItem(profile_menu, SWT.PUSH);
                        Messages.setLanguageText(deleteItem, "MainWindow.menu.speed_limits.delete");
                        deleteItem.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event arg0) {
                                slh.deleteProfile(p);
                            }
                        });
                    }
                }
                MenuItem saveItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(saveItem, "MainWindow.menu.speed_limits.save_current");
                saveItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        UISWTInputReceiver entry = new SimpleTextEntryWindow();
                        entry.allowEmptyInput(false);
                        entry.setLocalisedTitle(MessageText.getString("MainWindow.menu.speed_limits.profile"));
                        entry.prompt(new UIInputReceiverListener() {

                            @Override
                            public void UIInputReceiverClosed(UIInputReceiver entry) {
                                if (!entry.hasSubmittedInput()) {
                                    return;
                                }
                                String input = entry.getSubmittedInput().trim();
                                if (input.length() > 0) {
                                    Utils.showText("MainWindow.menu.speed_limits.info.title", MessageText.getString("MainWindow.menu.speed_limits.info.prof", new String[] { input }), slh.saveProfile(input));
                                }
                            }
                        });
                    }
                });
                addSeparatorMenuItem(menu);
                MenuItem resetItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(resetItem, "MainWindow.menu.speed_limits.reset");
                resetItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        Utils.showText("MainWindow.menu.speed_limits.info.title", "MainWindow.menu.speed_limits.info.curr", slh.clearCurrentLimits());
                    }
                });
                addSeparatorMenuItem(menu);
                MenuItem scheduleItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(scheduleItem, "MainWindow.menu.speed_limits.schedule");
                scheduleItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        Utils.editSpeedLimitHandlerConfig(slh);
                    }
                });
                addSeparatorMenuItem(menu);
                MenuItem helpItem = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(helpItem, "MainWindow.menu.speed_limits.wiki");
                helpItem.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event arg0) {
                        Utils.launch(Wiki.SPEED_LIMIT_SCHEDULER);
                    }
                });
            }
        }
    });
    return (speedLimitsMenuItem);
}
Also used : UISWTInputReceiver(com.biglybt.ui.swt.pif.UISWTInputReceiver) UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) ParameterListener(com.biglybt.core.config.ParameterListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) SpeedLimitHandler(com.biglybt.core.speedmanager.SpeedLimitHandler) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) List(java.util.List) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Core(com.biglybt.core.Core)

Example 14 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class SelectableSpeedMenu method generateMenuItems.

public static void generateMenuItems(final Menu parent, final Core core, final GlobalManager globalManager, final boolean up_menu) {
    // can't currently do this properly as global limits stored as K not B :(
    final int kInB = 1024;
    final MenuItem[] oldItems = parent.getItems();
    for (int i = 0; i < oldItems.length; i++) {
        oldItems[i].dispose();
    }
    final String configKey = up_menu ? TransferSpeedValidator.getActiveUploadParameter(globalManager) : "Max Download Speed KBs";
    final int speedPartitions = 12;
    int maxBandwidth = COConfigurationManager.getIntParameter(configKey);
    final boolean unlim = (maxBandwidth == 0);
    maxBandwidth = adjustMaxBandWidth(maxBandwidth, globalManager, up_menu, kInB);
    boolean auto = false;
    if (up_menu) {
        final String configAutoKey = TransferSpeedValidator.getActiveAutoUploadParameter(globalManager);
        auto = TransferSpeedValidator.isAutoSpeedActive(globalManager);
        // auto
        final MenuItem auto_item = new MenuItem(parent, SWT.CHECK);
        auto_item.setText(MessageText.getString("ConfigView.auto"));
        auto_item.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                COConfigurationManager.setParameter(configAutoKey, auto_item.getSelection());
                COConfigurationManager.save();
            }
        });
        if (auto)
            auto_item.setSelection(true);
        auto_item.setEnabled(TransferSpeedValidator.isAutoUploadAvailable(core));
        new MenuItem(parent, SWT.SEPARATOR);
    }
    MenuItem item = new MenuItem(parent, SWT.RADIO);
    item.setText(MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited"));
    item.setData("maxkb", new Integer(0));
    item.setSelection(unlim && !auto);
    item.addListener(SWT.Selection, getLimitMenuItemListener(up_menu, parent, globalManager, configKey));
    Integer[] speed_limits = null;
    final String config_prefix = "config.ui.speed.partitions.manual." + ((up_menu) ? "upload" : "download") + ".";
    if (COConfigurationManager.getBooleanParameter(config_prefix + "enabled", false)) {
        speed_limits = parseSpeedPartitionString(COConfigurationManager.getStringParameter(config_prefix + "values", ""));
    }
    if (speed_limits == null) {
        speed_limits = getGenericSpeedList(speedPartitions, maxBandwidth);
    }
    for (int i = 0; i < speed_limits.length; i++) {
        Integer i_value = speed_limits[i];
        int value = i_value.intValue();
        // Don't allow the user to easily select slow speeds.
        if (value < 5) {
            continue;
        }
        item = new MenuItem(parent, SWT.RADIO);
        item.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(value * kInB, true));
        item.setData("maxkb", i_value);
        item.addListener(SWT.Selection, getLimitMenuItemListener(up_menu, parent, globalManager, configKey));
        item.setSelection(!unlim && value == maxBandwidth && !auto);
    }
    new MenuItem(parent, SWT.SEPARATOR);
    final MenuItem itemDownSpeedManual = new MenuItem(parent, SWT.PUSH);
    Messages.setLanguageText(itemDownSpeedManual, "MyTorrentsView.menu.manual");
    itemDownSpeedManual.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String kbps_str = MessageText.getString("MyTorrentsView.dialog.setNumber.inKbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow();
            entryWindow.initTexts("MyTorrentsView.dialog.setSpeed.title", new String[] { MessageText.getString(up_menu ? "MyTorrentsView.dialog.setNumber.upload" : "MyTorrentsView.dialog.setNumber.download") }, "MyTorrentsView.dialog.setNumber.text", new String[] { kbps_str, MessageText.getString(up_menu ? "MyTorrentsView.dialog.setNumber.upload" : "MyTorrentsView.dialog.setNumber.download") });
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    String sReturn = entryWindow.getSubmittedInput();
                    if (sReturn == null)
                        return;
                    int newSpeed;
                    try {
                        newSpeed = (int) (Double.valueOf(sReturn).doubleValue());
                    } catch (NumberFormatException er) {
                        MessageBox mb = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
                        mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
                        mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
                        mb.open();
                        return;
                    }
                    if (up_menu) {
                        String configAutoKey = TransferSpeedValidator.getActiveAutoUploadParameter(globalManager);
                        COConfigurationManager.setParameter(configAutoKey, false);
                    }
                    final int cValue = ((Integer) new TransferSpeedValidator(configKey, new Integer(newSpeed)).getValue()).intValue();
                    COConfigurationManager.setParameter(configKey, cValue);
                    COConfigurationManager.save();
                }
            });
        }
    });
}
Also used : UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TransferSpeedValidator(com.biglybt.core.config.impl.TransferSpeedValidator)

Example 15 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.

the class ManagerUtils method findMoreLikeThis.

private static void findMoreLikeThis(final DownloadManager dm, final DiskManagerFileInfo file, Shell shell) {
    String expression = file == null ? dm.getDisplayName() : file.getFile(true).getName();
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("find.more.like.title", "find.more.like.msg");
    entryWindow.setPreenteredText(expression, false);
    entryWindow.selectPreenteredText(true);
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String expression = entryWindow.getSubmittedInput();
            if (expression != null && expression.trim().length() > 0) {
                expression = expression.trim();
                try {
                    PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("aercm");
                    if (pi != null && pi.getPluginState().isOperational() && pi.getIPC().canInvoke("lookupByExpression", new Object[] { "", new String[0], new HashMap() })) {
                        Map<String, Object> options = new HashMap<>();
                        options.put("Subscription", true);
                        // options.put( "Name", MessageText.getString( "label.more" ) + ": " + expression);
                        options.put("Name", expression);
                        pi.getIPC().invoke("lookupByExpression", new Object[] { expression, dm.getDownloadState().getNetworks(), options });
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    });
}
Also used : SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) PluginInterface(com.biglybt.pif.PluginInterface) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

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