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);
}
});
}
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);
}
});
}
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);
}
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);
}
}
}
});
}
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;
}
}
}
});
}
Aggregations