FileDocCategorySizeDatePackage
ColumnDateAdded2Liner.javaAPI DocAzureus 3.0.3.43324Thu Mar 01 23:47:30 GMT 2007com.aelitis.azureus.ui.swt.columns.torrent

ColumnDateAdded2Liner

public class ColumnDateAdded2Liner extends org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn implements org.gudy.azureus2.plugins.ui.tables.TableCellRefreshListener
author
TuxPaper
created
Jun 16, 2006

Fields Summary
public static String
COLUMN_ID
static final String[]
FORMATS
static int
globalFormat
int
curFormat
Constructors Summary
public ColumnDateAdded2Liner(String sTableID, boolean bVisible)


	     
		super(COLUMN_ID, ALIGN_TRAIL,
				bVisible ? POSITION_LAST : POSITION_INVISIBLE, 70, sTableID);
		setMaxWidthAuto(true);
	
Methods Summary
public voidrefresh(org.gudy.azureus2.plugins.ui.tables.TableCell cell)

		DownloadManager dm = (DownloadManager) cell.getDataSource();
		long value = (dm == null) ? 0 : dm.getDownloadState().getLongParameter(
				DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);

		if (!cell.setSortValue(value) && cell.isValid()
				&& curFormat == globalFormat) {
			return;
		}
		if (!cell.isShown()) {
			return;
		}

		int cellWidth = cell.getWidth();
		Date date = new Date(value);

		GC gc = new GC(Display.getDefault());
		Point minSize = new Point(99999, 0);
		int idxFormat = -1;
		for (int i = globalFormat; i < FORMATS.length; i++) {
			SimpleDateFormat temp = new SimpleDateFormat(FORMATS[i]);
			Point newSize = gc.stringExtent(temp.format(date));
			if (newSize.x < cellWidth) {
				idxFormat = i;
				break;
			}
			if (newSize.x < minSize.x) {
				minSize = newSize;
				idxFormat = i;
			}
		}
		gc.dispose();

		if (idxFormat >= 0) {
			if (idxFormat > globalFormat) {
				globalFormat = idxFormat;
				cell.getTableColumn().invalidateCells();
			} else if (idxFormat < globalFormat) {
				idxFormat = globalFormat;
			}
			curFormat = idxFormat;

			SimpleDateFormat temp = new SimpleDateFormat(FORMATS[idxFormat]
					+ "\nh:mm a");
			cell.setText(temp.format(date));
		}