Search in sources :

Example 36 with AERunnable

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

the class NatPanel method enableNext.

private void enableNext() {
    Display display = wizard.getDisplay();
    if (display == null || display.isDisposed())
        return;
    display.asyncExec(new AERunnable() {

        @Override
        public void runSupport() {
            if (bTestTCP == null || bTestTCP.isDisposed()) {
                return;
            }
            if (bTestUDP == null || bTestUDP.isDisposed()) {
                return;
            }
            wizard.setNextEnabled(true);
            bTestTCP.setEnabled(true);
            bTestUDP.setEnabled(true);
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable)

Example 37 with AERunnable

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

the class NatPanel method printMessage.

public void printMessage(final String message) {
    Display display = wizard.getDisplay();
    if (display == null || display.isDisposed())
        return;
    display.asyncExec(new AERunnable() {

        @Override
        public void runSupport() {
            if (textResults == null || textResults.isDisposed())
                return;
            textResults.append(message);
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable)

Example 38 with AERunnable

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

the class UISWTInstanceImpl method showDownloadBar.

@Override
public void showDownloadBar(Download download, final boolean display) {
    if (!(download instanceof DownloadImpl)) {
        return;
    }
    final DownloadManager dm = ((DownloadImpl) download).getDownload();
    // Not expecting this, but just in case...
    if (dm == null) {
        return;
    }
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (display) {
                DownloadBar.open(dm, getDisplay().getActiveShell());
            } else {
                DownloadBar.close(dm);
            }
        }
    }, false);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) DownloadImpl(com.biglybt.pifimpl.local.download.DownloadImpl) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 39 with AERunnable

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

the class TableCellPainted method redraw.

/* (non-Javadoc)
	 * @see TableCellCore#redraw()
	 */
@Override
public void redraw() {
    if (tableRowSWT == null || !tableRowSWT.isVisible() || redrawScheduled) {
        return;
    }
    redrawScheduled = true;
    if (DEBUG_CELLPAINT) {
        System.out.println(SystemTime.getCurrentTime() + "r" + tableRowSWT.getIndex() + "c" + tableColumnCore.getPosition() + "} cellredraw via " + Debug.getCompressedStackTrace());
    }
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (isDisposed()) {
                return;
            }
            redrawScheduled = false;
            if (DEBUG_CELLPAINT) {
                System.out.println(SystemTime.getCurrentTime() + "r" + tableRowSWT.getIndex() + "c" + tableColumnCore.getPosition() + "] cellredraw @ " + bounds);
            }
            if (bounds != null && tableRowSWT != null) {
                TableViewPainted view = (TableViewPainted) tableRowSWT.getView();
                if (view != null) {
                    view.swt_updateCanvasImage(bounds, false);
                }
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable)

Example 40 with AERunnable

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

the class FileHashItemBase method updateHash.

private static void updateHash(final String hash_type, final DiskManagerFileInfo file) {
    if (!isFileReady(file)) {
        return;
    }
    synchronized (pending) {
        Set<String> hashes = pending.get(file);
        if (hashes != null && hashes.contains(hash_type)) {
            return;
        }
        if (hashes == null) {
            hashes = new HashSet<>();
            pending.put(file, hashes);
        }
        hashes.add(hash_type);
    }
    dispatcher.dispatch(new AERunnable() {

        @Override
        public void runSupport() {
            try {
                DownloadManager dm = file.getDownloadManager();
                if (dm == null) {
                    return;
                }
                if (!isFileReady(file)) {
                    return;
                }
                active_percent = 0;
                active_hash = hash_type;
                active = file;
                File f = file.getFile(true);
                CRC32 crc32 = null;
                MessageDigest md = null;
                if (hash_type == HT_CRC32) {
                    crc32 = new CRC32();
                } else if (hash_type == HT_MD5) {
                    md = MessageDigest.getInstance("md5");
                } else {
                    md = MessageDigest.getInstance("SHA1");
                }
                FileInputStream fis = new FileInputStream(f);
                long size = f.length();
                long done = 0;
                if (size == 0) {
                    size = 1;
                }
                try {
                    byte[] buffer = new byte[512 * 1024];
                    while (true) {
                        int len = fis.read(buffer);
                        if (len <= 0) {
                            break;
                        }
                        if (crc32 != null) {
                            crc32.update(buffer, 0, len);
                        }
                        if (md != null) {
                            md.update(buffer, 0, len);
                        }
                        done += len;
                        active_percent = (int) ((1000 * done) / size);
                    }
                    byte[] hash;
                    if (crc32 != null) {
                        long val = crc32.getValue();
                        hash = ByteFormatter.intToByteArray(val);
                    } else {
                        hash = md.digest();
                    }
                    Map other_hashes = dm.getDownloadState().getMapAttribute(DownloadManagerState.AT_FILE_OTHER_HASHES);
                    if (other_hashes == null) {
                        other_hashes = new HashMap();
                    } else {
                        other_hashes = BEncoder.cloneMap(other_hashes);
                    }
                    Map file_hashes = (Map) other_hashes.get(String.valueOf(file.getIndex()));
                    if (file_hashes == null) {
                        file_hashes = new HashMap();
                        other_hashes.put(String.valueOf(file.getIndex()), file_hashes);
                    }
                    file_hashes.put(hash_type, hash);
                    dm.getDownloadState().setMapAttribute(DownloadManagerState.AT_FILE_OTHER_HASHES, other_hashes);
                } finally {
                    fis.close();
                }
            } catch (Throwable e) {
                Debug.out(e);
            } finally {
                synchronized (pending) {
                    Set<String> hashes = pending.get(file);
                    hashes.remove(hash_type);
                    if (hashes.size() == 0) {
                        pending.remove(file);
                    }
                    active = null;
                }
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) HashSet(java.util.HashSet) Set(java.util.Set) CRC32(java.util.zip.CRC32) HashMap(java.util.HashMap) DownloadManager(com.biglybt.core.download.DownloadManager) FileInputStream(java.io.FileInputStream) MessageDigest(java.security.MessageDigest) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

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