FileDocCategorySizeDatePackage
UpDownRatioItem.javaAPI DocAzureus 3.0.3.42616Sun Sep 23 04:55:16 BST 2007org.gudy.azureus2.ui.swt.views.tableitems.peers

UpDownRatioItem

public class UpDownRatioItem extends org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn implements TableCellRefreshListener
author
TuxPaper
author
MjrTom Jan/14/2006 subtract discarded bytes

Fields Summary
Constructors Summary
public UpDownRatioItem(String table_id)
Default Constructor

    super("UpDownRatio", ALIGN_TRAIL, POSITION_INVISIBLE, 70, table_id);
    setRefreshInterval(INTERVAL_LIVE);
  
Methods Summary
public voidrefresh(TableCell cell)

    PEPeer peer = (PEPeer)cell.getDataSource();
    float value = 0;
    long lDivisor = 0;
    long lDivident = 0;
    if (peer != null) {
      lDivisor = peer.getStats().getTotalDataBytesReceived() -peer.getStats().getTotalBytesDiscarded();
      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 = Constants.INFINITY_AS_INT;
    }

    if (!cell.setSortValue((long)(value * 1000)) && cell.isValid())
      return;

    String s;
    if (lDivisor <= 0) 
      s = "";
    else if (value == Constants.INFINITY_AS_INT)
      s = Constants.INFINITY_STRING + ":1";
    else if (value == -1)
      s = "1:" + Constants.INFINITY_STRING;
    else
      s = DisplayFormatters.formatDecimal(value, 2) + ":1";

    cell.setText(s);