FileDocCategorySizeDatePackage
ShareRatioItem.javaAPI DocAzureus 3.0.3.43443Mon Feb 19 14:24:06 GMT 2007org.gudy.azureus2.ui.swt.views.tableitems.mytorrents

ShareRatioItem

public class ShareRatioItem extends org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn implements TableCellRefreshListener, org.gudy.azureus2.core3.config.ParameterListener
author
Olivier
author
TuxPaper (2004/Apr/17: modified to TableCellAdapter)

Fields Summary
private static final String
CONFIG_ID
private int
iMinShareRatio
Constructors Summary
public ShareRatioItem(String sTableID)
Default Constructor


     
     
    super("shareRatio", ALIGN_TRAIL, POSITION_LAST, 70, sTableID);
		setType(TableColumn.TYPE_TEXT);
    setRefreshInterval(INTERVAL_LIVE);
    setMinWidthAuto(true);

    if (sTableID.equals(TableManager.TABLE_MYTORRENTS_COMPLETE))
      setPosition(POSITION_LAST);
    else
      setPosition(POSITION_INVISIBLE);

    iMinShareRatio = COConfigurationManager.getIntParameter(CONFIG_ID);
    COConfigurationManager.addParameterListener(CONFIG_ID, this);
  
Methods Summary
protected voidfinalize()

    super.finalize();
    COConfigurationManager.removeParameterListener(CONFIG_ID, this);
  
public voidparameterChanged(java.lang.String parameterName)

    iMinShareRatio = COConfigurationManager.getIntParameter(CONFIG_ID);
    invalidateCells();
  
public voidrefresh(TableCell cell)

    DownloadManager dm = (DownloadManager)cell.getDataSource();
                       
    int sr = (dm == null) ? 0 : dm.getStats().getShareRatio();
    if (sr == -1)
      sr = Constants.INFINITY_AS_INT;
      
    if (!cell.setSortValue(sr) && cell.isValid())
      return;
    
    String shareRatio = "";
    
    if (sr == Constants.INFINITY_AS_INT) {
      shareRatio = Constants.INFINITY_STRING;
    } else {
      String partial = String.valueOf(sr % 1000);
      while (partial.length() < 3) {
        partial = "0" + partial;
      }
      shareRatio = (sr / 1000) + "." + partial;
    }
    
    if( cell.setText(shareRatio) ) {
      ((TableCellSWT)cell).setForeground((sr < iMinShareRatio) ? Colors.colorWarning : null);
    }