Search in sources :

Example 26 with PEPeerManager

use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.

the class GeneralView method refresh.

public void refresh() {
    if (gFile == null || gFile.isDisposed() || manager == null)
        return;
    loopFactor++;
    if ((loopFactor % graphicsUpdate) == 0) {
        updateAvailability();
        availabilityImage.redraw();
        updatePiecesInfo(false);
        piecesImage.redraw();
    }
    DiskManager dm = manager.getDiskManager();
    String remaining;
    String eta = DisplayFormatters.formatETA(manager.getStats().getSmoothedETA());
    if (dm != null) {
        long rem = dm.getRemainingExcludingDND();
        String data_rem = DisplayFormatters.formatByteCountToKiBEtc(rem);
        if (rem > 0) {
            remaining = eta + (eta.length() == 0 ? "" : " ") + data_rem;
        } else {
            if (eta.length() == 0) {
                remaining = data_rem;
            } else {
                remaining = eta;
            }
        }
    } else {
        // only got eta value, just use that
        remaining = eta;
    }
    setTime(manager.getStats().getElapsedTime(), remaining);
    TRTrackerScraperResponse hd = manager.getTrackerScrapeResponse();
    String seeds_str = manager.getNbSeeds() + " " + MessageText.getString("GeneralView.label.connected");
    String peers_str = manager.getNbPeers() + " " + MessageText.getString("GeneralView.label.connected");
    String completed;
    if (hd != null && hd.isValid()) {
        seeds_str += " ( " + hd.getSeeds() + " " + MessageText.getString("GeneralView.label.in_swarm") + " )";
        peers_str += " ( " + hd.getPeers() + " " + MessageText.getString("GeneralView.label.in_swarm") + " )";
        completed = hd.getCompleted() > -1 ? Integer.toString(hd.getCompleted()) : "?";
    } else {
        completed = "?";
    }
    String _shareRatio = "";
    int sr = manager.getStats().getShareRatio();
    if (sr == -1)
        _shareRatio = Constants.INFINITY_STRING;
    if (sr > 0) {
        String partial = "" + sr % 1000;
        while (partial.length() < 3) partial = "0" + partial;
        _shareRatio = (sr / 1000) + "." + partial;
    }
    DownloadManagerStats stats = manager.getStats();
    String swarm_speed = DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getTotalAverage()) + " ( " + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getTotalAveragePerPeer()) + " " + MessageText.getString("GeneralView.label.averagespeed") + " )";
    String swarm_completion = "";
    String distributedCopies = "0.000";
    String piecesDoneAndSum = "" + manager.getNbPieces();
    PEPeerManager pm = manager.getPeerManager();
    if (pm != null) {
        int comp = pm.getAverageCompletionInThousandNotation();
        if (comp >= 0) {
            swarm_completion = DisplayFormatters.formatPercentFromThousands(comp);
        }
        piecesDoneAndSum = pm.getPiecePicker().getNbPiecesDone() + "/" + piecesDoneAndSum;
        distributedCopies = new DecimalFormat("0.000").format(pm.getPiecePicker().getMinAvailability() - pm.getNbSeeds() - (pm.isSeeding() && stats.getDownloadCompleted(false) == 1000 ? 1 : 0));
    }
    int kInB = DisplayFormatters.getKinB();
    setStats(DisplayFormatters.formatDownloaded(stats), DisplayFormatters.formatByteCountToKiBEtc(stats.getTotalDataBytesSent()), DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate()), DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate()), swarm_speed, "" + manager.getStats().getDownloadRateLimitBytesPerSecond() / kInB, "" + (manager.getStats().getUploadRateLimitBytesPerSecond() / kInB), seeds_str, peers_str, completed, DisplayFormatters.formatHashFails(manager), _shareRatio, swarm_completion, distributedCopies);
    TOTorrent torrent = manager.getTorrent();
    String creation_date = DisplayFormatters.formatDate(manager.getTorrentCreationDate() * 1000);
    byte[] created_by = torrent == null ? null : torrent.getCreatedBy();
    if (created_by != null) {
        try {
            creation_date = MessageText.getString("GeneralView.torrent_created_on_and_by", new String[] { creation_date, new String(created_by, Constants.DEFAULT_ENCODING) });
        } catch (java.io.UnsupportedEncodingException e) {
        /* forget it */
        }
    }
    setInfos(manager.getDisplayName(), DisplayFormatters.formatByteCountToKiBEtc(manager.getSize()), DisplayFormatters.formatDownloadStatus(manager), manager.getState() == DownloadManager.STATE_ERROR, manager.getSaveLocation().toString(), TorrentUtils.nicePrintTorrentHash(torrent), piecesDoneAndSum, manager.getPieceLength(), manager.getTorrentComment(), creation_date, manager.getDownloadState().getUserComment(), MessageText.getString("GeneralView." + (torrent != null && torrent.getPrivate() ? "yes" : "no")));
    // the initial layout fails.
    if (loopFactor == 2) {
        getComposite().layout(true);
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) DecimalFormat(java.text.DecimalFormat) TOTorrent(com.biglybt.core.torrent.TOTorrent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) DiskManager(com.biglybt.core.disk.DiskManager)

Example 27 with PEPeerManager

use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.

the class PeersViewBase method updateSwarmPeers.

private void updateSwarmPeers() {
    if (peers_changed) {
        Utils.execSWTThread(new Runnable() {

            public void run() {
                peers_changed = false;
                GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                List<PEPeer> peers = tv.getDataSources();
                swarm_peers = new HashSet<>(peers);
                final Map<PEPeerManager, int[]> done_pms = new HashMap<>();
                List<DownloadManager> dms = new ArrayList<>();
                for (PEPeer peer : peers) {
                    PEPeerManager pm = peer.getManager();
                    int[] count = done_pms.get(pm);
                    if (count == null) {
                        done_pms.put(pm, new int[] { 1 });
                        byte[] hash = pm.getHash();
                        DownloadManager dm = gm.getDownloadManager(new HashWrapper(hash));
                        if (dm != null) {
                            dms.add(dm);
                        }
                    } else {
                        count[0]++;
                    }
                }
                Collections.sort(dms, new Comparator<DownloadManager>() {

                    @Override
                    public int compare(DownloadManager o1, DownloadManager o2) {
                        PEPeerManager pm1 = o1.getPeerManager();
                        PEPeerManager pm2 = o2.getPeerManager();
                        int[] c1 = done_pms.get(pm1);
                        int[] c2 = done_pms.get(pm2);
                        int n1 = c1 == null ? 0 : c1[0];
                        int n2 = c2 == null ? 0 : c2[0];
                        return (n2 - n1);
                    }
                });
                swarm_view.dataSourceChanged(dms.toArray(new DownloadManager[dms.size()]));
            }
        });
    }
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) DownloadManager(com.biglybt.core.download.DownloadManager) Comparator(java.util.Comparator) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) ArrayList(java.util.ArrayList) List(java.util.List) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Map(java.util.Map) HashMap(java.util.HashMap) IdentityHashSet(com.biglybt.core.util.IdentityHashSet) HashSet(java.util.HashSet)

Example 28 with PEPeerManager

use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.

the class PeersViewBase method fillMenu.

private static void fillMenu(final Menu menu, final PEPeer[] peers, final Shell shell, DownloadManager download_specific) {
    boolean hasSelection = (peers.length > 0);
    boolean downSpeedDisabled = false;
    boolean downSpeedUnlimited = false;
    long totalDownSpeed = 0;
    long downSpeedSetMax = 0;
    long maxDown = 0;
    boolean upSpeedDisabled = false;
    boolean upSpeedUnlimited = false;
    long totalUpSpeed = 0;
    long upSpeedSetMax = 0;
    long maxUp = 0;
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    final IdentityHashSet<DownloadManager> download_managers = new IdentityHashSet<>();
    Map<PEPeer, DownloadManager> peer_dm_map = new HashMap<>();
    if (hasSelection) {
        for (int i = 0; i < peers.length; i++) {
            PEPeer peer = peers[i];
            PEPeerManager m = peer.getManager();
            if (m != null) {
                if (gm != null) {
                    DownloadManager dm = gm.getDownloadManager(new HashWrapper(m.getHash()));
                    if (dm != null) {
                        peer_dm_map.put(peer, dm);
                        download_managers.add(dm);
                    }
                }
            }
            try {
                int maxul = peer.getStats().getUploadRateLimitBytesPerSecond();
                maxUp += maxul * 4;
                if (maxul == 0) {
                    upSpeedUnlimited = true;
                } else {
                    if (maxul > upSpeedSetMax) {
                        upSpeedSetMax = maxul;
                    }
                }
                if (maxul == -1) {
                    maxul = 0;
                    upSpeedDisabled = true;
                }
                totalUpSpeed += maxul;
                int maxdl = peer.getStats().getDownloadRateLimitBytesPerSecond();
                maxDown += maxdl * 4;
                if (maxdl == 0) {
                    downSpeedUnlimited = true;
                } else {
                    if (maxdl > downSpeedSetMax) {
                        downSpeedSetMax = maxdl;
                    }
                }
                if (maxdl == -1) {
                    maxdl = 0;
                    downSpeedDisabled = true;
                }
                totalDownSpeed += maxdl;
            } catch (Exception ex) {
                Debug.printStackTrace(ex);
            }
        }
    }
    if (download_specific != null) {
        final MenuItem block_item = new MenuItem(menu, SWT.CHECK);
        PEPeer peer = peers.length == 0 ? null : peers[0];
        if (peer == null || peer.getManager().getDiskManager().getRemainingExcludingDND() > 0) {
            // disallow peer upload blocking when downloading
            block_item.setSelection(false);
            block_item.setEnabled(false);
        } else {
            block_item.setEnabled(true);
            block_item.setSelection(peer.isSnubbed());
        }
        if (peer != null) {
            final boolean newSnubbedValue = !peer.isSnubbed();
            Messages.setLanguageText(block_item, "PeersView.menu.blockupload");
            block_item.addListener(SWT.Selection, new PeersRunner(peers) {

                @Override
                public void run(PEPeer peer) {
                    peer.setSnubbed(newSnubbedValue);
                }
            });
        }
    } else {
        if (download_managers.size() > 0) {
            MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemDetails, "PeersView.menu.showdownload");
            Utils.setMenuItemImage(itemDetails, "details");
            itemDetails.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                    if (uiFunctions != null) {
                        for (DownloadManager dm : download_managers) {
                            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                        }
                    }
                }
            });
            new MenuItem(menu, SWT.SEPARATOR);
        }
    }
    BuddyPlugin bp = BuddyPluginUtils.getPlugin();
    if (bp != null) {
        boolean has_pb = false;
        boolean has_public = false;
        for (PEPeer peer : peers) {
            if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
                has_public = true;
                DownloadManager dm = peer_dm_map.get(peer);
                if (dm != null && bp.isPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer))) {
                    has_pb = true;
                }
            }
        }
        MenuItem boost_item = new MenuItem(menu, SWT.CHECK);
        Messages.setLanguageText(boost_item, "PeersView.menu.boost");
        boost_item.setSelection(has_pb);
        boost_item.setEnabled(has_public);
        boost_item.addListener(SWT.Selection, new PeersRunner(peers) {

            @Override
            public void run(PEPeer peer) {
                boolean sel = boost_item.getSelection();
                if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
                    DownloadManager dm = peer_dm_map.get(peer);
                    if (dm != null) {
                        bp.setPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer), sel);
                    }
                }
            }
        });
    }
    final MenuItem kick_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(kick_item, "PeersView.menu.kick");
    kick_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public void run(PEPeer peer) {
            peer.getManager().removePeer(peer, "Peer kicked");
        }
    });
    final MenuItem ban_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(ban_item, "PeersView.menu.kickandban");
    ban_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public void run(PEPeer peer) {
            String msg = MessageText.getString("PeersView.menu.kickandban.reason");
            IpFilterManagerFactory.getSingleton().getIPFilter().ban(peer.getIp(), msg, true);
            peer.getManager().removePeer(peer, "Peer kicked and banned");
        }
    });
    final MenuItem ban_for_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(ban_for_item, "PeersView.menu.kickandbanfor");
    ban_for_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public boolean run(final PEPeer[] peers) {
            String text = MessageText.getString("dialog.ban.for.period.text");
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.ban.for.period.title", "!" + text + "!");
            int def = COConfigurationManager.getIntParameter("ban.for.period.default", 60);
            entryWindow.setPreenteredText(String.valueOf(def), false);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    String sReturn = entryWindow.getSubmittedInput();
                    if (sReturn == null) {
                        return;
                    }
                    int mins = -1;
                    try {
                        mins = Integer.valueOf(sReturn).intValue();
                    } catch (NumberFormatException er) {
                    // Ignore
                    }
                    if (mins <= 0) {
                        MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
                        mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
                        mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
                        mb.open();
                        return;
                    }
                    COConfigurationManager.setParameter("ban.for.period.default", mins);
                    IpFilter filter = IpFilterManagerFactory.getSingleton().getIPFilter();
                    for (PEPeer peer : peers) {
                        String msg = MessageText.getString("PeersView.menu.kickandbanfor.reason", new String[] { String.valueOf(mins) });
                        filter.ban(peer.getIp(), msg, true, mins);
                        peer.getManager().removePeer(peer, "Peer kicked and banned");
                    }
                }
            });
            return (true);
        }
    });
    // === advanced menu ===
    final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu");
    itemAdvanced.setEnabled(hasSelection);
    final Menu menuAdvanced = new Menu(shell, SWT.DROP_DOWN);
    itemAdvanced.setMenu(menuAdvanced);
    // advanced > Download Speed Menu //
    Map<String, Object> menu_properties = new HashMap<>();
    menu_properties.put(ViewUtils.SM_PROP_PERMIT_UPLOAD_DISABLE, true);
    menu_properties.put(ViewUtils.SM_PROP_PERMIT_DOWNLOAD_DISABLE, true);
    ViewUtils.addSpeedMenu(shell, menuAdvanced, true, true, false, hasSelection, downSpeedDisabled, downSpeedUnlimited, totalDownSpeed, downSpeedSetMax, maxDown, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed, upSpeedSetMax, maxUp, peers.length, menu_properties, new ViewUtils.SpeedAdapter() {

        @Override
        public void setDownSpeed(int speed) {
            if (peers.length > 0) {
                for (int i = 0; i < peers.length; i++) {
                    try {
                        PEPeer peer = (PEPeer) peers[i];
                        peer.getStats().setDownloadRateLimitBytesPerSecond(speed);
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }

        @Override
        public void setUpSpeed(int speed) {
            if (peers.length > 0) {
                for (int i = 0; i < peers.length; i++) {
                    try {
                        PEPeer peer = (PEPeer) peers[i];
                        peer.getStats().setUploadRateLimitBytesPerSecond(speed);
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }
    });
    addPeersMenu(download_specific, "", menu);
}
Also used : IdentityHashSet(com.biglybt.core.util.IdentityHashSet) PEPeer(com.biglybt.core.peer.PEPeer) IpFilter(com.biglybt.core.ipfilter.IpFilter) SelectionListener(org.eclipse.swt.events.SelectionListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) Listener(org.eclipse.swt.widgets.Listener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) TableLifeCycleListener(com.biglybt.ui.common.table.TableLifeCycleListener) HashMap(java.util.HashMap) DownloadManager(com.biglybt.core.download.DownloadManager) BuddyPlugin(com.biglybt.plugin.net.buddy.BuddyPlugin) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) Menu(org.eclipse.swt.widgets.Menu) MenuItem(org.eclipse.swt.widgets.MenuItem) MessageBox(org.eclipse.swt.widgets.MessageBox) HashWrapper(com.biglybt.core.util.HashWrapper) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 29 with PEPeerManager

use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.

the class PiecesView method fillMenu.

@Override
public void fillMenu(String sColumnName, Menu menu) {
    final List<Object> selected = tv.getSelectedDataSources();
    if (selected.size() == 0) {
        return;
    }
    if (manager == null) {
        return;
    }
    PEPeerManager pm = manager.getPeerManager();
    if (pm == null) {
        return;
    }
    final PiecePicker picker = pm.getPiecePicker();
    boolean has_undone = false;
    boolean has_unforced = false;
    for (Object obj : selected) {
        PEPiece piece = (PEPiece) obj;
        if (!piece.getDMPiece().isDone()) {
            has_undone = true;
            if (picker.isForcePiece(piece.getPieceNumber())) {
                has_unforced = true;
            }
        }
    }
    final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
    Messages.setLanguageText(force_piece, "label.force.piece");
    force_piece.setEnabled(has_undone);
    if (has_undone) {
        force_piece.setSelection(has_unforced);
        force_piece.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean forced = force_piece.getSelection();
                for (Object obj : selected) {
                    PEPiece piece = (PEPiece) obj;
                    if (!piece.getDMPiece().isDone()) {
                        picker.setForcePiece(piece.getPieceNumber(), forced);
                    }
                }
            }
        });
    }
    final MenuItem cancel_reqs_piece = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(cancel_reqs_piece, "label.rerequest.blocks");
    cancel_reqs_piece.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (Object obj : selected) {
                PEPiece piece = (PEPiece) obj;
                for (int i = 0; i < piece.getNbBlocks(); i++) {
                    if (piece.isRequested(i)) {
                        piece.clearRequested(i);
                    }
                }
            }
        }
    });
    final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(reset_piece, "label.reset.piece");
    reset_piece.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (Object obj : selected) {
                PEPiece piece = (PEPiece) obj;
                piece.reset();
            }
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) MenuItem(org.eclipse.swt.widgets.MenuItem)

Example 30 with PEPeerManager

use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.

the class GeneralView method updateAvailability.

private void updateAvailability() {
    if (manager == null)
        return;
    try {
        this_mon.enter();
        final int[] available;
        PEPeerManager pm = manager.getPeerManager();
        if (manager.getPeerManager() == null) {
            if (availabilityPercent.getText().length() > 0) {
                availabilityPercent.setText("");
            }
            available = new int[manager.getNbPieces()];
        } else {
            available = pm.getAvailability();
        }
        if (display == null || display.isDisposed())
            return;
        if (availabilityImage == null || availabilityImage.isDisposed()) {
            return;
        }
        Rectangle bounds = availabilityImage.getClientArea();
        int xMax = bounds.width - 2;
        int yMax = bounds.height - 2;
        if (xMax < 10 || yMax < 5) {
            return;
        }
        if (aImage != null && !aImage.isDisposed()) {
            aImage.dispose();
        }
        aImage = new Image(display, bounds.width, bounds.height);
        GC gcImage = new GC(aImage);
        try {
            gcImage.setForeground(Colors.grey);
            gcImage.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
            int allMin = 0;
            int allMax = 0;
            int total = 0;
            String sTotal = "000";
            if (available != null) {
                allMin = available.length == 0 ? 0 : available[0];
                allMax = available.length == 0 ? 0 : available[0];
                int nbPieces = available.length;
                for (int i = 0; i < nbPieces; i++) {
                    if (available[i] < allMin)
                        allMin = available[i];
                    if (available[i] > allMax)
                        allMax = available[i];
                }
                int maxAboveMin = allMax - allMin;
                if (maxAboveMin == 0) {
                    // all the same.. easy paint
                    gcImage.setBackground(Colors.blues[allMin == 0 ? Colors.BLUES_LIGHTEST : Colors.BLUES_DARKEST]);
                    gcImage.fillRectangle(1, 1, xMax, yMax);
                } else {
                    for (int i = 0; i < nbPieces; i++) {
                        if (available[i] > allMin)
                            total++;
                    }
                    total = (total * 1000) / nbPieces;
                    sTotal = "" + total;
                    if (total < 10)
                        sTotal = "0" + sTotal;
                    if (total < 100)
                        sTotal = "0" + sTotal;
                    for (int i = 0; i < xMax; i++) {
                        int a0 = (i * nbPieces) / xMax;
                        int a1 = ((i + 1) * nbPieces) / xMax;
                        if (a1 == a0)
                            a1++;
                        if (a1 > nbPieces)
                            a1 = nbPieces;
                        int max = 0;
                        int min = available[a0];
                        int Pi = 1000;
                        for (int j = a0; j < a1; j++) {
                            if (available[j] > max)
                                max = available[j];
                            if (available[j] < min)
                                min = available[j];
                            Pi *= available[j];
                            Pi /= (available[j] + 1);
                        }
                        int pond = Pi;
                        if (max == 0)
                            pond = 0;
                        else {
                            int PiM = 1000;
                            for (int j = a0; j < a1; j++) {
                                PiM *= (max + 1);
                                PiM /= max;
                            }
                            pond *= PiM;
                            pond /= 1000;
                            pond *= (max - min);
                            pond /= 1000;
                            pond += min;
                        }
                        int index;
                        if (pond <= 0 || allMax == 0) {
                            index = 0;
                        } else {
                            // we will always have allMin, so subtract that
                            index = (pond - allMin) * (Colors.BLUES_DARKEST - 1) / maxAboveMin + 1;
                            // just in case?
                            if (index > Colors.BLUES_DARKEST) {
                                index = Colors.BLUES_DARKEST;
                            }
                        }
                        gcImage.setBackground(Colors.blues[index]);
                        gcImage.fillRectangle(i + 1, 1, 1, yMax);
                    }
                }
            }
            if (availabilityPercent == null || availabilityPercent.isDisposed()) {
                return;
            }
            availabilityPercent.setText(allMin + "." + sTotal);
        } finally {
            gcImage.dispose();
        }
    } finally {
        this_mon.exit();
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Aggregations

PEPeerManager (com.biglybt.core.peer.PEPeerManager)60 DownloadManager (com.biglybt.core.download.DownloadManager)29 PEPeer (com.biglybt.core.peer.PEPeer)18 DiskManager (com.biglybt.core.disk.DiskManager)13 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)9 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)8 PEPiece (com.biglybt.core.peer.PEPiece)8 PiecePicker (com.biglybt.core.peermanager.piecepicker.PiecePicker)7 List (java.util.List)7 LogEvent (com.biglybt.core.logging.LogEvent)6 Download (com.biglybt.pif.download.Download)6 File (java.io.File)6 ArrayList (java.util.ArrayList)6 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 URL (java.net.URL)5 Map (java.util.Map)5 GlobalManager (com.biglybt.core.global.GlobalManager)4 Tag (com.biglybt.core.tag.Tag)4 AERunnable (com.biglybt.core.util.AERunnable)4