Search in sources :

Example 26 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class MyTorrentsSubView method parameterChanged.

/* (non-Javadoc)
   * @see com.biglybt.ui.swt.views.MyTorrentsView#parameterChanged(java.lang.String)
   */
@Override
public void parameterChanged(String parameterName) {
    if ("TorrentTags.Any".equals(parameterName)) {
        anyTorrentTags = COConfigurationManager.getBooleanParameter(parameterName);
        if (btnAnyTags != null && !btnAnyTags.isDisposed()) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (btnAnyTags != null && !btnAnyTags.isDisposed()) {
                        btnAnyTags.setSelection(anyTorrentTags);
                    }
                }
            });
        }
        setCurrentTagsAny(anyTorrentTags);
    }
    super.parameterChanged(parameterName);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable)

Example 27 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class PeersGraphicView method dataSourceChanged.

protected void dataSourceChanged(Object newDataSource) {
    if (!comp_focused) {
        focus_pending_ds = newDataSource;
        return;
    }
    if (my_flag == null) {
        InetAddress ia = NetworkAdmin.getSingleton().getDefaultPublicAddress();
        if (ia != null) {
            my_flag = ImageRepository.getCountryFlag(ia, false);
        }
    }
    List<DownloadManager> existing = new ArrayList<>();
    synchronized (dm_data_lock) {
        for (ManagerData data : dm_data) {
            existing.add(data.manager);
        }
    }
    List<DownloadManager> newManagers = ViewUtils.getDownloadManagersFromDataSource(newDataSource, existing);
    synchronized (dm_data_lock) {
        Map<DownloadManager, ManagerData> map = new IdentityHashMap<>();
        for (ManagerData data : dm_data) {
            map.put(data.manager, data);
        }
        ManagerData[] new_data = new ManagerData[newManagers.size()];
        boolean changed = new_data.length != dm_data.length;
        for (int i = 0; i < new_data.length; i++) {
            DownloadManager dm = newManagers.get(i);
            ManagerData existing_data = map.remove(dm);
            if (existing_data != null) {
                new_data[i] = existing_data;
                if (i < dm_data.length && dm_data[i] != existing_data) {
                    changed = true;
                }
            } else {
                new_data[i] = new ManagerData(dm);
                changed = true;
            }
        }
        if (map.size() > 0) {
            changed = true;
            for (ManagerData data : map.values()) {
                data.delete();
            }
        }
        if (!changed) {
            return;
        }
        Arrays.sort(new_data, (a, b) -> {
            return (Long.compare(a.getAddTime(), b.getAddTime()));
        });
        dm_data = new_data;
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                synchronized (dm_data_lock) {
                    if (dm_data.length > 0) {
                        Utils.disposeComposite(canvas, false);
                    } else {
                        ViewUtils.setViewRequiresOneDownload(canvas);
                    }
                }
            }
        });
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) DownloadManager(com.biglybt.core.download.DownloadManager) Point(org.eclipse.swt.graphics.Point)

Example 28 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class TopBarView method skinObjectInitialShow.

@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    this.skin = skinObject.getSkin();
    skin.addListener("topbar-plugins", new SWTSkinObjectListener() {

        @Override
        public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
            if (eventType == SWTSkinObjectListener.EVENT_SHOW) {
                skin.removeListener("topbar-plugins", this);
                // building needs UISWTInstance, which needs core.
                CoreFactory.addCoreRunningListener(new CoreRunningListener() {

                    @Override
                    public void coreRunning(Core core) {
                        Utils.execSWTThreadLater(0, new AERunnable() {

                            @Override
                            public void runSupport() {
                                buildTopBarViews();
                            }
                        });
                    }
                });
            }
            return null;
        }
    });
    // trigger autobuild and hook in events
    skin.getSkinObject("topbar-area-plugin").addListener(new SWTSkinObjectListener() {

        @Override
        public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
            if (eventType == SWTSkinObjectListener.EVENT_SHOW) {
                if (activeTopBar != null) {
                    activeTopBar.triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
                }
            } else if (eventType == SWTSkinObjectListener.EVENT_HIDE) {
                if (activeTopBar != null) {
                    activeTopBar.triggerEvent(UISWTViewEvent.TYPE_FOCUSLOST, null);
                }
            }
            return (null);
        }
    });
    return null;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) CoreRunningListener(com.biglybt.core.CoreRunningListener) SWTSkinObjectListener(com.biglybt.ui.swt.skin.SWTSkinObjectListener) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) Core(com.biglybt.core.Core)

Example 29 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class NetworkAdminSWTImpl method updateStatus.

private void updateStatus() {
    if (!is_visible) {
        return;
    }
    Image icon;
    String tip;
    Object[] bs_status = network_admin.getBindingStatus();
    int bs_state = (Integer) bs_status[0];
    tip = (String) bs_status[1];
    if (bs_state == NetworkAdminImpl.BS_INACTIVE) {
        icon = icon_grey;
    } else if (bs_state == NetworkAdminImpl.BS_OK) {
        icon = icon_green;
    } else if (bs_state == NetworkAdminImpl.BS_WARNING) {
        icon = icon_yellow;
    } else {
        icon = icon_red;
    }
    if (last_icon != icon || !tip.equals(last_tip)) {
        final Image f_icon = icon;
        final String f_tip = tip;
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                last_icon = f_icon;
                last_tip = f_tip;
                status.setImage(f_icon);
                Utils.setTT(status, f_tip);
            }
        });
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Image(org.eclipse.swt.graphics.Image)

Example 30 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class AEProxySelectorSWTImpl method updateStatus.

private void updateStatus() {
    if (!is_visible) {
        return;
    }
    Image icon;
    String tip_key;
    Proxy active_proxy = proxy_selector.getActiveProxy();
    long now = SystemTime.getMonotonousTime();
    if (active_proxy == null) {
        icon = icon_grey;
        tip_key = "label.inactive";
    } else {
        long last_con = proxy_selector.getLastConnectionTime();
        long last_fail = proxy_selector.getLastFailTime();
        long con_ago = now - last_con;
        long fail_ago = now - last_fail;
        if (last_fail < 0) {
            icon = icon_green;
            tip_key = "PeerManager.status.ok";
        } else {
            if (fail_ago > 60 * 1000) {
                if (con_ago < fail_ago) {
                    icon = icon_green;
                    tip_key = "PeerManager.status.ok";
                } else {
                    icon = icon_grey;
                    tip_key = "PeersView.state.pending";
                }
            } else {
                icon = icon_yellow;
                tip_key = "label.con_prob";
            }
        }
    }
    if (flag_incoming) {
        boolean bad_incoming = false;
        if (now - last_bad_peer_update > 15 * 1000) {
            last_bad_peer_update = now;
            List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
            for (DownloadManager dm : dms) {
                PEPeerManager pm = dm.getPeerManager();
                if (pm != null) {
                    if (pm.getNbRemoteTCPConnections() + pm.getNbRemoteUDPConnections() + pm.getNbRemoteUTPConnections() > 0) {
                        List<PEPeer> peers = pm.getPeers();
                        for (PEPeer peer : peers) {
                            if (peer.isIncoming()) {
                                if (!peer.isLANLocal()) {
                                    try {
                                        if (InetAddress.getByAddress(HostNameToIPResolver.hostAddressToBytes(peer.getIp())).isLoopbackAddress()) {
                                            continue;
                                        }
                                    } catch (Throwable e) {
                                    }
                                    bad_incoming = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (bad_incoming) {
                    break;
                }
            }
        } else if (last_icon == icon_red) {
            bad_incoming = true;
        }
        if (bad_incoming) {
            icon = icon_red;
            tip_key = "proxy.socks.bad.incoming";
        }
    }
    if (last_icon != icon) {
        final Image f_icon = icon;
        final String f_key = tip_key;
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                last_icon = f_icon;
                status.setImage(f_icon);
                Utils.setTT(status, MessageText.getString("proxy.socks.ui.icon.tip", new String[] { MessageText.getString(f_key) }));
            }
        });
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) PEPeer(com.biglybt.core.peer.PEPeer) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) Proxy(java.net.Proxy) PEPeerManager(com.biglybt.core.peer.PEPeerManager)

Aggregations

AERunnable (com.biglybt.core.util.AERunnable)92 GridLayout (org.eclipse.swt.layout.GridLayout)12 DownloadManager (com.biglybt.core.download.DownloadManager)11 Image (org.eclipse.swt.graphics.Image)10 ArrayList (java.util.ArrayList)9 GridData (org.eclipse.swt.layout.GridData)9 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 File (java.io.File)7 PEPeer (com.biglybt.core.peer.PEPeer)6 Shell (org.eclipse.swt.widgets.Shell)6 Core (com.biglybt.core.Core)5 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)5 Point (org.eclipse.swt.graphics.Point)5 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 Subscription (com.biglybt.core.subs.Subscription)3 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)3 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3 MouseAdapter (org.eclipse.swt.events.MouseAdapter)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3