use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.
the class ChokedItem method refresh.
@Override
public void refresh(TableCell cell) {
PEPeer peer = (PEPeer) cell.getDataSource();
long value = (peer == null) ? 0 : (peer.isChokingMe() ? 1 : (peer.isUnchokeOverride() ? 2 : 0));
if (!cell.setSortValue(value) && cell.isValid())
return;
cell.setText((value > 0) ? (peer.isUnchokeOverride() ? "+" : "*") : "");
}
use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.
the class UpRatioItem method refresh.
@Override
public void refresh(TableCell cell) {
PEPeer peer = (PEPeer) cell.getDataSource();
float value = 0;
long lDivisor = 0;
long lDivident = 0;
if (peer != null) {
lDivisor = peer.getStats().getTotalBytesDownloadedByPeer() - peer.getStats().getTotalDataBytesSent();
lDivident = peer.getStats().getTotalDataBytesSent();
// skip if divisor is small (most likely handshake) or 0 (DivisionByZero)
if (lDivisor > 1024) {
value = lDivident / (float) lDivisor;
if (value == 0)
value = -1;
} else if (lDivident > 0)
value = Float.MAX_VALUE;
}
if (!cell.setSortValue((long) (value * 1000.0d)) && cell.isValid())
return;
String s;
if (lDivisor <= 0)
s = "";
else if (value == Float.MAX_VALUE)
s = Constants.INFINITY_STRING + ":1";
else if (value == -1)
s = "1:" + Constants.INFINITY_STRING;
else
s = DisplayFormatters.formatDecimal(value, 2) + ":1";
cell.setText(s);
}
use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.
the class UpSpeedItem method refresh.
@Override
public void refresh(TableCell cell) {
PEPeer peer = (PEPeer) cell.getDataSource();
long data_value = 0;
long prot_value = 0;
if (peer != null) {
data_value = peer.getStats().getDataSendRate();
prot_value = peer.getStats().getProtocolSendRate();
}
long sort_value = (data_value << 32) + prot_value;
if (!cell.setSortValue(sort_value) && cell.isValid())
return;
cell.setText(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(data_value, prot_value));
}
use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.
the class PeersGeneralView method taggableSync.
@Override
public void taggableSync(Tag tag) {
if (tv.getRowCount() != tag.getTaggedCount()) {
Set<PEPeer> peers_in_table = new HashSet<>(tv.getDataSources());
Set<PEPeer> peers_in_tag = new HashSet<>((Set) tag.getTagged());
for (PEPeer peer : peers_in_table) {
if (!peers_in_tag.contains(peer)) {
removePeer(peer);
}
}
for (PEPeer peer : peers_in_tag) {
if (!peers_in_table.contains(peer)) {
addPeer(peer);
}
}
}
}
use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.
the class PeersGraphicView method initialize.
protected void initialize(Composite composite) {
display = composite.getDisplay();
panel = new Canvas(composite, SWT.NO_BACKGROUND);
panel.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
int x = event.x;
int y = event.y;
String tt = "";
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
if (dm_data.length > 1) {
tt = manager.getDisplayName() + "\r\n";
}
tt += DisplayFormatters.formatDownloadStatus(manager) + ", " + DisplayFormatters.formatPercentFromThousands(manager.getStats().getCompleted());
break;
} else {
PEPeer target = null;
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
target = entry.getKey();
break;
}
}
if (target != null) {
PEPeerStats stats = target.getStats();
String[] details = PeerUtils.getCountryDetails(target);
String dstr = (details == null || details.length < 2) ? "" : (" - " + details[0] + "/" + details[1]);
/*
if ( dm_map.size() > 1 ){
tt = manager.getDisplayName() + "\r\n";
}
*/
tt = target.getIp() + dstr + ", " + DisplayFormatters.formatPercentFromThousands(target.getPercentDoneInThousandNotation()) + "\r\n" + "Up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", " + "Down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate());
break;
}
}
}
}
panel.setToolTipText(tt);
}
});
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent event) {
if (event.button == 3) {
int x = event.x;
int y = event.y;
PEPeer target = null;
DownloadManager target_manager = null;
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
target = entry.getKey();
target_manager = manager;
break;
}
}
if (target != null) {
break;
}
}
}
if (target == null) {
return;
}
Menu menu = panel.getMenu();
if (menu != null && !menu.isDisposed()) {
menu.dispose();
}
menu = new Menu(panel);
PeersViewBase.fillMenu(menu, target, target_manager);
final Point cursorLocation = Display.getCurrent().getCursorLocation();
menu.setLocation(cursorLocation.x, cursorLocation.y);
menu.setVisible(true);
}
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int x = event.x;
int y = event.y;
synchronized (dm_data_lock) {
for (ManagerData data : dm_data) {
DownloadManager manager = data.manager;
if (x >= data.me_hit_x && x <= data.me_hit_x + OWN_SIZE && y >= data.me_hit_y && y <= data.me_hit_y + OWN_SIZE) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, manager);
}
} else {
for (Map.Entry<PEPeer, int[]> entry : data.peer_hit_map.entrySet()) {
int[] loc = entry.getValue();
int loc_x = loc[0];
int loc_y = loc[1];
if (x >= loc_x && x <= loc_x + PEER_SIZE && y >= loc_y && y <= loc_y + PEER_SIZE) {
PEPeer target = entry.getKey();
try {
String dm_id = "DMDetails_" + Base32.encode(manager.getTorrent().getHash());
MdiEntry mdi_entry = UIFunctionsManager.getUIFunctions().getMDI().getEntry(dm_id);
if (mdi_entry != null) {
mdi_entry.setDatasource(new Object[] { manager, target });
}
Composite comp = panel.getParent();
while (comp != null) {
if (comp instanceof CTabFolder) {
CTabFolder tf = (CTabFolder) comp;
CTabItem[] items = tf.getItems();
for (CTabItem item : items) {
UISWTViewCore view = (UISWTViewCore) item.getData("TabbedEntry");
UISWTViewEventListener listener = view.getEventListener();
if (listener instanceof UISWTViewEventListenerHolder) {
listener = ((UISWTViewEventListenerHolder) listener).getDelegatedEventListener(view);
}
if (listener instanceof PeersView) {
tf.setSelection(item);
Event ev = new Event();
ev.item = item;
// manual setSelection doesn't file selection event - derp
tf.notifyListeners(SWT.Selection, ev);
((PeersView) listener).selectPeer(target);
return;
}
}
}
comp = comp.getParent();
}
} catch (Throwable e) {
}
break;
}
}
}
}
}
}
});
// without this we get a transient blank when mousing in and out of the tab folder on OSX :(
panel.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
doRefresh();
}
});
}
Aggregations