use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class UIDebugGenerator method obfuscateDownloadName.
public static String obfuscateDownloadName(PEPeer peer) {
if (peer == null)
return ("");
PEPeerManager manager = peer.getManager();
if (manager == null)
return ("");
String name = manager.getDisplayName();
if (name.length() > 3) {
return (name.substring(0, 3));
} else {
return (name);
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class SwarmAverageCompletion method refresh.
@Override
public void refresh(TableCell cell) {
int average = -1;
DownloadManager dm = (DownloadManager) cell.getDataSource();
if (dm != null) {
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
average = pm.getAverageCompletionInThousandNotation();
}
}
if (!cell.setSortValue(average) && cell.isValid()) {
return;
}
if (average < 0) {
cell.setText("");
} else {
cell.setText(DisplayFormatters.formatPercentFromThousands(average));
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class SwarmMaxCompletion method refresh.
@Override
public void refresh(TableCell cell) {
int average = -1;
DownloadManager dm = (DownloadManager) cell.getDataSource();
if (dm != null) {
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
average = pm.getMaxCompletionInThousandNotation(false);
}
}
if (!cell.setSortValue(average) && cell.isValid()) {
return;
}
if (average < 0) {
cell.setText("");
} else {
cell.setText(DisplayFormatters.formatPercentFromThousands(average));
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class PeersViewBase method addPeersMenu.
protected static boolean addPeersMenu(final DownloadManager man, String column_name, Menu menu) {
new MenuItem(menu, SWT.SEPARATOR);
MenuItem copy_me_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(copy_me_item, "menu.copy.my.peer");
copy_me_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String str = getMyPeerDetails();
if (str.isEmpty()) {
str = "<no usable peers>";
}
ClipboardCopy.copyToClipBoard(str);
}
});
if (man == null) {
return (true);
}
PEPeerManager pm = man.getPeerManager();
if (pm == null) {
return (true);
}
if (TorrentUtils.isReallyPrivate(man.getTorrent())) {
return (true);
}
MenuItem copy_all_peers = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(copy_all_peers, "menu.copy.all.peers");
copy_all_peers.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<PEPeer> peers = pm.getPeers();
String str = getMyPeerDetails();
for (PEPeer peer : peers) {
int port = peer.getTCPListenPort();
if (port > 0) {
String address = peer.getIp() + ":" + port;
str += (str.isEmpty() ? "" : ",") + address;
}
}
if (str.isEmpty()) {
str = "<no usable peers>";
}
ClipboardCopy.copyToClipBoard(str);
}
});
MenuItem add_peers_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(add_peers_item, "menu.add.peers");
add_peers_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.add.peers.title", "dialog.add.peers.msg");
String def = COConfigurationManager.getStringParameter("add.peers.default", "");
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;
}
COConfigurationManager.setParameter("add.peers.default", sReturn);
PEPeerManager pm = man.getPeerManager();
if (pm == null) {
return;
}
String[] bits = sReturn.split(",");
for (String bit : bits) {
bit = bit.trim();
int pos = bit.lastIndexOf(':');
if (pos != -1) {
String host = bit.substring(0, pos).trim();
String port = bit.substring(pos + 1).trim();
try {
int i_port = Integer.parseInt(port);
pm.addPeer(host, i_port, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
} catch (Throwable e) {
}
} else {
pm.addPeer(bit, 6881, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
}
}
}
});
}
});
return (true);
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class PieceGraphView method buildImage.
private void buildImage() {
if (canvas == null || canvas.isDisposed()) {
return;
}
// canvas.setBackground(ColorCache.getColor(canvas.getDisplay(), "#1b1b1b"));
Rectangle bounds = canvas.getClientArea();
if (bounds.isEmpty()) {
return;
}
if (dlm == null) {
canvas.redraw();
return;
}
PEPeerManager pm = dlm.getPeerManager();
DiskManager dm = dlm.getDiskManager();
if (pm == null || dm == null) {
canvas.redraw();
return;
}
final DiskManagerPiece[] dm_pieces = dm.getPieces();
if (dm_pieces == null || dm_pieces.length == 0) {
canvas.redraw();
return;
}
int numPieces = dm_pieces.length;
if (imgHaveAll == null || imgHaveAll.isDisposed()) {
imgHaveAll = new Image(canvas.getDisplay(), BLOCK_SIZE, BLOCK_SIZE);
GC gc = new GC(imgHaveAll);
try {
try {
gc.setAntialias(SWT.ON);
} catch (Exception e) {
// ignore
}
gc.setBackground(canvas.getBackground());
gc.fillRectangle(imgHaveAll.getBounds());
gc.setBackground(blockColors[BLOCKCOLOR_HAVEALL]);
gc.fillRoundRectangle(1, 1, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE);
} finally {
gc.dispose();
}
}
if (imgNoHave == null || imgNoHave.isDisposed()) {
imgNoHave = new Image(canvas.getDisplay(), BLOCK_SIZE, BLOCK_SIZE);
GC gc = new GC(imgNoHave);
try {
try {
gc.setAntialias(SWT.ON);
} catch (Exception e) {
// ignore
}
gc.setBackground(canvas.getBackground());
gc.fillRectangle(imgNoHave.getBounds());
gc.setBackground(blockColors[BLOCKCOLOR_NOHAVE]);
gc.fillRoundRectangle(1, 1, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE);
} finally {
gc.dispose();
}
}
boolean clearImage = img == null || img.isDisposed() || img.getBounds().width != bounds.width || img.getBounds().height != bounds.height;
if (clearImage) {
if (img != null && !img.isDisposed()) {
img.dispose();
}
// System.out.println("clear " + img);
img = new Image(canvas.getDisplay(), bounds.width, bounds.height);
squareCache = null;
}
PEPiece[] currentDLPieces = dlm.getCurrentPieces();
Arrays.sort(currentDLPieces, compFindPEPiece);
// find upload pieces
ArrayList currentULPieces = new ArrayList();
ArrayList futureULPieces = new ArrayList();
PEPeer[] peers = (PEPeer[]) pm.getPeers().toArray(new PEPeer[0]);
for (int i = 0; i < peers.length; i++) {
PEPeer peer = peers[i];
int[] peerRequestedPieces = peer.getIncomingRequestedPieceNumbers();
if (peerRequestedPieces != null && peerRequestedPieces.length > 0) {
currentULPieces.add(new Long(peerRequestedPieces[0]));
for (int j = 1; j < peerRequestedPieces.length; j++) {
futureULPieces.add(new Long(peerRequestedPieces[j]));
}
}
// we'll have duplicates
Collections.sort(currentULPieces);
Collections.sort(futureULPieces);
}
int iNumCols = bounds.width / BLOCK_SIZE;
int iNumRows = bounds.height / BLOCK_SIZE;
int numSquares = onePiecePerBlock ? numPieces : iNumCols * iNumRows;
double numPiecesPerSquare = numPieces / (double) numSquares;
if (squareCache == null || squareCache.length != numSquares) {
squareCache = new double[numSquares];
Arrays.fill(squareCache, -1);
}
int[] availability = pm.getAvailability();
int numRedraws = 0;
GC gc = new GC(img);
try {
int iRow = 0;
if (clearImage) {
gc.setBackground(canvas.getBackground());
gc.fillRectangle(bounds);
}
try {
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);
} catch (Exception e) {
// ignore
}
int iCol = 0;
for (int squareNo = 0; squareNo < numSquares; squareNo++) {
if (iCol >= iNumCols) {
iCol = 0;
iRow++;
}
int startNo = (int) (squareNo * numPiecesPerSquare);
int count = (int) ((squareNo + 1) * numPiecesPerSquare) - startNo;
if (count == 0) {
count = 1;
}
// if (count > 1) System.out.println("!!! " + startNo);
// System.out.println(startNo + ";" + count);
double pctDone = getPercentDone(startNo, count, dm_pieces);
// System.out.print(pctDone + ";");
int colorIndex;
int iXPos = iCol * BLOCK_SIZE;
int iYPos = iRow * BLOCK_SIZE;
if (pctDone == 1) {
if (squareCache[squareNo] != pctDone) {
squareCache[squareNo] = pctDone;
gc.drawImage(imgHaveAll, iXPos, iYPos);
if (!clearImage) {
numRedraws++;
canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
}
}
} else if (pctDone == 0) {
if (squareCache[squareNo] != pctDone) {
squareCache[squareNo] = pctDone;
gc.drawImage(imgNoHave, iXPos, iYPos);
if (!clearImage) {
numRedraws++;
canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
}
}
} else {
// !done
boolean isDownloading = false;
for (int i = startNo; i < startNo + count; i++) {
if (Arrays.binarySearch(currentDLPieces, new Long(i), compFindPEPiece) >= 0) {
isDownloading = true;
break;
}
}
double val = pctDone + (isDownloading ? 0 : 1);
if (squareCache[squareNo] != val) {
squareCache[squareNo] = val;
gc.drawImage(imgNoHave, iXPos, iYPos);
int size = (int) (BLOCK_FILLSIZE * pctDone);
if (size == 0) {
size = 1;
}
int q = (int) ((BLOCK_FILLSIZE - size) / 2.0 + 0.5) + 1;
colorIndex = isDownloading ? BLOCKCOLOR_DOWNLOADING : BLOCKCOLOR_HAVESOME;
gc.setBackground(blockColors[colorIndex]);
gc.fillOval(iXPos + q, iYPos + q, size, size);
// gc.fillRoundRectangle(iXPos + q, iYPos + q, size, size, size, size);
if (!clearImage) {
numRedraws++;
canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
}
}
}
for (int i = startNo; i < startNo + count; i++) {
if (Collections.binarySearch(currentULPieces, new Long(i)) >= 0) {
colorIndex = BLOCKCOLOR_UPLOADING;
int size = BLOCK_FILLSIZE + 1;
gc.setForeground(blockColors[colorIndex]);
gc.drawRoundRectangle(iXPos, iYPos, size, size, size, size);
if (!clearImage) {
numRedraws++;
canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
}
squareCache[squareNo] = -1;
break;
} else if (Collections.binarySearch(futureULPieces, new Long(i)) >= 0) {
colorIndex = BLOCKCOLOR_UPLOADING;
int size = BLOCK_FILLSIZE + 1;
gc.setForeground(blockColors[colorIndex]);
gc.setLineStyle(SWT.LINE_DOT);
gc.drawRoundRectangle(iXPos, iYPos, size, size, size, size);
if (!clearImage) {
numRedraws++;
canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
}
gc.setLineStyle(SWT.LINE_SOLID);
squareCache[squareNo] = -1;
break;
}
}
if (availability != null) {
boolean hasNoAvail = false;
for (int i = startNo; i < startNo + count; i++) {
if (availability[i] == 0) {
hasNoAvail = true;
squareCache[squareNo] = -1;
break;
}
}
if (hasNoAvail) {
gc.setForeground(blockColors[BLOCKCOLOR_NOAVAIL]);
gc.drawRectangle(iXPos, iYPos, BLOCK_FILLSIZE + 1, BLOCK_FILLSIZE + 1);
if (!clearImage) {
numRedraws++;
canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
}
}
}
iCol++;
}
// System.out.println("redraws " + numRedraws);
} catch (Exception e) {
Debug.out(e);
} finally {
gc.dispose();
}
// canvas.redraw();
}
Aggregations