Search in sources :

Example 16 with UIInputReceiverListener

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

the class BYOPanel method editSelected.

protected void editSelected() {
    final TreeItem[] selection = tree.getSelection();
    if (selection.length == 1) {
        SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("wizard.newtorrent.byo.editname.title", "wizard.newtorrent.byo.editname.text");
        entryWindow.setPreenteredText(selection[0].getText(), false);
        entryWindow.prompt(new UIInputReceiverListener() {

            @Override
            public void UIInputReceiverClosed(UIInputReceiver receiver) {
                if (receiver.hasSubmittedInput()) {
                    selection[0].setText(receiver.getSubmittedInput());
                }
            }
        });
    }
}
Also used : SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 17 with UIInputReceiverListener

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

the class BYOPanel method show.

/*
	 * (non-Javadoc)
	 *
	 * @see com.biglybt.ui.swt.maketorrent.IWizardPanel#show()
	 */
@Override
public void show() {
    wizard.setTitle(MessageText.getString("wizard.newtorrent.byo"));
    wizard.setCurrentInfo(MessageText.getString("wizard.newtorrent.byo.info"));
    Composite panel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    panel.setLayout(layout);
    GridData gridData;
    tree = new Tree(panel, SWT.BORDER | SWT.MULTI);
    tree.setHeaderVisible(true);
    TreeColumn treeColumn = new TreeColumn(tree, 0);
    Messages.setLanguageText(treeColumn, "label.torrent.structure");
    treeColumn.setWidth(Utils.adjustPXForDPI(180));
    treeColumn = new TreeColumn(tree, 0);
    Messages.setLanguageText(treeColumn, "label.original.file");
    treeColumn.setWidth(Utils.adjustPXForDPI(500));
    gridData = new GridData(GridData.FILL_BOTH);
    tree.setLayoutData(gridData);
    createDropTarget(tree);
    createDragSource(tree);
    tree.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            editSelected();
            e.doit = false;
        }
    });
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F2) {
                editSelected();
            } else if (e.keyCode == SWT.DEL) {
                TreeItem[] selection = tree.getSelection();
                for (TreeItem treeItem : selection) {
                    Object data = treeItem.getData();
                    treeItem.dispose();
                }
            }
        }
    });
    Composite cButtons = new Composite(panel, 0);
    Utils.setLayout(cButtons, new RowLayout());
    cButtons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button btnAddContainer = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnAddContainer, "button.add.container");
    btnAddContainer.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("wizard.newtorrent.byo.addcontainer.title", "wizard.newtorrent.byo.addcontainer.text");
            entryWindow.setPreenteredText("files", true);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (entryWindow.hasSubmittedInput()) {
                        createContainer(null, entryWindow.getSubmittedInput());
                    }
                }
            });
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Button btnAddFiles = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnAddFiles, "OpenTorrentWindow.addFiles");
    btnAddFiles.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fDialog = new FileDialog(Utils.findAnyShell(), SWT.OPEN | SWT.MULTI);
            fDialog.setFilterPath(TorrentOpener.getFilterPathData());
            fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file"));
            if (fDialog.open() != null) {
                String[] fileNames = fDialog.getFileNames();
                File last_file = null;
                for (String fileName : fileNames) {
                    File f = new File(fDialog.getFilterPath(), fileName);
                    addFilename(f);
                    last_file = f;
                }
                if (last_file != null) {
                    TorrentOpener.setFilterPathData(last_file.getAbsolutePath());
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Button btnAddFolder = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnAddFolder, "OpenTorrentWindow.addFiles.Folder");
    btnAddFolder.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog fDialog = new DirectoryDialog(Utils.findAnyShell(), SWT.NULL);
            fDialog.setFilterPath(TorrentOpener.getFilterPathData());
            fDialog.setMessage(MessageText.getString("MainWindow.dialog.choose.folder"));
            String path = fDialog.open();
            if (path != null) {
                File f = new File(path);
                addFilename(f);
                if (f.isDirectory()) {
                    TorrentOpener.setFilterPathData(f.getAbsolutePath());
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    if (wizard.byo_map != null) {
        List list = (List) wizard.byo_map.get("file_map");
        if (list != null) {
            for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
                Map map = (Map) iterator.next();
                String target = MapUtils.getMapString(map, "target", null);
                List path = MapUtils.getMapList(map, "logical_path", null);
                if (target != null && path != null) {
                    File targetFile = new File(target);
                    if (path.size() == 1) {
                        addFilename(targetFile, (String) path.get(0), null, true);
                    } else {
                        TreeItem[] items = tree.getItems();
                        TreeItem parent = null;
                        for (int i = 0; i < path.size() - 1; i++) {
                            TreeItem lastParent = parent;
                            String name = (String) path.get(i);
                            boolean found = false;
                            for (TreeItem item : items) {
                                if (item.getText().equals(name)) {
                                    parent = item;
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                parent = createContainer(lastParent, name);
                            }
                            items = parent.getItems();
                        }
                        String name = (String) path.get(path.size() - 1);
                        addFilename(targetFile, name, parent, false);
                    }
                }
            }
        }
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) RowLayout(org.eclipse.swt.layout.RowLayout) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) List(java.util.List) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) GridData(org.eclipse.swt.layout.GridData) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) File(java.io.File)

Example 18 with UIInputReceiverListener

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

the class MultiTrackerEditor method createWindow.

private void createWindow(Shell parent_shell) {
    if (parent_shell == null) {
        this.shell = ShellFactory.createMainShell(SWT.DIALOG_TRIM | SWT.RESIZE);
    } else {
        this.shell = ShellFactory.createShell(parent_shell, SWT.DIALOG_TRIM | SWT.RESIZE);
    }
    Messages.setLanguageText(this.shell, anonymous ? "wizard.multitracker.edit.title" : "wizard.multitracker.template.title");
    Utils.setShellIcon(shell);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    shell.setLayout(layout);
    GridData gridData;
    if (!anonymous) {
        Label labelName = new Label(shell, SWT.NULL);
        Messages.setLanguageText(labelName, "wizard.multitracker.edit.name");
        textName = new Text(shell, SWT.BORDER);
        textName.setText(currentName);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        textName.setLayoutData(gridData);
        textName.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent arg0) {
                currentName = textName.getText();
                computeSaveEnable();
            }
        });
    }
    treeGroups = new Tree(shell, SWT.BORDER);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 3;
    gridData.heightHint = 150;
    treeGroups.setLayoutData(gridData);
    treeGroups.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            if (treeGroups.getSelectionCount() == 1) {
                TreeItem treeItem = treeGroups.getSelection()[0];
                String type = (String) treeItem.getData("type");
                if (type.equals("tracker")) {
                    editTreeItem(treeItem);
                }
            }
        }
    });
    if (showTemplates) {
        // template operations
        Composite cTemplate = new Composite(shell, SWT.NONE);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 3;
        cTemplate.setLayoutData(gridData);
        GridLayout layoutTemplate = new GridLayout();
        layoutTemplate.numColumns = 5;
        cTemplate.setLayout(layoutTemplate);
        final Label labelTitle = new Label(cTemplate, SWT.NULL);
        Messages.setLanguageText(labelTitle, "Search.menu.engines");
        final Combo configList = new Combo(cTemplate, SWT.READ_ONLY);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        configList.setLayoutData(gridData);
        final List<Button> buttons = new ArrayList<>();
        String sel_str = COConfigurationManager.getStringParameter("multitrackereditor.last.selection", null);
        final String[] currentTemplate = { sel_str == null || sel_str.length() == 0 ? null : sel_str };
        final Runnable updateSelection = new Runnable() {

            @Override
            public void run() {
                int selection = configList.getSelectionIndex();
                boolean enabled = selection != -1;
                String sel_str = currentTemplate[0] = enabled ? configList.getItem(selection) : null;
                COConfigurationManager.setParameter("multitrackereditor.last.selection", sel_str == null ? "" : sel_str);
                Iterator<Button> it = buttons.iterator();
                // skip the new button
                it.next();
                while (it.hasNext()) {
                    it.next().setEnabled(enabled);
                }
            }
        };
        final Runnable updateTemplates = new Runnable() {

            @Override
            public void run() {
                Map<String, List<List<String>>> multiTrackers = TrackersUtil.getInstance().getMultiTrackers();
                configList.removeAll();
                List<String> names = new ArrayList<String>(multiTrackers.keySet());
                Collections.sort(names, new FormattersImpl().getAlphanumericComparator(true));
                for (String str : names) {
                    configList.add(str);
                }
                String toBeSelected = currentTemplate[0];
                if (toBeSelected != null) {
                    int selection = configList.indexOf(toBeSelected);
                    if (selection != -1) {
                        configList.select(selection);
                    } else if (configList.getItemCount() > 0) {
                        currentTemplate[0] = configList.getItem(0);
                        configList.select(0);
                    }
                }
                updateSelection.run();
            }
        };
        final TrackerEditorListener templateTEL = new TrackerEditorListener() {

            @Override
            public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
                TrackersUtil util = TrackersUtil.getInstance();
                if (oldName != null && !oldName.equals(newName)) {
                    util.removeMultiTracker(oldName);
                }
                util.addMultiTracker(newName, trackers);
                currentTemplate[0] = newName;
                updateTemplates.run();
            }
        };
        final Button btnNew = new Button(cTemplate, SWT.PUSH);
        buttons.add(btnNew);
        Messages.setLanguageText(btnNew, "wizard.multitracker.new");
        btnNew.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                List group = new ArrayList();
                List tracker = new ArrayList();
                group.add(tracker);
                new MultiTrackerEditor(btnNew.getShell(), null, group, templateTEL);
            }
        });
        configList.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                updateSelection.run();
            }
        });
        final Button btnEdit = new Button(cTemplate, SWT.PUSH);
        buttons.add(btnEdit);
        Messages.setLanguageText(btnEdit, "wizard.multitracker.edit");
        btnEdit.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Map multiTrackers = TrackersUtil.getInstance().getMultiTrackers();
                String selected = currentTemplate[0];
                new MultiTrackerEditor(btnEdit.getShell(), selected, (List) multiTrackers.get(selected), templateTEL);
            }
        });
        final Button btnDelete = new Button(cTemplate, SWT.PUSH);
        buttons.add(btnDelete);
        Messages.setLanguageText(btnDelete, "wizard.multitracker.delete");
        btnDelete.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                final String selected = currentTemplate[0];
                MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { selected }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        if (result == 0) {
                            TrackersUtil.getInstance().removeMultiTracker(selected);
                            updateTemplates.run();
                        }
                    }
                });
            }
        });
        Label labelApply = new Label(cTemplate, SWT.NULL);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        labelApply.setLayoutData(gridData);
        Messages.setLanguageText(labelApply, "apply.selected.template");
        final Button btnReplace = new Button(cTemplate, SWT.PUSH);
        buttons.add(btnReplace);
        Messages.setLanguageText(btnReplace, "label.replace");
        btnReplace.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Map<String, List<List<String>>> multiTrackers = TrackersUtil.getInstance().getMultiTrackers();
                String selected = currentTemplate[0];
                trackers = TorrentUtils.getClone(multiTrackers.get(selected));
                refresh();
                computeSaveEnable();
            }
        });
        final Button btnMerge = new Button(cTemplate, SWT.PUSH);
        buttons.add(btnMerge);
        Messages.setLanguageText(btnMerge, "label.merge");
        btnMerge.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Map<String, List<List<String>>> multiTrackers = TrackersUtil.getInstance().getMultiTrackers();
                String selected = currentTemplate[0];
                trackers = TorrentUtils.mergeAnnounceURLs(trackers, multiTrackers.get(selected));
                refresh();
                computeSaveEnable();
            }
        });
        final Button btnRemove = new Button(cTemplate, SWT.PUSH);
        buttons.add(btnRemove);
        Messages.setLanguageText(btnRemove, "Button.remove");
        btnRemove.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Map<String, List<List<String>>> multiTrackers = TrackersUtil.getInstance().getMultiTrackers();
                String selected = currentTemplate[0];
                trackers = TorrentUtils.removeAnnounceURLs(trackers, multiTrackers.get(selected), false);
                refresh();
                computeSaveEnable();
            }
        });
        updateTemplates.run();
        Utils.makeButtonsEqualWidth(buttons);
    }
    Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    labelSeparator.setLayoutData(gridData);
    // button row
    Composite cButtons = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    cButtons.setLayoutData(gridData);
    GridLayout layoutButtons = new GridLayout();
    layoutButtons.numColumns = 5;
    cButtons.setLayout(layoutButtons);
    List<Button> buttons = new ArrayList<>();
    final Button btnedittext = new Button(cButtons, SWT.PUSH);
    buttons.add(btnedittext);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnedittext.setLayoutData(gridData);
    Messages.setLanguageText(btnedittext, "wizard.multitracker.edit.text");
    btnedittext.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            btnSave.setEnabled(false);
            btnedittext.setEnabled(false);
            trackers = new ArrayList();
            TreeItem[] groupItems = treeGroups.getItems();
            for (int i = 0; i < groupItems.length; i++) {
                TreeItem group = groupItems[i];
                TreeItem[] trackerItems = group.getItems();
                List groupList = new ArrayList(group.getItemCount());
                for (int j = 0; j < trackerItems.length; j++) {
                    groupList.add(trackerItems[j].getText());
                }
                trackers.add(groupList);
            }
            final String old_text = TorrentUtils.announceGroupsToText(trackers);
            final TextViewerWindow viewer = new TextViewerWindow(shell, "wizard.multitracker.edit.text.title", "wizard.multitracker.edit.text.msg", old_text, false, false);
            viewer.setEditable(true);
            viewer.addListener(new TextViewerWindow.TextViewerWindowListener() {

                @Override
                public void closed() {
                    try {
                        if (viewer.getOKPressed()) {
                            String new_text = viewer.getText();
                            if (!old_text.equals(new_text)) {
                                String[] lines = new_text.split("\n");
                                StringBuilder valid_text = new StringBuilder(new_text.length() + 1);
                                for (String line : lines) {
                                    line = line.trim();
                                    if (line.length() > 0) {
                                        if (!validURL(line)) {
                                            continue;
                                        }
                                    }
                                    valid_text.append(line);
                                    valid_text.append("\n");
                                }
                                trackers = TorrentUtils.announceTextToGroups(valid_text.toString());
                                refresh();
                            }
                        }
                    } finally {
                        computeSaveEnable();
                        btnedittext.setEnabled(true);
                    }
                }
            });
        }
    });
    final Button btnAddTrackerList = new Button(cButtons, SWT.PUSH);
    buttons.add(btnAddTrackerList);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnAddTrackerList.setLayoutData(gridData);
    Messages.setLanguageText(btnAddTrackerList, "wizard.multitracker.add.trackerlist");
    btnAddTrackerList.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("enter.url", "enter.trackerlist.url");
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver receiver) {
                    if (!receiver.hasSubmittedInput()) {
                        return;
                    }
                    String url = receiver.getSubmittedInput().trim();
                    if (!url.isEmpty()) {
                        TreeItem group = newGroup();
                        TreeItem itemTracker = newTracker(group, "trackerlist:" + url.trim());
                    }
                }
            });
        }
    });
    Label label = new Label(cButtons, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(gridData);
    btnSave = new Button(cButtons, SWT.PUSH);
    buttons.add(btnSave);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnSave.setLayoutData(gridData);
    Messages.setLanguageText(btnSave, "wizard.multitracker.edit.save");
    btnSave.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            update();
            shell.dispose();
        }
    });
    btnCancel = new Button(cButtons, SWT.PUSH);
    buttons.add(btnCancel);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnCancel.setLayoutData(gridData);
    Messages.setLanguageText(btnCancel, "Button.cancel");
    btnCancel.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            shell.dispose();
        }
    });
    Utils.makeButtonsEqualWidth(buttons);
    shell.setDefaultButton(btnSave);
    shell.addListener(SWT.Traverse, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (e.character == SWT.ESC) {
                shell.dispose();
            }
        }
    });
    computeSaveEnable();
    refresh();
    constructMenu();
    editor = new TreeEditor(treeGroups);
    treeGroups.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (itemEdited != null && !itemEdited.isDisposed() && !editor.getEditor().isDisposed()) {
                itemEdited.setText(((Text) editor.getEditor()).getText());
            }
            removeEditor();
        }
    });
    Point size = shell.computeSize(500, SWT.DEFAULT);
    shell.setSize(size);
    Utils.centreWindow(shell);
    shell.open();
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) TrackersUtil(com.biglybt.core.util.TrackersUtil) ArrayList(java.util.ArrayList) List(java.util.List) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) TreeEditor(org.eclipse.swt.custom.TreeEditor) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MessageText(com.biglybt.core.internat.MessageText) Point(org.eclipse.swt.graphics.Point) FormattersImpl(com.biglybt.pifimpl.local.utils.FormattersImpl) Point(org.eclipse.swt.graphics.Point) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) GridData(org.eclipse.swt.layout.GridData) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Map(java.util.Map)

Example 19 with UIInputReceiverListener

use of com.biglybt.pif.ui.UIInputReceiverListener 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);
                            }
                        }
                    });
                }
            });
        }
    /**/
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) SpeedAdapter(com.biglybt.ui.swt.views.ViewUtils.SpeedAdapter) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 20 with UIInputReceiverListener

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

the class TagUIUtils method createSideBarMenuItems.

public static void createSideBarMenuItems(final Menu menu, final Tag tag) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    final TagType tag_type = tag.getTagType();
    boolean needs_separator_next = false;
    int countBefore = menu.getItemCount();
    if (tag_type.hasTagTypeFeature(TagFeature.TF_RATE_LIMIT)) {
        createTF_RateLimitMenuItems(menu, tag, tag_type, userMode);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_RUN_STATE)) {
        createTF_RunState(menu, tag);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_FILE_LOCATION)) {
        createTF_FileLocationMenuItems(menu, tag);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_EXEC_ON_ASSIGN)) {
        final TagFeatureExecOnAssign tf_eoa = (TagFeatureExecOnAssign) tag;
        int supported_actions = tf_eoa.getSupportedActions();
        if (supported_actions != TagFeatureExecOnAssign.ACTION_NONE) {
            final Menu eoa_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
            MenuItem eoa_item = new MenuItem(menu, SWT.CASCADE);
            Messages.setLanguageText(eoa_item, "label.exec.on.assign");
            eoa_item.setMenu(eoa_menu);
            int[] action_ids = { TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE, TagFeatureExecOnAssign.ACTION_DESTROY, TagFeatureExecOnAssign.ACTION_START, TagFeatureExecOnAssign.ACTION_FORCE_START, TagFeatureExecOnAssign.ACTION_NOT_FORCE_START, TagFeatureExecOnAssign.ACTION_STOP, TagFeatureExecOnAssign.ACTION_PAUSE, TagFeatureExecOnAssign.ACTION_RESUME, TagFeatureExecOnAssign.ACTION_SCRIPT };
            String[] action_keys = { "label.apply.options.template", "v3.MainWindow.button.delete", "v3.MainWindow.button.start", "v3.MainWindow.button.forcestart", "v3.MainWindow.button.notforcestart", "v3.MainWindow.button.stop", "v3.MainWindow.button.pause", "v3.MainWindow.button.resume", "label.script" };
            for (int i = 0; i < action_ids.length; i++) {
                final int action_id = action_ids[i];
                if (tf_eoa.supportsAction(action_id)) {
                    if (action_id == TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE) {
                        final MenuItem opts_item = new MenuItem(eoa_menu, SWT.CHECK);
                        opts_item.setText(MessageText.getString(action_keys[i]) + "...");
                        opts_item.setSelection(tf_eoa.getOptionsTemplateHandler().isActive());
                        opts_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                                if (uiFunctions != null) {
                                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, tf_eoa.getOptionsTemplateHandler());
                                }
                            }
                        });
                        new MenuItem(eoa_menu, SWT.SEPARATOR);
                    } else if (action_id == TagFeatureExecOnAssign.ACTION_SCRIPT) {
                        final MenuItem action_item = new MenuItem(eoa_menu, SWT.PUSH);
                        String script = tf_eoa.getActionScript();
                        if (script.length() > 23) {
                            script = script.substring(0, 20) + "...";
                        }
                        String msg = MessageText.getString(action_keys[i]);
                        if (script.length() > 0) {
                            msg += ": " + script;
                        }
                        msg += "...";
                        action_item.setText(msg);
                        action_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                String msg = MessageText.getString("UpdateScript.message");
                                SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateScript.title", "!" + msg + "!");
                                entryWindow.setPreenteredText(tf_eoa.getActionScript(), false);
                                entryWindow.selectPreenteredText(true);
                                entryWindow.prompt(new UIInputReceiverListener() {

                                    @Override
                                    public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                                        if (entryWindow.hasSubmittedInput()) {
                                            String text = entryWindow.getSubmittedInput().trim();
                                            tf_eoa.setActionScript(text);
                                        }
                                    }
                                });
                            }
                        });
                    } else {
                        final MenuItem action_item = new MenuItem(eoa_menu, SWT.CHECK);
                        Messages.setLanguageText(action_item, action_keys[i]);
                        action_item.setSelection(tf_eoa.isActionEnabled(action_id));
                        action_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                tf_eoa.setActionEnabled(action_id, action_item.getSelection());
                            }
                        });
                    }
                }
            }
        }
    }
    if (tag instanceof TagDownload) {
        needs_separator_next = true;
        MenuItem itemOptions = new MenuItem(menu, SWT.PUSH);
        final Set<DownloadManager> dms = ((TagDownload) tag).getTaggedDownloads();
        Messages.setLanguageText(itemOptions, "cat.options");
        itemOptions.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms.toArray(new DownloadManager[dms.size()]));
                }
            }
        });
        if (dms.size() == 0) {
            itemOptions.setEnabled(false);
        }
    }
    if (userMode > 0) {
        if (tag_type.hasTagTypeFeature(TagFeature.TF_PROPERTIES)) {
            createTFProperitesMenuItems(menu, tag);
        }
    }
    if (menu.getItemCount() > countBefore) {
        needs_separator_next = true;
    }
    if (needs_separator_next) {
        new MenuItem(menu, SWT.SEPARATOR);
        needs_separator_next = false;
    }
    if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
        needs_separator_next = true;
        MenuItem search = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(search, "tag.search");
        search.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                UIFunctionsManager.getUIFunctions().doSearch("tag:" + tag.getTagName(true));
            }
        });
    }
    // share with friends
    addShareWithFriendsMenuItems(menu, tag, tag_type);
    if (tag_type.hasTagTypeFeature(TagFeature.TF_RSS_FEED)) {
        final TagFeatureRSSFeed tfrss = (TagFeatureRSSFeed) tag;
        // rss feed
        final MenuItem rssOption = new MenuItem(menu, SWT.CHECK);
        rssOption.setSelection(tfrss.isTagRSSFeedEnabled());
        Messages.setLanguageText(rssOption, "cat.rss.gen");
        rssOption.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                boolean set = rssOption.getSelection();
                tfrss.setTagRSSFeedEnabled(set);
            }
        });
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_XCODE)) {
        createXCodeMenuItems(menu, tag);
    }
    needs_separator_next = true;
    if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
        MenuBuildUtils.addChatMenu(menu, "label.chat", getChatKey(tag));
    }
    MenuItem itemShowStats = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemShowStats, "tag.show.stats");
    itemShowStats.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "TagStatsView");
        }
    });
    if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
        MenuItem itemShowFiles = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemShowFiles, "menu.show.files");
        itemShowFiles.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                showFilesView((TagDownload) tag);
            }
        });
    }
    if (needs_separator_next) {
        new MenuItem(menu, SWT.SEPARATOR);
        needs_separator_next = false;
    }
    boolean auto = tag_type.isTagTypeAuto();
    boolean closable = auto;
    if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
        // extended closable tags to include manual ones due to user request
        closable = true;
    }
    Menu[] menuShowHide = { null };
    if (closable) {
        createCloseableMenuItems(menu, tag, tag_type, menuShowHide, needs_separator_next);
    }
    if (!auto) {
        createNonAutoMenuItems(menu, tag, tag_type, menuShowHide);
    }
    if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
        MenuItem itemExport = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemExport, "Subscription.menu.export");
        itemExport.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                export(Arrays.asList(tag));
            }
        });
    }
    MenuItem menuSettings = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(menuSettings, "TagSettingsView.title");
    menuSettings.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, tag);
        }
    });
    com.biglybt.pif.ui.menus.MenuItem[] items = MenuItemManager.getInstance().getAllAsArray(MenuManager.MENU_TAG_CONTEXT);
    if (items.length > 0) {
        MenuFactory.addSeparatorMenuItem(menu);
        // TODO: Don't send Tag.. send a yet-to-be-created plugin interface version of Tag
        MenuBuildUtils.addPluginMenuItems(items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Tag[] { tag }));
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) DownloadManager(com.biglybt.core.download.DownloadManager) UIFunctions(com.biglybt.ui.UIFunctions) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)29 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)29 SimpleTextEntryWindow (com.biglybt.ui.swt.SimpleTextEntryWindow)21 DownloadManager (com.biglybt.core.download.DownloadManager)8 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)8 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)6 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)5 List (java.util.List)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)3 MenuBuildUtils (com.biglybt.ui.swt.MenuBuildUtils)3 Core (com.biglybt.core.Core)2 MessageText (com.biglybt.core.internat.MessageText)2 PEPeer (com.biglybt.core.peer.PEPeer)2 PEPeerManager (com.biglybt.core.peer.PEPeerManager)2 TagProperty (com.biglybt.core.tag.TagFeatureProperties.TagProperty)2