Search in sources :

Example 1 with BufferedTruncatedLabel

use of com.biglybt.ui.swt.components.BufferedTruncatedLabel 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(Colors.blue);
    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)

Aggregations

TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1 BufferedTruncatedLabel (com.biglybt.ui.swt.components.BufferedTruncatedLabel)1 MultiTrackerEditor (com.biglybt.ui.swt.maketorrent.MultiTrackerEditor)1 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)1 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)1 UISWTViewCoreEventListener (com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener)1 List (java.util.List)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 Transfer (org.eclipse.swt.dnd.Transfer)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1