Search in sources :

Example 16 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.

the class BuddyPluginViewBetaChat method addFriendsMenu.

private void addFriendsMenu(Menu menu) {
    if (chat.isAnonymous()) {
        return;
    }
    final Menu friends_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem friends_menu_item = new MenuItem(menu, SWT.CASCADE);
    friends_menu_item.setMenu(friends_menu);
    friends_menu_item.setText(MessageText.getString("Views.plugins.azbuddy.title"));
    friends_menu.addMenuListener(new MenuAdapter() {

        @Override
        public void menuShown(MenuEvent e) {
            MenuItem[] items = friends_menu.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }
            boolean enabled = plugin.isClassicEnabled();
            if (enabled) {
                MenuItem mi = new MenuItem(friends_menu, SWT.PUSH);
                mi.setText(MessageText.getString("azbuddy.insert.friend.key"));
                mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        String uri = getFriendURI();
                        input_area.append(uri);
                    }
                });
                new MenuItem(friends_menu, SWT.SEPARATOR);
                mi = new MenuItem(friends_menu, SWT.PUSH);
                mi.setText(MessageText.getString("azbuddy.view.friends"));
                mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        view.selectClassicTab();
                    }
                });
            } else {
                MenuItem mi = new MenuItem(friends_menu, SWT.PUSH);
                mi.setText(MessageText.getString("label.enable"));
                mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        plugin.setClassicEnabled(true);
                    }
                });
            }
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 17 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.

the class BuddyPluginViewBetaChat method buildStatus.

private void buildStatus(Composite main_component, Composite component) {
    boolean public_chat = !chat.isPrivateChat();
    final Label menu_drop = new Label(component, SWT.NULL);
    Messages.setLanguageTooltip(menu_drop, "TagSettingsView.title");
    FontData fontData = menu_drop.getFont().getFontData()[0];
    Display display = menu_drop.getDisplay();
    italic_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC));
    bold_font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    big_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 1.5), SWT.BOLD));
    small_font = new Font(display, new FontData(fontData.getName(), (int) (fontData.getHeight() * 0.5), SWT.BOLD));
    ftux_dark_bg = new Color(display, 183, 200, 212);
    ftux_dark_fg = new Color(display, 0, 81, 134);
    ftux_light_bg = new Color(display, 236, 242, 246);
    component.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent arg0) {
            Font[] fonts = { italic_font, bold_font, big_font, small_font };
            for (Font f : fonts) {
                if (f != null) {
                    f.dispose();
                }
            }
            Color[] colours = { ftux_dark_bg, ftux_dark_fg, ftux_light_bg };
            for (Color c : colours) {
                if (c != null) {
                    c.dispose();
                }
            }
            if (drop_targets != null) {
                for (DropTarget dt : drop_targets) {
                    dt.dispose();
                }
            }
            closed();
        }
    });
    status = new BufferedLabel(component, SWT.LEFT | SWT.DOUBLE_BUFFERED);
    GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(status, grid_data);
    status.setText(MessageText.getString("PeersView.state.pending"));
    Image image = ImageLoader.getInstance().getImage("cog_down");
    menu_drop.setImage(image);
    grid_data = new GridData();
    grid_data.widthHint = image.getBounds().width;
    grid_data.heightHint = image.getBounds().height;
    Utils.setLayoutData(menu_drop, grid_data);
    menu_drop.setCursor(menu_drop.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    Control status_control = status.getControl();
    final Menu status_menu = new Menu(status_control);
    status.getControl().setMenu(status_menu);
    menu_drop.setMenu(status_menu);
    menu_drop.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            try {
                Point p = status_menu.getDisplay().map(menu_drop, null, event.x, event.y);
                status_menu.setLocation(p);
                status_menu.setVisible(true);
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    });
    if (public_chat) {
        Menu status_clip_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
        MenuItem status_clip_item = new MenuItem(status_menu, SWT.CASCADE);
        status_clip_item.setMenu(status_clip_menu);
        status_clip_item.setText(MessageText.getString("label.copy.to.clipboard"));
        MenuItem status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.key"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(chat.getKey());
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.url"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(chat.getURL());
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.rss.url"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard("azplug:?id=azbuddy&arg=" + UrlUtils.encode(chat.getURL() + "&format=rss"));
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.pk"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(Base32.encode(chat.getPublicKey()));
            }
        });
        status_mi = new MenuItem(status_clip_menu, SWT.PUSH);
        status_mi.setText(MessageText.getString("azbuddy.dchat.copy.channel.export"));
        status_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ClipboardCopy.copyToClipBoard(chat.export());
            }
        });
        if (!chat.isManaged()) {
            Menu status_channel_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
            MenuItem status_channel_item = new MenuItem(status_menu, SWT.CASCADE);
            status_channel_item.setMenu(status_channel_menu);
            status_channel_item.setText(MessageText.getString("azbuddy.dchat.rchans"));
            // Managed channel
            status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
            status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.managed"));
            status_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    try {
                        ChatInstance inst = chat.getManagedChannel();
                        BuddyPluginViewBetaChat.createChatWindow(view, plugin, inst);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            // RO channel
            status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
            status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.ro"));
            status_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    try {
                        ChatInstance inst = chat.getReadOnlyChannel();
                        createChatWindow(view, plugin, inst);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            // Random sub-channel
            status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
            status_mi.setText(MessageText.getString("azbuddy.dchat.rchans.rand"));
            status_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    try {
                        byte[] rand = new byte[20];
                        RandomUtils.nextSecureBytes(rand);
                        ChatInstance inst = beta.getChat(chat.getNetwork(), chat.getKey() + " {" + Base32.encode(rand) + "}");
                        createChatWindow(view, plugin, inst);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            if (beta.isI2PAvailable()) {
                status_mi = new MenuItem(status_channel_menu, SWT.PUSH);
                status_mi.setText(MessageText.getString(chat.getNetwork() == AENetworkClassifier.AT_I2P ? "azbuddy.dchat.rchans.pub" : "azbuddy.dchat.rchans.anon"));
                status_mi.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        try {
                            ChatInstance inst = beta.getChat(chat.getNetwork() == AENetworkClassifier.AT_I2P ? AENetworkClassifier.AT_PUBLIC : AENetworkClassifier.AT_I2P, chat.getKey());
                            createChatWindow(view, plugin, inst);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
            }
        }
        final MenuItem fave_mi = new MenuItem(status_menu, SWT.CHECK);
        fave_mi.setText(MessageText.getString("label.fave"));
        fave_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setFavourite(fave_mi.getSelection());
            }
        });
        final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
        sis_mi.setText(MessageText.getString(Utils.isAZ2UI() ? "label.show.in.tab" : "label.show.in.sidebar"));
        sis_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
            }
        });
        addFriendsMenu(status_menu);
        // advanced
        final Menu advanced_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
        MenuItem advanced_menu_item = new MenuItem(status_menu, SWT.CASCADE);
        advanced_menu_item.setMenu(advanced_menu);
        advanced_menu_item.setText(MessageText.getString("MyTorrentsView.menu.advancedmenu"));
        // rename
        final MenuItem rename_mi = new MenuItem(advanced_menu, SWT.PUSH);
        rename_mi.setText(MessageText.getString("MyTorrentsView.menu.rename"));
        rename_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String name = chat.getDisplayName();
                if (name == null) {
                    name = chat.getName();
                }
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                entry.setPreenteredText(name, false);
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(false);
                entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { name }));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() > 0) {
                            try {
                                chat.setDisplayName(input);
                            } catch (Throwable e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    }
                });
            }
        });
        // view type
        final Menu vt_menu = new Menu(status_menu.getShell(), SWT.DROP_DOWN);
        MenuItem vt_menu_item = new MenuItem(advanced_menu, SWT.CASCADE);
        vt_menu_item.setMenu(vt_menu);
        vt_menu_item.setText(MessageText.getString("menu.view.options"));
        SelectionAdapter listener = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int vt = -1;
                for (MenuItem mi : vt_menu.getItems()) {
                    if (mi.getSelection()) {
                        vt = (Integer) mi.getData();
                    }
                }
                if (vt != -1) {
                    chat.setViewType(vt);
                    buildSupport(main_component);
                    main_component.layout(true, true);
                }
            }
        };
        MenuItem vt_mi = new MenuItem(vt_menu, SWT.RADIO);
        vt_mi.setText(MessageText.getString("label.full"));
        vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_DEFAULT);
        vt_mi.addSelectionListener(listener);
        vt_mi = new MenuItem(vt_menu, SWT.RADIO);
        vt_mi.setText(MessageText.getString("ConfigView.section.sharing"));
        vt_mi.setData(BuddyPluginBeta.VIEW_TYPE_SHARING);
        if (chat.isReadOnly()) {
            vt_mi.setEnabled(false);
        }
        vt_mi.addSelectionListener(listener);
        vt_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                int vt = chat.getViewType();
                for (MenuItem mi : vt_menu.getItems()) {
                    mi.setSelection(vt == (Integer) mi.getData());
                }
            }
        });
        // persist messages
        final MenuItem persist_mi = new MenuItem(advanced_menu, SWT.CHECK);
        persist_mi.setText(MessageText.getString("azbuddy.dchat.save.messages"));
        persist_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setSaveMessages(persist_mi.getSelection());
            }
        });
        final MenuItem log_mi = new MenuItem(advanced_menu, SWT.CHECK);
        log_mi.setText(MessageText.getString("azbuddy.dchat.log.messages"));
        log_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setLogMessages(log_mi.getSelection());
            }
        });
        final MenuItem automute_mi = new MenuItem(advanced_menu, SWT.CHECK);
        automute_mi.setText(MessageText.getString("azbuddy.dchat.auto.mute"));
        automute_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setAutoMute(automute_mi.getSelection());
            }
        });
        final MenuItem postnotifications_mi = new MenuItem(advanced_menu, SWT.CHECK);
        postnotifications_mi.setText(MessageText.getString("azbuddy.dchat.post.to.notifcations"));
        postnotifications_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setEnableNotificationsPost(postnotifications_mi.getSelection());
            }
        });
        final MenuItem disableindicators_mi = new MenuItem(advanced_menu, SWT.CHECK);
        disableindicators_mi.setText(MessageText.getString("azbuddy.dchat.disable.msg.indicators"));
        disableindicators_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                chat.setDisableNewMsgIndications(disableindicators_mi.getSelection());
            }
        });
        // setup menu
        status_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                fave_mi.setSelection(chat.isFavourite());
                persist_mi.setSelection(chat.getSaveMessages());
                log_mi.setSelection(chat.getLogMessages());
                automute_mi.setSelection(chat.getAutoMute());
                postnotifications_mi.setSelection(chat.getEnableNotificationsPost());
                boolean disable_indications = chat.getDisableNewMsgIndications();
                disableindicators_mi.setSelection(disable_indications);
                postnotifications_mi.setEnabled(!disable_indications);
            }
        });
    } else {
        final Menu status_priv_menu = new Menu(component.getShell(), SWT.DROP_DOWN);
        MenuItem status_priv_item = new MenuItem(status_menu, SWT.CASCADE);
        status_priv_item.setMenu(status_priv_menu);
        status_priv_item.setText(MessageText.getString("label.private.chat"));
        SelectionAdapter listener = new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                beta.setPrivateChatState((Integer) ((MenuItem) e.widget).getData());
            }
        };
        MenuItem status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
        status_mi.setText(MessageText.getString("label.enabled"));
        status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_ENABLED);
        status_mi.addSelectionListener(listener);
        status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
        status_mi.setText(MessageText.getString("label.pinned.only"));
        status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_PINNED_ONLY);
        status_mi.addSelectionListener(listener);
        status_mi = new MenuItem(status_priv_menu, SWT.RADIO);
        status_mi.setText(MessageText.getString("label.disabled"));
        status_mi.setData(BuddyPluginBeta.PRIVATE_CHAT_DISABLED);
        status_mi.addSelectionListener(listener);
        status_priv_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                int pc_state = beta.getPrivateChatState();
                for (MenuItem mi : status_priv_menu.getItems()) {
                    mi.setSelection(pc_state == (Integer) mi.getData());
                }
            }
        });
        addFriendsMenu(status_menu);
        final MenuItem keep_alive_mi = new MenuItem(status_menu, SWT.CHECK);
        keep_alive_mi.setText(MessageText.getString("label.keep.alive"));
        status_menu.addMenuListener(new MenuAdapter() {

            @Override
            public void menuShown(MenuEvent e) {
                keep_alive_mi.setSelection(chat.getUserData("AC:KeepAlive") != null);
            }
        });
        keep_alive_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ChatInstance clone = (ChatInstance) chat.getUserData("AC:KeepAlive");
                if (clone != null) {
                    clone.destroy();
                    clone = null;
                } else {
                    try {
                        clone = chat.getClone();
                    } catch (Throwable f) {
                    }
                }
                chat.setUserData("AC:KeepAlive", clone);
            }
        });
        final MenuItem sis_mi = new MenuItem(status_menu, SWT.PUSH);
        sis_mi.setText(MessageText.getString("label.show.in.sidebar"));
        sis_mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BuddyPluginUI.openChat(chat.getNetwork(), chat.getKey());
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) Label(org.eclipse.swt.widgets.Label) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) Control(org.eclipse.swt.widgets.Control) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent) UISWTInputReceiver(com.biglybt.ui.swt.pif.UISWTInputReceiver) MouseEvent(org.eclipse.swt.events.MouseEvent) FontData(org.eclipse.swt.graphics.FontData) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) GridData(org.eclipse.swt.layout.GridData) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) DropTarget(org.eclipse.swt.dnd.DropTarget) Display(org.eclipse.swt.widgets.Display)

Example 18 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.

the class TorrentUtil method fillTorrentMenu.

// selected_dl_types -> 0 (determine that automatically), +1 (downloading), +2 (seeding), +3 (mixed - not used by anything yet)
public static void fillTorrentMenu(final Menu menu, final DownloadManager[] dms, final Core core, boolean include_show_details, int selected_dl_types, final TableView tv) {
    // TODO: Build submenus on the fly
    Shell shell = Utils.findAnyShell();
    Shell menu_shell = menu.getShell();
    final boolean isSeedingView;
    switch(selected_dl_types) {
        case 1:
            isSeedingView = false;
            break;
        case 2:
            isSeedingView = true;
            break;
        case 0:
            {
                if (dms.length == 1) {
                    isSeedingView = dms[0].isDownloadComplete(false);
                    break;
                }
            }
        default:
            // I was going to raise an error, but let's not be too hasty. :)
            isSeedingView = false;
    }
    boolean hasSelection = dms.length > 0;
    boolean isSingleSelection = dms.length == 1;
    boolean isTrackerOn = TRTrackerUtils.isTrackerEnabled();
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    // Enable/Disable Logic
    boolean bChangeDir = hasSelection;
    boolean start, stop, pause, changeUrl, barsOpened, forceStart;
    boolean forceStartEnabled, recheck, manualUpdate, fileMove, canSetMOC, canClearMOC, fileExport, fileRescan;
    changeUrl = barsOpened = manualUpdate = fileMove = canSetMOC = fileExport = fileRescan = true;
    forceStart = forceStartEnabled = recheck = start = stop = pause = canClearMOC = false;
    boolean canSetSuperSeed = false;
    boolean superSeedAllYes = true;
    boolean superSeedAllNo = true;
    boolean upSpeedDisabled = false;
    long totalUpSpeed = 0;
    boolean upSpeedUnlimited = false;
    long upSpeedSetMax = 0;
    boolean downSpeedDisabled = false;
    long totalDownSpeed = 0;
    boolean downSpeedUnlimited = false;
    long downSpeedSetMax = 0;
    boolean allScanSelected = true;
    boolean allScanNotSelected = true;
    boolean allStopped = true;
    boolean allResumeIncomplete = true;
    boolean hasClearableLinks = false;
    boolean hasRevertableFiles = false;
    if (hasSelection) {
        for (int i = 0; i < dms.length; i++) {
            DownloadManager dm = (DownloadManager) dms[i];
            try {
                int maxul = dm.getStats().getUploadRateLimitBytesPerSecond();
                if (maxul == 0) {
                    upSpeedUnlimited = true;
                } else {
                    if (maxul > upSpeedSetMax) {
                        upSpeedSetMax = maxul;
                    }
                }
                if (maxul == -1) {
                    maxul = 0;
                    upSpeedDisabled = true;
                }
                totalUpSpeed += maxul;
                int maxdl = dm.getStats().getDownloadRateLimitBytesPerSecond();
                if (maxdl == 0) {
                    downSpeedUnlimited = true;
                } else {
                    if (maxdl > downSpeedSetMax) {
                        downSpeedSetMax = maxdl;
                    }
                }
                if (maxdl == -1) {
                    maxdl = 0;
                    downSpeedDisabled = true;
                }
                totalDownSpeed += maxdl;
            } catch (Exception ex) {
                Debug.printStackTrace(ex);
            }
            if (barsOpened && !DownloadBar.getManager().isOpen(dm)) {
                barsOpened = false;
            }
            stop = stop || ManagerUtils.isStopable(dm);
            start = start || ManagerUtils.isStartable(dm);
            pause = pause || ManagerUtils.isPauseable(dm);
            recheck = recheck || dm.canForceRecheck();
            forceStartEnabled = forceStartEnabled || ManagerUtils.isForceStartable(dm);
            forceStart = forceStart || dm.isForceStart();
            boolean stopped = ManagerUtils.isStopped(dm);
            allStopped &= stopped;
            fileMove = fileMove && dm.canMoveDataFiles();
            fileExport = fileExport && dm.canExportDownload();
            if (userMode < 2) {
                TRTrackerAnnouncer trackerClient = dm.getTrackerClient();
                if (trackerClient != null) {
                    boolean update_state = ((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
                    manualUpdate = manualUpdate & update_state;
                }
            }
            int state = dm.getState();
            bChangeDir &= (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
            /**
             * Only perform a test on disk if:
             *    1) We are currently set to allow the "Change Data Directory" option, and
             *    2) We've only got one item selected - otherwise, we may potentially end up checking massive
             *       amounts of files across multiple torrents before we generate a menu.
             */
            if (bChangeDir && dms.length == 1) {
                bChangeDir = dm.isDataAlreadyAllocated();
                if (bChangeDir && state == DownloadManager.STATE_ERROR) {
                    // filesExist is way too slow!
                    bChangeDir = !dm.filesExist(true);
                } else {
                    bChangeDir = false;
                }
            }
            boolean incomplete = !dm.isDownloadComplete(true);
            DownloadManagerState dm_state = dm.getDownloadState();
            String moc_dir = dm_state.getAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR);
            canSetMOC &= incomplete;
            canClearMOC |= (moc_dir != null && moc_dir.length() > 0);
            boolean scan = dm_state.getFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES);
            // include DND files in incomplete stat, since a recheck may
            // find those files have been completed
            allScanSelected = incomplete && allScanSelected && scan;
            allScanNotSelected = incomplete && allScanNotSelected && !scan;
            PEPeerManager pm = dm.getPeerManager();
            if (pm != null) {
                if (pm.canToggleSuperSeedMode()) {
                    canSetSuperSeed = true;
                }
                if (pm.isSuperSeedMode()) {
                    superSeedAllYes = false;
                } else {
                    superSeedAllNo = false;
                }
            } else {
                superSeedAllYes = false;
                superSeedAllNo = false;
            }
            if (dm_state.isResumeDataComplete()) {
                allResumeIncomplete = false;
            }
            if (stopped && !hasClearableLinks) {
                if (dm.getDiskManagerFileInfoSet().nbFiles() > 1) {
                    if (dm_state.getFileLinks().hasLinks()) {
                        hasClearableLinks = true;
                    }
                }
            }
            if (dm_state.getFileLinks().size() > 0) {
                hasRevertableFiles = true;
            }
        }
        fileRescan = allScanSelected || allScanNotSelected;
    } else {
        // empty right-click
        barsOpened = false;
        forceStart = false;
        forceStartEnabled = false;
        start = false;
        stop = false;
        fileMove = false;
        fileExport = false;
        fileRescan = false;
        canSetMOC = false;
        upSpeedDisabled = true;
        downSpeedDisabled = true;
        changeUrl = false;
        recheck = false;
        manualUpdate = false;
    }
    if (bChangeDir) {
        MenuItem menuItemChangeDir = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(menuItemChangeDir, "MyTorrentsView.menu.changeDirectory");
        menuItemChangeDir.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                changeDirSelectedTorrents(dms, shell);
            }
        });
    }
    // Open Details
    if (include_show_details) {
        final MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemDetails, "MyTorrentsView.menu.showdetails");
        menu.setDefaultItem(itemDetails);
        Utils.setMenuItemImage(itemDetails, "details");
        itemDetails.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                }
            }
        });
        itemDetails.setEnabled(hasSelection);
    }
    // Open Bar
    final MenuItem itemBar = new MenuItem(menu, SWT.CHECK);
    Messages.setLanguageText(itemBar, "MyTorrentsView.menu.showdownloadbar");
    Utils.setMenuItemImage(itemBar, "downloadBar");
    itemBar.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            if (DownloadBar.getManager().isOpen(dm)) {
                DownloadBar.close(dm);
            } else {
                DownloadBar.open(dm, shell);
            }
        }
    });
    itemBar.setEnabled(hasSelection);
    itemBar.setSelection(barsOpened);
    // ---
    new MenuItem(menu, SWT.SEPARATOR);
    // Run Data File
    final MenuItem itemOpen = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemOpen, "MyTorrentsView.menu.open");
    Utils.setMenuItemImage(itemOpen, "run");
    itemOpen.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            runDataSources(dms);
        }
    });
    itemOpen.setEnabled(hasSelection);
    // Explore (or open containing folder)
    final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
    final MenuItem itemExplore = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemExplore, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"));
    itemExplore.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

        @Override
        public void run(DownloadManager dm) {
            ManagerUtils.open(dm, use_open_containing_folder);
        }
    });
    itemExplore.setEnabled(hasSelection);
    // Open in browser
    final Menu menuBrowse = new Menu(menu_shell, SWT.DROP_DOWN);
    final MenuItem itemBrowse = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(itemBrowse, "MyTorrentsView.menu.browse");
    itemBrowse.setMenu(menuBrowse);
    final MenuItem itemBrowsePublic = new MenuItem(menuBrowse, SWT.PUSH);
    itemBrowsePublic.setText(MessageText.getString("label.public") + "...");
    itemBrowsePublic.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            ManagerUtils.browse(dm, false, true);
        }
    });
    final MenuItem itemBrowseAnon = new MenuItem(menuBrowse, SWT.PUSH);
    itemBrowseAnon.setText(MessageText.getString("label.anon") + "...");
    itemBrowseAnon.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            ManagerUtils.browse(dm, true, true);
        }
    });
    new MenuItem(menuBrowse, SWT.SEPARATOR);
    final MenuItem itemBrowseURL = new MenuItem(menuBrowse, SWT.PUSH);
    Messages.setLanguageText(itemBrowseURL, "label.copy.url.to.clip");
    itemBrowseURL.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    String url = ManagerUtils.browse(dms[0], true, false);
                    if (url != null) {
                        ClipboardCopy.copyToClipBoard(url);
                    }
                }
            });
        }
    });
    itemBrowseURL.setEnabled(isSingleSelection);
    new MenuItem(menuBrowse, SWT.SEPARATOR);
    final MenuItem itemBrowseDir = new MenuItem(menuBrowse, SWT.CHECK);
    Messages.setLanguageText(itemBrowseDir, "library.launch.web.in.browser.dir.list");
    itemBrowseDir.setSelection(COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowserDirList"));
    itemBrowseDir.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            COConfigurationManager.setParameter("Library.LaunchWebsiteInBrowserDirList", itemBrowseDir.getSelection());
        }
    });
    itemBrowse.setEnabled(hasSelection);
    // === advanced menu ===
    final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu");
    itemAdvanced.setEnabled(hasSelection);
    final Menu menuAdvanced = new Menu(menu_shell, SWT.DROP_DOWN);
    itemAdvanced.setMenu(menuAdvanced);
    // advanced > Download Speed Menu //
    long kInB = DisplayFormatters.getKinB();
    long maxDownload = COConfigurationManager.getIntParameter("Max Download Speed KBs", 0) * kInB;
    long maxUpload = COConfigurationManager.getIntParameter("Max Upload Speed KBs", 0) * kInB;
    ViewUtils.addSpeedMenu(menu_shell, menuAdvanced, true, true, true, hasSelection, downSpeedDisabled, downSpeedUnlimited, totalDownSpeed, downSpeedSetMax, maxDownload, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed, upSpeedSetMax, maxUpload, dms.length, null, new ViewUtils.SpeedAdapter() {

        @Override
        public void setDownSpeed(final int speed) {
            ListenerDMTask task = new ListenerDMTask(dms) {

                @Override
                public void run(DownloadManager dm) {
                    dm.getStats().setDownloadRateLimitBytesPerSecond(speed);
                }
            };
            task.go();
        }

        @Override
        public void setUpSpeed(final int speed) {
            ListenerDMTask task = new ListenerDMTask(dms) {

                @Override
                public void run(DownloadManager dm) {
                    dm.getStats().setUploadRateLimitBytesPerSecond(speed);
                }
            };
            task.go();
        }
    });
    // advanced > Speed Limits
    final Menu speedLimitsMenu = new Menu(menuAdvanced.getShell(), SWT.DROP_DOWN);
    final MenuItem speedLimitsMenuItem = new MenuItem(menuAdvanced, SWT.CASCADE);
    Messages.setLanguageText(speedLimitsMenuItem, IMenuConstants.MENU_ID_SPEED_LIMITS);
    speedLimitsMenuItem.setMenu(speedLimitsMenu);
    MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenu, new MenuBuildUtils.MenuBuilder() {

        @Override
        public void buildMenu(Menu menu, MenuEvent menuEvent) {
            addSpeedLimitsMenu(dms, speedLimitsMenu);
        }
    });
    // advanced > Tracker Menu //
    final Menu menuTracker = new Menu(menu_shell, SWT.DROP_DOWN);
    final MenuItem itemTracker = new MenuItem(menuAdvanced, SWT.CASCADE);
    Messages.setLanguageText(itemTracker, "MyTorrentsView.menu.tracker");
    itemTracker.setMenu(menuTracker);
    itemExplore.setEnabled(hasSelection);
    addTrackerTorrentMenu(menuTracker, dms, changeUrl, manualUpdate, allStopped, use_open_containing_folder, fileMove);
    // advanced > files
    final MenuItem itemFiles = new MenuItem(menuAdvanced, SWT.CASCADE);
    Messages.setLanguageText(itemFiles, "ConfigView.section.files");
    final Menu menuFiles = new Menu(menu_shell, SWT.DROP_DOWN);
    itemFiles.setMenu(menuFiles);
    final MenuItem itemFileMoveData = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileMoveData, "MyTorrentsView.menu.movedata");
    itemFileMoveData.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            moveDataFiles(shell, dms);
        }
    });
    itemFileMoveData.setEnabled(fileMove);
    final MenuItem itemFileMoveTorrent = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileMoveTorrent, "MyTorrentsView.menu.movetorrent");
    itemFileMoveTorrent.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            moveTorrentFile(shell, dms);
        }
    });
    itemFileMoveTorrent.setEnabled(fileMove);
    // move on complete
    final Menu moc_menu = new Menu(shell, SWT.DROP_DOWN);
    MenuItem moc_item = new MenuItem(menuFiles, SWT.CASCADE);
    Messages.setLanguageText(moc_item, "label.move.on.comp");
    moc_item.setMenu(moc_menu);
    MenuItem clear_item = new MenuItem(moc_menu, SWT.PUSH);
    Messages.setLanguageText(clear_item, "Button.clear");
    clear_item.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            clearMOC(dms);
        }
    });
    clear_item.setEnabled(canClearMOC);
    MenuItem set_item = new MenuItem(moc_menu, SWT.PUSH);
    Messages.setLanguageText(set_item, "label.set");
    set_item.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            setMOC(shell, dms);
        }
    });
    set_item.setEnabled(canSetMOC);
    moc_item.setEnabled(canClearMOC || canSetMOC);
    // file export
    final MenuItem itemFileExport = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileExport, "MyTorrentsView.menu.exportdownload");
    itemFileExport.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            exportDownloads(shell, dms);
        }
    });
    itemFileExport.setEnabled(fileExport);
    final MenuItem itemCheckFilesExist = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemCheckFilesExist, "MyTorrentsView.menu.checkfilesexist");
    itemCheckFilesExist.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.filesExist(true);
        }
    });
    final MenuItem itemLocateFiles = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemLocateFiles, "MyTorrentsView.menu.locatefiles");
    itemLocateFiles.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            ManagerUtils.locateFiles(dms, shell);
        }
    });
    final MenuItem itemFileRescan = new MenuItem(menuFiles, SWT.CHECK);
    Messages.setLanguageText(itemFileRescan, "MyTorrentsView.menu.rescanfile");
    itemFileRescan.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES, itemFileRescan.getSelection());
        }
    });
    itemFileRescan.setSelection(allScanSelected);
    itemFileRescan.setEnabled(fileRescan);
    // revert
    final MenuItem itemRevertFiles = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemRevertFiles, "MyTorrentsView.menu.revertfiles");
    itemRevertFiles.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            FilesViewMenuUtil.revertFiles(tv, dms);
        }
    });
    itemRevertFiles.setEnabled(hasRevertableFiles);
    // clear links
    final MenuItem itemClearLinks = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemClearLinks, "FilesView.menu.clear.links");
    itemClearLinks.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            if (ManagerUtils.isStopped(dm) && dm.getDownloadState().getFileLinks().hasLinks()) {
                DiskManagerFileInfoSet fis = dm.getDiskManagerFileInfoSet();
                if (fis.nbFiles() > 1) {
                    DiskManagerFileInfo[] files = fis.getFiles();
                    for (DiskManagerFileInfo file_info : files) {
                        File file_link = file_info.getFile(true);
                        File file_nolink = file_info.getFile(false);
                        if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
                            file_info.setLink(null);
                        }
                    }
                }
            }
        }
    });
    itemClearLinks.setEnabled(hasClearableLinks);
    // clear allocation
    MenuItem itemFileClearAlloc = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileClearAlloc, "MyTorrentsView.menu.clear_alloc_data");
    itemFileClearAlloc.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.setDataAlreadyAllocated(false);
        }
    });
    itemFileClearAlloc.setEnabled(allStopped);
    // clear resume
    MenuItem itemFileClearResume = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileClearResume, "MyTorrentsView.menu.clear_resume_data");
    itemFileClearResume.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.getDownloadState().clearResumeData();
        }
    });
    itemFileClearResume.setEnabled(allStopped);
    // set resume complete
    MenuItem itemFileSetResumeComplete = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileSetResumeComplete, "MyTorrentsView.menu.set.resume.complete");
    itemFileSetResumeComplete.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            TorrentUtils.setResumeDataCompletelyValid(dm.getDownloadState());
        }
    });
    itemFileSetResumeComplete.setEnabled(allStopped && allResumeIncomplete);
    // Advanced -> archive
    final List<Download> ar_dms = new ArrayList<>();
    for (DownloadManager dm : dms) {
        Download stub = PluginCoreUtils.wrap(dm);
        if (!stub.canStubbify()) {
            continue;
        }
        ar_dms.add(stub);
    }
    MenuItem itemArchive = new MenuItem(menuAdvanced, SWT.PUSH);
    Messages.setLanguageText(itemArchive, "MyTorrentsView.menu.archive");
    Utils.setMenuItemImage(itemArchive, "archive");
    itemArchive.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            ManagerUtils.moveToArchive(ar_dms, null);
        }
    });
    itemArchive.setEnabled(ar_dms.size() > 0);
    // Advanced - > Rename
    final MenuItem itemRename = new MenuItem(menuAdvanced, SWT.DROP_DOWN);
    Messages.setLanguageText(itemRename, "MyTorrentsView.menu.rename");
    itemRename.setEnabled(hasSelection);
    itemRename.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            for (DownloadManager dm : dms) {
                AdvRenameWindow window = new AdvRenameWindow();
                window.open(dm);
            }
        }
    });
    if (ManagerUtils.canFindMoreLikeThis()) {
        final MenuItem itemFindMore = new MenuItem(menuAdvanced, SWT.PUSH);
        Messages.setLanguageText(itemFindMore, "MyTorrentsView.menu.findmorelikethis");
        itemFindMore.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.findMoreLikeThis(dms[0], shell);
            }
        });
        itemFindMore.setSelection(isSingleSelection);
    }
    // === advanced > quick view
    final Menu quickViewMenu = new Menu(menuAdvanced.getShell(), SWT.DROP_DOWN);
    final MenuItem quickViewMenuItem = new MenuItem(menuAdvanced, SWT.CASCADE);
    Messages.setLanguageText(quickViewMenuItem, IMenuConstants.MENU_ID_QUICK_VIEW);
    quickViewMenuItem.setMenu(quickViewMenu);
    MenuBuildUtils.addMaintenanceListenerForMenu(quickViewMenu, new MenuBuildUtils.MenuBuilder() {

        @Override
        public void buildMenu(Menu menu, MenuEvent menuEvent) {
            DownloadManager dm = dms[0];
            DiskManagerFileInfo[] files = dm.getDiskManagerFileInfoSet().getFiles();
            int added = 0;
            for (final DiskManagerFileInfo file : files) {
                if (Utils.isQuickViewSupported(file)) {
                    final MenuItem addItem = new MenuItem(menu, SWT.CHECK);
                    addItem.setSelection(Utils.isQuickViewActive(file));
                    addItem.setText(file.getTorrentFile().getRelativePath());
                    addItem.addListener(SWT.Selection, new Listener() {

                        @Override
                        public void handleEvent(Event arg) {
                            Utils.setQuickViewActive(file, addItem.getSelection());
                        }
                    });
                    added++;
                }
            }
            if (added == 0) {
                final MenuItem addItem = new MenuItem(menu, SWT.PUSH);
                addItem.setText(MessageText.getString("quick.view.no.files"));
                addItem.setEnabled(false);
            }
        }
    });
    quickViewMenuItem.setEnabled(isSingleSelection);
    // Alerts
    MenuFactory.addAlertsMenu(menuAdvanced, true, dms);
    if (userMode > 0) {
        final MenuItem itemExport = new MenuItem(menuAdvanced, SWT.CASCADE);
        // $NON-NLS-1$
        Messages.setLanguageText(itemExport, "MyTorrentsView.menu.exportmenu");
        Utils.setMenuItemImage(itemExport, "export");
        itemExport.setEnabled(hasSelection);
        final Menu menuExport = new Menu(menu_shell, SWT.DROP_DOWN);
        itemExport.setMenu(menuExport);
        // Advanced > Export > Export XML
        final MenuItem itemExportXML = new MenuItem(menuExport, SWT.PUSH);
        Messages.setLanguageText(itemExportXML, "MyTorrentsView.menu.export");
        itemExportXML.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                // First only.
                DownloadManager dm = dms[0];
                if (dm != null)
                    new ExportTorrentWizard(itemExportXML.getDisplay(), dm);
            }
        });
        // Advanced > Export > Export Torrent
        final MenuItem itemExportTorrent = new MenuItem(menuExport, SWT.PUSH);
        Messages.setLanguageText(itemExportTorrent, "MyTorrentsView.menu.exporttorrent");
        itemExportTorrent.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                exportTorrent(dms, shell);
            }
        });
        // end DMTask
        // Advanced > Export > WebSeed URL
        final MenuItem itemWebSeed = new MenuItem(menuExport, SWT.PUSH);
        Messages.setLanguageText(itemWebSeed, "MyTorrentsView.menu.exporthttpseeds");
        itemWebSeed.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                exportHTTPSeeds(dms);
            }
        });
    }
    if (userMode > 0) {
        final MenuItem itemExportXML = new MenuItem(menuAdvanced, SWT.PUSH);
        Messages.setLanguageText(itemExportXML, "label.options.and.info");
        itemExportXML.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
                }
            }
        });
    }
    if (userMode > 0) {
        final MenuItem itemPeerSource = new MenuItem(menuAdvanced, SWT.CASCADE);
        // $NON-NLS-1$
        Messages.setLanguageText(itemPeerSource, "MyTorrentsView.menu.peersource");
        final Menu menuPeerSource = new Menu(menu_shell, SWT.DROP_DOWN);
        itemPeerSource.setMenu(menuPeerSource);
        addPeerSourceSubMenu(dms, menuPeerSource);
    }
    // Sequential download
    {
        final MenuItem dl_seq_enable = new MenuItem(menuAdvanced, SWT.CHECK);
        Messages.setLanguageText(dl_seq_enable, "menu.sequential.download");
        dl_seq_enable.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, dl_seq_enable.getSelection());
            }
        });
        boolean allSeq = true;
        boolean AllNonSeq = true;
        for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = dms[j];
            boolean seq = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD);
            if (seq) {
                AllNonSeq = false;
            } else {
                allSeq = false;
            }
        }
        boolean bChecked;
        if (allSeq) {
            bChecked = true;
        } else if (AllNonSeq) {
            bChecked = false;
        } else {
            bChecked = false;
        }
        dl_seq_enable.setSelection(bChecked);
    }
    // IP Filter Enable
    if (userMode > 0) {
        final MenuItem ipf_enable = new MenuItem(menuAdvanced, SWT.CHECK);
        Messages.setLanguageText(ipf_enable, "MyTorrentsView.menu.ipf_enable");
        ipf_enable.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, !ipf_enable.getSelection());
            }
        });
        boolean bEnabled = IpFilterManagerFactory.getSingleton().getIPFilter().isEnabled();
        if (bEnabled) {
            boolean allChecked = true;
            boolean allUnchecked = true;
            for (int j = 0; j < dms.length; j++) {
                DownloadManager dm = (DownloadManager) dms[j];
                boolean b = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
                if (b) {
                    allUnchecked = false;
                } else {
                    allChecked = false;
                }
            }
            boolean bChecked;
            if (allUnchecked) {
                bChecked = true;
            } else if (allChecked) {
                bChecked = false;
            } else {
                bChecked = false;
            }
            ipf_enable.setSelection(bChecked);
        }
        ipf_enable.setEnabled(bEnabled);
    }
    if (userMode > 1) {
        final MenuItem itemNetworks = new MenuItem(menuAdvanced, SWT.CASCADE);
        // $NON-NLS-1$
        Messages.setLanguageText(itemNetworks, "MyTorrentsView.menu.networks");
        final Menu menuNetworks = new Menu(menu_shell, SWT.DROP_DOWN);
        itemNetworks.setMenu(menuNetworks);
        addNetworksSubMenu(dms, menuNetworks);
    }
    // superseed
    if (userMode > 1 && isSeedingView) {
        final MenuItem itemSuperSeed = new MenuItem(menuAdvanced, SWT.CHECK);
        Messages.setLanguageText(itemSuperSeed, "ManagerItem.superseeding");
        boolean enabled = canSetSuperSeed && (superSeedAllNo || superSeedAllYes);
        itemSuperSeed.setEnabled(enabled);
        final boolean selected = superSeedAllNo;
        if (enabled) {
            itemSuperSeed.setSelection(selected);
            itemSuperSeed.addListener(SWT.Selection, new ListenerDMTask(dms) {

                @Override
                public void run(DownloadManager dm) {
                    PEPeerManager pm = dm.getPeerManager();
                    if (pm != null) {
                        if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {
                            pm.setSuperSeedMode(!selected);
                        }
                    }
                }
            });
        }
    }
    // Advanced > Pause For..
    if (userMode > 0) {
        boolean can_pause = false;
        for (int i = 0; i < dms.length; i++) {
            DownloadManager dm = dms[i];
            if (ManagerUtils.isPauseable(dm)) {
                can_pause = true;
                break;
            }
        }
        final MenuItem itemPauseFor = new MenuItem(menuAdvanced, SWT.PUSH);
        itemPauseFor.setEnabled(can_pause);
        Messages.setLanguageText(itemPauseFor, "MainWindow.menu.transfers.pausetransfersfor");
        itemPauseFor.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                pauseDownloadsFor(dms);
            }
        });
    }
    // Advanced > Reposition
    final MenuItem itemPositionManual = new MenuItem(menuAdvanced, SWT.PUSH);
    Messages.setLanguageText(itemPositionManual, "MyTorrentsView.menu.reposition.manual");
    Utils.setMenuItemImage(itemPositionManual, "move");
    itemPositionManual.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            repositionManual(tv, dms, shell, isSeedingView);
        }
    });
    // back to main menu
    if (userMode > 0 && isTrackerOn) {
        // Host
        final MenuItem itemHost = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemHost, "MyTorrentsView.menu.host");
        Utils.setMenuItemImage(itemHost, "host");
        itemHost.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                hostTorrents(dms);
            }
        });
        // Publish
        final MenuItem itemPublish = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemPublish, "MyTorrentsView.menu.publish");
        Utils.setMenuItemImage(itemPublish, "publish");
        itemPublish.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                publishTorrents(dms);
            }
        });
        itemHost.setEnabled(hasSelection);
        itemPublish.setEnabled(hasSelection);
    }
    /*  //TODO ensure that all limits combined don't go under the min 5kbs ?
		 //Disable at the end of the list, thus the first item of the array is instanciated last.
		 itemsSpeed[0] = new MenuItem(menuSpeed,SWT.PUSH);
		 Messages.setLanguageText(itemsSpeed[0],"MyTorrentsView.menu.setSpeed.disable");
		 itemsSpeed[0].setData("maxul", new Integer(-1));
		 itemsSpeed[0].addListener(SWT.Selection,itemsSpeedListener);
		 */
    // Category
    Menu menuCategory = new Menu(menu_shell, SWT.DROP_DOWN);
    final MenuItem itemCategory = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    Messages.setLanguageText(itemCategory, "MyTorrentsView.menu.setCategory");
    // itemCategory.setImage(ImageRepository.getImage("speed"));
    itemCategory.setMenu(menuCategory);
    itemCategory.setEnabled(hasSelection);
    addCategorySubMenu(dms, menuCategory);
    // Tags
    Menu menuTags = new Menu(menu_shell, SWT.DROP_DOWN);
    final MenuItem itemTags = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(itemTags, "label.tags");
    itemTags.setMenu(menuTags);
    itemTags.setEnabled(hasSelection);
    TagUIUtils.addLibraryViewTagsSubMenu(dms, menuTags);
    if (isSeedingView) {
        final MenuItem itemPersonalShare = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemPersonalShare, "MyTorrentsView.menu.create_personal_share");
        itemPersonalShare.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

            @Override
            public void run(DownloadManager dm) {
                File file = dm.getSaveLocation();
                Map<String, String> properties = new HashMap<>();
                properties.put(ShareManager.PR_PERSONAL, "true");
                if (file.isFile()) {
                    ShareUtils.shareFile(file.getAbsolutePath(), properties);
                } else if (file.isDirectory()) {
                    ShareUtils.shareDir(file.getAbsolutePath(), properties);
                }
            }
        });
        boolean can_share_pers = dms.length > 0;
        for (DownloadManager dm : dms) {
            File file = dm.getSaveLocation();
            if (!file.exists()) {
                can_share_pers = false;
                break;
            }
        }
        itemPersonalShare.setEnabled(can_share_pers);
    }
    // ---
    new MenuItem(menu, SWT.SEPARATOR);
    // Queue
    final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
    // $NON-NLS-1$
    Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue");
    Utils.setMenuItemImage(itemQueue, "start");
    itemQueue.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    queueDataSources(dms, true);
                }
            });
        }
    });
    itemQueue.setEnabled(start);
    // Force Start
    if (userMode > 0) {
        final MenuItem itemForceStart = new MenuItem(menu, SWT.CHECK);
        Messages.setLanguageText(itemForceStart, "MyTorrentsView.menu.forceStart");
        Utils.setMenuItemImage(itemForceStart, "forcestart");
        itemForceStart.addListener(SWT.Selection, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager dm) {
                if (ManagerUtils.isForceStartable(dm)) {
                    dm.setForceStart(itemForceStart.getSelection());
                }
            }
        });
        itemForceStart.setSelection(forceStart);
        itemForceStart.setEnabled(forceStartEnabled);
    }
    // Pause
    if (userMode > 0) {
        final MenuItem itemPause = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemPause, "v3.MainWindow.button.pause");
        Utils.setMenuItemImage(itemPause, "pause");
        itemPause.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Utils.getOffOfSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        pauseDataSources(dms);
                    }
                });
            }
        });
        itemPause.setEnabled(pause);
    }
    // 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) {
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    stopDataSources(dms);
                }
            });
        }
    });
    itemStop.setEnabled(stop);
    // Force Recheck
    final MenuItem itemRecheck = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemRecheck, "MyTorrentsView.menu.recheck");
    Utils.setMenuItemImage(itemRecheck, "recheck");
    itemRecheck.addListener(SWT.Selection, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            if (dm.canForceRecheck()) {
                dm.forceRecheck();
            }
        }
    });
    itemRecheck.setEnabled(recheck);
    // Delete
    final MenuItem itemRemove = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemRemove, "menu.delete.options");
    Utils.setMenuItemImage(itemRemove, "delete");
    itemRemove.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            removeDownloads(dms, null, true);
        }
    });
    itemRemove.setEnabled(hasSelection);
}
Also used : UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) WebSeedsEditorListener(com.biglybt.ui.swt.maketorrent.WebSeedsEditorListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) AdvRenameWindow(com.biglybt.ui.swt.shells.AdvRenameWindow) ExportTorrentWizard(com.biglybt.ui.swt.exporttorrent.wizard.ExportTorrentWizard) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) ViewUtils(com.biglybt.ui.swt.views.ViewUtils) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctions(com.biglybt.ui.UIFunctions) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Download(com.biglybt.pif.download.Download) MenuEvent(org.eclipse.swt.events.MenuEvent) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) IOException(java.io.IOException) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) File(java.io.File)

Example 19 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.

the class SearchUtils method addMenus.

public static void addMenus(Menu menu) {
    final Menu template_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem template_menu_item = new MenuItem(menu, SWT.CASCADE);
    template_menu_item.setMenu(template_menu);
    Messages.setLanguageText(template_menu_item, "Search.menu.engines");
    template_menu.addMenuListener(new MenuAdapter() {

        @Override
        public void menuShown(MenuEvent e) {
            for (MenuItem mi : template_menu.getItems()) {
                mi.dispose();
            }
            MenuItem import_mi = new MenuItem(template_menu, SWT.PUSH);
            Messages.setLanguageText(import_mi, "menu.import.json.from.clipboard");
            import_mi.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    importFromClipboard();
                }
            });
            new MenuItem(template_menu, SWT.SEPARATOR);
            Engine[] engines = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngines(true, false);
            Arrays.sort(engines, new Comparator<Engine>() {

                @Override
                public int compare(Engine o1, Engine o2) {
                    return (o1.getName().compareToIgnoreCase(o2.getName()));
                }
            });
            for (int i = 0; i < engines.length; i++) {
                final Engine engine = engines[i];
                final Menu engine_menu = new Menu(template_menu.getShell(), SWT.DROP_DOWN);
                MenuItem engine_menu_item = new MenuItem(template_menu, SWT.CASCADE);
                engine_menu_item.setMenu(engine_menu);
                engine_menu_item.setText(engine.getName());
                addMenus(engine_menu, engine, false);
            }
        }
    });
    MenuBuildUtils.addChatMenu(menu, "label.chat", "Search Templates");
    MenuItem itemExport = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemExport, "search.export.all");
    itemExport.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            exportAll();
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 20 with MenuEvent

use of org.eclipse.swt.events.MenuEvent in project netxms by netxms.

the class FilterBuilder method createColumnSelectionMenu.

/**
 * Create menu for selecting log column
 *
 * @param listener selection listener
 */
private void createColumnSelectionMenu(final ColumnSelectionHandler handler) {
    if (logHandle == null)
        return;
    if (columnSelectionMenu != null)
        columnSelectionMenu.dispose();
    columnSelectionMenu = new Menu(getShell(), SWT.POP_UP);
    getShell().setMenu(columnSelectionMenu);
    for (final LogColumn lc : logHandle.getColumns()) {
        MenuItem item = new MenuItem(columnSelectionMenu, SWT.PUSH);
        item.setText(lc.getDescription());
        item.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                handler.columnSelected(lc);
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
    }
    columnSelectionMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent e) {
        }

        @Override
        public void menuHidden(MenuEvent e) {
            getShell().setMenu(null);
        }
    });
    columnSelectionMenu.setVisible(true);
}
Also used : LogColumn(org.netxms.client.log.LogColumn) MenuListener(org.eclipse.swt.events.MenuListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) SelectionListener(org.eclipse.swt.events.SelectionListener) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

MenuEvent (org.eclipse.swt.events.MenuEvent)45 Menu (org.eclipse.swt.widgets.Menu)37 MenuItem (org.eclipse.swt.widgets.MenuItem)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 MenuAdapter (org.eclipse.swt.events.MenuAdapter)24 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)21 MenuListener (org.eclipse.swt.events.MenuListener)18 Point (org.eclipse.swt.graphics.Point)14 MenuManager (org.eclipse.jface.action.MenuManager)13 Event (org.eclipse.swt.widgets.Event)11 Listener (org.eclipse.swt.widgets.Listener)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 FocusEvent (org.eclipse.swt.events.FocusEvent)7 Composite (org.eclipse.swt.widgets.Composite)7 TableItem (org.eclipse.swt.widgets.TableItem)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 GridData (org.eclipse.swt.layout.GridData)6