Search in sources :

Example 91 with PaintEvent

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

the class SBC_LibraryView method skinObjectInitialShow.

// @see SkinView#showSupport(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(final SWTSkinObject skinObject, Object params) {
    selectedContentListener = new SelectedContentListener() {

        @Override
        public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewId) {
            selection_count = currentContent.length;
            long total_size = 0;
            long total_done = 0;
            List<DownloadManager> dms = new ArrayList<>(currentContent.length);
            // doesn't make sense to double count a download's files if it also has its own selection
            Set<DownloadManager> dms_only = new IdentityHashSet<>();
            for (ISelectedContent sc : currentContent) {
                DownloadManager dm = sc.getDownloadManager();
                if (dm != null) {
                    int file_index = sc.getFileIndex();
                    if (file_index == -1) {
                        dms_only.add(dm);
                    }
                }
            }
            for (ISelectedContent sc : currentContent) {
                DownloadManager dm = sc.getDownloadManager();
                if (dm != null) {
                    dms.add(dm);
                    int file_index = sc.getFileIndex();
                    if (file_index == -1) {
                        DiskManagerFileInfo[] file_infos = dm.getDiskManagerFileInfoSet().getFiles();
                        for (DiskManagerFileInfo file_info : file_infos) {
                            if (!file_info.isSkipped()) {
                                total_size += file_info.getLength();
                                total_done += file_info.getDownloaded();
                            }
                        }
                    } else {
                        if (!dms_only.contains(dm)) {
                            DiskManagerFileInfo file_info = dm.getDiskManagerFileInfoSet().getFiles()[file_index];
                            if (!file_info.isSkipped()) {
                                total_size += file_info.getLength();
                                total_done += file_info.getDownloaded();
                            }
                        }
                    }
                }
            }
            selection_size = total_size;
            selection_done = total_done;
            selection_dms = dms.toArray(new DownloadManager[dms.size()]);
            SB_Transfers transfers = MainMDISetup.getSb_transfers();
            if (transfers != null) {
                transfers.triggerCountRefreshListeners();
            }
        }
    };
    SelectedContentManager.addCurrentlySelectedContentListener(selectedContentListener);
    soWait = null;
    try {
        soWait = getSkinObject("library-wait");
        soWaitProgress = getSkinObject("library-wait-progress");
        soWaitTask = (SWTSkinObjectText) getSkinObject("library-wait-task");
        if (soWaitProgress != null) {
            soWaitProgress.getControl().addPaintListener(new PaintListener() {

                @Override
                public void paintControl(PaintEvent e) {
                    assert e != null;
                    Control c = (Control) e.widget;
                    Point size = c.getSize();
                    e.gc.setBackground(ColorCache.getColor(e.display, "#23a7df"));
                    int breakX = size.x * waitProgress / 100;
                    e.gc.fillRectangle(0, 0, breakX, size.y);
                    e.gc.setBackground(ColorCache.getColor(e.display, "#cccccc"));
                    e.gc.fillRectangle(breakX, 0, size.x - breakX, size.y);
                }
            });
        }
        soLibraryInfo = (SWTSkinObjectText) getSkinObject("library-info");
        if (soLibraryInfo != null) {
            MainMDISetup.getSb_transfers().addCountRefreshListener(new SB_Transfers.countRefreshListener() {

                final Map<Composite, ExtraInfoProvider> extra_info_map = new HashMap<>();

                {
                    soLibraryInfo.getControl().getParent().setData("ViewUtils:ViewTitleExtraInfo", new ViewUtils.ViewTitleExtraInfo() {

                        @Override
                        public void setCountProvider(Composite reporter, CountProvider cp) {
                            ExtraInfoProvider provider = getProvider(reporter);
                            if (provider == null) {
                                return;
                            }
                            provider.countProvider = cp;
                        }

                        @Override
                        public void searchUpdate(Composite reporter, int count, int active) {
                            ExtraInfoProvider provider = getProvider(reporter);
                            if (provider == null) {
                                return;
                            }
                            if (provider.value != count || provider.active != active) {
                                provider.value = count;
                                provider.active = active;
                                if (viewMode == provider.view_mode && provider.search_active) {
                                    SB_Transfers xfers = MainMDISetup.getSb_transfers();
                                    if (xfers != null) {
                                        xfers.triggerCountRefreshListeners();
                                    }
                                }
                            }
                        }

                        @Override
                        public void setSearchActive(Composite reporter, boolean active) {
                            ExtraInfoProvider provider = getProvider(reporter);
                            if (provider == null) {
                                return;
                            }
                            if (provider.search_active != active) {
                                provider.search_active = active;
                                if (viewMode == provider.view_mode) {
                                    MainMDISetup.getSb_transfers().triggerCountRefreshListeners();
                                }
                            }
                        }

                        private ExtraInfoProvider getProvider(Composite reporter) {
                            synchronized (extra_info_map) {
                                ExtraInfoProvider provider = extra_info_map.get(reporter);
                                if (provider != null) {
                                    return (provider);
                                }
                                Composite temp = reporter;
                                while (temp != null) {
                                    Integer vm = (Integer) temp.getData("SBC_LibraryView:ViewMode");
                                    if (vm != null) {
                                        provider = new ExtraInfoProvider(vm);
                                        extra_info_map.put(reporter, provider);
                                        return (provider);
                                    }
                                    temp = temp.getParent();
                                }
                                Debug.out("No view mode found for " + reporter);
                                return (null);
                            }
                        }
                    });
                }

                // @see SBC_LibraryView.countRefreshListener#countRefreshed(SBC_LibraryView.stats, SBC_LibraryView.stats)
                @Override
                public void countRefreshed(SB_Transfers.stats statsWithLowNoise, SB_Transfers.stats statsNoLowNoise) {
                    SB_Transfers.stats stats = viewMode == MODE_SMALLTABLE ? statsWithLowNoise : statsNoLowNoise;
                    String s;
                    List<ViewUtils.ViewTitleExtraInfo.CountProvider> count_provs = new ArrayList<>();
                    int filter_total = 0;
                    int filter_active = 0;
                    boolean filter_enabled = false;
                    synchronized (extra_info_map) {
                        for (ExtraInfoProvider provider : extra_info_map.values()) {
                            if (viewMode == provider.view_mode) {
                                if (provider.search_active) {
                                    filter_enabled = true;
                                    filter_total += provider.value;
                                    filter_active += provider.active;
                                }
                                ViewUtils.ViewTitleExtraInfo.CountProvider cp = provider.countProvider;
                                if (cp != null) {
                                    count_provs.add(cp);
                                }
                            }
                        }
                    }
                    int extra_total = 0;
                    int extra_active = 0;
                    int extra_queued = 0;
                    for (ViewUtils.ViewTitleExtraInfo.CountProvider cp : count_provs) {
                        int[] counts = cp.getCounts();
                        extra_total += counts[0];
                        extra_active += counts[1];
                        extra_queued += counts[2];
                    }
                    String extra_search = null;
                    if (filter_enabled) {
                        extra_search = MessageText.getString("filter.header.matches2", new String[] { String.valueOf(filter_total), String.valueOf(filter_active) });
                    }
                    if (torrentFilterMode == TORRENTS_ALL || (datasource instanceof Tag)) {
                        boolean addExtra = false;
                        if (datasource instanceof Category) {
                            Category cat = (Category) datasource;
                            String id = "library.category.header";
                            s = MessageText.getString(id, new String[] { (cat.getType() != Category.TYPE_USER) ? MessageText.getString(cat.getName()) : cat.getName() });
                            addExtra = true;
                        } else if (datasource instanceof Tag) {
                            Tag tag = (Tag) datasource;
                            String id = "library.tag.header";
                            s = MessageText.getString(id, new String[] { tag.getTagName(true) });
                            String desc = tag.getDescription();
                            if (desc != null) {
                                s += " - " + desc;
                            }
                            addExtra = true;
                        } else if (datasource instanceof TagGroup) {
                            String id = "library.taggroup.header";
                            TagGroup tg = (TagGroup) datasource;
                            s = MessageText.getString(id, new String[] { tg.getName(), String.valueOf(tg.getTags().size()) });
                            addExtra = true;
                        } else {
                            String id = "library.all.header";
                            if (stats.numComplete + stats.numIncomplete != 1) {
                                id += ".p";
                            }
                            s = MessageText.getString(id, new String[] { String.valueOf(stats.numComplete + stats.numIncomplete), String.valueOf(stats.numSeeding + stats.numDownloading) });
                            if (stats.numQueued > 0) {
                                s += ", " + MessageText.getString("label.num_queued", new String[] { String.valueOf(stats.numQueued) });
                            }
                        }
                        if (addExtra) {
                            String id = "library.all.header";
                            if (extra_total != 1) {
                                id += ".p";
                            }
                            s += " - " + MessageText.getString(id, new String[] { String.valueOf(extra_total), String.valueOf(extra_active) });
                            if (extra_queued > 0) {
                                s += ", " + MessageText.getString("label.num_queued", new String[] { String.valueOf(extra_queued) });
                            }
                        }
                    } else if (torrentFilterMode == TORRENTS_INCOMPLETE) {
                        String id = "library.incomplete.header";
                        if (stats.numDownloading != 1) {
                            id += ".p";
                        }
                        int numWaiting = Math.max(stats.numIncomplete - stats.numDownloading, 0);
                        s = MessageText.getString(id, new String[] { String.valueOf(stats.numDownloading), String.valueOf(numWaiting) });
                    } else if (torrentFilterMode == TORRENTS_UNOPENED || torrentFilterMode == TORRENTS_COMPLETE) {
                        // complete filtering currently uses same display text as unopened
                        String id = "library.unopened.header";
                        if (stats.numUnOpened != 1) {
                            id += ".p";
                        }
                        s = MessageText.getString(id, new String[] { String.valueOf(stats.numUnOpened) });
                    } else {
                        s = "";
                    }
                    if (extra_search != null) {
                        s += " " + extra_search;
                    }
                    SB_Transfers transfers = MainMDISetup.getSb_transfers();
                    if (selection_count > 1) {
                        s += ", " + MessageText.getString("label.num_selected", new String[] { String.valueOf(selection_count) });
                        String size_str = null;
                        String rate_str = null;
                        if (selection_size > 0) {
                            if (selection_size == selection_done) {
                                size_str = DisplayFormatters.formatByteCountToKiBEtc(selection_size);
                            } else {
                                size_str = DisplayFormatters.formatByteCountToKiBEtc(selection_done) + "/" + DisplayFormatters.formatByteCountToKiBEtc(selection_size);
                            }
                        }
                        DownloadManager[] dms = selection_dms;
                        if (transfers.header_show_rates && dms.length > 1) {
                            long total_data_up = 0;
                            long total_prot_up = 0;
                            long total_data_down = 0;
                            long total_prot_down = 0;
                            for (DownloadManager dm : dms) {
                                DownloadManagerStats dm_stats = dm.getStats();
                                total_prot_up += dm_stats.getProtocolSendRate();
                                total_data_up += dm_stats.getDataSendRate();
                                total_prot_down += dm_stats.getProtocolReceiveRate();
                                total_data_down += dm_stats.getDataReceiveRate();
                            }
                            rate_str = MessageText.getString("ConfigView.download.abbreviated") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(total_data_down, total_prot_down) + " " + MessageText.getString("ConfigView.upload.abbreviated") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(total_data_up, total_prot_up);
                        }
                        if (size_str != null || rate_str != null) {
                            String temp;
                            if (size_str == null) {
                                temp = rate_str;
                            } else if (rate_str == null) {
                                temp = size_str;
                            } else {
                                temp = size_str + "; " + rate_str;
                            }
                            s += " (" + temp + ")";
                        }
                    }
                    if (transfers.header_show_uptime && transfers.totalStats != null) {
                        long up_secs = (transfers.totalStats.getSessionUpTime() / 60) * 60;
                        String op;
                        if (up_secs < 60) {
                            up_secs = 60;
                            op = "<";
                        } else {
                            op = " ";
                        }
                        String up_str = TimeFormatter.format2(up_secs, false);
                        if (s.equals("")) {
                            Debug.out("eh");
                        }
                        s += "; " + MessageText.getString("label.uptime_coarse", new String[] { op, up_str });
                    }
                    soLibraryInfo.setText(s);
                }

                class ExtraInfoProvider {

                    int view_mode;

                    ViewUtils.ViewTitleExtraInfo.CountProvider countProvider;

                    boolean search_active;

                    int value;

                    int active;

                    private ExtraInfoProvider(int vm) {
                        view_mode = vm;
                    }
                }
            });
        }
    } catch (Exception ignored) {
    }
    // Core core = CoreFactory.getSingleton();
    if (!CoreFactory.isCoreRunning()) {
        if (soWait != null) {
            soWait.setVisible(true);
        // soWait.getControl().getParent().getParent().getParent().layout(true, true);
        }
        final Initializer initializer = Initializer.getLastInitializer();
        if (initializer != null) {
            initializer.addListener(new InitializerListener() {

                @Override
                public void reportPercent(final int percent) {
                    Utils.execSWTThread(new AERunnable() {

                        @Override
                        public void runSupport() {
                            if (soWaitProgress != null && !soWaitProgress.isDisposed()) {
                                waitProgress = percent;
                                soWaitProgress.getControl().redraw();
                                soWaitProgress.getControl().update();
                            }
                        }
                    });
                    if (percent > 100) {
                        initializer.removeListener(this);
                    }
                }

                @Override
                public void reportCurrentTask(String currentTask) {
                    if (soWaitTask != null && !soWaitTask.isDisposed()) {
                        soWaitTask.setText(currentTask);
                    }
                }
            });
        }
    }
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(final Core core) {
            PluginInterface pi = PluginInitializer.getDefaultInterface();
            final UIManager uim = pi.getUIManager();
            uim.addUIListener(new UIManagerListener() {

                @Override
                public void UIDetached(UIInstance instance) {
                }

                @Override
                public void UIAttached(UIInstance instance) {
                    if (instance instanceof UISWTInstance) {
                        uim.removeUIListener(this);
                        Utils.execSWTThread(new AERunnable() {

                            @Override
                            public void runSupport() {
                                if (soWait != null) {
                                    soWait.setVisible(false);
                                }
                                if (!skinObject.isDisposed()) {
                                    setupView(core, skinObject);
                                }
                            }
                        });
                    }
                }
            });
        }
    });
    return null;
}
Also used : Category(com.biglybt.core.category.Category) UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) ViewUtils(com.biglybt.ui.swt.views.ViewUtils) Control(org.eclipse.swt.widgets.Control) CoreRunningListener(com.biglybt.core.CoreRunningListener) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) UIInstance(com.biglybt.pif.ui.UIInstance) Core(com.biglybt.core.Core) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) TagGroup(com.biglybt.core.tag.TagGroup) PluginInterface(com.biglybt.pif.PluginInterface) SelectedContentListener(com.biglybt.ui.selectedcontent.SelectedContentListener) InitializerListener(com.biglybt.ui.InitializerListener) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) PluginInitializer(com.biglybt.pifimpl.local.PluginInitializer) Initializer(com.biglybt.ui.swt.Initializer) Tag(com.biglybt.core.tag.Tag) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener)

Example 92 with PaintEvent

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

the class PeerInfoView method createPeerInfoPanel.

private Composite createPeerInfoPanel(Composite parent) {
    GridLayout layout;
    GridData gridData;
    // Peer Info section contains
    // - Peer's Block display
    // - Peer's Datarate
    peerInfoComposite = new Composite(parent, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    peerInfoComposite.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    peerInfoComposite.setLayoutData(gridData);
    imageLabel = new Label(peerInfoComposite, SWT.NULL);
    gridData = new GridData();
    if (ImageRepository.hasCountryFlags(false) || countryLocator != null)
        gridData.widthHint = 28;
    imageLabel.setLayoutData(gridData);
    topLabel = new Label(peerInfoComposite, SWT.NULL);
    gridData = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
    topLabel.setLayoutData(gridData);
    sc = new ScrolledComposite(peerInfoComposite, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    sc.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
    sc.setLayoutData(gridData);
    sc.getVerticalBar().setIncrement(BLOCK_SIZE);
    peerInfoCanvas = new Canvas(sc, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL, SWT.DEFAULT, true, false);
    peerInfoCanvas.setLayoutData(gridData);
    peerInfoCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (e.width <= 0 || e.height <= 0)
                return;
            try {
                Rectangle bounds = (img == null) ? null : img.getBounds();
                if (bounds == null) {
                    e.gc.fillRectangle(e.x, e.y, e.width, e.height);
                } else {
                    if (e.x + e.width > bounds.width)
                        e.gc.fillRectangle(bounds.width, e.y, e.x + e.width - bounds.width + 1, e.height);
                    if (e.y + e.height > bounds.height)
                        e.gc.fillRectangle(e.x, bounds.height, e.width, e.y + e.height - bounds.height + 1);
                    int width = Math.min(e.width, bounds.width - e.x);
                    int height = Math.min(e.height, bounds.height - e.y);
                    e.gc.drawImage(img, e.x, e.y, width, height, e.x, e.y, width, height);
                }
            } catch (Exception ex) {
            }
        }
    });
    Listener doNothingListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
        }
    };
    peerInfoCanvas.addListener(SWT.KeyDown, doNothingListener);
    peerInfoCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (refreshInfoCanvasQueued || !peerInfoCanvas.isVisible()) {
                return;
            }
            // wrap in asyncexec because sc.setMinWidth (called later) doesn't work
            // too well inside a resize (the canvas won't size isn't always updated)
            Utils.execSWTThreadLater(100, new AERunnable() {

                @Override
                public void runSupport() {
                    if (refreshInfoCanvasQueued) {
                        return;
                    }
                    refreshInfoCanvasQueued = true;
                    if (img != null) {
                        int iOldColCount = img.getBounds().width / BLOCK_SIZE;
                        int iNewColCount = peerInfoCanvas.getClientArea().width / BLOCK_SIZE;
                        if (iOldColCount != iNewColCount)
                            refreshInfoCanvas();
                    }
                }
            });
        }
    });
    sc.setContent(peerInfoCanvas);
    Legend.createLegendComposite(peerInfoComposite, blockColors, new String[] { "PeersView.BlockView.Avail.Have", "PeersView.BlockView.Avail.NoHave", "PeersView.BlockView.NoAvail.Have", "PeersView.BlockView.NoAvail.NoHave", "PeersView.BlockView.Transfer", "PeersView.BlockView.NextRequest", "PeersView.BlockView.AvailCount" }, new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
    font = FontUtils.getFontPercentOf(peerInfoCanvas.getFont(), 0.7f);
    return peerInfoComposite;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PaintListener(org.eclipse.swt.events.PaintListener) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) LogEvent(com.biglybt.core.logging.LogEvent)

Example 93 with PaintEvent

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

the class PingGraphic method initialize.

@Override
public void initialize(Canvas canvas) {
    super.initialize(canvas);
    drawCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (bufferImage != null && !bufferImage.isDisposed()) {
                Rectangle bounds = bufferImage.getBounds();
                if (bounds.width >= (e.width + e.x) && bounds.height >= (e.height + e.y)) {
                    e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
                }
            }
        }
    });
    drawCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            drawChart(true);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ParameterListener(com.biglybt.core.config.ParameterListener) Listener(org.eclipse.swt.widgets.Listener) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent)

Example 94 with PaintEvent

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

the class SpeedGraphic method initialize.

@Override
public void initialize(Canvas canvas) {
    super.initialize(canvas);
    drawCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (bufferImage != null && !bufferImage.isDisposed()) {
                Rectangle bounds = bufferImage.getBounds();
                if (bounds.width >= (e.width + e.x) && bounds.height >= (e.height + e.y)) {
                    e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
                }
            }
        }
    });
    drawCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            drawChart(true);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ParameterListener(com.biglybt.core.config.ParameterListener) Listener(org.eclipse.swt.widgets.Listener) PaintListener(org.eclipse.swt.events.PaintListener) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent)

Example 95 with PaintEvent

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

the class PeersGraphicView method initialize.

protected void initialize(Composite composite) {
    display = composite.getDisplay();
    canvas = new Canvas(composite, SWT.NO_BACKGROUND);
    canvas.addListener(SWT.MouseHover, new Listener() {

        @Override
        public void handleEvent(Event event) {
            int x = event.x;
            int y = event.y;
            String tt = "";
            synchronized (dm_data_lock) {
                for (ManagerData data : dm_data) {
                    DownloadManager manager = data.manager;
                    if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
                        if (always_show_dm_name || dm_data.length > 1) {
                            tt = manager.getDisplayName() + "\r\n";
                        }
                        tt += DisplayFormatters.formatDownloadStatus(manager) + ", " + DisplayFormatters.formatPercentFromThousands(manager.getStats().getCompleted());
                        break;
                    } else {
                        PEPeer target = null;
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                target = entry.getKey();
                                break;
                            }
                        }
                        if (target != null) {
                            PEPeerStats stats = target.getStats();
                            String[] details = PeerUtils.getCountryDetails(target);
                            String dstr = (details == null || details.length < 2) ? "" : (" - " + details[0] + "/" + details[1]);
                            /*
							if ( dm_map.size() > 1 ){

								tt = manager.getDisplayName() + "\r\n";
							}
							*/
                            tt = target.getIp() + dstr + ", " + DisplayFormatters.formatPercentFromThousands(target.getPercentDoneInThousandNotation()) + "\r\n" + "Up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", " + "Down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate());
                            break;
                        }
                    }
                }
            }
            Utils.setTT(canvas, tt);
        }
    });
    canvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent event) {
            if (event.button == 3) {
                int x = event.x;
                int y = event.y;
                PEPeer target = null;
                DownloadManager target_manager = null;
                synchronized (dm_data_lock) {
                    for (ManagerData data : dm_data) {
                        DownloadManager manager = data.manager;
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                target = entry.getKey();
                                target_manager = manager;
                                break;
                            }
                        }
                        if (target != null) {
                            break;
                        }
                    }
                }
                if (target == null) {
                    return;
                }
                Menu menu = canvas.getMenu();
                if (menu != null && !menu.isDisposed()) {
                    menu.dispose();
                }
                menu = new Menu(canvas);
                PeersViewBase.fillMenu(menu, target, target_manager);
                final Point cursorLocation = Display.getCurrent().getCursorLocation();
                menu.setLocation(cursorLocation.x, cursorLocation.y);
                menu.setVisible(true);
            }
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            int x = event.x;
            int y = event.y;
            synchronized (dm_data_lock) {
                for (ManagerData data : dm_data) {
                    DownloadManager manager = data.manager;
                    if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
                        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                        if (uiFunctions != null) {
                            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
                        }
                    } else {
                        for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
                            int[] loc = entry.getValue();
                            int loc_x = loc[0];
                            int loc_y = loc[1];
                            if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
                                PEPeer target = entry.getKey();
                                try {
                                    MdiEntry mdi_entry = UIFunctionsManager.getUIFunctions().getMDI().getEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
                                    if (mdi_entry != null) {
                                        mdi_entry.setDatasource(new Object[] { manager });
                                    }
                                    Composite comp = canvas.getParent();
                                    while (comp != null) {
                                        if (comp instanceof CTabFolder) {
                                            CTabFolder tf = (CTabFolder) comp;
                                            CTabItem[] items = tf.getItems();
                                            for (CTabItem item : items) {
                                                UISWTViewCore view = (UISWTViewCore) item.getData("TabbedEntry");
                                                UISWTViewEventListener listener = view.getEventListener();
                                                if (listener instanceof PeersView) {
                                                    tf.setSelection(item);
                                                    Event ev = new Event();
                                                    ev.item = item;
                                                    // manual setSelection doesn't file selection event - derp
                                                    tf.notifyListeners(SWT.Selection, ev);
                                                    ((PeersView) listener).selectPeer(target);
                                                    return;
                                                }
                                            }
                                        }
                                        comp = comp.getParent();
                                    }
                                } catch (Throwable e) {
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    });
    // without this we get a transient blank when mousing in and out of the tab folder on OSX :(
    canvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (img != null && !img.isDisposed()) {
                Rectangle bounds = img.getBounds();
                if (bounds.width >= (e.width + e.x) && bounds.height >= (e.height + e.y)) {
                    e.gc.drawImage(img, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
                }
            } else {
                e.gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
        }
    });
    canvas.addListener(SWT.Dispose, (ev) -> {
        if (img != null && !img.isDisposed()) {
            img.dispose();
            img = null;
        }
    });
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) Listener(org.eclipse.swt.widgets.Listener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) DownloadManagerPeerListener(com.biglybt.core.download.DownloadManagerPeerListener) CTabFolder(org.eclipse.swt.custom.CTabFolder) Rectangle(org.eclipse.swt.graphics.Rectangle) PEPeerStats(com.biglybt.core.peer.PEPeerStats) DownloadManager(com.biglybt.core.download.DownloadManager) CTabItem(org.eclipse.swt.custom.CTabItem) MdiEntry(com.biglybt.ui.mdi.MdiEntry) UIFunctions(com.biglybt.ui.UIFunctions) MdiEntry(com.biglybt.ui.mdi.MdiEntry) Menu(org.eclipse.swt.widgets.Menu) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent)

Aggregations

PaintEvent (org.eclipse.swt.events.PaintEvent)96 PaintListener (org.eclipse.swt.events.PaintListener)92 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 MouseEvent (org.eclipse.swt.events.MouseEvent)27 GridData (org.eclipse.swt.layout.GridData)26 Point (org.eclipse.swt.graphics.Point)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 DisposeEvent (org.eclipse.swt.events.DisposeEvent)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 DisposeListener (org.eclipse.swt.events.DisposeListener)15 FillLayout (org.eclipse.swt.layout.FillLayout)15 Event (org.eclipse.swt.widgets.Event)15 MouseAdapter (org.eclipse.swt.events.MouseAdapter)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 ControlEvent (org.eclipse.swt.events.ControlEvent)12 Control (org.eclipse.swt.widgets.Control)12 GC (org.eclipse.swt.graphics.GC)11 Listener (org.eclipse.swt.widgets.Listener)11