PeersViewpublic class PeersView extends org.gudy.azureus2.ui.swt.views.table.impl.TableViewTab implements org.gudy.azureus2.ui.swt.views.table.TableViewSWTMenuFillListener, org.gudy.azureus2.core3.download.DownloadManagerPeerListener, TableDataSourceChangedListener, TableLifeCycleListener
Fields Summary |
---|
private static final TableColumnCore[] | basicItems | private org.gudy.azureus2.core3.download.DownloadManager | manager | private org.gudy.azureus2.ui.swt.views.table.TableViewSWT | tv | private Shell | shell |
Constructors Summary |
---|
public PeersView()Initialize
tv = new TableViewSWTImpl(TableManager.TABLE_TORRENT_PEERS, "PeersView",
basicItems, "pieces", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
setTableView(tv);
tv.setRowDefaultHeight(16);
tv.setEnableTabViews(true);
tv.setCoreTabViews(new IView[] {
new PeerInfoView(),
new LoggerView()
});
tv.addTableDataSourceChangedListener(this, true);
tv.addLifeCycleListener(this);
tv.addMenuFillListener(this);
|
Methods Summary |
---|
private void | addExistingDatasources()Add datasources already in existance before we called addListener.
Faster than allowing addListener to call us one datasource at a time.
if (manager == null || tv.isDisposed()) {
return;
}
Object[] dataSources = manager.getCurrentPeers();
if (dataSources == null || dataSources.length == 0) {
return;
}
tv.addDataSources(dataSources);
tv.processDataSourceQueue();
| public void | addThisColumnSubMenu(java.lang.String columnName, Menu menuThisColumn)
| public void | fillMenu(Menu menu)fillMenu(menu, tv, shell, true);
| public static void | fillMenu(Menu menu, TableView tv, Shell shell, boolean download_specific)
Object[] peers = tv.getSelectedDataSources();
boolean hasSelection = (peers.length > 0);
boolean downSpeedDisabled = false;
boolean downSpeedUnlimited = false;
long totalDownSpeed = 0;
long downSpeedSetMax = 0;
long maxDown = 0;
boolean upSpeedDisabled = false;
boolean upSpeedUnlimited = false;
long totalUpSpeed = 0;
long upSpeedSetMax = 0;
long maxUp = 0;
if (hasSelection){
for (int i = 0; i < peers.length; i++) {
PEPeer peer = (PEPeer)peers[i];
try {
int maxul = peer.getStats().getUploadRateLimitBytesPerSecond();
maxUp += maxul * 4;
if (maxul == 0) {
upSpeedUnlimited = true;
}else{
if ( maxul > upSpeedSetMax ){
upSpeedSetMax = maxul;
}
}
if (maxul == -1) {
maxul = 0;
upSpeedDisabled = true;
}
totalUpSpeed += maxul;
int maxdl = peer.getStats().getDownloadRateLimitBytesPerSecond();
maxDown += maxdl * 4;
if (maxdl == 0) {
downSpeedUnlimited = true;
}else{
if ( maxdl > downSpeedSetMax ){
downSpeedSetMax = maxdl;
}
}
if (maxdl == -1) {
maxdl = 0;
downSpeedDisabled = true;
}
totalDownSpeed += maxdl;
} catch (Exception ex) {
Debug.printStackTrace(ex);
}
}
}
if (download_specific) {
final MenuItem block_item = new MenuItem(menu, SWT.CHECK);
PEPeer peer = (PEPeer) tv.getFirstSelectedDataSource();
if ( peer == null || peer.getManager().getDiskManager().getRemainingExcludingDND() > 0 ){
// disallow peer upload blocking when downloading
block_item.setSelection(false);
block_item.setEnabled(false);
}
else {
block_item.setEnabled(true);
block_item.setSelection(peer.isSnubbed());
}
Messages.setLanguageText(block_item, "PeersView.menu.blockupload");
block_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
public void run(TableRowCore row) {
((PEPeer) row.getDataSource(true))
.setSnubbed(block_item.getSelection());
}
});
}
final MenuItem ban_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(ban_item, "PeersView.menu.kickandban");
ban_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
public void run(TableRowCore row) {
PEPeer peer = (PEPeer) row.getDataSource(true);
String msg = MessageText.getString("PeersView.menu.kickandban.reason");
IpFilterManagerFactory.getSingleton().getIPFilter().ban(peer.getIp(),
msg, true );
peer.getManager().removePeer(peer);
}
});
// === advanced menu ===
final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu"); //$NON-NLS-1$
itemAdvanced.setEnabled(hasSelection);
final Menu menuAdvanced = new Menu(shell, SWT.DROP_DOWN);
itemAdvanced.setMenu(menuAdvanced);
// advanced > Download Speed Menu //
ViewUtils.addSpeedMenu(
shell,
menuAdvanced,
hasSelection,
downSpeedDisabled,
downSpeedUnlimited,
totalDownSpeed,
downSpeedSetMax,
maxDown,
upSpeedDisabled,
upSpeedUnlimited,
totalUpSpeed,
upSpeedSetMax,
maxUp,
peers.length,
new ViewUtils.SpeedAdapter()
{
public void
setDownSpeed(
int speed )
{
setSelectedPeersDownSpeed( speed, tv );
}
public void
setUpSpeed(
int speed )
{
setSelectedPeersUpSpeed( speed, tv );
}
});
new MenuItem(menu, SWT.SEPARATOR);
| static TableColumnCore[] | getBasicColumnItems(java.lang.String table_id)
return new TableColumnCore[] {
new IpItem(table_id),
new ClientItem(table_id),
new TypeItem(table_id),
new MessagingItem(table_id),
new EncryptionItem(table_id),
new PiecesItem(table_id),
new PercentItem(table_id),
new DownSpeedItem(table_id),
new UpSpeedItem(table_id),
new PeerSourceItem(table_id),
new HostNameItem(table_id),
new PortItem(table_id),
new InterestedItem(table_id),
new ChokedItem(table_id),
new DownItem(table_id),
new InterestingItem(table_id),
new ChokingItem(table_id),
new OptimisticUnchokeItem(table_id),
new UpItem(table_id),
new UpDownRatioItem(table_id),
new GainItem(table_id),
new StatUpItem(table_id),
new SnubbedItem(table_id),
new TotalDownSpeedItem(table_id),
new DiscardedItem(table_id),
new UniquePieceItem(table_id),
new TimeToSendPieceItem(table_id),
new DLedFromOthersItem(table_id),
new UpRatioItem(table_id),
new StateItem(table_id),
new ConnectedTimeItem(table_id),
new PieceItem(table_id),
new IncomingRequestCountItem(table_id),
new OutgoingRequestCountItem(table_id),
new UpSpeedLimitItem(table_id),
new DownSpeedLimitItem(table_id),
new LANItem(table_id),
new PeerIDItem(table_id),
new PeerByteIDItem(table_id),
new HandshakeReservedBytesItem(table_id),
new ClientIdentificationItem(table_id),
};
| public void | peerAdded(org.gudy.azureus2.core3.peer.PEPeer created)
tv.addDataSource(created);
| public void | peerManagerAdded(org.gudy.azureus2.core3.peer.PEPeerManager manager)
| public void | peerManagerRemoved(org.gudy.azureus2.core3.peer.PEPeerManager manager)
tv.removeAllTableRows();
| public void | peerManagerWillBeAdded(org.gudy.azureus2.core3.peer.PEPeerManager peer_manager)
| public void | peerRemoved(org.gudy.azureus2.core3.peer.PEPeer removed)
tv.removeDataSource(removed);
| public void | pieceAdded(org.gudy.azureus2.core3.peer.PEPiece piece)
| public void | pieceRemoved(org.gudy.azureus2.core3.peer.PEPiece piece)
| private static void | setSelectedPeersDownSpeed(int speed, TableView tv)
Object[] peers = tv.getSelectedDataSources();
if(peers.length > 0) {
for (int i = 0; i < peers.length; i++) {
try {
PEPeer peer = (PEPeer)peers[i];
peer.getStats().setDownloadRateLimitBytesPerSecond(speed);
} catch (Exception e) {
Debug.printStackTrace( e );
}
}
}
| private static void | setSelectedPeersUpSpeed(int speed, TableView tv)
Object[] peers = tv.getSelectedDataSources();
if(peers.length > 0) {
for (int i = 0; i < peers.length; i++) {
try {
PEPeer peer = (PEPeer)peers[i];
peer.getStats().setUploadRateLimitBytesPerSecond(speed);
} catch (Exception e) {
Debug.printStackTrace( e );
}
}
}
| public void | tableDataSourceChanged(java.lang.Object newDataSource)
if (manager != null)
manager.removePeerListener(this);
if (newDataSource == null)
manager = null;
else if (newDataSource instanceof Object[])
manager = (DownloadManager)((Object[])newDataSource)[0];
else
manager = (DownloadManager)newDataSource;
if (manager != null && !tv.isDisposed()) {
manager.addPeerListener(this, false);
addExistingDatasources();
}
| public void | tableViewDestroyed()
if (manager != null) {
manager.removePeerListener(this);
}
| public void | tableViewInitialized()
if (tv instanceof TableViewSWT) {
shell = ((TableViewSWT)tv).getComposite().getShell();
} else {
shell = Utils.findAnyShell();
}
if (manager != null) {
manager.removePeerListener(this);
manager.addPeerListener(this, false);
}
addExistingDatasources();
|
|