Search in sources :

Example 76 with Transfer

use of org.eclipse.swt.dnd.Transfer in project BiglyBT by BiglySoftware.

the class BuddyPluginViewInstance method createClassic.

private void createClassic(Composite main) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    main.setLayout(layout);
    GridData grid_data = new GridData(GridData.FILL_BOTH);
    main.setLayoutData(grid_data);
    // info
    Composite info_area = new Composite(main, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 4;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    info_area.setLayout(layout);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    grid_data.horizontalSpan = 3;
    info_area.setLayoutData(grid_data);
    Label label = new Label(info_area, SWT.NULL);
    label.setText(lu.getLocalisedMessageText("azbuddy.classic.info"));
    new LinkLabel(info_area, "ConfigView.label.please.visit.here", Wiki.FRIENDS);
    label = new Label(info_area, SWT.NULL);
    grid_data = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(grid_data);
    final Button config_button = new Button(info_area, SWT.NULL);
    config_button.setText(lu.getLocalisedMessageText("plugins.basicview.config"));
    config_button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            plugin.showConfig();
        }
    });
    classic_enabled = plugin.isClassicEnabled();
    if (!classic_enabled) {
        Label control_label = new Label(main, SWT.NULL);
        control_label.setText(lu.getLocalisedMessageText("azbuddy.disabled"));
        return;
    }
    final Composite form = new Composite(main, SWT.NONE);
    FormLayout flayout = new FormLayout();
    flayout.marginHeight = 0;
    flayout.marginWidth = 0;
    form.setLayout(flayout);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    form.setLayoutData(gridData);
    final Composite child1 = new Composite(form, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    child1.setLayout(layout);
    CTabFolder tab_folder = new CTabFolder(child1, SWT.LEFT);
    tab_folder.setBorderVisible(true);
    tab_folder.setTabHeight(20);
    grid_data = new GridData(GridData.FILL_BOTH);
    tab_folder.setLayoutData(grid_data);
    CTabItem public_item = null;
    Composite public_area = null;
    CTabItem anon_item = null;
    Composite anon_area = null;
    for (int i = 0; i < 2; i++) {
        boolean is_pub_tab = i == 0;
        CTabItem tab_item = new CTabItem(tab_folder, SWT.NULL);
        Composite tab_area = new Composite(tab_folder, SWT.NULL);
        if (is_pub_tab) {
            public_item = tab_item;
            public_area = tab_area;
        } else {
            anon_item = tab_item;
            anon_area = tab_area;
        }
        tab_item.setText(lu.getLocalisedMessageText(is_pub_tab ? "label.public" : "label.anon"));
        tab_item.setControl(tab_area);
        layout = new GridLayout();
        layout.numColumns = 1;
        layout.horizontalSpacing = 0;
        layout.verticalSpacing = 0;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        tab_area.setLayout(layout);
        final Composite controls = new Composite(tab_area, SWT.NONE);
        layout = new GridLayout();
        layout.numColumns = 5;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        controls.setLayout(layout);
        grid_data = new GridData(GridData.FILL_HORIZONTAL);
        controls.setLayoutData(grid_data);
        ;
        Label control_label = new Label(controls, SWT.NULL);
        control_label.setText(lu.getLocalisedMessageText("azbuddy.ui.new_buddy") + " ");
        final Text control_text = new Text(controls, SWT.BORDER);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        control_text.setLayoutData(gridData);
        final Button control_button = new Button(controls, SWT.NULL);
        control_button.setText(lu.getLocalisedMessageText("Button.add"));
        control_button.setEnabled(false);
        control_text.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                control_button.setEnabled(plugin.verifyPublicKey(is_pub_tab, control_text.getText().trim()));
            }
        });
        control_button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                plugin.addBuddy(is_pub_tab, control_text.getText().trim(), BuddyPluginNetwork.SUBSYSTEM_AZ2);
                control_text.setText("");
            }
        });
        final Label control_lab_pk = new Label(controls, SWT.NULL);
        control_lab_pk.setText(lu.getLocalisedMessageText("azbuddy.ui.mykey") + " ");
        final Label control_val_pk = new Label(controls, SWT.NULL);
        gridData = new GridData();
        control_val_pk.setLayoutData(gridData);
        ClipboardCopy.addCopyToClipMenu(control_val_pk, new ClipboardCopy.copyToClipProvider() {

            @Override
            public String getText() {
                return ((String) control_val_pk.getData("key"));
            }
        });
        control_val_pk.setData("key", "");
        final CryptoManager crypt_man = CryptoManagerFactory.getSingleton();
        int ecc_inst = is_pub_tab ? 1 : 2;
        byte[] public_key = crypt_man.getECCHandler(ecc_inst).peekPublicKey();
        if (public_key == null) {
            Messages.setLanguageText(control_val_pk, "ConfigView.section.security.publickey.undef");
        } else {
            String str = Base32.encode(public_key);
            control_val_pk.setData("key", str);
            control_val_pk.setText(truncate(str));
        }
        Messages.setLanguageText(control_val_pk, "ConfigView.copy.to.clipboard.tooltip", true);
        control_val_pk.setCursor(main.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
        control_val_pk.setForeground(main.getDisplay().getSystemColor(SWT.COLOR_LINK_FOREGROUND));
        control_val_pk.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent arg0) {
                copyToClipboard();
            }

            @Override
            public void mouseDown(MouseEvent arg0) {
                copyToClipboard();
            }

            protected void copyToClipboard() {
                new Clipboard(control_val_pk.getDisplay()).setContents(new Object[] { control_val_pk.getData("key") }, new Transfer[] { TextTransfer.getInstance() });
            }
        });
        cryptoManagerKeyListener = new CryptoManagerKeyListener() {

            @Override
            public void keyChanged(CryptoHandler handler) {
                if (control_val_pk.isDisposed()) {
                    crypt_man.removeKeyListener(this);
                } else if (handler.getType() == CryptoManager.HANDLER_ECC) {
                    if (handler.getInstance() == ecc_inst) {
                        control_val_pk.getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                byte[] public_key = handler.peekPublicKey();
                                if (public_key == null) {
                                    Messages.setLanguageText(control_val_pk, "ConfigView.section.security.publickey.undef");
                                    control_val_pk.setData("key", "");
                                } else {
                                    String str = Base32.encode(public_key);
                                    control_val_pk.setText(truncate(str));
                                    control_val_pk.setData("key", str);
                                }
                                controls.layout();
                            }
                        });
                    }
                }
            }

            @Override
            public void keyLockStatusChanged(CryptoHandler handler) {
            }
        };
        crypt_man.addKeyListener(cryptoManagerKeyListener);
        main.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (cryptoManagerKeyListener != null) {
                    CryptoManagerFactory.getSingleton().removeKeyListener(cryptoManagerKeyListener);
                }
            }
        });
    }
    final Sash sash = new Sash(form, SWT.HORIZONTAL);
    final Composite child2 = new Composite(form, SWT.NULL);
    layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    child2.setLayout(layout);
    FormData formData;
    // child1
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(0, 0);
    child1.setLayoutData(formData);
    final FormData child1Data = formData;
    final int SASH_WIDTH = 4;
    // sash
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(child1);
    formData.height = SASH_WIDTH;
    sash.setLayoutData(formData);
    // child2
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(100, 0);
    formData.bottom = new FormAttachment(100, 0);
    formData.top = new FormAttachment(sash);
    child2.setLayoutData(formData);
    final PluginConfig pc = plugin.getPluginInterface().getPluginconfig();
    sash.setData("PCT", new Float(pc.getPluginFloatParameter("swt.sash.position", 0.7f)));
    sash.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.DRAG) {
                return;
            }
            child1Data.height = e.y + e.height - SASH_WIDTH;
            form.layout();
            Float l = new Float((double) child1.getBounds().height / form.getBounds().height);
            sash.setData("PCT", l);
            pc.setPluginParameter("swt.sash.position", l.floatValue());
        }
    });
    form.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            Float l = (Float) sash.getData("PCT");
            if (l != null) {
                child1Data.height = (int) (form.getBounds().height * l.doubleValue());
                form.layout();
            }
        }
    });
    // table
    Comparator<BuddyPluginBuddy> comparator = addBuddyTable(public_area, true);
    addBuddyTable(anon_area, false);
    Utils.setEnabled(anon_area, I2PHelpers.isI2PInstalled());
    Label pblab = new Label(child1, SWT.NULL);
    pblab.setText(lu.getLocalisedMessageText("label.partial.friends"));
    Comparator<PartialBuddy> pbcomparator = addPartialBuddyTable(child1);
    // log area
    log = new StyledText(child2, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    grid_data = new GridData(GridData.FILL_BOTH);
    grid_data.horizontalSpan = 1;
    log.setLayoutData(grid_data);
    log.setIndent(4);
    public_buddies.clear();
    anon_buddies.clear();
    List<BuddyPluginBuddy> buddies = plugin.getBuddies();
    for (BuddyPluginBuddy buddy : buddies) {
        if (buddy.isPublicNetwork()) {
            public_buddies.add(buddy);
        } else {
            anon_buddies.add(buddy);
        }
        buddyAdded(buddy);
    }
    Collections.sort(public_buddies, comparator);
    Collections.sort(anon_buddies, comparator);
    partial_buddies = plugin.getPartialBuddies();
    for (int i = 0; i < partial_buddies.size(); i++) {
        partialBuddyAdded(partial_buddies.get(i));
    }
    Collections.sort(partial_buddies, pbcomparator);
    plugin.addListener(this);
    plugin.addPartialBuddyListener(this);
    tab_folder.setSelection(public_item);
    init_complete = true;
    updateTable(true);
    updateTable(false);
    updatePartialBuddyTable();
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoManagerKeyListener(com.biglybt.core.security.CryptoManagerKeyListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) CryptoManager(com.biglybt.core.security.CryptoManager) CryptoManagerKeyListener(com.biglybt.core.security.CryptoManagerKeyListener) CryptoHandler(com.biglybt.core.security.CryptoHandler) MessageText(com.biglybt.core.internat.MessageText) ClipboardCopy(com.biglybt.ui.swt.mainwindow.ClipboardCopy) Point(org.eclipse.swt.graphics.Point) PluginConfig(com.biglybt.pif.PluginConfig) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 77 with Transfer

use of org.eclipse.swt.dnd.Transfer in project BiglyBT by BiglySoftware.

the class TorrentMenuFancy method buildTorrentCustomMenu_Content.

protected void buildTorrentCustomMenu_Content(final Composite detailArea, final DownloadManager[] dms) {
    // Run Data File
    if (hasSelection) {
        createRow(detailArea, "MyTorrentsView.menu.open", "run", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.runDataSources(dms);
            }
        });
    }
    // Explore (or open containing folder)
    if (hasSelection) {
        final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
        createRow(detailArea, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"), null, new ListenerDMTask(dms, false) {

            @Override
            public void run(DownloadManager dm) {
                ManagerUtils.open(dm, use_open_containing_folder);
            }
        });
    }
    if (hasSelection) {
        createMenuRow(detailArea, "MyTorrentsView.menu.browse", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menuBrowse) {
                final MenuItem itemBrowsePublic = new MenuItem(menuBrowse, SWT.PUSH);
                itemBrowsePublic.setText(MessageText.getString("label.public") + "...");
                itemBrowsePublic.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

                    @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, false) {

                    @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(dms.length == 1);
                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());
                    }
                });
            }
        });
    }
    // set thumbnail
    createRow(detailArea, "MyTorrentsView.menu.torrent.set.thumb", null, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            FileDialog fDialog = new FileDialog(parentShell, SWT.OPEN | SWT.MULTI);
            fDialog.setText(MessageText.getString("MainWindow.dialog.choose.thumb"));
            String path = fDialog.open();
            if (path == null)
                return;
            File file = new File(path);
            try {
                byte[] thumbnail = FileUtil.readFileAsByteArray(file);
                String name = file.getName();
                int pos = name.lastIndexOf(".");
                String ext;
                if (pos != -1) {
                    ext = name.substring(pos + 1);
                } else {
                    ext = "";
                }
                String type = HTTPUtils.guessContentTypeFromFileType(ext);
                for (DownloadManager dm : dms) {
                    try {
                        TOTorrent torrent = dm.getTorrent();
                        PlatformTorrentUtils.setContentThumbnail(torrent, thumbnail, type);
                    } catch (Throwable e) {
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    });
    boolean fileMove = true;
    boolean locateFiles = false;
    boolean exportFiles = true;
    boolean canSetMOC = dms.length > 0;
    boolean canClearMOC = false;
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        if (!dm.canMoveDataFiles()) {
            fileMove = false;
        }
        if (!dm.canExportDownload()) {
            exportFiles = false;
        }
        if (!dm.isDownloadComplete(false) || dm.getState() == DownloadManager.STATE_ERROR) {
            locateFiles = true;
        }
        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);
    }
    if (fileMove) {
        createRow(detailArea, "MyTorrentsView.menu.movedata", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.moveDataFiles(parentShell, dms, false);
            }
        });
        int userMode = COConfigurationManager.getIntParameter("User Mode");
        if (userMode > 0) {
            createRow(detailArea, "MyTorrentsView.menu.movedata.batch", null, new ListenerDMTask(dms) {

                @Override
                public void run(DownloadManager[] dms) {
                    TorrentUtil.moveDataFiles(parentShell, dms, true);
                }
            });
        }
    }
    if (canSetMOC || canClearMOC) {
        boolean f_canSetMOC = canSetMOC;
        boolean f_canClearMOC = canClearMOC;
        createMenuRow(detailArea, "label.move.on.comp", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu 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) {
                        TorrentUtil.clearMOC(dms);
                    }
                });
                clear_item.setEnabled(f_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) {
                        TorrentUtil.setMOC(parentShell, dms);
                    }
                });
                set_item.setEnabled(f_canSetMOC);
            }
        });
    }
    if (exportFiles) {
        createRow(detailArea, "MyTorrentsView.menu.exportdownload", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.exportDownloads(parentShell, dms);
            }
        });
    }
    createRow(detailArea, "MyTorrentsView.menu.checkfilesexist", null, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.filesExist(true);
        }
    });
    if (locateFiles) {
        createRow(detailArea, "MyTorrentsView.menu.locatefiles", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.locateFiles(dms, parentShell);
            }
        });
    }
    if (dms.length == 1 && ManagerUtils.canFindMoreLikeThis()) {
        createRow(detailArea, "MyTorrentsView.menu.findmorelikethis", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.findMoreLikeThis(dms[0], parentShell);
            }
        });
    }
    createRow(detailArea, "MyTorrentsView.menu.thisColumn.toClipboard", null, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String sToClipboard = "";
            if (column == null) {
                return;
            }
            String columnName = column.getName();
            if (columnName == null) {
                return;
            }
            TableRowCore[] rows = tv.getSelectedRows();
            for (TableRowCore row : rows) {
                if (row != rows[0]) {
                    sToClipboard += "\n";
                }
                TableCellCore cell = row.getTableCellCore(columnName);
                if (cell != null) {
                    sToClipboard += cell.getClipboardText();
                }
            }
            if (sToClipboard.length() == 0) {
                return;
            }
            new Clipboard(Display.getDefault()).setContents(new Object[] { sToClipboard }, new Transfer[] { TextTransfer.getInstance() });
        }
    });
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TOTorrent(com.biglybt.core.torrent.TOTorrent) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File)

Example 78 with Transfer

use of org.eclipse.swt.dnd.Transfer in project BiglyBT by BiglySoftware.

the class ScrapeInfoView method initialize.

private void initialize(Composite parent) {
    cParent = parent;
    Label label;
    GridData gridData;
    final Display display = parent.getDisplay();
    if (cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
        cScrapeInfoView = new Composite(parent, SWT.NONE);
    }
    gridData = new GridData(GridData.FILL_BOTH);
    cScrapeInfoView.setLayoutData(gridData);
    GridLayout layoutInfo = new GridLayout();
    layoutInfo.numColumns = 4;
    cScrapeInfoView.setLayout(layoutInfo);
    label = new Label(cScrapeInfoView, SWT.LEFT);
    // $NON-NLS-1$
    Messages.setLanguageText(label, "GeneralView.label.trackerurl");
    label.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
    label.setForeground(display.getSystemColor(SWT.COLOR_LINK_FOREGROUND));
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            String announce = trackerUrlValue.getText();
            if (announce != null && announce.length() != 0) {
                new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
            }
        }

        @Override
        public void mouseDown(MouseEvent arg0) {
            String announce = trackerUrlValue.getText();
            if (announce != null && announce.length() != 0) {
                new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
            }
        }
    });
    menuTracker = new Menu(parent.getShell(), SWT.POP_UP);
    itemSelect = new MenuItem(menuTracker, SWT.CASCADE);
    Messages.setLanguageText(itemSelect, "GeneralView.menu.selectTracker");
    MenuItem itemEdit = new MenuItem(menuTracker, SWT.NULL);
    Messages.setLanguageText(itemEdit, "MyTorrentsView.menu.editTracker");
    cScrapeInfoView.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            menuTracker.dispose();
        }
    });
    itemEdit.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            final TOTorrent torrent = manager.getTorrent();
            if (torrent == null) {
                return;
            }
            List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
            new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {

                @Override
                public void trackersChanged(String str, String str2, List<List<String>> _group) {
                    TorrentUtils.listToAnnounceGroups(_group, torrent);
                    try {
                        TorrentUtils.writeToFile(torrent);
                    } catch (Throwable e2) {
                        Debug.printStackTrace(e2);
                    }
                    TRTrackerAnnouncer tc = manager.getTrackerClient();
                    if (tc != null) {
                        tc.resetTrackerUrl(true);
                    }
                }
            }, true, true);
        }
    });
    TOTorrent torrent = manager == null ? null : manager.getTorrent();
    itemEdit.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
    final Listener menuListener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (e.widget instanceof MenuItem) {
                String text = ((MenuItem) e.widget).getText();
                TOTorrent torrent = manager.getTorrent();
                TorrentUtils.announceGroupsSetFirst(torrent, text);
                try {
                    TorrentUtils.writeToFile(torrent);
                } catch (TOTorrentException f) {
                    Debug.printStackTrace(f);
                }
                TRTrackerAnnouncer tc = manager.getTrackerClient();
                if (tc != null) {
                    tc.resetTrackerUrl(false);
                }
            }
        }
    };
    menuTracker.addListener(SWT.Show, new Listener() {

        @Override
        public void handleEvent(Event e) {
            Menu menuSelect = itemSelect.getMenu();
            if (menuSelect != null && !menuSelect.isDisposed()) {
                menuSelect.dispose();
            }
            if (manager == null || cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
                return;
            }
            List<List<String>> groups = TorrentUtils.announceGroupsToList(manager.getTorrent());
            menuSelect = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
            itemSelect.setMenu(menuSelect);
            for (List<String> trackers : groups) {
                MenuItem menuItem = new MenuItem(menuSelect, SWT.CASCADE);
                Messages.setLanguageText(menuItem, "wizard.multitracker.group");
                Menu menu = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
                menuItem.setMenu(menu);
                for (String url : trackers) {
                    MenuItem menuItemTracker = new MenuItem(menu, SWT.CASCADE);
                    menuItemTracker.setText(url);
                    menuItemTracker.addListener(SWT.Selection, menuListener);
                }
            }
        }
    });
    trackerUrlValue = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 70);
    trackerUrlValue.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            if (event.button == 3 || (event.button == 1 && event.stateMask == SWT.CONTROL)) {
                menuTracker.setVisible(true);
            } else if (event.button == 1) {
                String url = trackerUrlValue.getText();
                if (url.startsWith("http://") || url.startsWith("https://")) {
                    int pos = -1;
                    if ((pos = url.indexOf("/announce")) != -1) {
                        url = url.substring(0, pos + 1);
                    }
                    Utils.launch(url);
                }
            }
        }
    });
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    trackerUrlValue.setLayoutData(gridData);
    // //////////////////////
    label = new Label(cScrapeInfoView, SWT.LEFT);
    Messages.setLanguageText(label, "GeneralView.label.tracker");
    tracker_status = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 150);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    tracker_status.setLayoutData(gridData);
    label = new Label(cScrapeInfoView, SWT.LEFT);
    Messages.setLanguageText(label, "GeneralView.label.updatein");
    trackerUpdateIn = new BufferedLabel(cScrapeInfoView, SWT.LEFT);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
    trackerUpdateIn.setLayoutData(gridData);
    updateButton = new Button(cScrapeInfoView, SWT.PUSH);
    Messages.setLanguageText(updateButton, "GeneralView.label.trackerurlupdate");
    updateButton.setLayoutData(new GridData());
    updateButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            new AEThread2("SIV:async") {

                @Override
                public void run() {
                    if (manager.getTrackerClient() != null) {
                        manager.requestTrackerAnnounce(false);
                    } else {
                        manager.requestTrackerScrape(true);
                    }
                }
            }.start();
        }
    });
    cScrapeInfoView.layout(true);
}
Also used : UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedTruncatedLabel(com.biglybt.ui.swt.components.BufferedTruncatedLabel) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) BufferedTruncatedLabel(com.biglybt.ui.swt.components.BufferedTruncatedLabel) GridLayout(org.eclipse.swt.layout.GridLayout) List(java.util.List) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) MultiTrackerEditor(com.biglybt.ui.swt.maketorrent.MultiTrackerEditor) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) GridData(org.eclipse.swt.layout.GridData) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 79 with Transfer

use of org.eclipse.swt.dnd.Transfer in project BiglyBT by BiglySoftware.

the class DebugMenuHelper method createDebugMenuItem.

/**
 * Creates the Debug menu and its children
 * NOTE: This is a development only menu and so it's not modularized into separate menu items
 * because this menu is always rendered in its entirety
 * @param menu
 * @param mainWindow
 * @return
 */
public static MenuItem createDebugMenuItem(final Menu menuDebug) {
    MenuItem item;
    final UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (null == uiFunctions) {
        throw new IllegalStateException("UIFunctionsManagerSWT.getUIFunctionsSWT() is returning null");
    }
    item = new MenuItem(menuDebug, SWT.PUSH);
    item.setText("Run GC");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            System.gc();
        }
    });
    item = new MenuItem(menuDebug, SWT.PUSH);
    item.setText("&CoreReq");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    new MessageBoxShell(0, "Done", "Core Now Avail").open(null);
                }
            });
        }
    });
    /*
		item = new MenuItem(menuDebug, SWT.CASCADE);
		item.setText("Subscriptions");
		Menu menuSubscriptions = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
		item.setMenu(menuSubscriptions);

		item = new MenuItem(menuSubscriptions, SWT.NONE);
		item.setText("Create RSS Feed");
		item.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				final Shell shell = new Shell(uiFunctions.getMainShell());
				shell.setLayout(new FormLayout());

				Label label = new Label(shell,SWT.NONE);
				label.setText("RSS Feed URL :");
				final Text urlText = new Text(shell,SWT.BORDER);
				urlText.setText(Utils.getLinkFromClipboard(shell.getDisplay(),false));
				Label separator = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
				Button cancel = new Button(shell,SWT.PUSH);
				cancel.setText("Cancel");
				Button ok = new Button(shell,SWT.PUSH);
				ok.setText("Ok");

				FormData data;

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(0,5);
				label.setLayoutData(data);

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(label);
				data.width = 400;
				urlText.setLayoutData(data);

				data = new FormData();
				data.left = new FormAttachment(0,5);
				data.right = new FormAttachment(100,-5);
				data.top = new FormAttachment(urlText);
				separator.setLayoutData(data);

				data = new FormData();
				data.right = new FormAttachment(ok);
				data.width = 100;
				data.top = new FormAttachment(separator);
				cancel.setLayoutData(data);

				data = new FormData();
				data.right = new FormAttachment(100,-5);
				data.width = 100;
				data.top = new FormAttachment(separator);
				ok.setLayoutData(data);

				cancel.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event arg0) {
						shell.dispose();
					}
				});

				ok.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event arg0) {
						String url_str = urlText.getText();
						shell.dispose();

						try{
							URL	url = new URL( url_str );

							SubscriptionManagerFactory.getSingleton().createSingletonRSS( url_str, url, 120, true );

						}catch( Throwable e ){

							Debug.printStackTrace(e);
						}
					}
				});

				shell.pack();


				Utils.centerWindowRelativeTo(shell, uiFunctions.getMainShell());

				shell.open();
				shell.setFocus();
				urlText.setFocus();


			}
		});
		 */
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("DW");
    Menu menuBrowserTB = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuBrowserTB);
    item = new MenuItem(menuBrowserTB, SWT.NONE);
    item.setText("popup check");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean oldDebug = DonationWindow.DEBUG;
            DonationWindow.DEBUG = true;
            DonationWindow.checkForDonationPopup();
            DonationWindow.DEBUG = oldDebug;
        }
    });
    item = new MenuItem(menuBrowserTB, SWT.NONE);
    item.setText("show");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean oldDebug = DonationWindow.DEBUG;
            DonationWindow.DEBUG = true;
            DonationWindow.open(true, "debug");
            DonationWindow.DEBUG = oldDebug;
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Alerts");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String text = "This is a  long message with lots of information and " + "stuff you really should read.  Are you still reading? Good, because " + "reading <a href=\"http://moo.com\">stimulates</a> the mind.\n\nYeah Baby.";
            LogAlert logAlert = new LogAlert(true, LogAlert.AT_INFORMATION, "Simple");
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_WARNING, text);
            logAlert.details = "Details: \n\n" + text;
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_ERROR, "ShortText");
            logAlert.details = "Details";
            Logger.log(logAlert);
            logAlert = new LogAlert(true, LogAlert.AT_WARNING, "Forced Alert");
            logAlert.forceNotify = true;
            logAlert.details = "Details: \n\n" + text;
            Logger.log(logAlert);
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("MsgBox");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            VuzeMessageBox box = new VuzeMessageBox("Title", "Text", new String[] { "Ok", "Cancel" }, 0);
            box.setListener(new VuzeMessageBoxListener() {

                @Override
                public void shellReady(Shell shell, SWTSkinObjectContainer soExtra) {
                    SWTSkin skin = soExtra.getSkin();
                    skin.createSkinObject("dlg.generic.test", "dlg.generic.test", soExtra);
                    skin.layout(soExtra);
                    shell.layout(true, true);
                }
            });
            box.open(null);
        }
    });
    item = new MenuItem(menuDebug, SWT.CASCADE);
    item.setText("Size");
    Menu menuSize = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
    item.setMenu(menuSize);
    int[] sizes = { 640, 430, 800, 550, 1024, 718, 1280, 700, 1440, 850, 1600, 1050, 1920, 1150 };
    for (int i = 0; i < sizes.length; i += 2) {
        final int x = sizes[i];
        final int y = sizes[i + 1];
        item = new MenuItem(menuSize, SWT.NONE);
        item.setText("" + x + "," + y);
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell().setSize(x, y);
            }
        });
    }
    item = new MenuItem(menuDebug, SWT.PUSH);
    item.setText("Dump UI");
    item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Utils.dump(uiFunctions.getMainShell());
        }
    });
    item = new MenuItem(menuDebug, SWT.NONE);
    item.setText("Obfuscated Shell Image");
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            Display display = Display.getCurrent();
            java.util.List<Image> shell_images = UIDebugGenerator.getShellImages();
            Image biggest_image = null;
            long biggest_area = 0;
            for (Image image : shell_images) {
                Shell shell2 = new Shell(display);
                Rectangle bounds = image.getBounds();
                long area = bounds.width * bounds.height;
                if (area > biggest_area) {
                    biggest_image = image;
                }
                Point size = shell2.computeSize(bounds.width, bounds.height);
                shell2.setSize(size);
                shell2.setBackgroundImage(image);
                shell2.open();
            }
            if (biggest_image != null) {
                new Clipboard(display).setContents(new Object[] { biggest_image.getImageData() }, new Transfer[] { ImageTransfer.getInstance() });
            }
        }
    });
    return item;
}
Also used : VuzeMessageBoxListener(com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ObfuscateShell(com.biglybt.ui.swt.debug.ObfuscateShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) CoreRunningListener(com.biglybt.core.CoreRunningListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Core(com.biglybt.core.Core) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) Transfer(org.eclipse.swt.dnd.Transfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VuzeMessageBoxListener(com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener) Clipboard(org.eclipse.swt.dnd.Clipboard) VuzeMessageBox(com.biglybt.ui.swt.views.skin.VuzeMessageBox)

Example 80 with Transfer

use of org.eclipse.swt.dnd.Transfer in project BiglyBT by BiglySoftware.

the class ClipboardCopy method addCopyToClipMenu.

public static void addCopyToClipMenu(final Menu menu, final String text) {
    for (MenuItem e : menu.getItems()) {
        if (e.getData(MENU_ITEM_KEY) != null) {
            e.dispose();
        }
    }
    MenuItem item = new MenuItem(menu, SWT.NONE);
    item.setData(MENU_ITEM_KEY, "");
    String msg_text_id = "label.copy.to.clipboard";
    item.setText(MessageText.getString(msg_text_id));
    item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            new Clipboard(menu.getDisplay()).setContents(new Object[] { text }, new Transfer[] { TextTransfer.getInstance() });
        }
    });
}
Also used : Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) MenuItem(org.eclipse.swt.widgets.MenuItem) AERunnableObject(com.biglybt.core.util.AERunnableObject) Clipboard(org.eclipse.swt.dnd.Clipboard)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)151 TextTransfer (org.eclipse.swt.dnd.TextTransfer)71 Point (org.eclipse.swt.graphics.Point)63 Clipboard (org.eclipse.swt.dnd.Clipboard)51 Menu (org.eclipse.swt.widgets.Menu)37 IMenuManager (org.eclipse.jface.action.IMenuManager)32 MenuManager (org.eclipse.jface.action.MenuManager)32 Separator (org.eclipse.jface.action.Separator)32 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)32 EditingDomainViewerDropAdapter (org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter)30 LocalTransfer (org.eclipse.emf.edit.ui.dnd.LocalTransfer)30 ViewerDragAdapter (org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter)30 UnwrappingSelectionProvider (org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider)30 FileTransfer (org.eclipse.swt.dnd.FileTransfer)30 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)27 DropTarget (org.eclipse.swt.dnd.DropTarget)23 GridData (org.eclipse.swt.layout.GridData)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 Composite (org.eclipse.swt.widgets.Composite)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)20